X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FNVPTX%2FNVPTXGenericToNVVM.cpp;h=86d134baf5f9ddfe3d1cfcc47c8825e450318ed0;hb=417c5c172ce0d56105112481b1bcf0bc2fc011c2;hp=496cfbd7955d9595c1d13c9de514380db24d34df;hpb=bad06b13bac2c7f59d804c8f90caedc63978276d;p=oota-llvm.git diff --git a/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp b/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp index 496cfbd7955..86d134baf5f 100644 --- a/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp +++ b/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp @@ -22,10 +22,11 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Intrinsics.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" #include "llvm/IR/ValueMap.h" -#include "llvm/PassManager.h" +#include "llvm/Transforms/Utils/ValueMapper.h" using namespace llvm; @@ -54,8 +55,7 @@ private: IRBuilder<> &Builder); Value *remapConstantExpr(Module *M, Function *F, ConstantExpr *C, IRBuilder<> &Builder); - void remapNamedMDNode(Module *M, NamedMDNode *N); - MDNode *remapMDNode(Module *M, MDNode *N); + void remapNamedMDNode(ValueToValueMapTy &VM, NamedMDNode *N); typedef ValueMap GVMapTy; typedef ValueMap ConstantToValueMapTy; @@ -125,12 +125,17 @@ bool GenericToNVVM::runOnModule(Module &M) { ConstantToValueMap.clear(); } + // Copy GVMap over to a standard value map. + ValueToValueMapTy VM; + for (auto I = GVMap.begin(), E = GVMap.end(); I != E; ++I) + VM[I->first] = I->second; + // Walk through the metadata section and update the debug information // associated with the global variables in the default address space. for (Module::named_metadata_iterator I = M.named_metadata_begin(), E = M.named_metadata_end(); I != E; I++) { - remapNamedMDNode(&M, I); + remapNamedMDNode(VM, I); } // Walk through the global variable initializers, and replace any use of @@ -362,7 +367,7 @@ Value *GenericToNVVM::remapConstantExpr(Module *M, Function *F, ConstantExpr *C, } } -void GenericToNVVM::remapNamedMDNode(Module *M, NamedMDNode *N) { +void GenericToNVVM::remapNamedMDNode(ValueToValueMapTy &VM, NamedMDNode *N) { bool OperandChanged = false; SmallVector NewOperands; @@ -371,8 +376,8 @@ void GenericToNVVM::remapNamedMDNode(Module *M, NamedMDNode *N) { // Check if any operand is or contains a global variable in GVMap, and thus // converted to another value. for (unsigned i = 0; i < NumOperands; ++i) { - MDNode *Operand = cast(N->getOperand(i)); - MDNode *NewOperand = remapMDNode(M, Operand); + MDNode *Operand = N->getOperand(i); + MDNode *NewOperand = MapMetadata(Operand, VM); OperandChanged |= Operand != NewOperand; NewOperands.push_back(NewOperand); } @@ -390,47 +395,3 @@ void GenericToNVVM::remapNamedMDNode(Module *M, NamedMDNode *N) { N->addOperand(*I); } } - -MDNode *GenericToNVVM::remapMDNode(Module *M, MDNode *N) { - - bool OperandChanged = false; - SmallVector NewOperands; - unsigned NumOperands = N->getNumOperands(); - - // Check if any operand is or contains a global variable in GVMap, and thus - // converted to another value. - for (unsigned i = 0; i < NumOperands; ++i) { - Value *Operand = N->getOperand(i); - Value *NewOperand = Operand; - if (Operand) { - if (isa(Operand)) { - GVMapTy::iterator I = GVMap.find(cast(Operand)); - if (I != GVMap.end()) { - NewOperand = I->second; - if (++i < NumOperands) { - NewOperands.push_back(NewOperand); - // Address space of the global variable follows the global variable - // in the global variable debug info (see createGlobalVariable in - // lib/Analysis/DIBuilder.cpp). - NewOperand = - ConstantInt::get(Type::getInt32Ty(M->getContext()), - I->second->getType()->getAddressSpace()); - } - } - } else if (isa(Operand)) { - NewOperand = remapMDNode(M, cast(Operand)); - } - } - OperandChanged |= Operand != NewOperand; - NewOperands.push_back(NewOperand); - } - - // If none of the operands has been modified, return N as it is. - if (!OperandChanged) { - return N; - } - - // If any of the operands has been modified, create a new MDNode with the new - // operands. - return MDNode::get(M->getContext(), makeArrayRef(NewOperands)); -}