50 #ifndef LLVM_BUILD_GLOBAL_ISEL
51 #error "This shouldn't be built without GISel"
60 : ValueHandler(MIRBuilder, MRI, AssignFn), StackUsed(0) {}
64 auto &MFI = MIRBuilder.getMF().getFrameInfo();
65 int FI = MFI.CreateFixedObject(Size, Offset,
true);
67 unsigned AddrReg =
MRI.createGenericVirtualRegister(
LLT::pointer(0, 64));
68 MIRBuilder.buildFrameIndex(AddrReg, FI);
69 StackUsed =
std::max(StackUsed, Size + Offset);
75 markPhysRegUsed(PhysReg);
76 MIRBuilder.buildCopy(ValVReg, PhysReg);
82 auto MMO = MIRBuilder.getMF().getMachineMemOperand(
85 MIRBuilder.buildLoad(ValVReg, Addr, *MMO);
91 virtual void markPhysRegUsed(
unsigned PhysReg) = 0;
102 MIRBuilder.getMBB().addLiveIn(PhysReg);
122 : ValueHandler(MIRBuilder, MRI, AssignFn), MIB(MIB),
123 AssignFnVarArg(AssignFnVarArg), StackSize(0) {}
129 unsigned SPReg =
MRI.createGenericVirtualRegister(p0);
130 MIRBuilder.buildCopy(SPReg, AArch64::SP);
132 unsigned OffsetReg =
MRI.createGenericVirtualRegister(s64);
133 MIRBuilder.buildConstant(OffsetReg, Offset);
135 unsigned AddrReg =
MRI.createGenericVirtualRegister(p0);
136 MIRBuilder.buildGEP(AddrReg, SPReg, OffsetReg);
145 unsigned ExtReg = extendRegister(ValVReg, VA);
146 MIRBuilder.buildCopy(PhysReg, ExtReg);
151 auto MMO = MIRBuilder.getMF().getMachineMemOperand(
153 MIRBuilder.buildStore(ValVReg, Addr, *MMO);
162 Res = AssignFn(ValNo, ValVT, LocVT, LocInfo, Info.
Flags, State);
164 Res = AssignFnVarArg(ValNo, ValVT, LocVT, LocInfo, Info.
Flags, State);
175 void AArch64CallLowering::splitToValueTypes(
178 const SplitArgTy &PerformArgSplit)
const {
186 if (SplitVTs.
size() == 1) {
189 SplitArgs.
emplace_back(OrigArg.Reg, SplitVTs[0].getTypeForEVT(Ctx),
190 OrigArg.Flags, OrigArg.IsFixed);
194 unsigned FirstRegIdx = SplitArgs.
size();
195 for (
auto SplitVT : SplitVTs) {
197 Type *SplitTy = SplitVT.getTypeForEVT(Ctx);
200 SplitTy, OrigArg.Flags, OrigArg.IsFixed});
203 for (
unsigned i = 0; i < Offsets.
size(); ++i)
204 PerformArgSplit(SplitArgs[FirstRegIdx + i].
Reg, Offsets[i] * 8);
208 const Value *Val,
unsigned VReg)
const {
213 assert(((Val && VReg) || (!Val && !VReg)) &&
"Return value without a vreg");
225 splitToValueTypes(OrigArg, SplitArgs, DL, MRI,
248 for (
auto &Arg : F.
args()) {
249 ArgInfo OrigArg{VRegs[i], Arg.getType()};
253 unsigned Dst = VRegs[i];
255 splitToValueTypes(OrigArg, SplitArgs, DL, MRI,
279 FormalArgHandler Handler(MIRBuilder, MRI, AssignFn);
291 uint64_t StackOffset =
alignTo(Handler.StackUsed, 8);
315 for (
auto &OrigArg : OrigArgs) {
316 splitToValueTypes(OrigArg, SplitArgs, DL, MRI,
329 auto CallSeqStart = MIRBuilder.
buildInstr(AArch64::ADJCALLSTACKDOWN);
339 MIB.addRegMask(TRI->getCallPreservedMask(MF, F.
getCallingConv()));
369 splitToValueTypes(OrigRet, SplitArgs, DL, MRI,
375 CallReturnHandler Handler(MIRBuilder, MRI, MIB, RetAssignFn);
379 if (!RegOffsets.
empty())
383 CallSeqStart.addImm(Handler.
StackSize).addImm(0);
384 MIRBuilder.
buildInstr(AArch64::ADJCALLSTACKUP)
MachineBasicBlock & getMBB()
Getter for the basic block we currently build.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LLT getType(unsigned VReg) const
Get the low-level type of VReg or LLT{} if VReg is not a generic (target independent) virtual registe...
CCAssignFn * CCAssignFnForReturn(CallingConv::ID CC) const
Selects the correct CCAssignFn for a given CallingConvention value.
unsigned constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const MCInstrDesc &II, unsigned Reg, unsigned OpIdx)
Try to constrain Reg so that it is usable by argument OpIdx of the provided MCInstrDesc II...
CallReturnHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI, MachineInstrBuilder MIB, CCAssignFn *AssignFn)
void setVarArgsStackIndex(int Index)
const MachineInstrBuilder & add(const MachineOperand &MO) const
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...
static const MCPhysReg VRegs[32]
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
unsigned createGenericVirtualRegister(LLT Ty)
Create and return a new generic virtual register with low-level type Ty.
MachineInstrBuilder buildExtract(unsigned Res, unsigned Src, uint64_t Index)
Build and insert `Res0<def>, ...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Reg
All possible values of the reg field in the ModR/M byte.
This file contains the simple types necessary to represent the attributes associated with functions a...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
LLVM_NODISCARD bool empty() const
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
bool lowerCall(MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv, const MachineOperand &Callee, const ArgInfo &OrigRet, ArrayRef< ArgInfo > OrigArgs) const override
This hook must be implemented to lower the given call instruction, including argument and return valu...
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...
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset)
Stack pointer relative access.
IncomingArgHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI, CCAssignFn *AssignFn)
unsigned const MachineRegisterInfo * MRI
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.
void assignValueToAddress(unsigned ValVReg, unsigned Addr, uint64_t Size, MachinePointerInfo &MPO, CCValAssign &VA) override
The specified value has been assigned to a stack location.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const MachineOperand & getOperand(unsigned i) const
Helper class to build MachineInstr.
unsigned getStackAddress(uint64_t Size, int64_t Offset, MachinePointerInfo &MPO) override
Materialize a VReg containing the address of the specified stack-based object.
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineInstrBuilder buildInsert(unsigned Res, unsigned Src, unsigned Op, unsigned Index)
unsigned getNextStackOffset() const
getNextStackOffset - Return the next stack offset such that all stack slots satisfy their alignment r...
void markPhysRegUsed(unsigned PhysReg) override
How the physical register gets marked varies between formal parameters (it's a basic-block live-in)...
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...
LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
The memory access writes data.
bool lowerReturn(MachineIRBuilder &MIRBuiler, const Value *Val, unsigned VReg) const override
This hook must be implemented to lower outgoing return values, described by Val, into the specified v...
CCState - This class holds information needed while lowering arguments and return values...
void buildSequence(unsigned Res, ArrayRef< unsigned > Ops, ArrayRef< uint64_t > Indices)
Build and insert instructions to put Ops together at the specified p Indices to form a larger registe...
bool assignArg(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, const CallLowering::ArgInfo &Info, CCState &State) override
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
MachineInstrBuilder buildCopy(unsigned Res, unsigned Op)
Build and insert Res<def> = COPY Op.
CCValAssign - Represent assignment of one arg/retval to a location.
bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< unsigned > VRegs) const override
This hook must be implemented to lower the incoming (formal) arguments, described by Args...
This file declares the MachineIRBuilder class.
CCAssignFn * CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg) const
Selects the correct CCAssignFn for a given CallingConvention value.
bool isTargetDarwin() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
MachineInstrBuilder buildUndef(unsigned Dst)
Build and insert Res = IMPLICIT_DEF.
void emplace_back(ArgTypes &&...Args)
bool handleAssignments(MachineIRBuilder &MIRBuilder, ArrayRef< ArgInfo > Args, ValueHandler &Callback) const
Invoke Handler::assignArg on each of the given Args and then use Callback to move them to the assigne...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void assignValueToAddress(unsigned ValVReg, unsigned Addr, uint64_t Size, MachinePointerInfo &MPO, CCValAssign &VA) override
The specified value has been assigned to a stack location.
void setMBB(MachineBasicBlock &MBB)
Set the insertion point to the end of MBB.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
OutgoingArgHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI, MachineInstrBuilder MIB, CCAssignFn *AssignFn, CCAssignFn *AssignFnVarArg)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void setArgFlags(ArgInfo &Arg, unsigned OpNum, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
The memory access always returns the same value (or traps).
void assignValueToReg(unsigned ValVReg, unsigned PhysReg, CCValAssign &VA) override
The specified value has been assigned to a physical register, handle the appropriate COPY (either to ...
This file describes how to lower LLVM calls to machine code calls.
unsigned getReg() const
getReg - Returns the register number.
unsigned getStackAddress(uint64_t Size, int64_t Offset, MachinePointerInfo &MPO) override
Materialize a VReg containing the address of the specified stack-based object.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual const TargetInstrInfo * getInstrInfo() const
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 pointer(uint16_t AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space (defaulting to 0).
AArch64CallLowering(const AArch64TargetLowering &TLI)
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
static void Split(std::vector< std::string > &V, StringRef S)
Splits a string of comma separated items in to a vector of strings.
CCAssignFn * AssignFnVarArg
void assignValueToReg(unsigned ValVReg, unsigned PhysReg, CCValAssign &VA) override
The specified value has been assigned to a physical register, handle the appropriate COPY (either to ...
iterator_range< arg_iterator > args()