#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);
}
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;
}
}
-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())
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())
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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++) {
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 =
// 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;
return nullptr;
}
-Function *llvm::getParentFunction(Value *v) {
+Function *getParentFunction(Value *v) {
if (Function *F = dyn_cast<Function>(v))
return F;
}
// 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;
}
// 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;
}
// 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())
}
// Dump an instruction and all dependent instructions
-void llvm::dumpInstRec(Value *v) {
+void dumpInstRec(Value *v) {
std::set<Instruction *> visited;
//BasicBlock *B = getParentBlock(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;
return;
}
}
+
+} // 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);