36 : ValueHandler(B, MRI, AssignFn), MIB(MIB) {}
40 bool isIncomingArgumentHandler()
const override {
return false; }
58 ExtReg = MIRBuilder.buildAnyExt(
LLT::scalar(32), ValVReg).getReg(0);
60 ExtReg = extendRegister(ValVReg, VA);
62 MIRBuilder.buildCopy(PhysReg, ExtReg);
66 bool assignArg(
unsigned ValNo,
MVT ValVT,
MVT LocVT,
71 return AssignFn(ValNo, ValVT, LocVT, LocInfo, Flags, State);
76 uint64_t StackUsed = 0;
80 : ValueHandler(B, MRI, AssignFn) {}
84 auto &MFI = MIRBuilder.getMF().getFrameInfo();
85 int FI = MFI.CreateFixedObject(Size, Offset,
true);
87 Register AddrReg =
MRI.createGenericVirtualRegister(
89 MIRBuilder.buildFrameIndex(AddrReg, FI);
90 StackUsed =
std::max(StackUsed, Size + Offset);
96 markPhysRegUsed(PhysReg);
102 MIRBuilder.buildTrunc(ValVReg, Copy);
107 case CCValAssign::LocInfo::SExt:
108 case CCValAssign::LocInfo::ZExt:
109 case CCValAssign::LocInfo::AExt: {
111 MIRBuilder.buildTrunc(ValVReg, Copy);
115 MIRBuilder.buildCopy(ValVReg, PhysReg);
123 auto MMO = MIRBuilder.getMF().getMachineMemOperand(
125 MIRBuilder.buildLoad(ValVReg, Addr, *MMO);
131 virtual void markPhysRegUsed(
unsigned PhysReg) = 0;
134 bool isIncomingArgumentHandler()
const override {
return true; }
137 struct FormalArgHandler :
public IncomingArgHandler {
140 : IncomingArgHandler(B, MRI, AssignFn) {}
142 void markPhysRegUsed(
unsigned PhysReg)
override {
143 MIRBuilder.getMBB().addLiveIn(PhysReg);
153 void AMDGPUCallLowering::splitToValueTypes(
156 SplitArgTy PerformArgSplit)
const {
169 for (
EVT VT : SplitVTs) {
171 Type *Ty = VT.getTypeForEVT(Ctx);
195 for (
unsigned i = 0; i < NumParts; ++i) {
201 PerformArgSplit(SplitRegs, LLTy, PartLLT, SplitIdx);
223 assert(DstRegs.
size() > 1 &&
"Nothing to unpack");
236 for (
int i = 0,
e = DstRegs.
size(); i !=
e; ++i)
237 B.
buildAnyExt(DstRegs[i], UnmergeToEltTy.getReg(i));
241 if (SrcSize % PartSize == 0) {
246 const int NumRoundedParts = (SrcSize + PartSize - 1) / PartSize;
255 for (
unsigned i = 0,
e = DstRegs.
size(); i !=
e; ++i, Offset += PartSize)
267 auto &MF = B.
getMF();
268 const auto &
F = MF.getFunction();
275 ArgInfo OrigRetInfo(VRegs, Val->
getType());
280 OrigRetInfo, SplitRetInfos, DL, MRI, CC,
287 OutgoingValueHandler RetHandler(B, MF.getRegInfo(),
Ret, AssignFn);
300 assert(!Val == VRegs.
empty() &&
"Return value without a vreg");
304 const bool IsWaveEnd = (IsShader && MFI->
returnsVoid()) ||
315 IsShader ? AMDGPU::SI_RETURN_TO_EPILOG : AMDGPU::S_SETPC_B64_return;
319 if (ReturnOpc == AMDGPU::S_SETPC_B64_return) {
321 Ret.
addUse(ReturnAddrVReg);
324 if (!lowerReturnVal(B, Val, VRegs, Ret))
327 if (ReturnOpc == AMDGPU::S_SETPC_B64_return) {
330 &AMDGPU::SGPR_64RegClass);
331 B.
buildCopy(ReturnAddrVReg, LiveInReturn);
342 uint64_t Offset)
const {
351 Register DstReg = MRI.createGenericVirtualRegister(PtrType);
354 Register KernArgSegmentVReg = MRI.getLiveInVirtReg(KernArgSegmentPtr);
359 B.
buildPtrAdd(DstReg, KernArgSegmentVReg, OffsetReg);
365 Type *ParamTy, uint64_t Offset,
373 Register PtrReg = lowerParameterPtr(B, ParamTy, Offset);
393 MF.
addLiveIn(PrivateSegmentBufferReg, &AMDGPU::SGPR_128RegClass);
399 MF.
addLiveIn(DispatchPtrReg, &AMDGPU::SGPR_64RegClass);
405 MF.
addLiveIn(QueuePtrReg, &AMDGPU::SGPR_64RegClass);
422 MF.
addLiveIn(DispatchIDReg, &AMDGPU::SGPR_64RegClass);
428 MF.
addLiveIn(FlatScratchInitReg, &AMDGPU::SGPR_64RegClass);
454 const unsigned KernArgBaseAlign = 16;
456 uint64_t ExplicitArgOffset = 0;
461 unsigned AllocSize = DL.getTypeAllocSize(ArgTy);
465 unsigned ABIAlign = DL.getABITypeAlignment(ArgTy);
467 uint64_t ArgOffset =
alignTo(ExplicitArgOffset, ABIAlign) + BaseOffset;
468 ExplicitArgOffset =
alignTo(ExplicitArgOffset, ABIAlign) + AllocSize;
472 OrigArgRegs.
size() == 1
474 : MRI.createGenericVirtualRegister(
getLLTForType(*ArgTy, DL));
475 unsigned Align =
MinAlign(KernArgBaseAlign, ArgOffset);
476 ArgOffset =
alignTo(ArgOffset, DL.getABITypeAlignment(ArgTy));
477 lowerParameter(B, ArgTy, ArgOffset, Align, ArgReg);
478 if (OrigArgRegs.
size() > 1)
504 if (DstElts % PartElts == 0)
508 assert(PartElts == 2 && DstElts % 2 != 0);
509 int RoundedElts = PartElts * ((DstElts + PartElts - 1) / PartElts);
531 if (DstEltTy == PartLLT) {
540 }
else if (DstEltTy.getSizeInBits() > PartLLT.
getSizeInBits()) {
544 int PartsPerElt = DstEltTy.getSizeInBits() / PartLLT.
getSizeInBits();
592 Register ReturnAddrReg = TRI->getReturnAddressReg(MF);
594 &AMDGPU::SGPR_64RegClass);
596 B.
buildCopy(LiveInReturn, ReturnAddrReg);
601 MF.
addLiveIn(ImplicitBufferPtrReg, &AMDGPU::SGPR_64RegClass);
602 CCInfo.AllocateReg(ImplicitBufferPtrReg);
608 unsigned PSInputNum = 0;
614 const bool InReg =
Arg.hasAttribute(Attribute::InReg);
617 if (!IsShader && InReg)
620 if (
Arg.hasAttribute(Attribute::SwiftSelf) ||
621 Arg.hasAttribute(Attribute::SwiftError) ||
622 Arg.hasAttribute(Attribute::Nest))
626 const bool ArgUsed = !
Arg.use_empty();
638 for (
int I = 0,
E = VRegs[Idx].
size();
I !=
E; ++
I)
650 OrigArg, SplitArgs, DL, MRI, CC,
678 CCInfo.AllocateReg(AMDGPU::VGPR0);
679 CCInfo.AllocateReg(AMDGPU::VGPR1);
684 if (Subtarget.isAmdPalOS()) {
694 if ((PsInputBits & 0x7F) == 0 ||
695 ((PsInputBits & 0xF) == 0 &&
696 (PsInputBits >> 11 & 1)))
708 FormalArgHandler Handler(B, MRI, AssignFn);
unsigned addImplicitBufferPtr(const SIRegisterInfo &TRI)
unsigned getFrameOffsetReg() const
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
unsigned getScratchWaveOffsetReg() const
bool hasDispatchPtr() const
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
A parsed version of the target data layout string in and methods for querying it. ...
reference emplace_back(ArgTypes &&... Args)
Interface definition for SIRegisterInfo.
bool hasPrivateSegmentBuffer() const
static void allocateHSAUserSGPRs(CCState &CCInfo, MachineIRBuilder &B, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info)
static LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
MachineInstrBuilder buildUnmerge(ArrayRef< LLT > Res, const SrcOp &Op)
Build and insert Res0, ...
AMDGPU specific subclass of TargetSubtarget.
bool isPSInputAllocated(unsigned Index) const
This class represents lattice values for constants.
MachineInstrBuilder buildInsert(Register Res, Register Src, Register Op, unsigned Index)
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Certain targets require unusual breakdowns of certain types.
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
void push_back(const T &Elt)
unsigned addLiveIn(unsigned PReg, const TargetRegisterClass *RC)
addLiveIn - Add the specified physical register as a live-in value and create a corresponding virtual...
This file describes how to lower LLVM calls to machine code calls.
bool handleAssignments(MachineIRBuilder &MIRBuilder, SmallVectorImpl< ArgInfo > &Args, ValueHandler &Handler) const
Invoke Handler::assignArg on each of the given Args and then use Callback to move them to the assigne...
void allocateSpecialInputVGPRs(CCState &CCInfo, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info) const
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
unsigned addKernargSegmentPtr(const SIRegisterInfo &TRI)
bool hasImplicitBufferPtr() const
MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1)
Build and insert Res = G_PTR_ADD Op0, Op1.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change...
LLT getType(unsigned Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register...
unsigned getPSInputAddr() const
unsigned const TargetRegisterInfo * TRI
void markPSInputEnabled(unsigned Index)
bool hasDispatchID() const
SmallVector< ISD::ArgFlagsTy, 4 > Flags
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
MachineInstrBuilder buildExtract(const DstOp &Res, const SrcOp &Src, uint64_t Index)
Build and insert `Res0, ...
bool hasFlatScratchInit() const
unsigned countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
A description of a memory reference used in the backend.
MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ANYEXT Op0.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
unsigned addDispatchID(const SIRegisterInfo &TRI)
void setIfReturnsVoid(bool Value)
The returned value is undefined.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
The memory access is dereferenceable (i.e., doesn't trap).
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
LocInfo getLocInfo() const
LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
Type * getType() const
All values are typed, get the type of this value.
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
void allocateSpecialInputSGPRs(CCState &CCInfo, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info) const
MachineFunction & getMF()
Getter for the function we currently build.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
void markPSInputAllocated(unsigned Index)
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
Analysis containing CSE Info
Class to represent pointers.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
bool isVoidTy() const
Return true if this is 'void'.
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
MachineRegisterInfo * getMRI()
Getter for MRI.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
The instances of the Type class are immutable: once they are created, they are never changed...
void allocateSpecialEntryInputVGPRs(CCState &CCInfo, MachineFunction &MF, const SIRegisterInfo &TRI, SIMachineFunctionInfo &Info) const
This is an important class for using LLVM in a threaded context.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
MachineInstrBuilder buildBuildVector(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_BUILD_VECTOR Op0, ...
unsigned getReturnAddressReg(const MachineFunction &MF) const
bool isEntryFunctionCC(CallingConv::ID CC)
Helper class to build MachineInstr.
void setType(unsigned VReg, LLT Ty)
Set the low-level type of VReg to Ty.
SI DAG Lowering interface definition.
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
unsigned addQueuePtr(const SIRegisterInfo &TRI)
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_TRUNC Op.
Argument handling is mostly uniform between the four places that make these decisions: function forma...
This class contains a discriminated union of information about pointers in memory operands...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
unsigned addDispatchPtr(const SIRegisterInfo &TRI)
static CCAssignFn * CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg)
Selects the correct CCAssignFn for a given CallingConvention value.
LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
void unpackRegs(ArrayRef< Register > DstRegs, Register SrcReg, Type *PackedTy, MachineIRBuilder &MIRBuilder) const
Generate instructions for unpacking SrcReg into the DstRegs corresponding to the aggregate type Packe...
void allocateSystemSGPRs(CCState &CCInfo, MachineFunction &MF, SIMachineFunctionInfo &Info, CallingConv::ID CallConv, bool IsShader) const
bool lowerFormalArguments(MachineIRBuilder &B, const Function &F, ArrayRef< ArrayRef< Register >> VRegs) const override
This hook must be implemented to lower the incoming (formal) arguments, described by VRegs...
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
CCState - This class holds information needed while lowering arguments and return values...
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
bool hasKernargSegmentPtr() const
Align max(MaybeAlign Lhs, Align Rhs)
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Interface definition of the TargetLowering class that is common to all AMD GPUs.
unsigned getExplicitKernelArgOffset(const Function &F) const
Returns the offset in bytes from the start of the input buffer of the first explicit kernel argument...
Calling convention used for Mesa/AMDPAL pixel shaders.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
unsigned getScratchRSrcReg() const
Returns the physical register reserved for use as the resource descriptor for scratch accesses...
CCValAssign - Represent assignment of one arg/retval to a location.
bool lowerFormalArgumentsKernel(MachineIRBuilder &B, const Function &F, ArrayRef< ArrayRef< Register >> VRegs) const
unsigned getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
LLVM_READNONE bool isKernel(CallingConv::ID CC)
const Function & getFunction() const
Return the LLVM function that this machine code represents.
This file declares the MachineIRBuilder class.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
bool isShader(CallingConv::ID cc)
unsigned addPrivateSegmentBuffer(const SIRegisterInfo &TRI)
unsigned addFlatScratchInit(const SIRegisterInfo &TRI)
static CCAssignFn * CCAssignFnForReturn(CallingConv::ID CC, bool IsVarArg)
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
The memory access reads data.
unsigned getPSInputEnable() const
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Provides AMDGPU specific target descriptions.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
bool lowerReturn(MachineIRBuilder &B, const Value *Val, ArrayRef< Register > VRegs) const override
This hook behaves as the extended lowerReturn function, but for targets that do not support swifterro...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
void setMBB(MachineBasicBlock &MBB)
Set the insertion point to the end of MBB.
MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
The memory access always returns the same value (or traps).
Address space for private memory.
static void packSplitRegsToOrigType(MachineIRBuilder &B, ArrayRef< Register > OrigRegs, ArrayRef< Register > Regs, LLT LLTy, LLT PartLLT)
static void unpackRegsToOrigType(MachineIRBuilder &B, ArrayRef< Register > DstRegs, Register SrcReg, LLT SrcTy, LLT PartTy)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
static LLT getMultipleType(LLT OrigTy, int Factor)
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
MachineInstrBuilder buildMerge(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ...
SmallVector< Register, 4 > Regs
MachineInstrBuilder buildUndef(const DstOp &Res)
Build and insert Res = IMPLICIT_DEF.
static LLT vector(uint16_t NumElements, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
MachineInstrBuilder buildConcatVectors(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_CONCAT_VECTORS Op0, ...
unsigned AllocateReg(unsigned Reg)
AllocateReg - Attempt to allocate one register.
Calling convention for AMDGPU code object kernels.
AMDGPUCallLowering(const AMDGPUTargetLowering &TLI)
Address space for constant memory (VTX2).
iterator_range< arg_iterator > args()
Wrapper class representing virtual and physical registers.
bool empty() const
empty - Check if the array is empty.
Register getPreloadedReg(AMDGPUFunctionArgInfo::PreloadedValue Value) const
const SIRegisterInfo * getRegisterInfo() const override