38using AnnotationValues = std::map<std::string, std::vector<unsigned>>;
39using AnnotationMap = std::map<const GlobalValue *, AnnotationValues>;
41struct AnnotationCache {
43 std::map<const Module *, AnnotationMap> Cache;
46AnnotationCache &getAnnotationCache() {
47 static AnnotationCache AC;
65 auto &AC = getAnnotationCache();
66 std::lock_guard<sys::Mutex> Guard(AC.Lock);
71 AnnotationValues &RetVal) {
72 auto &AC = getAnnotationCache();
73 std::lock_guard<sys::Mutex> Guard(AC.Lock);
74 assert(MetadataNode &&
"Invalid mdnode for annotation");
76 "Invalid number of operands");
81 assert(Prop &&
"Annotation property not a string");
86 RetVal[
Key].push_back(Val->getZExtValue());
94 auto &AC = getAnnotationCache();
95 std::lock_guard<sys::Mutex> Guard(AC.Lock);
96 NamedMDNode *NMD = M->getNamedMetadata(
"nvvm.annotations");
100 AnnotationValues Tmp;
106 if (!Entity || Entity != GV)
115 AC.Cache[M][GV] = std::move(Tmp);
120 auto &AC = getAnnotationCache();
121 std::lock_guard<sys::Mutex> Guard(AC.Lock);
123 auto ACIt = AC.Cache.find(M);
124 if (ACIt == AC.Cache.end())
126 else if (ACIt->second.find(GV) == ACIt->second.end())
129 auto &KVP = AC.Cache[M][GV];
130 auto It = KVP.find(Prop.
str());
133 return It->second[0];
137 std::vector<unsigned> &RetVal) {
138 auto &AC = getAnnotationCache();
139 std::lock_guard<sys::Mutex> Guard(AC.Lock);
141 auto ACIt = AC.Cache.find(M);
142 if (ACIt == AC.Cache.end())
144 else if (ACIt->second.find(GV) == ACIt->second.end())
147 auto &KVP = AC.Cache[M][GV];
148 auto It = KVP.find(Prop.
str());
158 assert((*Annot == 1) &&
"Unexpected annotation on a symbol");
167 std::vector<unsigned> Annot;
177 return F.hasFnAttribute(Attr)
178 ? std::optional(
F.getFnAttributeAsParsedInteger(Attr))
185 auto &Ctx =
F.getContext();
187 if (
F.hasFnAttribute(Attr)) {
190 StringRef S =
F.getFnAttribute(Attr).getValueAsString();
191 for (
unsigned I = 0;
I < 3 && !S.
empty();
I++) {
194 if (
First.trim().getAsInteger(0, IntVal))
195 Ctx.emitError(
"can't parse integer attribute " +
First +
" in " + Attr);
208 return std::accumulate(V.begin(), V.end(),
uint64_t(1),
209 std::multiplies<uint64_t>{});
299 "only kernel arguments can be grid_constant");
323 I.getAttributes().getAttributes(Index).getStackAlignment())
327 if (
MDNode *AlignNode =
I.getMetadata(
"callalign")) {
328 for (
int I = 0,
N = AlignNode->getNumOperands();
I <
N;
I++) {
331 unsigned V = CI->getZExtValue();
332 if ((V >> 16) == Index)
333 return Align(V & 0xFFFF);
334 if ((V >> 16) > Index)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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 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
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.
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.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
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.
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr StringLiteral GridConstant("nvvm.grid_constant")
constexpr StringLiteral MaxNTID("nvvm.maxntid")
constexpr StringLiteral MaxNReg("nvvm.maxnreg")
constexpr StringLiteral MinCTASm("nvvm.minctasm")
constexpr StringLiteral ReqNTID("nvvm.reqntid")
constexpr StringLiteral MaxClusterRank("nvvm.maxclusterrank")
constexpr StringLiteral ClusterDim("nvvm.cluster_dim")
constexpr StringLiteral BlocksAreClusters("nvvm.blocksareclusters")
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract_or_null(Y &&MD)
Extract a Value from Metadata, if any, allowing null.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
This is an optimization pass for GlobalISel generic memory operations.
static void cacheAnnotationFromMD(const MDNode *MetadataNode, AnnotationValues &RetVal)
bool isManaged(const Value &V)
std::optional< uint64_t > getOverallClusterRank(const Function &F)
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)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
std::optional< unsigned > getMinCTASm(const Function &F)
SmallVector< unsigned, 3 > getReqNTID(const Function &F)
bool capturesFullProvenance(CaptureComponents CC)
static bool argHasNVVMAnnotation(const Value &Val, StringRef Annotation)
void clearAnnotationCache(const Module *Mod)
static bool globalHasNVVMAnnotation(const Value &V, StringRef Prop)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
std::optional< unsigned > getMaxClusterRank(const Function &F)
@ 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)
static std::optional< unsigned > getFnAttrParsedInt(const Function &F, StringRef Attr)
std::optional< uint64_t > getOverallReqNTID(const Function &F)
bool isKernelFunction(const Function &F)
static bool findAllNVVMAnnotation(const GlobalValue *GV, StringRef Prop, std::vector< unsigned > &RetVal)
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)
PTXOpaqueType getPTXOpaqueType(const GlobalVariable &GV)
static SmallVector< unsigned, 3 > getFnAttrParsedVector(const Function &F, StringRef Attr)
static std::optional< unsigned > findOneNVVMAnnotation(const GlobalValue *GV, StringRef Prop)
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.