36using AnnotationValues = std::map<std::string, std::vector<unsigned>>;
37using AnnotationMap = std::map<const GlobalValue *, AnnotationValues>;
39struct AnnotationCache {
41 std::map<const Module *, AnnotationMap> Cache;
44AnnotationCache &getAnnotationCache() {
45 static AnnotationCache AC;
51 auto &AC = getAnnotationCache();
52 std::lock_guard<sys::Mutex> Guard(AC.Lock);
57 AnnotationValues &RetVal) {
58 auto &AC = getAnnotationCache();
59 std::lock_guard<sys::Mutex> Guard(AC.Lock);
60 assert(MetadataNode &&
"Invalid mdnode for annotation");
62 "Invalid number of operands");
67 assert(Prop &&
"Annotation property not a string");
72 RetVal[
Key].push_back(Val->getZExtValue());
80 auto &AC = getAnnotationCache();
81 std::lock_guard<sys::Mutex> Guard(AC.Lock);
82 NamedMDNode *NMD = M->getNamedMetadata(
"nvvm.annotations");
92 if (!Entity || Entity != GV)
101 AC.Cache[M][GV] = std::move(Tmp);
105 const std::string &Prop) {
106 auto &AC = getAnnotationCache();
107 std::lock_guard<sys::Mutex> Guard(AC.Lock);
109 auto ACIt = AC.Cache.find(M);
110 if (ACIt == AC.Cache.end())
112 else if (ACIt->second.find(GV) == ACIt->second.end())
115 auto &KVP = AC.Cache[M][GV];
116 auto It = KVP.find(Prop);
119 return It->second[0];
123 const std::string &Prop,
124 std::vector<unsigned> &RetVal) {
125 auto &AC = getAnnotationCache();
126 std::lock_guard<sys::Mutex> Guard(AC.Lock);
128 auto ACIt = AC.Cache.find(M);
129 if (ACIt == AC.Cache.end())
131 else if (ACIt->second.find(GV) == ACIt->second.end())
134 auto &KVP = AC.Cache[M][GV];
135 auto It = KVP.find(Prop);
145 assert((*Annot == 1) &&
"Unexpected annotation on a symbol");
153 const std::string &Annotation) {
155 std::vector<unsigned> Annot;
165 return F.hasFnAttribute(Attr)
166 ? std::optional(
F.getFnAttributeAsParsedInteger(Attr))
173 auto &Ctx =
F.getContext();
175 if (
F.hasFnAttribute(Attr)) {
178 StringRef S =
F.getFnAttribute(Attr).getValueAsString();
179 for (
unsigned I = 0;
I < 3 && !S.
empty();
I++) {
182 if (
First.trim().getAsInteger(0, IntVal))
183 Ctx.emitError(
"can't parse integer attribute " +
First +
" in " + Attr);
196 return std::accumulate(V.begin(), V.end(),
uint64_t(1),
197 std::multiplies<uint64_t>{});
205 const char *AnnotationName =
"sampler";
277 return F.hasFnAttribute(
"nvvm.blocksareclusters");
282 "only kernel arguments can be grid_constant");
306 I.getAttributes().getAttributes(Index).getStackAlignment())
310 if (
MDNode *AlignNode =
I.getMetadata(
"callalign")) {
311 for (
int I = 0,
N = AlignNode->getNumOperands();
I <
N;
I++) {
314 unsigned V = CI->getZExtValue();
315 if ((V >> 16) == Index)
316 return Align(V & 0xFFFF);
317 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.
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.
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)
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)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool isImageReadWrite(const Value &V)
bool isImageReadOnly(const Value &V)
static std::optional< unsigned > findOneNVVMAnnotation(const GlobalValue *GV, const std::string &Prop)
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)
void clearAnnotationCache(const Module *Mod)
bool isSurface(const Value &V)
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)
bool isTexture(const Value &V)
bool isImageWriteOnly(const Value &V)
static bool findAllNVVMAnnotation(const GlobalValue *GV, const std::string &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)
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.