LLVM: lib/Target/NVPTX/NVPTXUtilities.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
27#include
28#include
29#include
30#include
31#include
32#include
33#include
34
35namespace llvm {
36
37namespace {
38typedef std::map<std::string, std::vector> key_val_pair_t;
39typedef std::map<const GlobalValue *, key_val_pair_t> global_val_annot_t;
40
41struct AnnotationCache {
43 std::map<const Module *, global_val_annot_t> Cache;
44};
45
46AnnotationCache &getAnnotationCache() {
47 static AnnotationCache AC;
48 return AC;
49}
50}
51
53 auto &AC = getAnnotationCache();
54 std::lock_guardsys::Mutex Guard(AC.Lock);
55 AC.Cache.erase(Mod);
56}
57
59 key_val_pair_t &retval) {
60 auto &AC = getAnnotationCache();
61 std::lock_guardsys::Mutex Guard(AC.Lock);
62 assert(MetadataNode && "Invalid mdnode for annotation");
64 "Invalid number of operands");
65
66
67 for (unsigned i = 1, e = MetadataNode->getNumOperands(); i != e; i += 2) {
68
70 assert(prop && "Annotation property not a string");
72
73
76 retval[Key].push_back(Val->getZExtValue());
77 } else {
79 }
80 }
81}
82
84 auto &AC = getAnnotationCache();
85 std::lock_guardsys::Mutex Guard(AC.Lock);
87 if (!NMD)
88 return;
89 key_val_pair_t tmp;
90 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
92
95
96 if (!entity)
97 continue;
98 if (entity != gv)
99 continue;
100
101
103 }
104
105 if (tmp.empty())
106 return;
107
108 AC.Cache[m][gv] = std::move(tmp);
109}
110
112 const std::string &prop) {
113 auto &AC = getAnnotationCache();
114 std::lock_guardsys::Mutex Guard(AC.Lock);
116 auto ACIt = AC.Cache.find(m);
117 if (ACIt == AC.Cache.end())
119 else if (ACIt->second.find(gv) == ACIt->second.end())
121
122
123 auto &KVP = AC.Cache[m][gv];
124 auto It = KVP.find(prop);
125 if (It == KVP.end())
126 return std::nullopt;
127 return It->second[0];
128}
129
131 const std::string &prop,
132 std::vector &retval) {
133 auto &AC = getAnnotationCache();
134 std::lock_guardsys::Mutex Guard(AC.Lock);
136 auto ACIt = AC.Cache.find(m);
137 if (ACIt == AC.Cache.end())
139 else if (ACIt->second.find(gv) == ACIt->second.end())
141
142
143 auto &KVP = AC.Cache[m][gv];
144 auto It = KVP.find(prop);
145 if (It == KVP.end())
146 return false;
147 retval = It->second;
148 return true;
149}
150
154 assert((*Annot == 1) && "Unexpected annotation on a symbol");
155 return true;
156 }
157
158 return false;
159}
160
162 const std::string &Annotation) {
164 const Function *Func = Arg->getParent();
165 std::vector Annot;
168 return true;
169 }
170 }
171 return false;
172}
173
176 return F.hasFnAttribute(Attr)
177 ? std::optional(F.getFnAttributeAsParsedInteger(Attr))
178 : std::nullopt;
179}
180
184 auto &Ctx = F.getContext();
185
186 if (F.hasFnAttribute(Attr)) {
187
188
189 StringRef S = F.getFnAttribute(Attr).getValueAsString();
190 for (unsigned I = 0; I < 3 && !S.empty(); I++) {
192 unsigned IntVal;
193 if (First.trim().getAsInteger(0, IntVal))
194 Ctx.emitError("can't parse integer attribute " + First + " in " + Attr);
195
196 V.push_back(IntVal);
197 S = Rest;
198 }
199 }
200 return V;
201}
202
204 if (V.empty())
205 return std::nullopt;
206
207 return std::accumulate(V.begin(), V.end(), 1, std::multiplies<uint64_t>{});
208}
209
212 "only kernel arguments can be grid_constant");
213
215 return false;
216
217
218
219
220
221
222
226 return true;
227 }
228
229
231 return true;
232
233 return false;
234}
235
237
239
241 const char *AnnotationName = "sampler";
242
245}
246
250
254
258
262
264
266 assert(V.hasName() && "Found texture variable with no name");
267 return V.getName();
268}
269
271 assert(V.hasName() && "Found surface variable with no name");
272 return V.getName();
273}
274
276 assert(V.hasName() && "Found sampler variable with no name");
277 return V.getName();
278}
279
283
287
291
293
294
295
296
297
298
301}
302
308
310
312 return ClusterRank;
313
314
317}
318
322
326
330
332 return F.hasFnAttribute("nvvm.blocksareclusters");
333}
334
336
338 I.getAttributes().getAttributes(Index).getStackAlignment())
339 return StackAlign;
340
341
342 if (MDNode *alignNode = I.getMetadata("callalign")) {
343 for (int i = 0, n = alignNode->getNumOperands(); i < n; i++) {
346 unsigned V = CI->getZExtValue();
347 if ((V >> 16) == Index)
348 return Align(V & 0xFFFF);
349 if ((V >> 16) > Index)
350 return std::nullopt;
351 }
352 }
353 }
354 return std::nullopt;
355}
356
360
362 const auto &ST =
364 if (!ST.hasNoReturn())
365 return false;
366
368 "Expect either a call instruction or a function");
369
371 return CallI->doesNotReturn() &&
372 CallI->getFunctionType()->getReturnType()->isVoidTy();
373
375 return F->doesNotReturn() &&
376 F->getFunctionType()->getReturnType()->isVoidTy() &&
378}
379
380}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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 file defines the SmallVector 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
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.
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.
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
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.
Primary interface to the complete machine description for the target machine.
LLVM Value Representation.
LLVM_ABI 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.
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 &V)
Definition NVPTXUtilities.cpp:263
std::optional< uint64_t > getOverallClusterRank(const Function &F)
Definition NVPTXUtilities.cpp:309
bool shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM)
Definition NVPTXUtilities.cpp:361
static bool globalHasNVVMAnnotation(const Value &V, const std::string &Prop)
Definition NVPTXUtilities.cpp:151
MaybeAlign getAlign(const CallInst &I, unsigned Index)
Definition NVPTXUtilities.cpp:335
static std::optional< uint64_t > getVectorProduct(ArrayRef< unsigned > V)
Definition NVPTXUtilities.cpp:203
std::optional< unsigned > getMaxNReg(const Function &F)
Definition NVPTXUtilities.cpp:327
bool capturesAddress(CaptureComponents CC)
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
StringRef getSamplerName(const Value &V)
Definition NVPTXUtilities.cpp:275
bool isImageReadWrite(const Value &V)
Definition NVPTXUtilities.cpp:255
bool isImageReadOnly(const Value &V)
Definition NVPTXUtilities.cpp:247
std::optional< unsigned > getMinCTASm(const Function &F)
Definition NVPTXUtilities.cpp:323
SmallVector< unsigned, 3 > getReqNTID(const Function &F)
Definition NVPTXUtilities.cpp:284
bool capturesFullProvenance(CaptureComponents CC)
bool isImage(const Value &V)
Definition NVPTXUtilities.cpp:259
bool isSampler(const Value &V)
Definition NVPTXUtilities.cpp:240
static void cacheAnnotationFromMD(const MDNode *MetadataNode, key_val_pair_t &retval)
Definition NVPTXUtilities.cpp:58
void clearAnnotationCache(const Module *Mod)
Definition NVPTXUtilities.cpp:52
bool isSurface(const Value &V)
Definition NVPTXUtilities.cpp:238
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
static bool findAllNVVMAnnotation(const GlobalValue *gv, const std::string &prop, std::vector< unsigned > &retval)
Definition NVPTXUtilities.cpp:130
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
std::optional< unsigned > getMaxClusterRank(const Function &F)
Definition NVPTXUtilities.cpp:319
StringRef getTextureName(const Value &V)
Definition NVPTXUtilities.cpp:265
@ 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)
Definition NVPTXUtilities.cpp:280
bool isParamGridConstant(const Argument &Arg)
Definition NVPTXUtilities.cpp:210
StringRef getSurfaceName(const Value &V)
Definition NVPTXUtilities.cpp:270
static std::optional< unsigned > getFnAttrParsedInt(const Function &F, StringRef Attr)
Definition NVPTXUtilities.cpp:174
static std::optional< unsigned > findOneNVVMAnnotation(const GlobalValue *gv, const std::string &prop)
Definition NVPTXUtilities.cpp:111
std::optional< uint64_t > getOverallReqNTID(const Function &F)
Definition NVPTXUtilities.cpp:303
bool isKernelFunction(const Function &F)
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
bool isTexture(const Value &V)
Definition NVPTXUtilities.cpp:236
Function * getMaybeBitcastedCallee(const CallBase *CB)
Definition NVPTXUtilities.cpp:357
bool isImageWriteOnly(const Value &V)
Definition NVPTXUtilities.cpp:251
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
std::optional< uint64_t > getOverallMaxNTID(const Function &F)
Definition NVPTXUtilities.cpp:292
bool hasBlocksAreClusters(const Function &F)
Definition NVPTXUtilities.cpp:331
SmallVector< unsigned, 3 > getClusterDim(const Function &F)
Definition NVPTXUtilities.cpp:288
static bool argHasNVVMAnnotation(const Value &Val, const std::string &Annotation)
Definition NVPTXUtilities.cpp:161
static SmallVector< unsigned, 3 > getFnAttrParsedVector(const Function &F, StringRef Attr)
Definition NVPTXUtilities.cpp:181
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.