37using AnnotationValues = std::map<std::string, std::vector<unsigned>>;
38using AnnotationMap = std::map<const GlobalValue *, AnnotationValues>;
40struct AnnotationCache {
42 std::map<const Module *, AnnotationMap> Cache;
48 static AnnotationCache AC;
66 std::lock_guard<sys::Mutex> Guard(AC.Lock);
71 AnnotationValues &RetVal) {
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());
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);
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) {
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>{});
306 if (
A.getValueAsString().getAsInteger(10,
Value))
318 "only kernel arguments can be grid_constant");
342 I.getAttributes().getAttributes(Index).getStackAlignment())
346 if (
MDNode *AlignNode =
I.getMetadata(
"callalign")) {
347 for (
int I = 0,
N = AlignNode->getNumOperands();
I <
N;
I++) {
350 unsigned V = CI->getZExtValue();
351 if ((V >> 16) == Index)
352 return Align(V & 0xFFFF);
353 if ((V >> 16) > Index)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
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.
static void cacheAnnotationFromMD(const MDNode *MetadataNode, AnnotationValues &RetVal)
static AnnotationCache & getAnnotationCache()
static bool findAllNVVMAnnotation(const GlobalValue *GV, StringRef Prop, std::vector< unsigned > &RetVal)
static std::optional< unsigned > getFnAttrParsedInt(const Function &F, StringRef Attr)
static std::optional< unsigned > findOneNVVMAnnotation(const GlobalValue *GV, StringRef Prop)
static bool globalHasNVVMAnnotation(const Value &V, StringRef Prop)
static bool argHasNVVMAnnotation(const Value &Val, StringRef Annotation)
static std::optional< uint64_t > getVectorProduct(ArrayRef< unsigned > V)
static SmallVector< unsigned, 3 > getFnAttrParsedVector(const Function &F, StringRef Attr)
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
Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM_ABI CaptureInfo getCaptureInfo() const
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
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...
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
Get the contents as an std::string.
constexpr bool empty() const
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 AbiPreserveControl("nvvm.abi_preserve_control")
constexpr StringLiteral MaxNReg("nvvm.maxnreg")
constexpr StringLiteral MinCTASm("nvvm.minctasm")
constexpr StringLiteral ReqNTID("nvvm.reqntid")
constexpr StringLiteral MaxClusterRank("nvvm.maxclusterrank")
constexpr StringLiteral AbiPreserve("nvvm.abi_preserve")
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.
bool isManaged(const Value &)
SmallVector< unsigned, 3 > getReqNTID(const Function &)
bool hasBlocksAreClusters(const Function &)
SmallVector< unsigned, 3 > getClusterDim(const Function &)
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 > getMaxNReg(const Function &)
PTXOpaqueType getPTXOpaqueType(const GlobalVariable &)
std::optional< uint64_t > getOverallClusterRank(const Function &)
std::optional< unsigned > getMinCTASm(const Function &)
bool capturesFullProvenance(CaptureComponents CC)
SmallVector< unsigned, 3 > getMaxNTID(const Function &)
std::optional< unsigned > getMaxClusterRank(const Function &)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Mod
The access may modify the value stored in memory.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
std::optional< uint64_t > getOverallReqNTID(const Function &)
bool isKernelFunction(const Function &F)
std::optional< uint64_t > getOverallMaxNTID(const Function &)
MaybeAlign getStackAlign(const Function &F, unsigned Index)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool isParamGridConstant(const Argument &)
void clearAnnotationCache(const Module *)
ABIPreserveInfo getABIPreserve(AttributeList Attrs)
On a function, the attributes are looked up on the function definition or declaration.
The number of registers that the callers of a function are responsible for preserving across a call,...
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.