35 : IncomingValueHandler(MIRBuilder, MRI),
44 MachinePointerInfo &MPO,
45 ISD::ArgFlagsTy Flags)
override;
47 const MachinePointerInfo &MPO,
48 const CCValAssign &VA)
override;
50 unsigned assignCustomValue(CallLowering::ArgInfo &Arg,
52 std::function<
void()> *Thunk =
nullptr)
override;
54 virtual void markPhysRegUsed(
unsigned PhysReg) {
55 MIRBuilder.getMRI()->addLiveIn(PhysReg);
56 MIRBuilder.getMBB().addLiveIn(PhysReg);
60class CallReturnHandler :
public MipsIncomingValueHandler {
62 CallReturnHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
63 MachineInstrBuilder &MIB)
64 : MipsIncomingValueHandler(MIRBuilder, MRI), MIB(MIB) {}
67 void markPhysRegUsed(
unsigned PhysReg)
override {
68 MIB.
addDef(PhysReg, RegState::Implicit);
71 MachineInstrBuilder &MIB;
76void MipsIncomingValueHandler::assignValueToReg(
Register ValVReg,
80 markPhysRegUsed(PhysReg);
81 IncomingValueHandler::assignValueToReg(ValVReg, PhysReg, VA);
84Register MipsIncomingValueHandler::getStackAddress(uint64_t
Size,
96 return MIRBuilder.buildFrameIndex(
LLT::pointer(0, 32), FI).getReg(0);
99void MipsIncomingValueHandler::assignValueToAddress(
105 MIRBuilder.buildLoad(ValVReg, Addr, *MMO);
115 std::function<
void()> *Thunk) {
121 "unexpected custom value");
129 Arg.
Regs = { CopyLo.getReg(0), CopyHi.getReg(0) };
130 MIRBuilder.buildMergeLikeInstr(Arg.
OrigRegs[0], {CopyLo, CopyHi});
139 const MipsSubtarget &STI;
142 MipsOutgoingValueHandler(MachineIRBuilder &MIRBuilder,
143 MachineRegisterInfo &MRI, MachineInstrBuilder &MIB)
144 : OutgoingValueHandler(MIRBuilder, MRI),
145 STI(MIRBuilder.getMF().getSubtarget<MipsSubtarget>()), MIB(MIB) {}
149 const CCValAssign &VA,
150 ISD::ArgFlagsTy Flags = {})
override;
153 MachinePointerInfo &MPO,
154 ISD::ArgFlagsTy Flags)
override;
157 const MachinePointerInfo &MPO,
158 const CCValAssign &VA)
override;
159 unsigned assignCustomValue(CallLowering::ArgInfo &Arg,
161 std::function<
void()> *Thunk)
override;
163 MachineInstrBuilder &MIB;
167void MipsOutgoingValueHandler::assignValueToReg(
Register ValVReg,
171 Register ExtReg = extendRegister(ValVReg, VA);
172 MIRBuilder.buildCopy(PhysReg, ExtReg);
176Register MipsOutgoingValueHandler::getStackAddress(uint64_t
Size,
187 auto OffsetReg = MIRBuilder.buildConstant(s32,
Offset);
188 auto AddrReg = MIRBuilder.buildPtrAdd(p0,
SPReg, OffsetReg);
189 return AddrReg.getReg(0);
192void MipsOutgoingValueHandler::assignValueToAddress(
202 Register ExtReg = extendRegister(ValVReg, VA);
203 MIRBuilder.buildStore(ExtReg, Addr, *MMO);
209 std::function<
void()> *Thunk) {
215 "unexpected custom value");
242 if (
T->isIntegerTy())
244 if (
T->isPointerTy())
246 if (
T->isFloatingPointTy())
252 if (
T->isIntegerTy())
254 if (
T->isPointerTy())
256 if (
T->isFloatingPointTy())
258 if (
T->isAggregateType())
272 if (!VRegs.
empty()) {
280 ArgInfo ArgRetInfo(VRegs, *Val, 0);
286 MipsCCState CCInfo(
F.getCallingConv(),
F.isVarArg(), MF, ArgLocs,
289 MipsOutgoingValueHandler RetHandler(MIRBuilder, MF.
getRegInfo(), Ret);
312 for (
auto &Arg :
F.args()) {
323 for (
auto &Arg :
F.args()) {
324 ArgInfo AInfo(VRegs[i], Arg, i);
332 MipsCCState CCInfo(
F.getCallingConv(),
F.isVarArg(), MF, ArgLocs,
338 CCInfo.
AllocateStack(ABI.GetCalleeAllocdArgSizeInBytes(
F.getCallingConv()),
345 MipsIncomingValueHandler Handler(MIRBuilder, MF.
getRegInfo());
356 if (ArgRegs.
size() == Idx)
368 for (
unsigned I = Idx;
I < ArgRegs.
size(); ++
I, VaArgOffset +=
RegSize) {
380 MIRBuilder.
buildStore(Copy, FrameIndex, *MMO);
393 for (
auto &Arg : Info.OrigArgs) {
396 if (Arg.
Flags[0].isByVal())
414 MIRBuilder.
buildInstr(Mips::ADJCALLSTACKDOWN);
416 const bool IsCalleeGlobalPIC =
420 Info.Callee.isReg() || IsCalleeGlobalPIC ? Mips::JALRPseudo : Mips::JAL);
422 if (IsCalleeGlobalPIC) {
427 if (!Info.Callee.getGlobal()->hasLocalLinkage())
431 MIB.
add(Info.Callee);
433 MIB.
addRegMask(
TRI->getCallPreservedMask(MF, Info.CallConv));
436 FuncOrigArgs.reserve(Info.OrigArgs.size());
439 for (
auto &Arg : Info.OrigArgs)
443 bool IsCalleeVarArg =
false;
444 if (Info.Callee.isGlobal()) {
445 const Function *CF =
static_cast<const Function *
>(Info.Callee.getGlobal());
451 MipsCCState CCInfo(Info.CallConv, IsCalleeVarArg, MF, ArgLocs,
454 CCInfo.
AllocateStack(ABI.GetCalleeAllocdArgSizeInBytes(Info.CallConv),
461 MipsOutgoingValueHandler ArgHandler(MIRBuilder, MF.
getRegInfo(), MIB);
466 unsigned StackAlignment =
F.getParent()->getOverrideStackAlignment();
467 if (!StackAlignment) {
471 StackSize =
alignTo(StackSize, StackAlignment);
474 if (IsCalleeGlobalPIC) {
481 if (MIB->
getOpcode() == Mips::JALRPseudo) {
487 if (!Info.OrigRet.Ty->isVoidTy()) {
495 CallReturnHandler RetHandler(MIRBuilder, MF.
getRegInfo(), MIB);
497 MipsCCState CCInfo(
F.getCallingConv(),
F.isVarArg(), MF, ArgLocs,
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file declares the MachineIRBuilder class.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static bool isSupportedReturnType(Type *T)
static bool isSupportedArgumentType(Type *T)
This file describes how to lower LLVM calls to machine code calls.
static constexpr MCPhysReg SPReg
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
unsigned getFirstUnallocated(ArrayRef< MCPhysReg > Regs) const
getFirstUnallocated - Return the index of the first unallocated register in the set,...
CallingConv::ID getCallingConv() const
int64_t AllocateStack(unsigned Size, Align Alignment)
AllocateStack - Allocate a chunk of stack space with the specified size and alignment.
uint64_t getStackSize() const
Returns the size of the currently allocated portion of the stack.
CCValAssign - Represent assignment of one arg/retval to a location.
Register getLocReg() const
int64_t getLocMemOffset() const
bool handleAssignments(ValueHandler &Handler, SmallVectorImpl< ArgInfo > &Args, CCState &CCState, SmallVectorImpl< CCValAssign > &ArgLocs, MachineIRBuilder &MIRBuilder, ArrayRef< Register > ThisReturnRegs={}) const
Use Handler to insert code to handle the argument/return values represented by Args.
void splitToValueTypes(const ArgInfo &OrigArgInfo, SmallVectorImpl< ArgInfo > &SplitArgs, const DataLayout &DL, CallingConv::ID CallConv, SmallVectorImpl< TypeSize > *Offsets=nullptr) const
Break OrigArgInfo into one or more pieces the calling convention can process, returned in SplitArgs.
bool determineAssignments(ValueAssigner &Assigner, SmallVectorImpl< ArgInfo > &Args, CCState &CCInfo) const
Analyze the argument list in Args, using Assigner to populate CCInfo.
CallLowering(const TargetLowering *TLI)
const TargetLowering * getTLI() const
Getter for generic TargetLowering class.
void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
A parsed version of the target data layout string in and methods for querying it.
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
LLVM_ABI 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 TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align 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.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Helper class to build MachineInstr.
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
MachineInstrBuilder buildGlobalValue(const DstOp &Res, const GlobalValue *GV)
Build and insert Res = G_GLOBAL_VALUE GV.
const TargetInstrInfo & getTII()
MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineInstrBuilder buildFrameIndex(const DstOp &Res, int Idx)
Build and insert Res = G_FRAME_INDEX Idx.
MachineFunction & getMF()
Getter for the function we currently build.
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
void constrainAllUses(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
const MachineInstrBuilder & addUse(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
A description of a memory reference used in the backend.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
void setTargetFlags(unsigned F)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
MipsCallLowering(const MipsTargetLowering &TLI)
bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< ArrayRef< Register > > VRegs, FunctionLoweringInfo &FLI) const override
This hook must be implemented to lower the incoming (formal) arguments, described by VRegs,...
bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const override
This hook must be implemented to lower the given call instruction, including argument and return valu...
bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, ArrayRef< Register > VRegs, FunctionLoweringInfo &FLI) const override
This hook behaves as the extended lowerReturn function, but for targets that do not support swifterro...
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
Register getGlobalBaseRegForGlobalISel(MachineFunction &MF)
const MipsRegisterInfo * getRegisterInfo() const override
const RegisterBankInfo * getRegBankInfo() const override
Align getStackAlignment() const
const MipsABIInfo & getABI() const
Wrapper class representing virtual and physical registers.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Information about stack frame layout on the target.
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
std::vector< ArgListEntry > ArgListTy
bool isPositionIndependent() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isPointerTy() const
True if this is an instance of PointerType.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
ArrayRef(const T &OneElt) -> ArrayRef< T >
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
LLVM_ABI Align inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
SmallVector< Register, 4 > Regs
SmallVector< Register, 2 > OrigRegs
SmallVector< ISD::ArgFlagsTy, 4 > Flags
Base class for ValueHandlers used for arguments coming into the current function, or for return value...
Base class for ValueHandlers used for arguments passed to a function call, or for return values.
This class contains a discriminated union of information about pointers in memory operands,...
LLVM_ABI unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
static LLVM_ABI MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.