summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXBaseInfo.h58
-rw-r--r--llvm/lib/Target/NVPTX/NVPTXUtilities.cpp147
-rw-r--r--llvm/lib/Target/NVPTX/NVPTXUtilities.h48
3 files changed, 88 insertions, 165 deletions
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXBaseInfo.h b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXBaseInfo.h
index a72ae2ef53a..1cb92005979 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXBaseInfo.h
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXBaseInfo.h
@@ -30,60 +30,6 @@ enum AddressSpace {
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 @@ enum {
IsSurfTexQueryFlag = 0x800,
IsTexModeUnifiedFlag = 0x1000
};
-}
-}
+} // namespace NVPTXII
+} // namespace llvm
#endif
diff --git a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
index 8c980a60ebd..e1264d0defb 100644
--- a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
@@ -26,16 +26,18 @@
#include <string>
#include <vector>
-using namespace llvm;
+namespace llvm {
+namespace {
typedef std::map<std::string, std::vector<unsigned> > key_val_pair_t;
typedef std::map<const GlobalValue *, key_val_pair_t> global_val_annot_t;
typedef std::map<const Module *, global_val_annot_t> per_module_annot_t;
+} // anonymous namespace
-ManagedStatic<per_module_annot_t> annotationCache;
+static ManagedStatic<per_module_annot_t> 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 MDNode *md, key_val_pair_t &retval) {
static void cacheAnnotationFromMD(const Module *m, const GlobalValue *gv) {
MutexGuard Guard(Lock);
- NamedMDNode *NMD = m->getNamedMetadata(llvm::NamedMDForAnnotations);
+ NamedMDNode *NMD = m->getNamedMetadata("nvvm.annotations");
if (!NMD)
return;
key_val_pair_t tmp;
@@ -99,8 +101,8 @@ static void cacheAnnotationFromMD(const Module *m, const GlobalValue *gv) {
}
}
-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 @@ bool llvm::findOneNVVMAnnotation(const GlobalValue *gv, const std::string &prop,
return true;
}
-bool llvm::findAllNVVMAnnotation(const GlobalValue *gv, const std::string &prop,
- std::vector<unsigned> &retval) {
+bool findAllNVVMAnnotation(const GlobalValue *gv, const std::string &prop,
+ std::vector<unsigned> &retval) {
MutexGuard Guard(Lock);
const Module *m = gv->getParent();
if ((*annotationCache).find(m) == (*annotationCache).end())
@@ -127,12 +129,10 @@ bool llvm::findAllNVVMAnnotation(const GlobalValue *gv, const std::string &prop,
return true;
}
-bool llvm::isTexture(const llvm::Value &val) {
+bool isTexture(const Value &val) {
if (const GlobalValue *gv = dyn_cast<GlobalValue>(&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 +140,10 @@ bool llvm::isTexture(const llvm::Value &val) {
return false;
}
-bool llvm::isSurface(const llvm::Value &val) {
+bool isSurface(const Value &val) {
if (const GlobalValue *gv = dyn_cast<GlobalValue>(&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 +151,12 @@ bool llvm::isSurface(const llvm::Value &val) {
return false;
}
-bool llvm::isSampler(const llvm::Value &val) {
+bool isSampler(const Value &val) {
+ const char *AnnotationName = "sampler";
+
if (const GlobalValue *gv = dyn_cast<GlobalValue>(&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 +164,7 @@ bool llvm::isSampler(const llvm::Value &val) {
if (const Argument *arg = dyn_cast<Argument>(&val)) {
const Function *func = arg->getParent();
std::vector<unsigned> 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 +172,11 @@ bool llvm::isSampler(const llvm::Value &val) {
return false;
}
-bool llvm::isImageReadOnly(const llvm::Value &val) {
+bool isImageReadOnly(const Value &val) {
if (const Argument *arg = dyn_cast<Argument>(&val)) {
const Function *func = arg->getParent();
std::vector<unsigned> 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 +184,11 @@ bool llvm::isImageReadOnly(const llvm::Value &val) {
return false;
}
-bool llvm::isImageWriteOnly(const llvm::Value &val) {
+bool isImageWriteOnly(const Value &val) {
if (const Argument *arg = dyn_cast<Argument>(&val)) {
const Function *func = arg->getParent();
std::vector<unsigned> 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 +196,11 @@ bool llvm::isImageWriteOnly(const llvm::Value &val) {
return false;
}
-bool llvm::isImageReadWrite(const llvm::Value &val) {
+bool isImageReadWrite(const Value &val) {
if (const Argument *arg = dyn_cast<Argument>(&val)) {
const Function *func = arg->getParent();
std::vector<unsigned> 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 +208,14 @@ bool llvm::isImageReadWrite(const llvm::Value &val) {
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<GlobalValue>(&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 +223,62 @@ bool llvm::isManaged(const llvm::Value &val) {
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<unsigned> 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 +291,7 @@ bool llvm::getAlign(const Function &F, unsigned index, unsigned &align) {
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 +312,7 @@ bool llvm::getAlign(const CallInst &I, unsigned index, unsigned &align) {
// The following are some useful utilities for debugging
-BasicBlock *llvm::getParentBlock(Value *v) {
+BasicBlock *getParentBlock(Value *v) {
if (BasicBlock *B = dyn_cast<BasicBlock>(v))
return B;
@@ -347,7 +322,7 @@ BasicBlock *llvm::getParentBlock(Value *v) {
return nullptr;
}
-Function *llvm::getParentFunction(Value *v) {
+Function *getParentFunction(Value *v) {
if (Function *F = dyn_cast<Function>(v))
return F;
@@ -361,7 +336,7 @@ Function *llvm::getParentFunction(Value *v) {
}
// 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 +351,7 @@ void llvm::dumpBlock(Value *v, char *blockName) {
}
// 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 +367,14 @@ Instruction *llvm::getInst(Value *base, char *instName) {
}
// 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<Instruction *> *visited) {
+void dumpInstRec(Value *v, std::set<Instruction *> *visited) {
if (Instruction *I = dyn_cast<Instruction>(v)) {
if (visited->find(I) != visited->end())
@@ -415,7 +390,7 @@ void llvm::dumpInstRec(Value *v, std::set<Instruction *> *visited) {
}
// Dump an instruction and all dependent instructions
-void llvm::dumpInstRec(Value *v) {
+void dumpInstRec(Value *v) {
std::set<Instruction *> visited;
//BasicBlock *B = getParentBlock(v);
@@ -424,7 +399,7 @@ void llvm::dumpInstRec(Value *v) {
}
// Dump the parent for Instruction, block or function
-void llvm::dumpParent(Value *v) {
+void dumpParent(Value *v) {
if (Instruction *I = dyn_cast<Instruction>(v)) {
I->getParent()->dump();
return;
@@ -440,3 +415,5 @@ void llvm::dumpParent(Value *v) {
return;
}
}
+
+} // namespace llvm
diff --git a/llvm/lib/Target/NVPTX/NVPTXUtilities.h b/llvm/lib/Target/NVPTX/NVPTXUtilities.h
index ec5bfc17afc..2e641e8937e 100644
--- a/llvm/lib/Target/NVPTX/NVPTXUtilities.h
+++ b/llvm/lib/Target/NVPTX/NVPTXUtilities.h
@@ -28,39 +28,39 @@ namespace llvm {
#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<unsigned> &);
-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);
OpenPOWER on IntegriCloud