Index: llvm/lib/Target/NVPTX/NVPTXUtilities.h =================================================================== --- llvm/lib/Target/NVPTX/NVPTXUtilities.h +++ llvm/lib/Target/NVPTX/NVPTXUtilities.h @@ -28,39 +28,39 @@ #define NVCL_IMAGE2D_READONLY_FUNCNAME "__is_image2D_readonly" #define NVCL_IMAGE3D_READONLY_FUNCNAME "__is_image3D_readonly" -void clearAnnotationCache(const llvm::Module *); +void clearAnnotationCache(const Module *); -bool findOneNVVMAnnotation(const llvm::GlobalValue *, const std::string &, +bool findOneNVVMAnnotation(const GlobalValue *, const std::string &, unsigned &); -bool findAllNVVMAnnotation(const llvm::GlobalValue *, const std::string &, +bool findAllNVVMAnnotation(const GlobalValue *, const std::string &, std::vector &); -bool isTexture(const llvm::Value &); -bool isSurface(const llvm::Value &); -bool isSampler(const llvm::Value &); -bool isImage(const llvm::Value &); -bool isImageReadOnly(const llvm::Value &); -bool isImageWriteOnly(const llvm::Value &); -bool isImageReadWrite(const llvm::Value &); -bool isManaged(const llvm::Value &); +bool isTexture(const Value &); +bool isSurface(const Value &); +bool isSampler(const Value &); +bool isImage(const Value &); +bool isImageReadOnly(const Value &); +bool isImageWriteOnly(const Value &); +bool isImageReadWrite(const Value &); +bool isManaged(const Value &); -std::string getTextureName(const llvm::Value &); -std::string getSurfaceName(const llvm::Value &); -std::string getSamplerName(const llvm::Value &); +std::string getTextureName(const Value &); +std::string getSurfaceName(const Value &); +std::string getSamplerName(const Value &); -bool getMaxNTIDx(const llvm::Function &, unsigned &); -bool getMaxNTIDy(const llvm::Function &, unsigned &); -bool getMaxNTIDz(const llvm::Function &, unsigned &); +bool getMaxNTIDx(const Function &, unsigned &); +bool getMaxNTIDy(const Function &, unsigned &); +bool getMaxNTIDz(const Function &, unsigned &); -bool getReqNTIDx(const llvm::Function &, unsigned &); -bool getReqNTIDy(const llvm::Function &, unsigned &); -bool getReqNTIDz(const llvm::Function &, unsigned &); +bool getReqNTIDx(const Function &, unsigned &); +bool getReqNTIDy(const Function &, unsigned &); +bool getReqNTIDz(const Function &, unsigned &); -bool getMinCTASm(const llvm::Function &, unsigned &); -bool isKernelFunction(const llvm::Function &); +bool getMinCTASm(const Function &, unsigned &); +bool isKernelFunction(const Function &); -bool getAlign(const llvm::Function &, unsigned index, unsigned &); -bool getAlign(const llvm::CallInst &, unsigned index, unsigned &); +bool getAlign(const Function &, unsigned index, unsigned &); +bool getAlign(const CallInst &, unsigned index, unsigned &); BasicBlock *getParentBlock(Value *v); Function *getParentFunction(Value *v); Index: llvm/lib/Target/NVPTX/NVPTXUtilities.cpp =================================================================== --- llvm/lib/Target/NVPTX/NVPTXUtilities.cpp +++ llvm/lib/Target/NVPTX/NVPTXUtilities.cpp @@ -26,16 +26,18 @@ #include #include -using namespace llvm; +namespace llvm { +namespace { typedef std::map > key_val_pair_t; typedef std::map global_val_annot_t; typedef std::map per_module_annot_t; +} // anonymous namespace -ManagedStatic annotationCache; +static ManagedStatic annotationCache; static sys::Mutex Lock; -void llvm::clearAnnotationCache(const llvm::Module *Mod) { +void clearAnnotationCache(const Module *Mod) { MutexGuard Guard(Lock); annotationCache->erase(Mod); } @@ -68,7 +70,7 @@ static void cacheAnnotationFromMD(const Module *m, const GlobalValue *gv) { MutexGuard Guard(Lock); - NamedMDNode *NMD = m->getNamedMetadata(llvm::NamedMDForAnnotations); + NamedMDNode *NMD = m->getNamedMetadata(NamedMDForAnnotations); if (!NMD) return; key_val_pair_t tmp; @@ -99,8 +101,8 @@ } } -bool llvm::findOneNVVMAnnotation(const GlobalValue *gv, const std::string &prop, - unsigned &retval) { +bool findOneNVVMAnnotation(const GlobalValue *gv, const std::string &prop, + unsigned &retval) { MutexGuard Guard(Lock); const Module *m = gv->getParent(); if ((*annotationCache).find(m) == (*annotationCache).end()) @@ -113,8 +115,8 @@ return true; } -bool llvm::findAllNVVMAnnotation(const GlobalValue *gv, const std::string &prop, - std::vector &retval) { +bool findAllNVVMAnnotation(const GlobalValue *gv, const std::string &prop, + std::vector &retval) { MutexGuard Guard(Lock); const Module *m = gv->getParent(); if ((*annotationCache).find(m) == (*annotationCache).end()) @@ -127,12 +129,11 @@ return true; } -bool llvm::isTexture(const llvm::Value &val) { +bool isTexture(const Value &val) { if (const GlobalValue *gv = dyn_cast(&val)) { unsigned annot; - if (llvm::findOneNVVMAnnotation( - gv, llvm::PropertyAnnotationName(llvm::PROPERTY_ISTEXTURE), - annot)) { + if (findOneNVVMAnnotation(gv, PropertyAnnotationName(PROPERTY_ISTEXTURE), + annot)) { assert((annot == 1) && "Unexpected annotation on a texture symbol"); return true; } @@ -140,12 +141,11 @@ return false; } -bool llvm::isSurface(const llvm::Value &val) { +bool isSurface(const Value &val) { if (const GlobalValue *gv = dyn_cast(&val)) { unsigned annot; - if (llvm::findOneNVVMAnnotation( - gv, llvm::PropertyAnnotationName(llvm::PROPERTY_ISSURFACE), - annot)) { + if (findOneNVVMAnnotation(gv, PropertyAnnotationName(PROPERTY_ISSURFACE), + annot)) { assert((annot == 1) && "Unexpected annotation on a surface symbol"); return true; } @@ -153,12 +153,11 @@ return false; } -bool llvm::isSampler(const llvm::Value &val) { +bool isSampler(const Value &val) { if (const GlobalValue *gv = dyn_cast(&val)) { unsigned annot; - if (llvm::findOneNVVMAnnotation( - gv, llvm::PropertyAnnotationName(llvm::PROPERTY_ISSAMPLER), - annot)) { + if (findOneNVVMAnnotation(gv, PropertyAnnotationName(PROPERTY_ISSAMPLER), + annot)) { assert((annot == 1) && "Unexpected annotation on a sampler symbol"); return true; } @@ -166,8 +165,21 @@ if (const Argument *arg = dyn_cast(&val)) { const Function *func = arg->getParent(); std::vector annot; - if (llvm::findAllNVVMAnnotation( - func, llvm::PropertyAnnotationName(llvm::PROPERTY_ISSAMPLER), + if (findAllNVVMAnnotation(func, PropertyAnnotationName(PROPERTY_ISSAMPLER), + annot)) { + if (is_contained(annot, arg->getArgNo())) + return true; + } + } + return false; +} + +bool isImageReadOnly(const Value &val) { + if (const Argument *arg = dyn_cast(&val)) { + const Function *func = arg->getParent(); + std::vector annot; + if (findAllNVVMAnnotation( + func, PropertyAnnotationName(PROPERTY_ISREADONLY_IMAGE_PARAM), annot)) { if (is_contained(annot, arg->getArgNo())) return true; @@ -176,13 +188,12 @@ return false; } -bool llvm::isImageReadOnly(const llvm::Value &val) { +bool isImageWriteOnly(const Value &val) { if (const Argument *arg = dyn_cast(&val)) { const Function *func = arg->getParent(); std::vector annot; - if (llvm::findAllNVVMAnnotation( - func, - llvm::PropertyAnnotationName(llvm::PROPERTY_ISREADONLY_IMAGE_PARAM), + if (findAllNVVMAnnotation( + func, PropertyAnnotationName(PROPERTY_ISWRITEONLY_IMAGE_PARAM), annot)) { if (is_contained(annot, arg->getArgNo())) return true; @@ -191,14 +202,13 @@ return false; } -bool llvm::isImageWriteOnly(const llvm::Value &val) { +bool isImageReadWrite(const Value &val) { if (const Argument *arg = dyn_cast(&val)) { const Function *func = arg->getParent(); std::vector annot; - if (llvm::findAllNVVMAnnotation(func, - llvm::PropertyAnnotationName( - llvm::PROPERTY_ISWRITEONLY_IMAGE_PARAM), - annot)) { + if (findAllNVVMAnnotation( + func, PropertyAnnotationName(PROPERTY_ISREADWRITE_IMAGE_PARAM), + annot)) { if (is_contained(annot, arg->getArgNo())) return true; } @@ -206,31 +216,15 @@ return false; } -bool llvm::isImageReadWrite(const llvm::Value &val) { - if (const Argument *arg = dyn_cast(&val)) { - const Function *func = arg->getParent(); - std::vector annot; - if (llvm::findAllNVVMAnnotation(func, - llvm::PropertyAnnotationName( - llvm::PROPERTY_ISREADWRITE_IMAGE_PARAM), - annot)) { - if (is_contained(annot, arg->getArgNo())) - return true; - } - } - return false; +bool isImage(const Value &val) { + return isImageReadOnly(val) || isImageWriteOnly(val) || isImageReadWrite(val); } -bool llvm::isImage(const llvm::Value &val) { - return llvm::isImageReadOnly(val) || llvm::isImageWriteOnly(val) || - llvm::isImageReadWrite(val); -} - -bool llvm::isManaged(const llvm::Value &val) { +bool isManaged(const Value &val) { if(const GlobalValue *gv = dyn_cast(&val)) { unsigned annot; - if (llvm::findOneNVVMAnnotation( - gv, llvm::PropertyAnnotationName(llvm::PROPERTY_MANAGED), annot)) { + if (findOneNVVMAnnotation(gv, PropertyAnnotationName(PROPERTY_MANAGED), + annot)) { assert((annot == 1) && "Unexpected annotation on a managed symbol"); return true; } @@ -238,71 +232,71 @@ return false; } -std::string llvm::getTextureName(const llvm::Value &val) { +std::string getTextureName(const Value &val) { assert(val.hasName() && "Found texture variable with no name"); return val.getName(); } -std::string llvm::getSurfaceName(const llvm::Value &val) { +std::string getSurfaceName(const Value &val) { assert(val.hasName() && "Found surface variable with no name"); return val.getName(); } -std::string llvm::getSamplerName(const llvm::Value &val) { +std::string getSamplerName(const Value &val) { assert(val.hasName() && "Found sampler variable with no name"); return val.getName(); } -bool llvm::getMaxNTIDx(const Function &F, unsigned &x) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationName(llvm::PROPERTY_MAXNTID_X), x)); +bool getMaxNTIDx(const Function &F, unsigned &x) { + return ( + findOneNVVMAnnotation(&F, PropertyAnnotationName(PROPERTY_MAXNTID_X), x)); } -bool llvm::getMaxNTIDy(const Function &F, unsigned &y) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationName(llvm::PROPERTY_MAXNTID_Y), y)); +bool getMaxNTIDy(const Function &F, unsigned &y) { + return ( + findOneNVVMAnnotation(&F, PropertyAnnotationName(PROPERTY_MAXNTID_Y), y)); } -bool llvm::getMaxNTIDz(const Function &F, unsigned &z) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationName(llvm::PROPERTY_MAXNTID_Z), z)); +bool getMaxNTIDz(const Function &F, unsigned &z) { + return ( + findOneNVVMAnnotation(&F, PropertyAnnotationName(PROPERTY_MAXNTID_Z), z)); } -bool llvm::getReqNTIDx(const Function &F, unsigned &x) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationName(llvm::PROPERTY_REQNTID_X), x)); +bool getReqNTIDx(const Function &F, unsigned &x) { + return ( + findOneNVVMAnnotation(&F, PropertyAnnotationName(PROPERTY_REQNTID_X), x)); } -bool llvm::getReqNTIDy(const Function &F, unsigned &y) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationName(llvm::PROPERTY_REQNTID_Y), y)); +bool getReqNTIDy(const Function &F, unsigned &y) { + return ( + findOneNVVMAnnotation(&F, PropertyAnnotationName(PROPERTY_REQNTID_Y), y)); } -bool llvm::getReqNTIDz(const Function &F, unsigned &z) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationName(llvm::PROPERTY_REQNTID_Z), z)); +bool getReqNTIDz(const Function &F, unsigned &z) { + return ( + findOneNVVMAnnotation(&F, PropertyAnnotationName(PROPERTY_REQNTID_Z), z)); } -bool llvm::getMinCTASm(const Function &F, unsigned &x) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationName(llvm::PROPERTY_MINNCTAPERSM), x)); +bool getMinCTASm(const Function &F, unsigned &x) { + return (findOneNVVMAnnotation( + &F, PropertyAnnotationName(PROPERTY_MINNCTAPERSM), x)); } -bool llvm::isKernelFunction(const Function &F) { +bool isKernelFunction(const Function &F) { unsigned x = 0; - bool retval = llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationName(llvm::PROPERTY_ISKERNEL_FUNCTION), x); + bool retval = findOneNVVMAnnotation( + &F, PropertyAnnotationName(PROPERTY_ISKERNEL_FUNCTION), x); if (!retval) { // There is no NVVM metadata, check the calling convention - return F.getCallingConv() == llvm::CallingConv::PTX_Kernel; + return F.getCallingConv() == CallingConv::PTX_Kernel; } return (x == 1); } -bool llvm::getAlign(const Function &F, unsigned index, unsigned &align) { +bool getAlign(const Function &F, unsigned index, unsigned &align) { std::vector Vs; - bool retval = llvm::findAllNVVMAnnotation( - &F, llvm::PropertyAnnotationName(llvm::PROPERTY_ALIGN), Vs); + bool retval = + findAllNVVMAnnotation(&F, PropertyAnnotationName(PROPERTY_ALIGN), Vs); if (!retval) return false; for (int i = 0, e = Vs.size(); i < e; i++) { @@ -315,7 +309,7 @@ return false; } -bool llvm::getAlign(const CallInst &I, unsigned index, unsigned &align) { +bool getAlign(const CallInst &I, unsigned index, unsigned &align) { if (MDNode *alignNode = I.getMetadata("callalign")) { for (int i = 0, n = alignNode->getNumOperands(); i < n; i++) { if (const ConstantInt *CI = @@ -336,7 +330,7 @@ // The following are some useful utilities for debugging -BasicBlock *llvm::getParentBlock(Value *v) { +BasicBlock *getParentBlock(Value *v) { if (BasicBlock *B = dyn_cast(v)) return B; @@ -346,7 +340,7 @@ return nullptr; } -Function *llvm::getParentFunction(Value *v) { +Function *getParentFunction(Value *v) { if (Function *F = dyn_cast(v)) return F; @@ -360,7 +354,7 @@ } // Dump a block by name -void llvm::dumpBlock(Value *v, char *blockName) { +void dumpBlock(Value *v, char *blockName) { Function *F = getParentFunction(v); if (!F) return; @@ -375,7 +369,7 @@ } // Find an instruction by name -Instruction *llvm::getInst(Value *base, char *instName) { +Instruction *getInst(Value *base, char *instName) { Function *F = getParentFunction(base); if (!F) return nullptr; @@ -391,14 +385,14 @@ } // Dump an instruction by name -void llvm::dumpInst(Value *base, char *instName) { +void dumpInst(Value *base, char *instName) { Instruction *I = getInst(base, instName); if (I) I->dump(); } // Dump an instruction and all dependent instructions -void llvm::dumpInstRec(Value *v, std::set *visited) { +void dumpInstRec(Value *v, std::set *visited) { if (Instruction *I = dyn_cast(v)) { if (visited->find(I) != visited->end()) @@ -414,7 +408,7 @@ } // Dump an instruction and all dependent instructions -void llvm::dumpInstRec(Value *v) { +void dumpInstRec(Value *v) { std::set visited; //BasicBlock *B = getParentBlock(v); @@ -423,7 +417,7 @@ } // Dump the parent for Instruction, block or function -void llvm::dumpParent(Value *v) { +void dumpParent(Value *v) { if (Instruction *I = dyn_cast(v)) { I->getParent()->dump(); return; @@ -439,3 +433,5 @@ return; } } + +} // namespace llvm