LLVM 24.0.0git
AMDGPUMemoryUtils.cpp
Go to the documentation of this file.
1//===-- AMDGPUMemoryUtils.cpp - -------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "AMDGPUMemoryUtils.h"
12#include "llvm/ADT/StringRef.h"
16#include "llvm/IR/DataLayout.h"
20#include "llvm/IR/IntrinsicsAMDGPU.h"
21#include "llvm/IR/LLVMContext.h"
26
27#define DEBUG_TYPE "amdgpu-memory-utils"
28
29using namespace llvm;
30
31namespace llvm::AMDGPU {
32
34 return DL.getValueOrABITypeAlignment(GV->getPointerAlignment(DL),
35 GV->getValueType());
36}
37
38unsigned getSyntheticApertureNumber(unsigned AS) {
39 switch (AS) {
42 case AMDGPUAS::VGPR:
44 default:
46 }
47}
48
49void copyMetadataForWidenedLoad(LoadInst &Dest, const LoadInst &Source) {
51 Source.getAllMetadata(MD);
52 for (const auto &[ID, N] : MD) {
53 switch (ID) {
54 case LLVMContext::MD_dbg:
55 case LLVMContext::MD_invariant_load:
56 case LLVMContext::MD_nontemporal:
57 Dest.setMetadata(ID, N);
58 break;
59 default:
60 break;
61 }
62 }
63}
64
65// Returns the target extension type of a global variable,
66// which can only be a TargetExtType, an array or single-element struct of it,
67// or their nesting combination.
68// TODO: allow struct of multiple TargetExtType elements of the same type.
69// TODO: Disallow other uses of target("amdgcn.named.barrier") including:
70// - Structs containing barriers in different scope/rank
71// - Structs containing a mixture of barriers and other data.
72// - Globals in other address spaces.
73// - Allocas.
75 Type *Ty = GV.getValueType();
76 while (true) {
77 if (auto *TTy = dyn_cast<TargetExtType>(Ty))
78 return TTy;
79 if (auto *STy = dyn_cast<StructType>(Ty)) {
80 if (STy->getNumElements() != 1)
81 return nullptr;
82 Ty = STy->getElementType(0);
83 continue;
84 }
85 if (auto *ATy = dyn_cast<ArrayType>(Ty)) {
86 Ty = ATy->getElementType();
87 continue;
88 }
89 return nullptr;
90 }
91}
92
95 return nullptr;
96 if (TargetExtType *Ty = getTargetExtType(GV))
97 return Ty->getName() == "amdgcn.named.barrier" ? Ty : nullptr;
98 return nullptr;
99}
100
102 const GlobalVariable &GV) {
104 unsigned GVSize = GV.getGlobalSize(DL);
105 assert(GVSize && (GVSize % NamedBarrierTypeSizeInBytes == 0));
106 return GVSize / NamedBarrierTypeSizeInBytes;
107}
108
110 // external zero size addrspace(3) without initializer is dynlds.
111 const Module *M = GV.getParent();
112 const DataLayout &DL = M->getDataLayout();
114 return false;
115 return GV.getGlobalSize(DL) == 0;
116}
117
120 return false;
121 }
122 if (isDynamicLDS(GV)) {
123 return true;
124 }
125 if (GV.isConstant()) {
126 // A constant undef variable can't be written to, and any load is
127 // undef, so it should be eliminated by the optimizer. It could be
128 // dropped by the back end if not. This pass skips over it.
129 return false;
130 }
131 if (GV.hasInitializer() && !isa<UndefValue>(GV.getInitializer())) {
132 // Initializers are unimplemented for LDS address space.
133 // Leave such variables in place for consistent error reporting.
134 return false;
135 }
136 return true;
137}
138
140 Module &M, function_ref<bool(const GlobalVariable &)> Filter) {
142 for (auto &GV : M.globals())
143 if (Filter(GV))
144 Worklist.push_back(&GV);
146}
147
149 function_ref<bool(const GlobalVariable &)> Filter,
150 FunctionVariableMap &Kernels,
151 FunctionVariableMap &Functions) {
152 // Get uses from the current function, excluding uses by called Functions
153 // Two output variables to avoid walking the globals list twice
154 for (auto &GV : M.globals()) {
155 if (!Filter(GV))
156 continue;
157 for (User *V : GV.users()) {
158 if (auto *I = dyn_cast<Instruction>(V)) {
159 Function *F = I->getFunction();
160 if (isKernel(*F))
161 Kernels[F].insert(&GV);
162 else
163 Functions[F].insert(&GV);
164 }
165 }
166 }
167}
168
169GVUsesInfoTy
171 function_ref<bool(const GlobalVariable &)> Filter) {
172
173 FunctionVariableMap DirectMapKernel;
174 FunctionVariableMap DirectMapFunction;
175 getUsesOfGVByFunction(CG, M, Filter, DirectMapKernel, DirectMapFunction);
176
177 // Collect functions whose address has escaped
178 DenseSet<Function *> AddressTakenFuncs;
179 for (Function &F : M.functions()) {
180 if (!isKernel(F))
181 if (F.hasAddressTaken(nullptr,
182 /* IgnoreCallbackUses */ false,
183 /* IgnoreAssumeLikeCalls */ false,
184 /* IgnoreLLVMUsed */ true,
185 /* IgnoreArcAttachedCall */ false)) {
186 AddressTakenFuncs.insert(&F);
187 }
188 }
189
190 // Collect variables that are used by functions whose address has escaped
191 DenseSet<GlobalVariable *> VariablesReachableThroughFunctionPointer;
192 for (Function *F : AddressTakenFuncs) {
193 set_union(VariablesReachableThroughFunctionPointer, DirectMapFunction[F]);
194 }
195
196 auto FunctionMakesUnknownCall = [&](const Function *F) -> bool {
197 assert(!F->isDeclaration());
198 for (const CallGraphNode::CallRecord &R : *CG[F]) {
199 if (!R.second->getFunction())
200 return true;
201 }
202 return false;
203 };
204
205 // Work out which variables are reachable through function calls
206 FunctionVariableMap TransitiveMapFunction = DirectMapFunction;
207
208 // If the function makes any unknown call, assume the worst case that it can
209 // access all variables accessed by functions whose address escaped
210 for (Function &F : M.functions()) {
211 if (!F.isDeclaration() && FunctionMakesUnknownCall(&F)) {
212 if (!isKernel(F)) {
213 set_union(TransitiveMapFunction[&F],
214 VariablesReachableThroughFunctionPointer);
215 }
216 }
217 }
218
219 // Direct implementation of collecting all variables reachable from each
220 // function
221 for (Function &Func : M.functions()) {
222 if (Func.isDeclaration() || isKernel(Func))
223 continue;
224
225 DenseSet<Function *> seen; // catches cycles
226 SmallVector<Function *, 4> wip = {&Func};
227
228 while (!wip.empty()) {
229 Function *F = wip.pop_back_val();
230
231 // Can accelerate this by referring to transitive map for functions that
232 // have already been computed, with more care than this
233 set_union(TransitiveMapFunction[&Func], DirectMapFunction[F]);
234
235 for (const CallGraphNode::CallRecord &R : *CG[F]) {
236 Function *Ith = R.second->getFunction();
237 if (Ith) {
238 if (!seen.contains(Ith)) {
239 seen.insert(Ith);
240 wip.push_back(Ith);
241 }
242 }
243 }
244 }
245 }
246
247 // Collect variables that are transitively used by functions whose address has
248 // escaped
249 for (Function *F : AddressTakenFuncs) {
250 set_union(VariablesReachableThroughFunctionPointer,
251 TransitiveMapFunction[F]);
252 }
253
254 // DirectMapKernel lists which variables are used by the kernel
255 // find the variables which are used through a function call
256 FunctionVariableMap IndirectMapKernel;
257
258 for (Function &Func : M.functions()) {
259 if (Func.isDeclaration() || !isKernel(Func))
260 continue;
261
262 for (const CallGraphNode::CallRecord &R : *CG[&Func]) {
263 Function *Ith = R.second->getFunction();
264 if (Ith) {
265 set_union(IndirectMapKernel[&Func], TransitiveMapFunction[Ith]);
266 }
267 }
268
269 // Check if the kernel encounters unknows calls, wheher directly or
270 // indirectly.
271 bool SeesUnknownCalls = [&]() {
272 SmallVector<Function *> WorkList = {CG[&Func]->getFunction()};
274
275 while (!WorkList.empty()) {
276 Function *F = WorkList.pop_back_val();
277
278 for (const CallGraphNode::CallRecord &CallRecord : *CG[F]) {
279 if (!CallRecord.second)
280 continue;
281
282 Function *Callee = CallRecord.second->getFunction();
283 if (!Callee)
284 return true;
285
286 if (Visited.insert(Callee).second)
287 WorkList.push_back(Callee);
288 }
289 }
290 return false;
291 }();
292
293 if (SeesUnknownCalls) {
294 set_union(IndirectMapKernel[&Func],
295 VariablesReachableThroughFunctionPointer);
296 }
297 }
298
299 return {std::move(DirectMapKernel), std::move(IndirectMapKernel)};
300}
301
304 // Verify that we fall into one of 2 cases:
305 // - All variables are either absolute
306 // or direct mapped dynamic LDS that is not lowered.
307 // - No variables are absolute.
308 // Named-barriers which are absolute symbols are removed
309 // from the maps.
310 std::optional<bool> HasAbsoluteGVs;
311 for (auto &Map : {UsesInfo.DirectAccess, UsesInfo.IndirectAccess}) {
312 for (auto &[Fn, GVs] : Map) {
313 for (auto *GV : GVs) {
314 bool IsAbsolute = GV->isAbsoluteSymbolRef();
315 bool IsDirectMapDynLDSGV =
316 AMDGPU::isDynamicLDS(*GV) && UsesInfo.DirectAccess.contains(Fn);
317 if (IsDirectMapDynLDSGV)
318 continue;
319
320 if (HasAbsoluteGVs.has_value()) {
321 if (*HasAbsoluteGVs != IsAbsolute) {
323 "module cannot mix absolute and non-absolute LDS GVs");
324 }
325 } else
326 HasAbsoluteGVs = IsAbsolute;
327 }
328 }
329 }
330
331 // If we only had absolute GVs, we have nothing to do, return an empty
332 // result.
333 if (HasAbsoluteGVs && *HasAbsoluteGVs)
334 return GVUsesInfoTy();
335
336 return UsesInfo;
337}
338
340 ArrayRef<StringRef> FnAttrs) {
341 for (StringRef Attr : FnAttrs)
342 KernelRoot->removeFnAttr(Attr);
343
344 SmallVector<Function *> WorkList = {CG[KernelRoot]->getFunction()};
346 bool SeenUnknownCall = false;
347
348 while (!WorkList.empty()) {
349 Function *F = WorkList.pop_back_val();
350
351 for (auto &CallRecord : *CG[F]) {
352 if (!CallRecord.second)
353 continue;
354
355 Function *Callee = CallRecord.second->getFunction();
356 if (!Callee) {
357 if (!SeenUnknownCall) {
358 SeenUnknownCall = true;
359
360 // If we see any indirect calls, assume nothing about potential
361 // targets.
362 // TODO: This could be refined to possible LDS global users.
363 for (auto &ExternalCallRecord : *CG.getExternalCallingNode()) {
364 Function *PotentialCallee =
365 ExternalCallRecord.second->getFunction();
366 assert(PotentialCallee);
367 if (!isKernel(*PotentialCallee)) {
368 for (StringRef Attr : FnAttrs)
369 PotentialCallee->removeFnAttr(Attr);
370 }
371 }
372 }
373 } else {
374 for (StringRef Attr : FnAttrs)
375 Callee->removeFnAttr(Attr);
376 if (Visited.insert(Callee).second)
377 WorkList.push_back(Callee);
378 }
379 }
380 }
381}
382
384 Instruction *DefInst = Def->getMemoryInst();
385
386 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(DefInst)) {
387 switch (II->getIntrinsicID()) {
388 case Intrinsic::amdgcn_s_barrier:
389 case Intrinsic::amdgcn_s_cluster_barrier:
390 case Intrinsic::amdgcn_s_barrier_signal:
391 case Intrinsic::amdgcn_s_barrier_signal_var:
392 case Intrinsic::amdgcn_s_barrier_signal_isfirst:
393 case Intrinsic::amdgcn_s_barrier_init:
394 case Intrinsic::amdgcn_s_barrier_join:
395 case Intrinsic::amdgcn_s_barrier_wait:
396 case Intrinsic::amdgcn_s_barrier_leave:
397 case Intrinsic::amdgcn_s_get_barrier_state:
398 case Intrinsic::amdgcn_s_wakeup_barrier:
399 case Intrinsic::amdgcn_wave_barrier:
400 case Intrinsic::amdgcn_sched_barrier:
401 case Intrinsic::amdgcn_sched_group_barrier:
402 case Intrinsic::amdgcn_iglp_opt:
403 return false;
404 default:
405 break;
406 }
407 }
408
409 // Ignore non-acquire fences/atomics not aliasing with the original load; MSSA
410 // counts any atomic or fence as a universal MemoryDef.
411 // Acquire (or stronger) fences/atomics act as clobbers because they can bring
412 // in effects from other threads.
413 const auto MayAlias = [AA, Ptr](auto I) -> bool {
414 return !AA->isNoAlias(I->getPointerOperand(), Ptr);
415 };
416
417 // TODO Not respecting acquire operations is unsound and leads to
418 // miscompilations. This needs to be removed once sufficient performance
419 // optimizations are in place to recover the cost of respecting them.
420 bool RespectAcquireClobbers = false;
421
422 if (const auto *F = dyn_cast<FenceInst>(DefInst)) {
423 if (!RespectAcquireClobbers || !isAcquireOrStronger(F->getOrdering()))
424 return false;
425 SIAtomicAddrSpace AccessedAS =
427 return (AccessedAS & getSynchronizeAddrSpace(*F)) !=
429 }
430
431 if (const auto *I = dyn_cast<AtomicRMWInst>(DefInst))
432 return (RespectAcquireClobbers && isAcquireOrStronger(I->getOrdering())) ||
433 MayAlias(I);
434
435 if (const auto *I = dyn_cast<AtomicCmpXchgInst>(DefInst))
436 return (RespectAcquireClobbers &&
437 isAcquireOrStronger(I->getMergedOrdering())) ||
438 MayAlias(I);
439
440 // TODO This is pessimistic for one-as load-acquires from a different AS.
441 if (const auto *I = dyn_cast<LoadInst>(DefInst))
442 return isAcquireOrStronger(I->getOrdering());
443
444 // (Atomic) stores that don't alias do not clobber.
445 if (const auto *I = dyn_cast<StoreInst>(DefInst))
446 return MayAlias(I);
447
448 return true;
449}
450
452 AAResults *AA) {
453 MemorySSAWalker *Walker = MSSA->getWalker();
457 Walker->getClobberingMemoryAccess(Use->getDefiningAccess(), Loc)};
459
460 LLVM_DEBUG(dbgs() << "Checking clobbering of: " << *Load << '\n');
461
462 // Start with a nearest dominating clobbering access, it will be either
463 // live on entry (nothing to do, load is not clobbered), MemoryDef, or
464 // MemoryPhi if several MemoryDefs can define this memory state. In that
465 // case add all Defs to WorkList and continue going up and checking all
466 // the definitions of this memory location until the root. When all the
467 // defs are exhausted and came to the entry state we have no clobber.
468 // Along the scan ignore barriers which are considered clobbers by the
469 // MemorySSA, but not really writing anything into the memory.
470 while (!WorkList.empty()) {
471 MemoryAccess *MA = WorkList.pop_back_val();
472 if (!Visited.insert(MA).second)
473 continue;
474
475 if (MSSA->isLiveOnEntryDef(MA))
476 continue;
477
478 if (MemoryDef *Def = dyn_cast<MemoryDef>(MA)) {
479 LLVM_DEBUG(dbgs() << " Def: " << *Def->getMemoryInst() << '\n');
480
481 if (isReallyAClobber(Load->getPointerOperand(), Def, AA)) {
482 LLVM_DEBUG(dbgs() << " -> load is clobbered\n");
483 return true;
484 }
485
486 WorkList.push_back(
487 Walker->getClobberingMemoryAccess(Def->getDefiningAccess(), Loc));
488 continue;
489 }
490
491 const MemoryPhi *Phi = cast<MemoryPhi>(MA);
492 for (const auto &Use : Phi->incoming_values())
493 WorkList.push_back(
495 }
496
497 LLVM_DEBUG(dbgs() << " -> no clobber\n");
498 return false;
499}
500
502 SIAtomicAddrSpace::FLAT, //< AMDGPUAS::FLAT_ADDRESS
503 SIAtomicAddrSpace::GLOBAL, //< AMDGPUAS::GLOBAL_ADDRESS
504 SIAtomicAddrSpace::GDS, //< AMDGPUAS::REGION_ADDRESS
505 SIAtomicAddrSpace::LDS, //< AMDGPUAS::LOCAL_ADDRESS
506 SIAtomicAddrSpace::GLOBAL, //< AMDGPUAS::CONSTANT_ADDRESS
507 SIAtomicAddrSpace::SCRATCH, //< AMDGPUAS::PRIVATE_ADDRESS
508 SIAtomicAddrSpace::GLOBAL, //< AMDGPUAS::CONSTANT_ADDRESS_32BIT
509 SIAtomicAddrSpace::GLOBAL, //< AMDGPUAS::BUFFER_FAT_POINTER
510 SIAtomicAddrSpace::GLOBAL, //< AMDGPUAS::BUFFER_RESOURCE
511 SIAtomicAddrSpace::GLOBAL, //< AMDGPUAS::BUFFER_STRIDED_POINTER
512};
513
514SIAtomicAddrSpace toSIAtomicAddrSpace(unsigned LLVMAddrSpace) {
515 constexpr unsigned SizeOfLLVMToSIAtomicAddrSpaceMapping =
518 if (LLVMAddrSpace > AMDGPUAS::MAX_AMDGPU_ADDRESS)
520 if (LLVMAddrSpace < SizeOfLLVMToSIAtomicAddrSpaceMapping)
521 return LLVMToSIAtomicAddrSpaceMapping[LLVMAddrSpace];
523}
524
526 {"global", SIAtomicAddrSpace::GLOBAL},
527 {"local", SIAtomicAddrSpace::LDS},
528}};
529
531 const Function *DiagFn,
532 const DebugLoc &DL) {
533 static constexpr StringLiteral FenceASPrefix = "amdgpu-synchronize-as";
534
535 if (!MMRA)
537
538 SIAtomicAddrSpace Result{};
539 for (const auto &[Prefix, Suffix] : MMRA) {
540 if (Prefix != FenceASPrefix)
541 continue;
542
543 if (auto It = ASNames.find(Suffix); It != ASNames.end()) {
544 Result |= It->second;
545 } else if (DiagFn) {
547 raw_svector_ostream OS(Str);
548 OS << "unknown address space '" << Suffix << "'; expected one of ";
549 ListSeparator LS;
550 for (const auto &[Name, Val] : ASNames)
551 OS << LS << '\'' << Name << '\'';
552 DiagFn->getContext().diagnose(
553 DiagnosticInfoUnsupported(*DiagFn, Str, DL, DS_Warning));
554 }
555 }
556
557 if (Result == SIAtomicAddrSpace::NONE)
559
560 return Result;
561}
562
566
567} // end namespace llvm::AMDGPU
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU address space definition.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
#define F(x, y, z)
Definition MD5.cpp:54
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
uint64_t IntrinsicInst * II
This file defines generic set operations that may be used on set's of different types,...
#define LLVM_DEBUG(...)
Definition Debug.h:119
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
std::pair< std::optional< WeakTrackingVH >, CallGraphNode * > CallRecord
A pair of the calling instruction (a call or invoke) and the call graph node being called.
Definition CallGraph.h:174
The basic data container for the call graph of a Module of IR.
Definition CallGraph.h:72
CallGraphNode * getExternalCallingNode() const
Returns the CallGraphNode which is used to represent undetermined calls into the callgraph.
Definition CallGraph.h:127
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
A debug info location.
Definition DebugLoc.h:126
Implements a dense probed hash-table based set.
Definition DenseSet.h:283
Diagnostic information for unsupported feature in backend.
const Function & getFunction() const
Definition Function.h:167
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
Definition Function.cpp:689
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:352
unsigned getAddressSpace() const
Module * getParent()
Get the module that this global value is contained inside of...
PointerType * getType() const
Global values are always pointers.
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
Definition Globals.cpp:640
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
A wrapper class for inspecting calls to intrinsic functions.
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
A helper class to return the specified delimiter string after the first invocation of operator String...
An instruction for reading from memory.
Helper class to manipulate !mmra metadata nodes.
bool contains(const KeyT &Key) const
Definition MapVector.h:149
Represents a read-write access to memory, whether it is a must-alias, or a may-alias.
Definition MemorySSA.h:372
Representation for a specific memory location.
static LLVM_ABI MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
Represents phi nodes for memory accesses.
Definition MemorySSA.h:476
This is the generic walker interface for walkers of MemorySSA.
Definition MemorySSA.h:1012
MemoryAccess * getClobberingMemoryAccess(const Instruction *I, BatchAAResults &AA)
Given a memory Mod/Ref/ModRef'ing instruction, calling this will give you the nearest dominating Memo...
Definition MemorySSA.h:1041
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition MemorySSA.h:692
LLVM_ABI MemorySSAWalker * getWalker()
MemoryUseOrDef * getMemoryAccess(const Instruction *I) const
Given a memory Mod/Ref'ing instruction, get the MemorySSA access associated with it.
Definition MemorySSA.h:710
bool isLiveOnEntryDef(const MemoryAccess *MA) const
Return true if MA represents the live on entry value.
Definition MemorySSA.h:730
Class that has the common methods + fields of memory uses/defs.
Definition MemorySSA.h:256
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:28
void push_back(const T &Elt)
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...
Definition StringRef.h:880
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Class to represent target extensions types, which are generally unintrospectable from target-independ...
StringRef getName() const
Return the name for this target extension type.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
Definition Value.cpp:985
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:210
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition DenseSet.h:183
An efficient, type-erasing, non-owning reference to a callable.
A raw_ostream that writes to an SmallVector or SmallString.
Abstract Attribute helper functions.
Definition Attributor.h:166
@ BARRIER
Address space for modeling barrier IDs as addresses.
@ LOCAL_ADDRESS
Address space for local memory.
@ VGPR
Address space for VGPRs.
GVUsesInfoTy getTransitiveUsesOfLDSForLowering(const CallGraph &CG, Module &M)
Collects all uses of LDS Global Variables in M using getUsesOfGVByFunction, with isLDSVariableToLower...
static constexpr unsigned NamedBarrierTypeSizeInBytes
SIAtomicAddrSpace toSIAtomicAddrSpace(unsigned LLVMAddrSpace)
bool isDynamicLDS(const GlobalVariable &GV)
static const StringMap< SIAtomicAddrSpace > ASNames
void removeFnAttrFromReachable(CallGraph &CG, Function *KernelRoot, ArrayRef< StringRef > FnAttrs)
Strip FnAttr attribute from any functions where we may have introduced its use.
bool eliminateGVConstantExprUsesFromAllInstructions(Module &M, function_ref< bool(const GlobalVariable &)> Filter)
Iterates over all GlobalVariables in M, and whenever Filter returns true, replace all constant users ...
LLVM_READNONE constexpr bool isKernel(CallingConv::ID CC)
SIAtomicAddrSpace
The distinct address spaces supported by the AMDGPU target for atomic memory operation.
@ ATOMIC
The address spaces that support atomic instructions.
@ FLAT
The address spaces that can be accessed by a FLAT instruction.
void getUsesOfGVByFunction(const CallGraph &CG, Module &M, function_ref< bool(const GlobalVariable &)> Filter, FunctionVariableMap &Kernels, FunctionVariableMap &Functions)
Finds uses of Global Variables on a per-function basis.
SIAtomicAddrSpace getSynchronizeAddrSpace(const MMRAMetadata &MMRA, const Function *DiagFn, const DebugLoc &DL)
Parses the values for the "amdgpu-synchronize-as" MMRA.
static constexpr SIAtomicAddrSpace LLVMToSIAtomicAddrSpaceMapping[]
bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA)
Given a Def clobbering a load from Ptr according to the MSSA check if this is actually a memory updat...
static TargetExtType * getTargetExtType(const GlobalVariable &GV)
MapVector< Function *, DenseSet< GlobalVariable * > > FunctionVariableMap
TargetExtType * isNamedBarrier(const GlobalVariable &GV)
bool isLDSVariableToLower(const GlobalVariable &GV)
Align getAlign(const DataLayout &DL, const GlobalVariable *GV)
unsigned getNumNamedBarriersDeclared(const DataLayout &DL, const GlobalVariable &GV)
unsigned getSyntheticApertureNumber(unsigned AS)
void copyMetadataForWidenedLoad(LoadInst &Dest, const LoadInst &Source)
bool isClobberedInFunction(const LoadInst *Load, MemorySSA *MSSA, AAResults *AA)
Check is a Load is clobbered in its function.
GVUsesInfoTy getTransitiveUsesOfGV(const CallGraph &CG, Module &M, function_ref< bool(const GlobalVariable &)> Filter)
Collects all uses of Global Variables in M using getUsesOfGVByFunction.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
@ Load
The value being inserted comes from a load (InsertElement only).
LLVM_ABI bool convertUsersOfConstantsToInstructions(ArrayRef< Constant * > Consts, Function *RestrictToFunc=nullptr, bool RemoveDeadConstants=true, bool IncludeSelf=false)
Replace constant expressions users of the given constants with instructions.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
bool set_union(S1Ty &S1, const S2Ty &S2)
set_union(A, B) - Compute A := A u B, return whether A changed.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
bool isAcquireOrStronger(AtomicOrdering AO)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
#define N
FunctionVariableMap DirectAccess
FunctionVariableMap IndirectAccess
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39