38typedef std::map<std::string, std::vector<unsigned>> key_val_pair_t;
39typedef std::map<const GlobalValue *, key_val_pair_t> global_val_annot_t;
41struct AnnotationCache {
43 std::map<const Module *, global_val_annot_t> Cache;
46AnnotationCache &getAnnotationCache() {
47 static AnnotationCache AC;
53 auto &AC = getAnnotationCache();
54 std::lock_guard<sys::Mutex> Guard(AC.Lock);
59 key_val_pair_t &retval) {
60 auto &AC = getAnnotationCache();
61 std::lock_guard<sys::Mutex> Guard(AC.Lock);
62 assert(MetadataNode &&
"Invalid mdnode for annotation");
64 "Invalid number of operands");
67 for (
unsigned i = 1, e = MetadataNode->
getNumOperands(); i != e; i += 2) {
70 assert(prop &&
"Annotation property not a string");
74 if (
ConstantInt *Val = mdconst::dyn_extract<ConstantInt>(
76 retval[Key].push_back(Val->getZExtValue());
84 auto &AC = getAnnotationCache();
85 std::lock_guard<sys::Mutex> Guard(AC.Lock);
94 mdconst::dyn_extract_or_null<GlobalValue>(elem->
getOperand(0));
108 AC.Cache[m][gv] = std::move(tmp);
112 const std::string &prop) {
113 auto &AC = getAnnotationCache();
114 std::lock_guard<sys::Mutex> Guard(AC.Lock);
116 auto ACIt = AC.Cache.find(m);
117 if (ACIt == AC.Cache.end())
119 else if (ACIt->second.find(gv) == ACIt->second.end())
123 auto &KVP = AC.Cache[m][gv];
124 auto It = KVP.find(prop);
127 return It->second[0];
131 const std::string &prop,
132 std::vector<unsigned> &retval) {
133 auto &AC = getAnnotationCache();
134 std::lock_guard<sys::Mutex> Guard(AC.Lock);
136 auto ACIt = AC.Cache.find(m);
137 if (ACIt == AC.Cache.end())
139 else if (ACIt->second.find(gv) == ACIt->second.end())
143 auto &KVP = AC.Cache[m][gv];
144 auto It = KVP.find(prop);
152 if (
const auto *GV = dyn_cast<GlobalValue>(&V))
154 assert((*Annot == 1) &&
"Unexpected annotation on a symbol");
162 const std::string &Annotation) {
163 if (
const Argument *Arg = dyn_cast<Argument>(&Val)) {
164 const Function *Func = Arg->getParent();
165 std::vector<unsigned> Annot;
176 return F.hasFnAttribute(Attr)
177 ? std::optional(
F.getFnAttributeAsParsedInteger(Attr))
184 auto &Ctx =
F.getContext();
186 if (
F.hasFnAttribute(Attr)) {
189 StringRef S =
F.getFnAttribute(Attr).getValueAsString();
190 for (
unsigned I = 0;
I < 3 && !S.
empty();
I++) {
193 if (
First.trim().getAsInteger(0, IntVal))
194 Ctx.emitError(
"can't parse integer attribute " +
First +
" in " + Attr);
207 return std::accumulate(V.begin(), V.end(), 1, std::multiplies<uint64_t>{});
212 "only kernel arguments can be grid_constant");
241 const char *AnnotationName =
"sampler";
266 assert(V.hasName() &&
"Found texture variable with no name");
271 assert(V.hasName() &&
"Found surface variable with no name");
276 assert(V.hasName() &&
"Found sampler variable with no name");
332 return F.hasFnAttribute(
"nvvm.blocksareclusters");
338 I.getAttributes().getAttributes(
Index).getStackAlignment())
342 if (
MDNode *alignNode =
I.getMetadata(
"callalign")) {
343 for (
int i = 0, n = alignNode->getNumOperands(); i < n; i++) {
345 mdconst::dyn_extract<ConstantInt>(alignNode->getOperand(i))) {
346 unsigned V = CI->getZExtValue();
347 if ((V >> 16) ==
Index)
348 return Align(V & 0xFFFF);
349 if ((V >> 16) >
Index)
364 if (!ST.hasNoReturn())
367 assert((isa<Function>(V) || isa<CallInst>(V)) &&
368 "Expect either a call instruction or a function");
370 if (
const CallInst *CallI = dyn_cast<CallInst>(V))
371 return CallI->doesNotReturn() &&
372 CallI->getFunctionType()->getReturnType()->isVoidTy();
375 return F->doesNotReturn() &&
376 F->getFunctionType()->getReturnType()->isVoidTy() &&
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
This file defines the SmallVector class.
This class represents an incoming formal argument to a Function.
LLVM_ABI bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
LLVM_ABI bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
LLVM_ABI bool hasByValAttr() const
Return true if this argument has the byval attribute.
const Function * getParent() const
LLVM_ABI AttributeSet getAttributes() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM_ABI CaptureInfo getCaptureInfo() const
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Value * getCalledOperand() const
This class represents a function call, abstracting a target machine's calling convention.
This is the shared class of boolean and integer constants.
Module * getParent()
Get the module that this global value is contained inside of...
const MDOperand & getOperand(unsigned I) const
unsigned getNumOperands() const
Return number of MDNode operands.
LLVM_ABI StringRef getString() const
A Module instance is used to store all the information related to an LLVM module.
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI unsigned getNumOperands() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
Primary interface to the complete machine description for the target machine.
LLVM Value Representation.
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
This is an optimization pass for GlobalISel generic memory operations.
bool isManaged(const Value &V)
std::optional< uint64_t > getOverallClusterRank(const Function &F)
bool shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM)
static bool globalHasNVVMAnnotation(const Value &V, const std::string &Prop)
MaybeAlign getAlign(const CallInst &I, unsigned Index)
static std::optional< uint64_t > getVectorProduct(ArrayRef< unsigned > V)
std::optional< unsigned > getMaxNReg(const Function &F)
bool capturesAddress(CaptureComponents CC)
StringRef getSamplerName(const Value &V)
bool isImageReadWrite(const Value &V)
bool isImageReadOnly(const Value &V)
std::optional< unsigned > getMinCTASm(const Function &F)
SmallVector< unsigned, 3 > getReqNTID(const Function &F)
bool capturesFullProvenance(CaptureComponents CC)
bool isImage(const Value &V)
bool isSampler(const Value &V)
static void cacheAnnotationFromMD(const MDNode *MetadataNode, key_val_pair_t &retval)
void clearAnnotationCache(const Module *Mod)
bool isSurface(const Value &V)
static bool findAllNVVMAnnotation(const GlobalValue *gv, const std::string &prop, std::vector< unsigned > &retval)
std::optional< unsigned > getMaxClusterRank(const Function &F)
StringRef getTextureName(const Value &V)
@ Mod
The access may modify the value stored in memory.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
SmallVector< unsigned, 3 > getMaxNTID(const Function &F)
bool isParamGridConstant(const Argument &Arg)
StringRef getSurfaceName(const Value &V)
static std::optional< unsigned > getFnAttrParsedInt(const Function &F, StringRef Attr)
static std::optional< unsigned > findOneNVVMAnnotation(const GlobalValue *gv, const std::string &prop)
std::optional< uint64_t > getOverallReqNTID(const Function &F)
bool isKernelFunction(const Function &F)
bool isTexture(const Value &V)
Function * getMaybeBitcastedCallee(const CallBase *CB)
bool isImageWriteOnly(const Value &V)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
std::optional< uint64_t > getOverallMaxNTID(const Function &F)
bool hasBlocksAreClusters(const Function &F)
SmallVector< unsigned, 3 > getClusterDim(const Function &F)
static bool argHasNVVMAnnotation(const Value &Val, const std::string &Annotation)
static SmallVector< unsigned, 3 > getFnAttrParsedVector(const Function &F, StringRef Attr)
This struct is a compact representation of a valid (non-zero power of two) alignment.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.