30 assignValueToReg(VReg, VA, VT);
32 assignValueToAddress(VReg, VA);
41 unsigned ArgLocsStartIndex,
43 for (
unsigned i = 0; i < VRegs.
size(); ++i)
44 if (!assign(VRegs[i], ArgLocs[ArgLocsStartIndex + i], VT))
51 if (!MIRBuilder.getMF().getDataLayout().isLittleEndian())
59 const Function &
F = MIRBuilder.getMF().getFunction();
62 MIRBuilder.getMF().getSubtarget().getTargetLowering());
64 for (
unsigned ArgsIndex = 0, ArgLocsIndex = 0; ArgsIndex < Args.
size();
65 ++ArgsIndex, ArgLocsIndex += SplitLength) {
69 assert(Args[ArgsIndex].Regs.
size() == 1 &&
"Can't handle multple regs yet");
71 if (SplitLength > 1) {
75 for (
unsigned i = 0; i < SplitLength; ++i)
78 if (!handleSplit(VRegs, ArgLocs, ArgLocsIndex, Args[ArgsIndex].Regs[0],
82 if (!assign(Args[ArgsIndex].Regs[0], ArgLocs[ArgLocsIndex], VT))
97 const EVT &VT)
override;
108 virtual void markPhysRegUsed(
unsigned PhysReg) {
115 Register Addr = getStackAddress(VA, MMO);
120 class CallReturnHandler :
public IncomingValueHandler {
124 : IncomingValueHandler(MIRBuilder, MRI), MIB(MIB) {}
127 void markPhysRegUsed(
unsigned PhysReg)
override {
136 void IncomingValueHandler::assignValueToReg(
Register ValVReg,
140 static_cast<const MipsSubtarget &
>(MIRBuilder.getMF().getSubtarget());
142 if (VT ==
MVT::f64 && PhysReg >= Mips::A0 && PhysReg <= Mips::A3) {
144 static_cast<const MipsSubtarget &
>(MIRBuilder.getMF().getSubtarget());
147 .buildInstr(STI.
isFP64bit() ? Mips::BuildPairF64_64
150 .addUse(PhysReg + (STI.
isLittle() ? 0 : 1))
151 .addUse(PhysReg + (STI.
isLittle() ? 1 : 0))
154 markPhysRegUsed(PhysReg);
155 markPhysRegUsed(PhysReg + 1);
156 }
else if (VT ==
MVT::f32 && PhysReg >= Mips::A0 && PhysReg <= Mips::A3) {
157 MIRBuilder.buildInstr(Mips::MTC1)
162 markPhysRegUsed(PhysReg);
165 case CCValAssign::LocInfo::SExt:
166 case CCValAssign::LocInfo::ZExt:
167 case CCValAssign::LocInfo::AExt: {
168 auto Copy = MIRBuilder.buildCopy(
LLT{VA.
getLocVT()}, PhysReg);
169 MIRBuilder.buildTrunc(ValVReg, Copy);
173 MIRBuilder.buildCopy(ValVReg, PhysReg);
176 markPhysRegUsed(PhysReg);
196 MIRBuilder.buildFrameIndex(AddrReg, FI);
201 void IncomingValueHandler::assignValueToAddress(
Register ValVReg,
207 buildLoad(LoadReg, VA);
208 MIRBuilder.buildTrunc(ValVReg, LoadReg);
210 buildLoad(ValVReg, VA);
215 unsigned ArgLocsStartIndex,
217 if (!assignVRegs(VRegs, ArgLocs, ArgLocsStartIndex, VT))
219 setLeastSignificantFirst(VRegs);
220 MIRBuilder.buildMerge(ArgsReg, VRegs);
233 const EVT &VT)
override;
250 void OutgoingValueHandler::assignValueToReg(
Register ValVReg,
255 static_cast<const MipsSubtarget &
>(MIRBuilder.getMF().getSubtarget());
257 if (VT ==
MVT::f64 && PhysReg >= Mips::A0 && PhysReg <= Mips::A3) {
259 .buildInstr(STI.
isFP64bit() ? Mips::ExtractElementF64_64
261 .addDef(PhysReg + (STI.
isLittle() ? 1 : 0))
267 .buildInstr(STI.
isFP64bit() ? Mips::ExtractElementF64_64
269 .addDef(PhysReg + (STI.
isLittle() ? 0 : 1))
274 }
else if (VT ==
MVT::f32 && PhysReg >= Mips::A0 && PhysReg <= Mips::A3) {
275 MIRBuilder.buildInstr(Mips::MFC1)
281 Register ExtReg = extendRegister(ValVReg, VA);
282 MIRBuilder.buildCopy(PhysReg, ExtReg);
294 Register SPReg =
MRI.createGenericVirtualRegister(p0);
295 MIRBuilder.buildCopy(SPReg,
Register(Mips::SP));
297 Register OffsetReg =
MRI.createGenericVirtualRegister(s32);
299 MIRBuilder.buildConstant(OffsetReg, Offset);
301 Register AddrReg =
MRI.createGenericVirtualRegister(p0);
302 MIRBuilder.buildPtrAdd(AddrReg, SPReg, OffsetReg);
313 void OutgoingValueHandler::assignValueToAddress(
Register ValVReg,
316 Register Addr = getStackAddress(VA, MMO);
317 Register ExtReg = extendRegister(ValVReg, VA);
318 MIRBuilder.buildStore(ExtReg, Addr, *MMO);
326 Register ExtReg =
MRI.createGenericVirtualRegister(LocTy);
327 MIRBuilder.buildSExt(ExtReg, ValReg);
331 Register ExtReg =
MRI.createGenericVirtualRegister(LocTy);
332 MIRBuilder.buildZExt(ExtReg, ValReg);
336 Register ExtReg =
MRI.createGenericVirtualRegister(LocTy);
337 MIRBuilder.buildAnyExt(ExtReg, ValReg);
351 unsigned ArgLocsStartIndex,
353 MIRBuilder.buildUnmerge(VRegs, ArgsReg);
354 setLeastSignificantFirst(VRegs);
355 if (!assignVRegs(VRegs, ArgLocs, ArgLocsStartIndex, VT))
390 return CCValAssign::LocInfo::SExt;
392 return CCValAssign::LocInfo::ZExt;
393 return CCValAssign::LocInfo::AExt;
396 template <
typename T>
399 for (
unsigned i = 0; i < ArgLocs.
size(); ++i) {
402 Arguments[i].VT, Arguments[i].ArgVT, Arguments[i].Flags);
422 if (!VRegs.
empty()) {
433 splitToValueTypes(DL, ArgRetInfo, 0, RetInfos, OrigArgIndices);
436 subTargetRegTypeForCallingConv(F, RetInfos, OrigArgIndices, Outs);
444 OutgoingValueHandler RetHandler(MIRBuilder, MF.
getRegInfo(),
Ret);
445 if (!RetHandler.handle(ArgLocs, RetInfos)) {
476 ArgInfos.push_back(AInfo);
482 subTargetRegTypeForCallingConv(F, ArgInfos, OrigArgIndices, Ins);
496 IncomingValueHandler Handler(MIRBuilder, MF.
getRegInfo());
497 if (!Handler.handle(ArgLocs, ArgInfos))
502 unsigned Idx = CCInfo.getFirstUnallocated(ArgRegs);
505 unsigned RegSize = 4;
506 if (ArgRegs.
size() == Idx)
507 VaArgOffset =
alignTo(CCInfo.getNextStackOffset(), RegSize);
511 (
int)(RegSize * (ArgRegs.
size() - Idx));
518 for (
unsigned I = Idx;
I < ArgRegs.
size(); ++
I, VaArgOffset += RegSize) {
530 MIRBuilder.
buildStore(Copy, FrameIndex, *MMO);
546 if (
Arg.Flags[0].isByVal())
548 if (
Arg.Flags[0].isSRet() && !
Arg.Ty->isPointerTy())
564 MIRBuilder.
buildInstr(Mips::ADJCALLSTACKDOWN);
566 const bool IsCalleeGlobalPIC =
570 Info.
Callee.
isReg() || IsCalleeGlobalPIC ? Mips::JALRPseudo : Mips::JAL);
572 if (IsCalleeGlobalPIC) {
586 FuncOrigArgs.reserve(Info.
OrigArgs.size());
595 FuncOrigArgs.push_back(Entry);
603 subTargetRegTypeForCallingConv(F, ArgInfos, OrigArgIndices, Outs);
606 bool IsCalleeVarArg =
false;
620 OutgoingValueHandler RetHandler(MIRBuilder, MF.getRegInfo(), MIB);
621 if (!RetHandler.handle(ArgLocs, ArgInfos)) {
625 unsigned NextStackOffset = CCInfo.getNextStackOffset();
628 NextStackOffset =
alignTo(NextStackOffset, StackAlignment);
631 if (IsCalleeGlobalPIC) {
638 if (MIB->
getOpcode() == Mips::JALRPseudo) {
649 splitToValueTypes(DL, Info.
OrigRet, 0, ArgInfos, OrigRetIndices);
652 subTargetRegTypeForCallingConv(F, ArgInfos, OrigRetIndices, Ins);
662 CallReturnHandler Handler(MIRBuilder, MF.getRegInfo(), MIB);
663 if (!Handler.handle(ArgLocs, ArgInfos))
672 template <
typename T>
673 void MipsCallLowering::subTargetRegTypeForCallingConv(
680 for (
auto &
Arg : Args) {
688 for (
unsigned i = 0; i < NumRegs; ++i) {
696 ISDArgs.
emplace_back(Flags, RegisterVT, VT,
true, OrigArgIndices[ArgNo],
703 void MipsCallLowering::splitToValueTypes(
715 for (
unsigned i = 0; i < SplitEVTs.
size(); ++i) {
719 SplitArgsOrigIndices.
push_back(OriginalIndex);
const RegisterBankInfo * getRegBankInfo() const override
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
const MachineInstrBuilder & add(const MachineOperand &MO) const
A parsed version of the target data layout string in and methods for querying it. ...
reference emplace_back(ArgTypes &&... Args)
MachineOperand Callee
Destination of the call.
static LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
bool hasLocalLinkage() const
This class represents lattice values for constants.
Register getLocReg() const
void setTargetFlags(unsigned F)
static bool isSupportedReturnType(Type *T)
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
void push_back(const T &Elt)
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
bool assignVRegs(ArrayRef< Register > VRegs, ArrayRef< CCValAssign > ArgLocs, unsigned ArgLocsStartIndex, const EVT &VT)
unsigned getValNo() const
C - The default llvm calling convention, compatible with C.
unsigned const TargetRegisterInfo * TRI
SmallVector< ISD::ArgFlagsTy, 4 > Flags
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
A description of a memory reference used in the backend.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
CCAssignFn * CCAssignFnForCall() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isIntegerTy() const
True if this is an instance of IntegerType.
unsigned GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const
Obtain the size of the area allocated by the callee for arguments.
MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Return the register type for a given MVT, ensuring vectors are treated as a series of gpr sized integ...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const char * getSymbolName() const
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
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
static bool isSupportedArgumentType(Type *T)
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Type * getType() const
All values are typed, get the type of this value.
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn, const Type *RetTy, const char *Func)
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
MipsCallLowering(const MipsTargetLowering &TLI)
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
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
static CCValAssign getReg(unsigned ValNo, MVT ValVT, unsigned RegNo, MVT LocVT, LocInfo HTP)
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.
virtual const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const
Return a mask of call-preserved registers for the given calling convention on the current function...
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
MachineRegisterInfo * getMRI()
Getter for MRI.
MO_GOT_CALL - Represents the offset into the global offset table at which the address of a call site ...
unsigned const MachineRegisterInfo * MRI
bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< ArrayRef< Register >> VRegs) const override
This hook must be implemented to lower the incoming (formal) arguments, described by VRegs...
The instances of the Type class are immutable: once they are created, they are never changed...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This is an important class for using LLVM in a threaded context.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
size_t size() const
size - Get the array size.
Register getGlobalBaseRegForGlobalISel()
bool isPointerTy() const
True if this is an instance of PointerType.
const GlobalValue * getGlobal() const
Helper class to build MachineInstr.
AMDGPU Lower Kernel Arguments
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
MachineInstrBuilder buildGlobalValue(const DstOp &Res, const GlobalValue *GV)
Build and insert Res = G_GLOBAL_VALUE GV.
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
static void setLocInfo(SmallVectorImpl< CCValAssign > &ArgLocs, const SmallVectorImpl< T > &Arguments)
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. ...
std::vector< ArgListEntry > ArgListTy
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
static constexpr const Align None()
Returns a default constructed Align which corresponds to no alignment.
bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, ArrayRef< Register > VRegs) const override
This hook behaves as the extended lowerReturn function, but for targets that do not support swifterro...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
This class contains a discriminated union of information about pointers in memory operands...
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
This struct is a compact representation of a valid (non-zero power of two) alignment.
The memory access writes data.
SmallVector< ArgInfo, 8 > OrigArgs
List of descriptors of the arguments passed to the function.
void setOrigAlign(Align A)
unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Return the number of registers for a given MVT, ensuring vectors are treated as a series of gpr sized...
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
const MipsRegisterInfo * getRegisterInfo() const override
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
CCValAssign - Represent assignment of one arg/retval to a location.
MachineInstrBuilder buildFrameIndex(const DstOp &Res, int Idx)
Build and insert Res = G_FRAME_INDEX Idx.
Information about stack frame layout on the target.
bool isAggregateType() const
Return true if the type is an aggregate type.
Promote Memory to Register
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
const TargetInstrInfo & getTII()
const Function & getFunction() const
Return the LLVM function that this machine code represents.
void setLeastSignificantFirst(SmallVectorImpl< Register > &VRegs)
This file declares the MachineIRBuilder class.
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.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Representation of each machine instruction.
void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
ArrayRef< MCPhysReg > GetVarArgRegs() const
The registers to use for the variable argument list.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
unsigned AllocateStack(unsigned Size, unsigned Alignment)
AllocateStack - Allocate a chunk of stack space with the specified size and alignment.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned getLocMemOffset() const
CallingConv::ID CallConv
Calling convention to be used for the call.
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
virtual const TargetFrameLowering * getFrameLowering() const
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
static CCValAssign getMem(unsigned ValNo, MVT ValVT, unsigned Offset, MVT LocVT, LocInfo HTP)
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
This file describes how to lower LLVM calls to machine code calls.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const override
This hook must be implemented to lower the given call instruction, including argument and return valu...
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.
CCAssignFn * CCAssignFnForReturn() const
SmallVector< Register, 4 > Regs
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
static CCValAssign::LocInfo determineLocInfo(const MVT RegisterVT, const EVT VT, const ISD::ArgFlagsTy &Flags)
Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
Align getABIAlignmentForCallingConv(Type *ArgTy, DataLayout DL) const override
Return the correct alignment for the current calling convention.
const MachineOperand & getOperand(unsigned i) const
ArgInfo OrigRet
Descriptor for the return type of the function.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool handle(ArrayRef< CCValAssign > ArgLocs, ArrayRef< CallLowering::ArgInfo > Args)
iterator_range< arg_iterator > args()
bool constrainAllUses(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
Wrapper class representing virtual and physical registers.
bool empty() const
empty - Check if the array is empty.