35typedef std::map<std::string, std::vector<unsigned> > key_val_pair_t;
36typedef std::map<const GlobalValue *, key_val_pair_t> global_val_annot_t;
38struct AnnotationCache {
40 std::map<const Module *, global_val_annot_t> Cache;
43AnnotationCache &getAnnotationCache() {
44 static AnnotationCache AC;
50 auto &AC = getAnnotationCache();
51 std::lock_guard<sys::Mutex> Guard(AC.Lock);
56 std::vector<unsigned> &Vec) {
57 for (
unsigned i = 0, e = MetadataNode->
getNumOperands(); i != e; ++i) {
59 mdconst::extract<ConstantInt>(MetadataNode->
getOperand(i));
65 key_val_pair_t &retval) {
66 auto &AC = getAnnotationCache();
67 std::lock_guard<sys::Mutex> Guard(AC.Lock);
68 assert(MetadataNode &&
"Invalid mdnode for annotation");
70 "Invalid number of operands");
73 for (
unsigned i = 1, e = MetadataNode->
getNumOperands(); i != e; i += 2) {
76 assert(prop &&
"Annotation property not a string");
80 if (
ConstantInt *Val = mdconst::dyn_extract<ConstantInt>(
82 retval[Key].push_back(Val->getZExtValue());
84 dyn_cast<MDNode>(MetadataNode->
getOperand(i + 1))) {
89 if (retval.find(Key) == retval.end()) {
100 auto &AC = getAnnotationCache();
101 std::lock_guard<sys::Mutex> Guard(AC.Lock);
110 mdconst::dyn_extract_or_null<GlobalValue>(elem->
getOperand(0));
124 if (AC.Cache.find(m) != AC.Cache.end())
125 AC.Cache[m][gv] = std::move(tmp);
127 global_val_annot_t tmp1;
128 tmp1[gv] = std::move(tmp);
129 AC.Cache[m] = std::move(tmp1);
135 auto &AC = getAnnotationCache();
136 std::lock_guard<sys::Mutex> Guard(AC.Lock);
138 if (AC.Cache.find(m) == AC.Cache.end())
140 else if (AC.Cache[m].find(gv) == AC.Cache[m].end())
142 if (AC.Cache[m][gv].find(prop) == AC.Cache[m][gv].end())
144 retval = AC.Cache[m][gv][prop][0];
148static std::optional<unsigned>
157 std::vector<unsigned> &retval) {
158 auto &AC = getAnnotationCache();
159 std::lock_guard<sys::Mutex> Guard(AC.Lock);
161 if (AC.Cache.find(m) == AC.Cache.end())
163 else if (AC.Cache[m].find(gv) == AC.Cache[m].end())
165 if (AC.Cache[m][gv].find(prop) == AC.Cache[m][gv].end())
167 retval = AC.Cache[m][gv][prop];
172 if (
const GlobalValue *gv = dyn_cast<GlobalValue>(&val)) {
175 assert((Annot == 1) &&
"Unexpected annotation on a texture symbol");
183 if (
const GlobalValue *gv = dyn_cast<GlobalValue>(&val)) {
186 assert((Annot == 1) &&
"Unexpected annotation on a surface symbol");
194 const std::string &Annotation,
195 const bool StartArgIndexAtOne =
false) {
196 if (
const Argument *Arg = dyn_cast<Argument>(&Val)) {
197 const Function *Func = Arg->getParent();
198 std::vector<unsigned> Annot;
200 const unsigned BaseOffset = StartArgIndexAtOne ? 1 : 0;
201 if (
is_contained(Annot, BaseOffset + Arg->getArgNo())) {
210 if (
const Argument *Arg = dyn_cast<Argument>(&V)) {
212 if (Arg->hasByValAttr() &&
216 "only kernel arguments can be grid_constant");
224 const char *AnnotationName =
"sampler";
226 if (
const GlobalValue *gv = dyn_cast<GlobalValue>(&val)) {
229 assert((Annot == 1) &&
"Unexpected annotation on a sampler symbol");
253 if(
const GlobalValue *gv = dyn_cast<GlobalValue>(&val)) {
256 assert((Annot == 1) &&
"Unexpected annotation on a managed symbol");
264 assert(val.
hasName() &&
"Found texture variable with no name");
265 return std::string(val.
getName());
269 assert(val.
hasName() &&
"Found surface variable with no name");
270 return std::string(val.
getName());
274 assert(val.
hasName() &&
"Found sampler variable with no name");
275 return std::string(val.
getName());
300 if (MaxNTIDx || MaxNTIDy || MaxNTIDz)
301 return MaxNTIDx.value_or(1) * MaxNTIDy.value_or(1) * MaxNTIDz.value_or(1);
326 if (ReqNTIDx || ReqNTIDy || ReqNTIDz)
327 return ReqNTIDx.value_or(1) * ReqNTIDy.value_or(1) * ReqNTIDz.value_or(1);
351 F.getAttributes().getAttributes(
Index).getStackAlignment())
355 std::vector<unsigned> Vs;
359 for (
unsigned V : Vs)
360 if ((V >> 16) ==
Index)
361 return Align(V & 0xFFFF);
369 I.getAttributes().getAttributes(
Index).getStackAlignment())
373 if (
MDNode *alignNode =
I.getMetadata(
"callalign")) {
374 for (
int i = 0, n = alignNode->getNumOperands(); i < n; i++) {
376 mdconst::dyn_extract<ConstantInt>(alignNode->getOperand(i))) {
377 unsigned V = CI->getZExtValue();
378 if ((V >> 16) ==
Index)
379 return Align(V & 0xFFFF);
380 if ((V >> 16) >
Index)
395 if (!ST.hasNoReturn())
398 assert((isa<Function>(V) || isa<CallInst>(V)) &&
399 "Expect either a call instruction or a function");
401 if (
const CallInst *CallI = dyn_cast<CallInst>(V))
402 return CallI->doesNotReturn() &&
403 CallI->getFunctionType()->getReturnType()->isVoidTy();
406 return F->doesNotReturn() &&
407 F->getFunctionType()->getReturnType()->isVoidTy() &&
412 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...
Module.h This file contains the declarations for the Module class.
const char LLVMTargetMachineRef TM
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
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.
StringRef getName() const
Return a constant reference to the value's name.
#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 shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM)
std::optional< unsigned > getMaxNTIDy(const Function &F)
static void readIntVecFromMDNode(const MDNode *MetadataNode, std::vector< unsigned > &Vec)
std::string getSamplerName(const Value &val)
bool isParamGridConstant(const Value &V)
bool getMinCTASm(const Function &F, unsigned &x)
bool isImage(const Value &val)
std::optional< unsigned > getMaxNTIDz(const Function &F)
MaybeAlign getAlign(const Function &F, unsigned Index)
std::optional< unsigned > getMaxNTIDx(const Function &F)
bool isImageReadOnly(const Value &val)
bool isManaged(const Value &val)
bool isSurface(const Value &val)
bool findAllNVVMAnnotation(const GlobalValue *gv, const std::string &prop, std::vector< unsigned > &retval)
static void cacheAnnotationFromMD(const MDNode *MetadataNode, key_val_pair_t &retval)
void clearAnnotationCache(const Module *Mod)
std::string getSurfaceName(const Value &val)
std::optional< unsigned > getReqNTIDy(const Function &F)
@ Mod
The access may modify the value stored in memory.
bool getMaxNReg(const Function &F, unsigned &x)
bool isTexture(const Value &val)
bool isImageWriteOnly(const Value &val)
static bool argHasNVVMAnnotation(const Value &Val, const std::string &Annotation, const bool StartArgIndexAtOne=false)
bool isImageReadWrite(const Value &val)
std::string getTextureName(const Value &val)
bool isKernelFunction(const Function &F)
Function * getMaybeBitcastedCallee(const CallBase *CB)
bool findOneNVVMAnnotation(const GlobalValue *gv, const std::string &prop, unsigned &retval)
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)
bool isSampler(const Value &val)
bool getMaxClusterRank(const Function &F, unsigned &x)
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.