@@ -45,8 +45,6 @@ class GenericToNVVM : public ModulePass {
45
45
void getAnalysisUsage (AnalysisUsage &AU) const override {}
46
46
47
47
private:
48
- Value *getOrInsertCVTA (Module *M, Function *F, GlobalVariable *GV,
49
- IRBuilder<> &Builder);
50
48
Value *remapConstant (Module *M, Function *F, Constant *C,
51
49
IRBuilder<> &Builder);
52
50
Value *remapConstantVectorOrConstantAggregate (Module *M, Function *F,
@@ -156,46 +154,6 @@ bool GenericToNVVM::runOnModule(Module &M) {
156
154
return true ;
157
155
}
158
156
159
- Value *GenericToNVVM::getOrInsertCVTA (Module *M, Function *F,
160
- GlobalVariable *GV,
161
- IRBuilder<> &Builder) {
162
- PointerType *GVType = GV->getType ();
163
- Value *CVTA = nullptr ;
164
-
165
- // See if the address space conversion requires the operand to be bitcast
166
- // to i8 addrspace(n)* first.
167
- EVT ExtendedGVType = EVT::getEVT (GV->getValueType (), true );
168
- if (!ExtendedGVType.isInteger () && !ExtendedGVType.isFloatingPoint ()) {
169
- // A bitcast to i8 addrspace(n)* on the operand is needed.
170
- LLVMContext &Context = M->getContext ();
171
- unsigned int AddrSpace = GVType->getAddressSpace ();
172
- Type *DestTy = PointerType::get (Type::getInt8Ty (Context), AddrSpace);
173
- CVTA = Builder.CreateBitCast (GV, DestTy, " cvta" );
174
- // Insert the address space conversion.
175
- Type *ResultType =
176
- PointerType::get (Type::getInt8Ty (Context), llvm::ADDRESS_SPACE_GENERIC);
177
- Function *CVTAFunction = Intrinsic::getDeclaration (
178
- M, Intrinsic::nvvm_ptr_global_to_gen, {ResultType, DestTy});
179
- CVTA = Builder.CreateCall (CVTAFunction, CVTA, " cvta" );
180
- // Another bitcast from i8 * to <the element type of GVType> * is
181
- // required.
182
- DestTy =
183
- PointerType::get (GV->getValueType (), llvm::ADDRESS_SPACE_GENERIC);
184
- CVTA = Builder.CreateBitCast (CVTA, DestTy, " cvta" );
185
- } else {
186
- // A simple CVTA is enough.
187
- SmallVector<Type *, 2 > ParamTypes;
188
- ParamTypes.push_back (PointerType::get (GV->getValueType (),
189
- llvm::ADDRESS_SPACE_GENERIC));
190
- ParamTypes.push_back (GVType);
191
- Function *CVTAFunction = Intrinsic::getDeclaration (
192
- M, Intrinsic::nvvm_ptr_global_to_gen, ParamTypes);
193
- CVTA = Builder.CreateCall (CVTAFunction, GV, " cvta" );
194
- }
195
-
196
- return CVTA;
197
- }
198
-
199
157
Value *GenericToNVVM::remapConstant (Module *M, Function *F, Constant *C,
200
158
IRBuilder<> &Builder) {
201
159
// If the constant C has been converted already in the given function F, just
@@ -207,17 +165,17 @@ Value *GenericToNVVM::remapConstant(Module *M, Function *F, Constant *C,
207
165
208
166
Value *NewValue = C;
209
167
if (isa<GlobalVariable>(C)) {
210
- // If the constant C is a global variable and is found in GVMap, generate a
211
- // set set of instructions that convert the clone of C with the global
212
- // address space specifier to a generic pointer.
213
- // The constant C cannot be used here, as it will be erased from the
214
- // module eventually. And the clone of C with the global address space
215
- // specifier cannot be used here either, as it will affect the types of
216
- // other instructions in the function. Hence, this address space conversion
217
- // is required.
168
+ // If the constant C is a global variable and is found in GVMap, substitute
169
+ //
170
+ // addrspacecast GVMap[C] to addrspace(0)
171
+ //
172
+ // for our use of C.
218
173
GVMapTy::iterator I = GVMap.find (cast<GlobalVariable>(C));
219
174
if (I != GVMap.end ()) {
220
- NewValue = getOrInsertCVTA (M, F, I->second , Builder);
175
+ GlobalVariable *GV = I->second ;
176
+ NewValue = Builder.CreateAddrSpaceCast (
177
+ GV,
178
+ PointerType::get (GV->getValueType (), llvm::ADDRESS_SPACE_GENERIC));
221
179
}
222
180
} else if (isa<ConstantAggregate>(C)) {
223
181
// If any element in the constant vector or aggregate C is or uses a global
0 commit comments