Index: llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXBaseInfo.h =================================================================== --- llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXBaseInfo.h +++ llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXBaseInfo.h @@ -30,60 +30,6 @@ ADDRESS_SPACE_PARAM = 101 }; -enum PropertyAnnotation { - PROPERTY_MAXNTID_X = 0, - PROPERTY_MAXNTID_Y, - PROPERTY_MAXNTID_Z, - PROPERTY_REQNTID_X, - PROPERTY_REQNTID_Y, - PROPERTY_REQNTID_Z, - PROPERTY_MINNCTAPERSM, - PROPERTY_ISTEXTURE, - PROPERTY_ISSURFACE, - PROPERTY_ISSAMPLER, - PROPERTY_ISREADONLY_IMAGE_PARAM, - PROPERTY_ISWRITEONLY_IMAGE_PARAM, - PROPERTY_ISREADWRITE_IMAGE_PARAM, - PROPERTY_ISKERNEL_FUNCTION, - PROPERTY_ALIGN, - PROPERTY_MANAGED, - - // last property - PROPERTY_LAST -}; - -const unsigned AnnotationNameLen = 9; // length of each annotation name -const char PropertyAnnotationNames[PROPERTY_LAST + 1][AnnotationNameLen + 1] = { - "maxntidx", // PROPERTY_MAXNTID_X - "maxntidy", // PROPERTY_MAXNTID_Y - "maxntidz", // PROPERTY_MAXNTID_Z - "reqntidx", // PROPERTY_REQNTID_X - "reqntidy", // PROPERTY_REQNTID_Y - "reqntidz", // PROPERTY_REQNTID_Z - "minctasm", // PROPERTY_MINNCTAPERSM - "texture", // PROPERTY_ISTEXTURE - "surface", // PROPERTY_ISSURFACE - "sampler", // PROPERTY_ISSAMPLER - "rdoimage", // PROPERTY_ISREADONLY_IMAGE_PARAM - "wroimage", // PROPERTY_ISWRITEONLY_IMAGE_PARAM - "rdwrimage", // PROPERTY_ISREADWRITE_IMAGE_PARAM - "kernel", // PROPERTY_ISKERNEL_FUNCTION - "align", // PROPERTY_ALIGN - "managed", // PROPERTY_MANAGED - - // last property - "proplast", // PROPERTY_LAST -}; - -// name of named metadata used for global annotations -#if defined(__GNUC__) -// As this is declared to be static but some of the .cpp files that -// include NVVM.h do not use this array, gcc gives a warning when -// compiling those .cpp files, hence __attribute__((unused)). -__attribute__((unused)) -#endif - static const char *NamedMDForAnnotations = "nvvm.annotations"; - namespace NVPTXII { enum { // These must be kept in sync with TSFlags in NVPTXInstrFormats.td @@ -94,7 +40,7 @@ IsSurfTexQueryFlag = 0x800, IsTexModeUnifiedFlag = 0x1000 }; -} -} +} // namespace NVPTXII +} // namespace llvm #endif 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,11 @@ static void cacheAnnotationFromMD(const Module *m, const GlobalValue *gv) { MutexGuard Guard(Lock); - NamedMDNode *NMD = m->getNamedMetadata(llvm::NamedMDForAnnotations); +<<<<<<< HEAD + NamedMDNode *NMD = m->getNamedMetadata("nvvm.annotations"); +======= + NamedMDNode *NMD = m->getNamedMetadata(NamedMDForAnnotations); +>>>>>>> c62a43e... [NVPTX] Move NVPTXUtilities.{h,cpp} into namespace llvm. if (!NMD) return; key_val_pair_t tmp; @@ -99,8 +105,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 +119,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 +133,10 @@ 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::PropertyAnnotationNames[llvm::PROPERTY_ISTEXTURE], - annot)) { + if (findOneNVVMAnnotation(gv, "texture", annot)) { assert((annot == 1) && "Unexpected annotation on a texture symbol"); return true; } @@ -140,12 +144,10 @@ 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::PropertyAnnotationNames[llvm::PROPERTY_ISSURFACE], - annot)) { + if (findOneNVVMAnnotation(gv, "surface", annot)) { assert((annot == 1) && "Unexpected annotation on a surface symbol"); return true; } @@ -153,12 +155,12 @@ return false; } -bool llvm::isSampler(const llvm::Value &val) { +bool isSampler(const Value &val) { + const char *AnnotationName = "sampler"; + if (const GlobalValue *gv = dyn_cast(&val)) { unsigned annot; - if (llvm::findOneNVVMAnnotation( - gv, llvm::PropertyAnnotationNames[llvm::PROPERTY_ISSAMPLER], - annot)) { + if (findOneNVVMAnnotation(gv, AnnotationName, annot)) { assert((annot == 1) && "Unexpected annotation on a sampler symbol"); return true; } @@ -166,9 +168,7 @@ if (const Argument *arg = dyn_cast(&val)) { const Function *func = arg->getParent(); std::vector annot; - if (llvm::findAllNVVMAnnotation( - func, llvm::PropertyAnnotationNames[llvm::PROPERTY_ISSAMPLER], - annot)) { + if (findAllNVVMAnnotation(func, AnnotationName, annot)) { if (is_contained(annot, arg->getArgNo())) return true; } @@ -176,14 +176,11 @@ return false; } -bool llvm::isImageReadOnly(const llvm::Value &val) { +bool isImageReadOnly(const Value &val) { if (const Argument *arg = dyn_cast(&val)) { const Function *func = arg->getParent(); std::vector annot; - if (llvm::findAllNVVMAnnotation(func, - llvm::PropertyAnnotationNames[ - llvm::PROPERTY_ISREADONLY_IMAGE_PARAM], - annot)) { + if (findAllNVVMAnnotation(func, "rdoimage", annot)) { if (is_contained(annot, arg->getArgNo())) return true; } @@ -191,14 +188,11 @@ return false; } -bool llvm::isImageWriteOnly(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::PropertyAnnotationNames[ - llvm::PROPERTY_ISWRITEONLY_IMAGE_PARAM], - annot)) { + if (findAllNVVMAnnotation(func, "wroimage", annot)) { if (is_contained(annot, arg->getArgNo())) return true; } @@ -206,14 +200,11 @@ return false; } -bool llvm::isImageReadWrite(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::PropertyAnnotationNames[ - llvm::PROPERTY_ISREADWRITE_IMAGE_PARAM], - annot)) { + if (findAllNVVMAnnotation(func, "rdwrimage", annot)) { if (is_contained(annot, arg->getArgNo())) return true; } @@ -221,17 +212,14 @@ return false; } -bool llvm::isImage(const llvm::Value &val) { - return llvm::isImageReadOnly(val) || llvm::isImageWriteOnly(val) || - llvm::isImageReadWrite(val); +bool isImage(const Value &val) { + return isImageReadOnly(val) || isImageWriteOnly(val) || 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::PropertyAnnotationNames[llvm::PROPERTY_MANAGED], - annot)) { + if (findOneNVVMAnnotation(gv, "managed", annot)) { assert((annot == 1) && "Unexpected annotation on a managed symbol"); return true; } @@ -239,71 +227,62 @@ 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::PropertyAnnotationNames[llvm::PROPERTY_MAXNTID_X], x)); +bool getMaxNTIDx(const Function &F, unsigned &x) { + return findOneNVVMAnnotation(&F, "maxntidx", x); } -bool llvm::getMaxNTIDy(const Function &F, unsigned &y) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationNames[llvm::PROPERTY_MAXNTID_Y], y)); +bool getMaxNTIDy(const Function &F, unsigned &y) { + return findOneNVVMAnnotation(&F, "maxntidy", y); } -bool llvm::getMaxNTIDz(const Function &F, unsigned &z) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationNames[llvm::PROPERTY_MAXNTID_Z], z)); +bool getMaxNTIDz(const Function &F, unsigned &z) { + return findOneNVVMAnnotation(&F, "maxntidz", z); } -bool llvm::getReqNTIDx(const Function &F, unsigned &x) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationNames[llvm::PROPERTY_REQNTID_X], x)); +bool getReqNTIDx(const Function &F, unsigned &x) { + return findOneNVVMAnnotation(&F, "reqntidx", x); } -bool llvm::getReqNTIDy(const Function &F, unsigned &y) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationNames[llvm::PROPERTY_REQNTID_Y], y)); +bool getReqNTIDy(const Function &F, unsigned &y) { + return findOneNVVMAnnotation(&F, "reqntidy", y); } -bool llvm::getReqNTIDz(const Function &F, unsigned &z) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationNames[llvm::PROPERTY_REQNTID_Z], z)); +bool getReqNTIDz(const Function &F, unsigned &z) { + return findOneNVVMAnnotation(&F, "reqntidz", z); } -bool llvm::getMinCTASm(const Function &F, unsigned &x) { - return (llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationNames[llvm::PROPERTY_MINNCTAPERSM], x)); +bool getMinCTASm(const Function &F, unsigned &x) { + return findOneNVVMAnnotation(&F, "minctasm", x); } -bool llvm::isKernelFunction(const Function &F) { +bool isKernelFunction(const Function &F) { unsigned x = 0; - bool retval = llvm::findOneNVVMAnnotation( - &F, llvm::PropertyAnnotationNames[llvm::PROPERTY_ISKERNEL_FUNCTION], x); + bool retval = findOneNVVMAnnotation(&F, "kernel", 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::PropertyAnnotationNames[llvm::PROPERTY_ALIGN], Vs); + bool retval = findAllNVVMAnnotation(&F, "align", Vs); if (!retval) return false; for (int i = 0, e = Vs.size(); i < e; i++) { @@ -316,7 +295,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 = @@ -337,7 +316,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; @@ -347,7 +326,7 @@ return nullptr; } -Function *llvm::getParentFunction(Value *v) { +Function *getParentFunction(Value *v) { if (Function *F = dyn_cast(v)) return F; @@ -361,7 +340,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; @@ -376,7 +355,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; @@ -392,14 +371,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()) @@ -415,7 +394,7 @@ } // Dump an instruction and all dependent instructions -void llvm::dumpInstRec(Value *v) { +void dumpInstRec(Value *v) { std::set visited; //BasicBlock *B = getParentBlock(v); @@ -424,7 +403,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; @@ -440,3 +419,5 @@ return; } } + +} // namespace llvm