60 unsigned NumXMMRegs = 0;
63 uint64_t getStackSize() {
return StackSize; }
64 unsigned getNumXmmRegs() {
return NumXMMRegs; }
66 X86OutgoingValueAssigner(
CCAssignFn *AssignFn_)
69 bool assignArg(
unsigned ValNo,
EVT OrigVT,
MVT ValVT,
MVT LocVT,
73 bool Res = AssignFn(ValNo, ValVT, LocVT, LocInfo, Flags, State);
76 static const MCPhysReg XMMArgRegs[] = {X86::XMM0, X86::XMM1, X86::XMM2,
77 X86::XMM3, X86::XMM4, X86::XMM5,
78 X86::XMM6, X86::XMM7};
89 : OutgoingValueHandler(MIRBuilder,
MRI), MIB(MIB),
90 DL(MIRBuilder.getMF().getDataLayout()),
99 MIRBuilder.buildCopy(p0, STI.getRegisterInfo()->getStackRegister());
101 auto OffsetReg = MIRBuilder.buildConstant(SType,
Offset);
103 auto AddrReg = MIRBuilder.buildPtrAdd(p0, SPReg, OffsetReg);
106 return AddrReg.getReg(0);
112 Register ExtReg = extendRegister(ValVReg, VA);
113 MIRBuilder.buildCopy(PhysReg, ExtReg);
120 Register ExtReg = extendRegister(ValVReg, VA);
124 MIRBuilder.buildStore(ExtReg,
Addr, *MMO);
140 CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
148 "Return value without a vreg");
153 Register RetReg = STI.is64Bit() ? X86::RAX : X86::EAX;
159 }
else if (
Register Reg = FuncInfo->getSRetReturnReg()) {
162 }
else if (!VRegs.
empty()) {
173 X86OutgoingValueAssigner Assigner(
RetCC_X86);
174 X86OutgoingValueHandler Handler(MIRBuilder,
MRI, MIB);
176 MIRBuilder,
F.getCallingConv(),
190 : IncomingValueHandler(MIRBuilder,
MRI),
191 DL(MIRBuilder.getMF().getDataLayout()) {}
196 auto &MFI = MIRBuilder.getMF().getFrameInfo();
200 const bool IsImmutable = !Flags.isByVal();
202 int FI = MFI.CreateFixedObject(
Size,
Offset, IsImmutable);
217 MIRBuilder.buildLoad(ValVReg,
Addr, *MMO);
222 markPhysRegUsed(PhysReg);
223 IncomingValueHandler::assignValueToReg(ValVReg, PhysReg, VA);
229 virtual void markPhysRegUsed(
unsigned PhysReg) = 0;
239 void markPhysRegUsed(
unsigned PhysReg)
override {
245struct CallReturnHandler :
public X86IncomingValueHandler {
248 : X86IncomingValueHandler(MIRBuilder,
MRI), MIB(MIB) {}
250 void markPhysRegUsed(
unsigned PhysReg)
override {
279 for (
const auto &Arg :
F.args()) {
281 if (Arg.hasAttribute(Attribute::ByVal) ||
282 Arg.hasAttribute(Attribute::InReg) ||
283 Arg.hasAttribute(Attribute::SwiftSelf) ||
284 Arg.hasAttribute(Attribute::SwiftError) ||
285 Arg.hasAttribute(Attribute::Nest) || VRegs[
Idx].size() > 1)
288 if (Arg.hasAttribute(Attribute::StructRet)) {
290 "Unexpected amount of registers for sret argument.");
291 FuncInfo->setSRetReturnReg(VRegs[
Idx][0]);
300 if (SplitArgs.empty())
307 X86OutgoingValueAssigner Assigner(
CC_X86);
310 F.getCallingConv(),
F.isVarArg()))
334 unsigned AdjStackDown =
TII.getCallFrameSetupOpcode();
335 auto CallSeqStart = MIRBuilder.
buildInstr(AdjStackDown);
339 bool Is64Bit = STI.is64Bit();
340 unsigned CallOpc =
Info.Callee.isReg()
341 ? (Is64Bit ? X86::CALL64r : X86::CALL32r)
342 : (Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32);
349 for (
const auto &OrigArg :
Info.OrigArgs) {
352 if (OrigArg.Flags[0].isByVal())
355 if (OrigArg.Regs.size() > 1)
361 X86OutgoingValueAssigner Assigner(
CC_X86);
362 X86OutgoingValueHandler Handler(MIRBuilder,
MRI, MIB);
367 bool IsFixed =
Info.OrigArgs.empty() ?
true :
Info.OrigArgs.back().IsFixed;
379 .
addImm(Assigner.getNumXmmRegs());
389 if (
Info.Callee.isReg())
399 if (
Info.CanLowerReturn && !
Info.OrigRet.Ty->isVoidTy()) {
400 if (
Info.OrigRet.Regs.size() > 1)
408 X86OutgoingValueAssigner Assigner(
RetCC_X86);
409 CallReturnHandler Handler(MIRBuilder,
MRI, MIB);
414 if (!NewRegs.
empty())
418 CallSeqStart.
addImm(Assigner.getStackSize())
422 unsigned AdjStackUp =
TII.getCallFrameDestroyOpcode();
424 .
addImm(Assigner.getStackSize())
427 if (!
Info.CanLowerReturn)
429 Info.DemoteRegister,
Info.DemoteStackIndex);
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
Analysis containing CSE Info
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
const HexagonInstrInfo * TII
Implement a low-level type suitable for MachineInstr level instruction selection.
Implement a low-level type suitable for MachineInstr level instruction selection.
This file declares the MachineIRBuilder class.
unsigned const TargetRegisterInfo * TRI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This file describes how to lower LLVM calls to machine code calls.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
CCState - This class holds information needed while lowering arguments and return values.
unsigned getFirstUnallocated(ArrayRef< MCPhysReg > Regs) const
getFirstUnallocated - Return the index of the first unallocated register in the set,...
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.
void insertSRetLoads(MachineIRBuilder &MIRBuilder, Type *RetTy, ArrayRef< Register > VRegs, Register DemoteReg, int FI) const
Load the returned value from the stack into virtual registers in VRegs.
bool determineAndHandleAssignments(ValueHandler &Handler, ValueAssigner &Assigner, SmallVectorImpl< ArgInfo > &Args, MachineIRBuilder &MIRBuilder, CallingConv::ID CallConv, bool IsVarArg, ArrayRef< Register > ThisReturnRegs=std::nullopt) const
Invoke ValueAssigner::assignArg on each of the given Args and then use Handler to move them to the as...
void splitToValueTypes(const ArgInfo &OrigArgInfo, SmallVectorImpl< ArgInfo > &SplitArgs, const DataLayout &DL, CallingConv::ID CallConv, SmallVectorImpl< uint64_t > *Offsets=nullptr) const
Break OrigArgInfo into one or more pieces the calling convention can process, returned in SplitArgs.
void insertSRetIncomingArgument(const Function &F, SmallVectorImpl< ArgInfo > &SplitArgs, Register &DemoteReg, MachineRegisterInfo &MRI, const DataLayout &DL) const
Insert the hidden sret ArgInfo to the beginning of SplitArgs.
void insertSRetStores(MachineIRBuilder &MIRBuilder, Type *RetTy, ArrayRef< Register > VRegs, Register DemoteReg) const
Store the return value given by VRegs into stack starting at the offset specified in DemoteReg.
bool checkReturn(CCState &CCInfo, SmallVectorImpl< BaseArgInfo > &Outs, CCAssignFn *Fn) const
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...
Register DemoteRegister
DemoteRegister - if CanLowerReturn is false, DemoteRegister is a vreg allocated to hold a pointer to ...
bool CanLowerReturn
CanLowerReturn - true iff the function's return value can be lowered to registers.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
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.
This is an important class for using LLVM in a threaded context.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
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.
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...
Helper class to build MachineInstr.
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
MachineInstrBuilder buildMergeLikeInstr(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ... or Res = G_BUILD_VECTOR Op0, ... or Res = G_CONCAT_VEC...
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
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.
MachineRegisterInfo * getMRI()
Getter for MRI.
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.
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 & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineOperand & getOperand(unsigned i) const
@ MOLoad
The memory access reads data.
@ MOInvariant
The memory access always returns the same value (or traps).
@ MOStore
The memory access writes data.
void setReg(Register Reg)
Change the register this operand corresponds to.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
void addLiveIn(MCRegister Reg, Register vreg=Register())
addLiveIn - Add the specified register as a live-in.
Wrapper class representing virtual and physical registers.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
virtual const TargetInstrInfo * getInstrInfo() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
X86CallLowering(const X86TargetLowering &TLI)
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...
bool canLowerReturn(MachineFunction &MF, CallingConv::ID CallConv, SmallVectorImpl< BaseArgInfo > &Outs, bool IsVarArg) const override
This hook must be implemented to check whether the return values described by Outs can fit into the r...
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,...
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
const X86InstrInfo * getInstrInfo() const override
bool isCallingConvWin64(CallingConv::ID CC) const
const X86RegisterInfo * getRegisterInfo() const override
bool isTargetLinux() const
@ X86_64_SysV
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
@ C
The default llvm calling convention, compatible with C.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
This is an optimization pass for GlobalISel generic memory operations.
Register constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const TargetRegisterClass &RegClass, MachineOperand &RegMO)
Constrain the Register operand OpIdx, so that it is now constrained to the TargetRegisterClass passed...
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
bool RetCC_X86(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
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.
bool CC_X86(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
Align inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO)
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.
MachineIRBuilder & MIRBuilder
MachineRegisterInfo & MRI
This class contains a discriminated union of information about pointers in memory operands,...
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.