39 #define DEBUG_TYPE "amdgpu-lower-kernel-arguments" 66 auto &TPC = getAnalysis<TargetPassConfig>();
75 const Align KernArgBaseAlign(16);
76 const uint64_t BaseOffset = ST.getExplicitKernelArgOffset(F);
80 const uint64_t TotalKernArgSize = ST.getKernArgSegmentSize(F, MaxAlign);
81 if (TotalKernArgSize == 0)
85 Builder.CreateIntrinsic(Intrinsic::amdgcn_kernarg_segment_ptr, {}, {},
86 nullptr, F.
getName() +
".kernarg.segment");
93 uint64_t ExplicitArgOffset = 0;
101 uint64_t EltOffset =
alignTo(ExplicitArgOffset, ABITypeAlign) + BaseOffset;
102 ExplicitArgOffset =
alignTo(ExplicitArgOffset, ABITypeAlign) + AllocSize;
107 if (
PointerType *PT = dyn_cast<PointerType>(ArgTy)) {
114 !ST.hasUsableDSOffset())
119 if (
Arg.hasNoAliasAttr())
129 int64_t AlignDownOffset =
alignDown(EltOffset, 4);
130 int64_t OffsetDiff = EltOffset - AlignDownOffset;
132 KernArgBaseAlign, DoShiftOpt ? AlignDownOffset : EltOffset);
143 ArgPtr = Builder.CreateConstInBoundsGEP1_64(
144 Builder.getInt8Ty(), KernArgSegment, AlignDownOffset,
145 Arg.getName() +
".kernarg.offset.align.down");
148 ArgPtr = Builder.CreateConstInBoundsGEP1_64(
149 Builder.getInt8Ty(), KernArgSegment, EltOffset,
150 Arg.getName() +
".kernarg.offset");
151 AdjustedArgTy = ArgTy;
154 if (IsV3 && Size >= 32) {
157 AdjustedArgTy = V4Ty;
160 ArgPtr = Builder.CreateBitCast(ArgPtr, AdjustedArgTy->
getPointerTo(AS),
163 Builder.CreateAlignedLoad(AdjustedArgTy, ArgPtr, AdjustedAlign.
value());
168 if (isa<PointerType>(ArgTy)) {
169 if (
Arg.hasNonNullAttr())
172 uint64_t DerefBytes =
Arg.getDereferenceableBytes();
173 if (DerefBytes != 0) {
175 LLVMContext::MD_dereferenceable,
181 uint64_t DerefOrNullBytes =
Arg.getDereferenceableOrNullBytes();
182 if (DerefOrNullBytes != 0) {
184 LLVMContext::MD_dereferenceable_or_null,
187 DerefOrNullBytes))));
190 unsigned ParamAlign =
Arg.getParamAlignment();
191 if (ParamAlign != 0) {
193 LLVMContext::MD_align,
203 Value *ExtractBits = OffsetDiff == 0 ?
204 Load : Builder.CreateLShr(Load, OffsetDiff * 8);
207 Value *Trunc = Builder.CreateTrunc(ExtractBits, ArgIntTy);
208 Value *NewVal = Builder.CreateBitCast(Trunc, ArgTy,
209 Arg.getName() +
".load");
210 Arg.replaceAllUsesWith(NewVal);
214 Arg.getName() +
".load");
215 Arg.replaceAllUsesWith(Shuf);
218 Arg.replaceAllUsesWith(Load);
230 "AMDGPU Lower Kernel Arguments",
false,
false)
234 char AMDGPULowerKernelArguments::
ID = 0;
237 return new AMDGPULowerKernelArguments();
Type * getVectorElementType() const
A parsed version of the target data layout string in and methods for querying it. ...
This class represents an incoming formal argument to a Function.
AMDGPU specific subclass of TargetSubtarget.
This class represents lattice values for constants.
ConstantAsMetadata * createConstant(Constant *C)
Return the given constant as metadata.
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
This class represents a function call, abstracting a target machine's calling convention.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
An instruction for reading from memory.
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
iterator begin()
Instruction iterator methods.
uint64_t alignDown(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the largest uint64_t less than or equal to Value and is Skew mod Align.
AnalysisUsage & addRequired()
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
LLVMContext & getContext() const
Get the global data context.
static Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
This file contains the simple types necessary to represent the attributes associated with functions a...
void setName(const Twine &Name)
Change the name of the value.
uint64_t getNumElements() const
For scalable vectors, this will return the minimum number of elements in the vector.
Align commonAlignment(Align A, Align B)
Returns the alignment that satisfies both alignments.
Target-Independent Code Generator Pass Configuration Options.
Address space for region memory. (GDS)
Type * getType() const
All values are typed, get the type of this value.
uint64_t value() const
This is a hole in the type system and should not be abused.
Class to represent pointers.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
static bool runOnFunction(Function &F, bool PostInlining)
FunctionPass * createAMDGPULowerKernelArgumentsPass()
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
AMDGPU Lower Kernel Arguments
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Class to represent integer types.
The AMDGPU TargetMachine interface definition for hw codgen targets.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Align max(MaybeAlign Lhs, Align Rhs)
INITIALIZE_PASS_BEGIN(AMDGPULowerKernelArguments, DEBUG_TYPE, "AMDGPU Lower Kernel Arguments", false, false) INITIALIZE_PASS_END(AMDGPULowerKernelArguments
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Address space for local memory.
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
bool isAggregateType() const
Return true if the type is an aggregate type.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Class to represent vector types.
void setPreservesAll()
Set by analyses that do not transform their input at all.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
static IntegerType * getInt32Ty(LLVMContext &C)
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
StringRef getName() const
Return a constant reference to the value's name.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Primary interface to the complete machine description for the target machine.
Calling convention for AMDGPU code object kernels.
iterator_range< arg_iterator > args()