@@ -1102,48 +1102,34 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
1102
1102
// %4 = bitcast %struct.net_device** %dev1 to i64*
1103
1103
// it is transformed to:
1104
1104
// %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
1109
1107
// The original Call inst is removed.
1110
1108
1111
1109
// Load the global variable.
1112
1110
auto *LDInst = new LoadInst (Type::getInt64Ty (BB->getContext ()), GV, " " ,
1113
1111
Call->getIterator ());
1114
1112
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
-
1121
1113
// 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);
1124
1116
GEP->insertBefore (Call->getIterator ());
1125
1117
1126
- // Generate a BitCast
1127
- auto *BCInst2 = new BitCastInst (GEP, Call->getType ());
1128
- BCInst2->insertBefore (Call->getIterator ());
1129
-
1130
1118
// For the following code,
1131
1119
// Block0:
1132
1120
// ...
1133
1121
// if (...) goto Block1 else ...
1134
1122
// Block1:
1135
1123
// %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
1138
1125
// ...
1139
1126
// goto CommonExit
1140
1127
// Block2:
1141
1128
// ...
1142
1129
// if (...) goto Block3 else ...
1143
1130
// Block3:
1144
1131
// %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
1147
1133
// ...
1148
1134
// goto CommonExit
1149
1135
// CommonExit
@@ -1157,8 +1143,7 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
1157
1143
// Block_Common:
1158
1144
// PHI = [llvm.sk_buff:0:50$0:0:0:2:0, llvm.bpf_map:0:40$0:0:0:2:0]
1159
1145
// %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
1162
1147
// ...
1163
1148
// goto CommonExit
1164
1149
// For the above code, we cannot perform proper relocation since
@@ -1173,7 +1158,7 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
1173
1158
// This approach is also used in other places when global var
1174
1159
// representing a relocation is used.
1175
1160
Instruction *PassThroughInst =
1176
- BPFCoreSharedInfo::insertPassThrough (M, BB, BCInst2 , Call);
1161
+ BPFCoreSharedInfo::insertPassThrough (M, BB, GEP , Call);
1177
1162
Call->replaceAllUsesWith (PassThroughInst);
1178
1163
Call->eraseFromParent ();
1179
1164
0 commit comments