26 static const unsigned MaxNumRegsForArgsRet = 16;
32 bool CoerceGenericPtrArgToGlobal;
34 ArgInfo classifyReturnType(
const Type *RetTy)
const;
35 ArgInfo classifyKernelArgumentType(
const Type *Ty)
const;
36 ArgInfo classifyArgumentType(
const Type *Ty,
bool Variadic,
37 unsigned &NumRegsLeft)
const;
44 bool CoerceGenericPtrArgToGlobal)
46 CoerceGenericPtrArgToGlobal(CoerceGenericPtrArgToGlobal) {}
58uint64_t AMDGPUTargetInfo::getNumRegsForType(
const Type *Ty)
const {
64 const Type *EltTy = VT->getElementType();
65 uint64_t EltSize = EltTy->getSizeInBits().getFixedValue();
66 unsigned NumElts = VT->getNumElements().getFixedValue();
70 return (NumElts + 1) / 2;
72 uint64_t EltNumRegs = (EltSize + 31) / 32;
73 return EltNumRegs * NumElts;
77 for (
const FieldInfo &
Field : RT->getFields())
78 NumRegs += getNumRegsForType(
Field.FieldType);
82 return (Ty->getSizeInBits().getFixedValue() + 31) / 32;
85ArgInfo AMDGPUTargetInfo::classifyReturnType(
const Type *RetTy)
const {
96 if (RT && RT->isEmpty())
103 if (RT && RT->hasFlexibleArrayMember())
115 const Type *I32Ty =
TB.getIntegerType(32,
Align(4),
false);
119 if (getNumRegsForType(RetTy) <= MaxNumRegsForArgsRet)
130ArgInfo AMDGPUTargetInfo::classifyKernelArgumentType(
const Type *Ty)
const {
138 if (CoerceGenericPtrArgToGlobal) {
141 const Type *Coerced =
142 TB.getPointerType(PtrTy->getSizeInBits().getFixedValue(),
162ArgInfo AMDGPUTargetInfo::classifyArgumentType(
const Type *Ty,
bool Variadic,
163 unsigned &NumRegsLeft)
const {
164 assert(NumRegsLeft <= MaxNumRegsForArgsRet &&
"register estimate underflow");
171 std::nullopt,
false);
182 if (Ty->isEmptyRecord())
190 RT && RT->hasFlexibleArrayMember())
196 unsigned NumRegs = (
Size + 31) / 32;
197 NumRegsLeft -= std::min(NumRegsLeft, NumRegs);
205 const Type *I32Ty =
TB.getIntegerType(32,
Align(4),
false);
209 if (NumRegsLeft > 0) {
210 uint64_t NumRegs = getNumRegsForType(Ty);
211 if (NumRegsLeft >= NumRegs) {
212 NumRegsLeft -= NumRegs;
224 if (!AI.isIndirect()) {
225 uint64_t NumRegs = getNumRegsForType(Ty);
226 NumRegsLeft -= std::min(NumRegs,
uint64_t{NumRegsLeft});
240 unsigned ArgumentIndex = 0;
243 unsigned NumRegsLeft = MaxNumRegsForArgsRet;
246 Arg.Info = classifyKernelArgumentType(Arg.ABIType);
248 bool FixedArgument = ArgumentIndex++ < NumFixedArguments;
249 Arg.Info = classifyArgumentType(Arg.ABIType, !FixedArgument, NumRegsLeft);
254std::unique_ptr<TargetInfo>
256 return std::make_unique<AMDGPUTargetInfo>(TB,
ABICompatInfo(),
257 CoerceGenericPtrArgToGlobal);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU address space definition.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Default ABI classification shared by targets without special rules.
OptimizedStructLayoutField Field
Target-specific ABI information and factory functions.
The instances of the Type class are immutable: once they are created, they are never changed.
void computeInfo(FunctionInfo &FI) const override
Populate FI with the target's ABI-lowering decisions for each argument and return value.
const ABICompatInfo & getABICompatInfo() const override
Return this target's ABI compatibility flags.
AMDGPUTargetInfo(TypeBuilder &TypeBuilder, const ABICompatInfo &Compat, bool CoerceGenericPtrArgToGlobal)
unsigned getAllocaAddrSpace() const override
Indirect arguments live in the private (alloca) address space on AMDGPU.
Helper class to encapsulate information about how a specific type should be passed to or returned fro...
static ArgInfo getIgnore()
static ArgInfo getIndirectAliased(Align Align, unsigned AddrSpace, bool Realign=false)
An aliased indirect argument.
static ArgInfo getIndirect(Align Align, bool ByVal, unsigned AddrSpace=0, bool Realign=false)
Realign: the caller couldn't guarantee sufficient alignment - the callee must copy the argument to a ...
static ArgInfo getDirect(const Type *T=nullptr, unsigned Offset=0, MaybeAlign Align=std::nullopt, bool CanBeFlattened=true)
Self-consistent classification that conforms to no particular ABI.
ArgInfo classifyArgumentType(const Type *Ty) const
ArgInfo classifyReturnType(const Type *RetTy) const
ArrayRef< ArgEntry > arguments() const
unsigned getNumRequiredArgs() const
CallingConv::ID getCallingConvention() const
ArgInfo & getReturnInfo()
const Type * getReturnType() const
LLVM_ABI const Type * isSingleElementStruct(const Type *Ty) const
Returns the scalar a single-element struct reduces to, else null.
LLVM_ABI bool maybeCommonClassifyReturnType(FunctionInfo &FI) const
Apply rules for classifying return types that are common to all targets.
LLVM_ABI bool isAggregateTypeForABI(const Type *Ty) const
LLVM_ABI const Type * useFirstFieldIfTransparentUnion(const Type *Ty) const
If Ty is a transparent union, return its first field type; otherwise return Ty unchanged.
LLVM_ABI RecordArgABI getRecordArgABI(const RecordType *RT) const
TypeBuilder manages the lifecycle of ABI types using bump pointer allocation.
Represents the ABI-specific view of a type in LLVM.
This file defines the type system for the LLVMABI library, which mirrors ABI-relevant aspects of fron...
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
@ FLAT_ADDRESS
Address space for flat memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
@ PRIVATE_ADDRESS
Address space for private memory.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
LLVM_ABI std::unique_ptr< TargetInfo > createAMDGPUTargetInfo(TypeBuilder &TB, bool CoerceGenericPtrArgToGlobal=false)
@ RAA_DirectInMemory
Pass it on the stack using its defined layout.
@ RAA_Default
Pass it using the normal C aggregate rules for the ABI, potentially introducing extra copies and pass...
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.
Flags controlling ABI compatibility behaviour that applies to every target.