33typedef std::map<std::string, std::vector<unsigned>> key_val_pair_t;
34typedef std::map<const GlobalValue *, key_val_pair_t> global_val_annot_t;
36struct AnnotationCache {
38 std::map<const Module *, global_val_annot_t> Cache;
41AnnotationCache &getAnnotationCache() {
42 static AnnotationCache AC;
48 auto &AC = getAnnotationCache();
49 std::lock_guard<sys::Mutex> Guard(AC.Lock);
54 std::vector<unsigned> &Vec) {
55 for (
unsigned i = 0, e = MetadataNode->
getNumOperands(); i != e; ++i) {
57 mdconst::extract<ConstantInt>(MetadataNode->
getOperand(i));
63 key_val_pair_t &retval) {
64 auto &AC = getAnnotationCache();
65 std::lock_guard<sys::Mutex> Guard(AC.Lock);
66 assert(MetadataNode &&
"Invalid mdnode for annotation");
68 "Invalid number of operands");
71 for (
unsigned i = 1, e = MetadataNode->
getNumOperands(); i != e; i += 2) {
74 assert(prop &&
"Annotation property not a string");
78 if (
ConstantInt *Val = mdconst::dyn_extract<ConstantInt>(
80 retval[Key].push_back(Val->getZExtValue());
82 dyn_cast<MDNode>(MetadataNode->
getOperand(i + 1))) {
87 auto [It, Inserted] = retval.try_emplace(Key);
99 auto &AC = getAnnotationCache();
100 std::lock_guard<sys::Mutex> Guard(AC.Lock);
109 mdconst::dyn_extract_or_null<GlobalValue>(elem->
getOperand(0));
123 AC.Cache[m][gv] = std::move(tmp);
127 const std::string &prop) {
128 auto &AC = getAnnotationCache();
129 std::lock_guard<sys::Mutex> Guard(AC.Lock);
131 if (AC.Cache.find(m) == AC.Cache.end())
133 else if (AC.Cache[m].find(gv) == AC.Cache[m].end())
135 if (AC.Cache[m][gv].find(prop) == AC.Cache[m][gv].end())
137 return AC.Cache[m][gv][prop][0];
141 const std::string &prop,
142 std::vector<unsigned> &retval) {
143 auto &AC = getAnnotationCache();
144 std::lock_guard<sys::Mutex> Guard(AC.Lock);
146 if (AC.Cache.find(m) == AC.Cache.end())
148 else if (AC.Cache[m].find(gv) == AC.Cache[m].end())
150 if (AC.Cache[m][gv].find(prop) == AC.Cache[m][gv].end())
152 retval = AC.Cache[m][gv][prop];
157 if (
const auto *GV = dyn_cast<GlobalValue>(&V))
159 assert((*Annot == 1) &&
"Unexpected annotation on a symbol");
167 const std::string &Annotation,
168 const bool StartArgIndexAtOne =
false) {
169 if (
const Argument *Arg = dyn_cast<Argument>(&Val)) {
170 const Function *Func = Arg->getParent();
171 std::vector<unsigned> Annot;
173 const unsigned BaseOffset = StartArgIndexAtOne ? 1 : 0;
174 if (
is_contained(Annot, BaseOffset + Arg->getArgNo())) {
183 if (
const Argument *Arg = dyn_cast<Argument>(&V)) {
185 if (Arg->hasByValAttr() &&
189 "only kernel arguments can be grid_constant");
201 const char *AnnotationName =
"sampler";
226 assert(V.hasName() &&
"Found texture variable with no name");
231 assert(V.hasName() &&
"Found surface variable with no name");
236 assert(V.hasName() &&
"Found sampler variable with no name");
262 if (MaxNTIDx || MaxNTIDy || MaxNTIDz)
263 return MaxNTIDx.value_or(1) * MaxNTIDy.value_or(1) * MaxNTIDz.value_or(1);
300 if (ReqNTIDx || ReqNTIDy || ReqNTIDz)
301 return ReqNTIDx.value_or(1) * ReqNTIDy.value_or(1) * ReqNTIDz.value_or(1);
324 F.getAttributes().getAttributes(
Index).getStackAlignment())
328 std::vector<unsigned> Vs;
332 for (
unsigned V : Vs)
333 if ((V >> 16) ==
Index)
334 return Align(V & 0xFFFF);
342 I.getAttributes().getAttributes(
Index).getStackAlignment())
346 if (
MDNode *alignNode =
I.getMetadata(
"callalign")) {
347 for (
int i = 0, n = alignNode->getNumOperands(); i < n; i++) {
349 mdconst::dyn_extract<ConstantInt>(alignNode->getOperand(i))) {
350 unsigned V = CI->getZExtValue();
351 if ((V >> 16) ==
Index)
352 return Align(V & 0xFFFF);
353 if ((V >> 16) >
Index)
368 if (!ST.hasNoReturn())
371 assert((isa<Function>(V) || isa<CallInst>(V)) &&
372 "Expect either a call instruction or a function");
374 if (
const CallInst *CallI = dyn_cast<CallInst>(V))
375 return CallI->doesNotReturn() &&
376 CallI->getFunctionType()->getReturnType()->isVoidTy();
379 return F->doesNotReturn() &&
380 F->getFunctionType()->getReturnType()->isVoidTy() &&
385 return (VT == MVT::v2f16 || VT == MVT::v2bf16 || VT == MVT::v2i16);
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents an incoming formal argument to a Function.
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.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
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.
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.
MDNode * getOperand(unsigned i) const
unsigned getNumOperands() const
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
Primary interface to the complete machine description for the target machine.
LLVM Value Representation.
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.
@ PTX_Kernel
Call to a PTX kernel. Passes all arguments in parameter space.
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
This is an optimization pass for GlobalISel generic memory operations.
bool isManaged(const Value &V)
bool shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM)
static bool globalHasNVVMAnnotation(const Value &V, const std::string &Prop)
std::optional< unsigned > getMaxNReg(const Function &F)
std::optional< unsigned > getMaxNTIDy(const Function &F)
static void readIntVecFromMDNode(const MDNode *MetadataNode, std::vector< unsigned > &Vec)
bool isParamGridConstant(const Value &V)
StringRef getSamplerName(const Value &V)
bool isImageReadWrite(const Value &V)
bool isImageReadOnly(const Value &V)
std::optional< unsigned > getMaxNTIDz(const Function &F)
MaybeAlign getAlign(const Function &F, unsigned Index)
std::optional< unsigned > getMaxNTIDx(const Function &F)
std::optional< unsigned > getMinCTASm(const Function &F)
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)
std::optional< unsigned > getReqNTIDy(const Function &F)
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)
std::optional< unsigned > getClusterDimx(const Function &F)
@ Mod
The access may modify the value stored in memory.
static bool argHasNVVMAnnotation(const Value &Val, const std::string &Annotation, const bool StartArgIndexAtOne=false)
StringRef getSurfaceName(const Value &V)
std::optional< unsigned > getClusterDimy(const Function &F)
static std::optional< unsigned > findOneNVVMAnnotation(const GlobalValue *gv, const std::string &prop)
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< unsigned > getReqNTIDz(const Function &F)
std::optional< unsigned > getReqNTIDx(const Function &F)
std::optional< unsigned > getClusterDimz(const Function &F)
std::optional< unsigned > getReqNTID(const Function &F)
std::optional< unsigned > getMaxNTID(const Function &F)
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.