Go to the documentation of this file.
26 #define DEBUG_TYPE "amdgpu-promote-kernel-arguments"
32 class AMDGPUPromoteKernelArguments :
public FunctionPass {
41 void enqueueUsers(
Value *Ptr);
43 bool promotePointer(
Value *Ptr);
65 void AMDGPUPromoteKernelArguments::enqueueUsers(
Value *Ptr) {
68 while (!PtrUsers.empty()) {
69 Instruction *U = dyn_cast<Instruction>(PtrUsers.pop_back_val());
78 if (
LD->getPointerOperand()->stripInBoundsOffsets() == Ptr &&
84 case Instruction::GetElementPtr:
85 case Instruction::AddrSpaceCast:
86 case Instruction::BitCast:
94 bool AMDGPUPromoteKernelArguments::promotePointer(
Value *Ptr) {
97 LoadInst *LI = dyn_cast<LoadInst>(Ptr);
99 Changed |= promoteLoad(LI);
113 IRBuilder<> B(LI ? &*std::next(cast<Instruction>(Ptr)->getIterator())
121 B.CreateAddrSpaceCast(Ptr, NewPT,
Twine(Ptr->
getName(),
".global"));
123 B.CreateAddrSpaceCast(Cast, PT,
Twine(Ptr->
getName(),
".flat"));
125 [Cast](
Use &U) {
return U.
getUser() != Cast; });
130 bool AMDGPUPromoteKernelArguments::promoteLoad(
LoadInst *LI) {
142 AllocaInst *AI = dyn_cast<AllocaInst>(&*InsPt);
176 Ptrs.push_back(&
Arg);
179 bool Changed =
false;
180 while (!Ptrs.empty()) {
181 Value *Ptr = Ptrs.pop_back_val();
182 Changed |= promotePointer(Ptr);
189 MemorySSA &MSSA = getAnalysis<MemorySSAWrapperPass>().getMSSA();
190 AliasAnalysis &
AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
195 "AMDGPU Promote Kernel Arguments",
false,
false)
201 char AMDGPUPromoteKernelArguments::
ID = 0;
204 return new AMDGPUPromoteKernelArguments();
212 if (AMDGPUPromoteKernelArguments().run(
F, MSSA,
AA)) {
A set of analyses that are preserved following a run of a transformation pass.
This class represents an incoming formal argument to a Function.
A manager for alias analyses.
This is an optimization pass for GlobalISel generic memory operations.
InstListType::iterator iterator
Instruction iterators...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
user_iterator user_begin()
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
LLVM Basic Block Representation.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Legacy analysis pass which computes MemorySSA.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool isClobberedInFunction(const LoadInst *Load, MemorySSA *MSSA, AAResults *AA)
Check is a Load is clobbered in its function.
User * getUser() const
Returns the User that contains this Use.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
void preserve()
Mark an analysis as preserved.
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
Encapsulates MemorySSA, including all data associated with memory accesses.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
Class to represent pointers.
An analysis that produces MemorySSA for a function.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
Type * getType() const
All values are typed, get the type of this value.
Represents analyses that only rely on functions' control flow.
LLVMContext & getContext() const
All values hold a context through their type.
StringRef getName() const
Return a constant reference to the value's name.
An instruction for reading from memory.
const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
@ AMDGPU_KERNEL
Calling convention for AMDGPU code object kernels.
static bool runOnFunction(Function &F, bool PostInlining)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void setPreservesAll()
Set by analyses that do not transform their input at all.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
FunctionPass * createAMDGPUPromoteKernelArgumentsPass()
void preserveSet()
Mark an analysis set as preserved.
static PointerType * getWithSamePointeeType(PointerType *PT, unsigned AddressSpace)
This constructs a pointer type with the same pointee type as input PointerType (or opaque pointer if ...
@ FLAT_ADDRESS
Address space for flat memory.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
A container for analyses that lazily runs them and caches their results.
FunctionPass class - This class is used to implement most global optimizations.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
void replaceUsesWithIf(Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)
Go through the uses list for this definition and make each use point to "V" if the callback ShouldRep...
AnalysisUsage & addRequired()
an instruction to allocate memory on the stack
Value * getOperand(unsigned i) const
LLVM Value Representation.
iterator_range< user_iterator > users()
A Use represents the edge between a Value definition and its users.