diff options
| author | Koakuma <koachan@protonmail.com> | 2024-07-08 19:19:54 +0700 |
|---|---|---|
| committer | Koakuma <koachan@protonmail.com> | 2024-07-08 19:19:54 +0700 |
| commit | 5c4fdc2fd5898ebd9e89999a4f4b8aa289ca637f (patch) | |
| tree | f3b92a07f3dfc6e70f36d1000605f36a3c15af46 /llvm/lib/Target/NVPTX/NVPTXUtilities.cpp | |
| parent | dbda8e2f2cd8764e0badd983915d62a2c3377f4d (diff) | |
| parent | e9b8cd0c806db00f0981fb36717077c941426302 (diff) | |
[𝘀𝗽𝗿] changes introduced through rebaseusers/koachan/spr/main.sparcias-enable-parseforallfeatures-in-matchoperandparserimpl
Created using spr 1.3.5
[skip ci]
Diffstat (limited to 'llvm/lib/Target/NVPTX/NVPTXUtilities.cpp')
| -rw-r--r-- | llvm/lib/Target/NVPTX/NVPTXUtilities.cpp | 143 |
1 files changed, 78 insertions, 65 deletions
diff --git a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp index 3a536db1c972..e4b2ec868519 100644 --- a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp @@ -52,29 +52,46 @@ void clearAnnotationCache(const Module *Mod) { AC.Cache.erase(Mod); } -static void cacheAnnotationFromMD(const MDNode *md, key_val_pair_t &retval) { +static void readIntVecFromMDNode(const MDNode *MetadataNode, + std::vector<unsigned> &Vec) { + for (unsigned i = 0, e = MetadataNode->getNumOperands(); i != e; ++i) { + ConstantInt *Val = + mdconst::extract<ConstantInt>(MetadataNode->getOperand(i)); + Vec.push_back(Val->getZExtValue()); + } +} + +static void cacheAnnotationFromMD(const MDNode *MetadataNode, + key_val_pair_t &retval) { auto &AC = getAnnotationCache(); std::lock_guard<sys::Mutex> Guard(AC.Lock); - assert(md && "Invalid mdnode for annotation"); - assert((md->getNumOperands() % 2) == 1 && "Invalid number of operands"); + assert(MetadataNode && "Invalid mdnode for annotation"); + assert((MetadataNode->getNumOperands() % 2) == 1 && + "Invalid number of operands"); // start index = 1, to skip the global variable key // increment = 2, to skip the value for each property-value pairs - for (unsigned i = 1, e = md->getNumOperands(); i != e; i += 2) { + for (unsigned i = 1, e = MetadataNode->getNumOperands(); i != e; i += 2) { // property - const MDString *prop = dyn_cast<MDString>(md->getOperand(i)); + const MDString *prop = dyn_cast<MDString>(MetadataNode->getOperand(i)); assert(prop && "Annotation property not a string"); + std::string Key = prop->getString().str(); // value - ConstantInt *Val = mdconst::dyn_extract<ConstantInt>(md->getOperand(i + 1)); - assert(Val && "Value operand not a constant int"); - - std::string keyname = prop->getString().str(); - if (retval.find(keyname) != retval.end()) - retval[keyname].push_back(Val->getZExtValue()); - else { - std::vector<unsigned> tmp; - tmp.push_back(Val->getZExtValue()); - retval[keyname] = tmp; + if (ConstantInt *Val = mdconst::dyn_extract<ConstantInt>( + MetadataNode->getOperand(i + 1))) { + retval[Key].push_back(Val->getZExtValue()); + } else if (MDNode *VecMd = + dyn_cast<MDNode>(MetadataNode->getOperand(i + 1))) { + // note: only "grid_constant" annotations support vector MDNodes. + // assert: there can only exist one unique key value pair of + // the form (string key, MDNode node). Operands of such a node + // shall always be unsigned ints. + if (retval.find(Key) == retval.end()) { + readIntVecFromMDNode(VecMd, retval[Key]); + continue; + } + } else { + llvm_unreachable("Value operand not a constant int or an mdnode"); } } } @@ -153,9 +170,9 @@ bool findAllNVVMAnnotation(const GlobalValue *gv, const std::string &prop, bool isTexture(const Value &val) { if (const GlobalValue *gv = dyn_cast<GlobalValue>(&val)) { - unsigned annot; - if (findOneNVVMAnnotation(gv, "texture", annot)) { - assert((annot == 1) && "Unexpected annotation on a texture symbol"); + unsigned Annot; + if (findOneNVVMAnnotation(gv, "texture", Annot)) { + assert((Annot == 1) && "Unexpected annotation on a texture symbol"); return true; } } @@ -164,70 +181,67 @@ bool isTexture(const Value &val) { bool isSurface(const Value &val) { if (const GlobalValue *gv = dyn_cast<GlobalValue>(&val)) { - unsigned annot; - if (findOneNVVMAnnotation(gv, "surface", annot)) { - assert((annot == 1) && "Unexpected annotation on a surface symbol"); + unsigned Annot; + if (findOneNVVMAnnotation(gv, "surface", Annot)) { + assert((Annot == 1) && "Unexpected annotation on a surface symbol"); return true; } } return false; } -bool isSampler(const Value &val) { - const char *AnnotationName = "sampler"; - - if (const GlobalValue *gv = dyn_cast<GlobalValue>(&val)) { - unsigned 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 (findAllNVVMAnnotation(func, AnnotationName, annot)) { - if (is_contained(annot, arg->getArgNo())) +static bool argHasNVVMAnnotation(const Value &Val, + const std::string &Annotation, + const bool StartArgIndexAtOne = false) { + if (const Argument *Arg = dyn_cast<Argument>(&Val)) { + const Function *Func = Arg->getParent(); + std::vector<unsigned> Annot; + if (findAllNVVMAnnotation(Func, Annotation, Annot)) { + const unsigned BaseOffset = StartArgIndexAtOne ? 1 : 0; + if (is_contained(Annot, BaseOffset + Arg->getArgNo())) { return true; + } } } return false; } -bool isImageReadOnly(const Value &val) { - if (const Argument *arg = dyn_cast<Argument>(&val)) { - const Function *func = arg->getParent(); - std::vector<unsigned> annot; - if (findAllNVVMAnnotation(func, "rdoimage", annot)) { - if (is_contained(annot, arg->getArgNo())) - return true; +bool isParamGridConstant(const Value &V) { + if (const Argument *Arg = dyn_cast<Argument>(&V)) { + // "grid_constant" counts argument indices starting from 1 + if (Arg->hasByValAttr() && + argHasNVVMAnnotation(*Arg, "grid_constant", /*StartArgIndexAtOne*/true)) { + assert(isKernelFunction(*Arg->getParent()) && + "only kernel arguments can be grid_constant"); + return true; } } return false; } -bool isImageWriteOnly(const Value &val) { - if (const Argument *arg = dyn_cast<Argument>(&val)) { - const Function *func = arg->getParent(); - std::vector<unsigned> annot; - if (findAllNVVMAnnotation(func, "wroimage", annot)) { - if (is_contained(annot, arg->getArgNo())) - return true; +bool isSampler(const Value &val) { + const char *AnnotationName = "sampler"; + + if (const GlobalValue *gv = dyn_cast<GlobalValue>(&val)) { + unsigned Annot; + if (findOneNVVMAnnotation(gv, AnnotationName, Annot)) { + assert((Annot == 1) && "Unexpected annotation on a sampler symbol"); + return true; } } - return false; + return argHasNVVMAnnotation(val, AnnotationName); +} + +bool isImageReadOnly(const Value &val) { + return argHasNVVMAnnotation(val, "rdoimage"); +} + +bool isImageWriteOnly(const Value &val) { + return argHasNVVMAnnotation(val, "wroimage"); } bool isImageReadWrite(const Value &val) { - if (const Argument *arg = dyn_cast<Argument>(&val)) { - const Function *func = arg->getParent(); - std::vector<unsigned> annot; - if (findAllNVVMAnnotation(func, "rdwrimage", annot)) { - if (is_contained(annot, arg->getArgNo())) - return true; - } - } - return false; + return argHasNVVMAnnotation(val, "rdwrimage"); } bool isImage(const Value &val) { @@ -236,9 +250,9 @@ bool isImage(const Value &val) { bool isManaged(const Value &val) { if(const GlobalValue *gv = dyn_cast<GlobalValue>(&val)) { - unsigned annot; - if (findOneNVVMAnnotation(gv, "managed", annot)) { - assert((annot == 1) && "Unexpected annotation on a managed symbol"); + unsigned Annot; + if (findOneNVVMAnnotation(gv, "managed", Annot)) { + assert((Annot == 1) && "Unexpected annotation on a managed symbol"); return true; } } @@ -323,8 +337,7 @@ bool getMaxNReg(const Function &F, unsigned &x) { bool isKernelFunction(const Function &F) { unsigned x = 0; - bool retval = findOneNVVMAnnotation(&F, "kernel", x); - if (!retval) { + if (!findOneNVVMAnnotation(&F, "kernel", x)) { // There is no NVVM metadata, check the calling convention return F.getCallingConv() == CallingConv::PTX_Kernel; } |
