@@ -1102,48 +1102,34 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
11021102 // %4 = bitcast %struct.net_device** %dev1 to i64*
11031103 // it is transformed to:
11041104 // %6 = load llvm.sk_buff:0:50$0:0:0:2:0
1105- // %7 = bitcast %struct.sk_buff* %2 to i8*
1106- // %8 = getelementptr i8, i8* %7, %6
1107- // %9 = bitcast i8* %8 to i64*
1108- // using %9 instead of %4
1105+ // %8 = getelementptr i8, i8* %2, %6
1106+ // using %8 instead of %4
11091107 // The original Call inst is removed.
11101108
11111109 // Load the global variable.
11121110 auto *LDInst = new LoadInst (Type::getInt64Ty (BB->getContext ()), GV, " " ,
11131111 Call->getIterator ());
11141112
1115- // Generate a BitCast
1116- auto *BCInst = new BitCastInst (
1117- Base, PointerType::get (BB->getContext (),
1118- Base->getType ()->getPointerAddressSpace ()));
1119- BCInst->insertBefore (Call->getIterator ());
1120-
11211113 // Generate a GetElementPtr
1122- auto *GEP = GetElementPtrInst::Create (Type::getInt8Ty (BB->getContext ()),
1123- BCInst, LDInst);
1114+ auto *GEP = GetElementPtrInst::Create (Type::getInt8Ty (BB->getContext ()), Base,
1115+ LDInst);
11241116 GEP->insertBefore (Call->getIterator ());
11251117
1126- // Generate a BitCast
1127- auto *BCInst2 = new BitCastInst (GEP, Call->getType ());
1128- BCInst2->insertBefore (Call->getIterator ());
1129-
11301118 // For the following code,
11311119 // Block0:
11321120 // ...
11331121 // if (...) goto Block1 else ...
11341122 // Block1:
11351123 // %6 = load llvm.sk_buff:0:50$0:0:0:2:0
1136- // %7 = bitcast %struct.sk_buff* %2 to i8*
1137- // %8 = getelementptr i8, i8* %7, %6
1124+ // %8 = getelementptr i8, i8* %2, %6
11381125 // ...
11391126 // goto CommonExit
11401127 // Block2:
11411128 // ...
11421129 // if (...) goto Block3 else ...
11431130 // Block3:
11441131 // %6 = load llvm.bpf_map:0:40$0:0:0:2:0
1145- // %7 = bitcast %struct.sk_buff* %2 to i8*
1146- // %8 = getelementptr i8, i8* %7, %6
1132+ // %8 = getelementptr i8, i8* %2, %6
11471133 // ...
11481134 // goto CommonExit
11491135 // CommonExit
@@ -1157,8 +1143,7 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
11571143 // Block_Common:
11581144 // PHI = [llvm.sk_buff:0:50$0:0:0:2:0, llvm.bpf_map:0:40$0:0:0:2:0]
11591145 // %6 = load PHI
1160- // %7 = bitcast %struct.sk_buff* %2 to i8*
1161- // %8 = getelementptr i8, i8* %7, %6
1146+ // %8 = getelementptr i8, i8* %2, %6
11621147 // ...
11631148 // goto CommonExit
11641149 // For the above code, we cannot perform proper relocation since
@@ -1173,7 +1158,7 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
11731158 // This approach is also used in other places when global var
11741159 // representing a relocation is used.
11751160 Instruction *PassThroughInst =
1176- BPFCoreSharedInfo::insertPassThrough (M, BB, BCInst2 , Call);
1161+ BPFCoreSharedInfo::insertPassThrough (M, BB, GEP , Call);
11771162 Call->replaceAllUsesWith (PassThroughInst);
11781163 Call->eraseFromParent ();
11791164
0 commit comments