diff options
| author | Justin Lebar <jlebar@google.com> | 2018-02-28 23:57:48 +0000 |
|---|---|---|
| committer | Justin Lebar <jlebar@google.com> | 2018-02-28 23:57:48 +0000 |
| commit | 5a7de898d236e2b426e050ce51fb72e382eafa28 (patch) | |
| tree | 982bad855deb78c82eaabf268ce5121fc7f4fffb /llvm/lib | |
| parent | 285271cb78f449f211bec34b4e954153feb0add9 (diff) | |
| download | bcm5719-llvm-5a7de898d236e2b426e050ce51fb72e382eafa28.tar.gz bcm5719-llvm-5a7de898d236e2b426e050ce51fb72e382eafa28.zip | |
[NVPTX] Use addrspacecast instead of target-specific intrinsics in NVPTXGenericToNVVM.
Summary:
NVPTXGenericToNVVM was using target-specific intrinsics to do address
space casts. Using the addrspacecast instruction is (a lot) simpler.
But it also has the advantage of being understandable to other passes.
In particular, InferAddrSpaces is able to understand these address space
casts and remove them in most cases.
Reviewers: tra
Subscribers: jholewinski, sanjoy, hiraditya, llvm-commits
Differential Revision: https://reviews.llvm.org/D43914
llvm-svn: 326389
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp | 60 |
1 files changed, 9 insertions, 51 deletions
diff --git a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp index 916b0e11566..fd63fdbaced 100644 --- a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp @@ -45,8 +45,6 @@ public: void getAnalysisUsage(AnalysisUsage &AU) const override {} private: - Value *getOrInsertCVTA(Module *M, Function *F, GlobalVariable *GV, - IRBuilder<> &Builder); Value *remapConstant(Module *M, Function *F, Constant *C, IRBuilder<> &Builder); Value *remapConstantVectorOrConstantAggregate(Module *M, Function *F, @@ -156,46 +154,6 @@ bool GenericToNVVM::runOnModule(Module &M) { return true; } -Value *GenericToNVVM::getOrInsertCVTA(Module *M, Function *F, - GlobalVariable *GV, - IRBuilder<> &Builder) { - PointerType *GVType = GV->getType(); - Value *CVTA = nullptr; - - // See if the address space conversion requires the operand to be bitcast - // to i8 addrspace(n)* first. - EVT ExtendedGVType = EVT::getEVT(GV->getValueType(), true); - if (!ExtendedGVType.isInteger() && !ExtendedGVType.isFloatingPoint()) { - // A bitcast to i8 addrspace(n)* on the operand is needed. - LLVMContext &Context = M->getContext(); - unsigned int AddrSpace = GVType->getAddressSpace(); - Type *DestTy = PointerType::get(Type::getInt8Ty(Context), AddrSpace); - CVTA = Builder.CreateBitCast(GV, DestTy, "cvta"); - // Insert the address space conversion. - Type *ResultType = - PointerType::get(Type::getInt8Ty(Context), llvm::ADDRESS_SPACE_GENERIC); - Function *CVTAFunction = Intrinsic::getDeclaration( - M, Intrinsic::nvvm_ptr_global_to_gen, {ResultType, DestTy}); - CVTA = Builder.CreateCall(CVTAFunction, CVTA, "cvta"); - // Another bitcast from i8 * to <the element type of GVType> * is - // required. - DestTy = - PointerType::get(GV->getValueType(), llvm::ADDRESS_SPACE_GENERIC); - CVTA = Builder.CreateBitCast(CVTA, DestTy, "cvta"); - } else { - // A simple CVTA is enough. - SmallVector<Type *, 2> ParamTypes; - ParamTypes.push_back(PointerType::get(GV->getValueType(), - llvm::ADDRESS_SPACE_GENERIC)); - ParamTypes.push_back(GVType); - Function *CVTAFunction = Intrinsic::getDeclaration( - M, Intrinsic::nvvm_ptr_global_to_gen, ParamTypes); - CVTA = Builder.CreateCall(CVTAFunction, GV, "cvta"); - } - - return CVTA; -} - Value *GenericToNVVM::remapConstant(Module *M, Function *F, Constant *C, IRBuilder<> &Builder) { // 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, Value *NewValue = C; if (isa<GlobalVariable>(C)) { - // If the constant C is a global variable and is found in GVMap, generate a - // set set of instructions that convert the clone of C with the global - // address space specifier to a generic pointer. - // The constant C cannot be used here, as it will be erased from the - // module eventually. And the clone of C with the global address space - // specifier cannot be used here either, as it will affect the types of - // other instructions in the function. Hence, this address space conversion - // is required. + // If the constant C is a global variable and is found in GVMap, substitute + // + // addrspacecast GVMap[C] to addrspace(0) + // + // for our use of C. GVMapTy::iterator I = GVMap.find(cast<GlobalVariable>(C)); if (I != GVMap.end()) { - NewValue = getOrInsertCVTA(M, F, I->second, Builder); + GlobalVariable *GV = I->second; + NewValue = Builder.CreateAddrSpaceCast( + GV, + PointerType::get(GV->getValueType(), llvm::ADDRESS_SPACE_GENERIC)); } } else if (isa<ConstantAggregate>(C)) { // If any element in the constant vector or aggregate C is or uses a global |

