51 #include "X86GenCallingConv.inc" 56 bool X86CallLowering::splitToValueTypes(
const ArgInfo &OrigArg,
60 SplitArgTy PerformArgSplit)
const {
68 if (SplitVTs.
size() != 1) {
88 for (
unsigned i = 0; i < NumParts; ++i) {
91 PartTy, OrigArg.
Flags};
96 PerformArgSplit(SplitRegs);
109 unsigned getStackAddress(uint64_t
Size, int64_t
Offset,
114 MIRBuilder.
buildCopy(SPReg, STI.getRegisterInfo()->getStackRegister());
120 MIRBuilder.
buildGEP(AddrReg, SPReg, OffsetReg);
126 void assignValueToReg(
unsigned ValVReg,
unsigned PhysReg,
137 unsigned PhysRegSize =
141 if (PhysRegSize > ValSize && LocSize == ValSize) {
142 assert((PhysRegSize == 128 || PhysRegSize == 80) &&
"We expect that to be 128 bit");
146 ExtReg = extendRegister(ValVReg, VA);
151 void assignValueToAddress(
unsigned ValVReg,
unsigned Addr, uint64_t Size,
153 unsigned ExtReg = extendRegister(ValVReg, VA);
160 bool assignArg(
unsigned ValNo,
MVT ValVT,
MVT LocVT,
163 bool Res = AssignFn(ValNo, ValVT, LocVT, LocInfo, Info.
Flags, State);
166 static const MCPhysReg XMMArgRegs[] = {X86::XMM0, X86::XMM1, X86::XMM2,
167 X86::XMM3, X86::XMM4, X86::XMM5,
168 X86::XMM6, X86::XMM7};
175 uint64_t getStackSize() {
return StackSize; }
176 uint64_t getNumXmmRegs() {
return NumXMMRegs; }
180 uint64_t StackSize = 0;
183 unsigned NumXMMRegs = 0;
189 const Value *Val,
unsigned VReg)
const {
190 assert(((Val && VReg) || (!Val && !VReg)) &&
"Return value without a vreg");
204 if (!splitToValueTypes(OrigArg, SplitArgs, DL, MRI,
210 OutgoingValueHandler Handler(MIRBuilder, MRI, MIB, RetCC_X86);
227 unsigned getStackAddress(uint64_t
Size, int64_t
Offset,
239 void assignValueToAddress(
unsigned ValVReg,
unsigned Addr, uint64_t Size,
244 MIRBuilder.
buildLoad(ValVReg, Addr, *MMO);
247 void assignValueToReg(
unsigned ValVReg,
unsigned PhysReg,
249 markPhysRegUsed(PhysReg);
259 unsigned PhysRegSize =
263 if (PhysRegSize > ValSize && LocSize == ValSize) {
272 case CCValAssign::LocInfo::SExt:
273 case CCValAssign::LocInfo::ZExt:
274 case CCValAssign::LocInfo::AExt: {
285 virtual void markPhysRegUsed(
unsigned PhysReg) = 0;
291 struct FormalArgHandler :
public IncomingValueHandler {
294 : IncomingValueHandler(MIRBuilder, MRI, AssignFn) {}
296 void markPhysRegUsed(
unsigned PhysReg)
override {
301 struct CallReturnHandler :
public IncomingValueHandler {
304 : IncomingValueHandler(MIRBuilder, MRI, AssignFn), MIB(MIB) {}
306 void markPhysRegUsed(
unsigned PhysReg)
override {
335 if (
Arg.hasAttribute(Attribute::ByVal) ||
336 Arg.hasAttribute(Attribute::InReg) ||
337 Arg.hasAttribute(Attribute::StructRet) ||
338 Arg.hasAttribute(Attribute::SwiftSelf) ||
339 Arg.hasAttribute(Attribute::SwiftError) ||
340 Arg.hasAttribute(Attribute::Nest))
345 if (!splitToValueTypes(OrigArg, SplitArgs, DL, MRI,
357 FormalArgHandler Handler(MIRBuilder, MRI, CC_X86);
385 unsigned AdjStackDown = TII.getCallFrameSetupOpcode();
386 auto CallSeqStart = MIRBuilder.
buildInstr(AdjStackDown);
391 unsigned CallOpc = Callee.
isReg()
392 ? (Is64Bit ? X86::CALL64r : X86::CALL32r)
393 : (Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32);
396 TRI->getCallPreservedMask(MF, CallConv));
399 for (
const auto &OrigArg : OrigArgs) {
405 if (!splitToValueTypes(OrigArg, SplitArgs, DL, MRI,
412 OutgoingValueHandler Handler(MIRBuilder, MRI, MIB, CC_X86);
416 bool IsFixed = OrigArgs.empty() ?
true : OrigArgs.back().IsFixed;
428 .
addImm(Handler.getNumXmmRegs());
451 if (!splitToValueTypes(OrigRet, SplitArgs, DL, MRI,
457 CallReturnHandler Handler(MIRBuilder, MRI, RetCC_X86, MIB);
461 if (!NewRegs.
empty())
465 CallSeqStart.
addImm(Handler.getStackSize())
469 unsigned AdjStackUp = TII.getCallFrameDestroyOpcode();
471 .
addImm(Handler.getStackSize())
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
MachineInstrBuilder buildCopy(unsigned Res, unsigned Op)
Build and insert Res = COPY Op.
unsigned getFirstUnallocated(ArrayRef< MCPhysReg > Regs) const
getFirstUnallocated - Return the index of the first unallocated register in the set, or Regs.size() if they are all allocated.
bool is64Bit() const
Is this x86_64? (disregarding specific ABI / programming model)
void push_back(const T &Elt)
const MachineInstrBuilder & add(const MachineOperand &MO) const
A parsed version of the target data layout string in and methods for querying it. ...
C - The default llvm calling convention, compatible with C.
Compute iterated dominance frontiers using a linear time algorithm.
MachineInstrBuilder buildGEP(unsigned Res, unsigned Op0, unsigned Op1)
Build and insert Res = G_GEP Op0, Op1.
const X86InstrInfo * getInstrInfo() const override
MachineInstrBuilder buildStore(unsigned Val, unsigned Addr, MachineMemOperand &MMO)
Build and insert G_STORE Val, Addr, MMO.
unsigned getReg() const
getReg - Returns the register number.
MachineInstrBuilder buildUnmerge(ArrayRef< unsigned > Res, unsigned Op)
Build and insert Res0, ...
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 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...
static const MCPhysReg VRegs[32]
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
MachineInstrBuilder buildAnyExt(unsigned Res, unsigned Op)
Build and insert Res = G_ANYEXT Op0.
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
unsigned const TargetRegisterInfo * TRI
block Block Frequency true
void setMBB(MachineBasicBlock &MBB)
Set the insertion point to the end of MBB.
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...
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
bool handleAssignments(MachineIRBuilder &MIRBuilder, ArrayRef< ArgInfo > Args, ValueHandler &Handler) const
Invoke Handler::assignArg on each of the given Args and then use Callback to move them to the assigne...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
const HexagonInstrInfo * TII
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
const MachineInstrBuilder & addUse(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This file contains the simple types necessary to represent the attributes associated with functions a...
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
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
MachineInstrBuilder buildInstrNoInsert(unsigned Opcode)
Build but don't insert <empty> = Opcode <empty>.
unsigned getSizeInBits() const
void assign(size_type NumElts, const T &Elt)
unsigned getNextStackOffset() const
getNextStackOffset - Return the next stack offset such that all stack slots satisfy their alignment r...
Type * getType() const
All values are typed, get the type of this value.
virtual const TargetInstrInfo * getInstrInfo() const
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
amdgpu Simplify well known AMD library false Value * Callee
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...
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
TargetInstrInfo - Interface to description of machine instruction set.
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...
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const TargetRegisterInfo * getTargetRegisterInfo() const
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...
This is an important class for using LLVM in a threaded context.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
void setInstr(MachineInstr &MI)
Set the insertion point to before MI.
void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
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.
const X86RegisterInfo * getRegisterInfo() const override
unsigned createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
CCState - This class holds information needed while lowering arguments and return values...
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...
CCValAssign - Represent assignment of one arg/retval to a location.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
MachineInstrBuilder buildFrameIndex(unsigned Res, int Idx)
Build and insert Res = G_FRAME_INDEX Idx.
MachineInstrBuilder buildTrunc(unsigned Res, unsigned Op)
Build and insert Res = G_TRUNC Op.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
This file declares the MachineIRBuilder class.
MachineInstrBuilder insertInstr(MachineInstrBuilder MIB)
Insert an existing instruction at the insertion point.
This file describes how to lower LLVM calls to machine code calls.
MachineInstrBuilder buildConstant(unsigned Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
amdgpu Simplify well known AMD library false Value Value * Arg
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.
MachineInstrBuilder buildMerge(unsigned Res, ArrayRef< unsigned > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
void emplace_back(ArgTypes &&... Args)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
LLVM_NODISCARD bool empty() const
void setReg(unsigned Reg)
Change the register this operand corresponds to.
MachineInstrBuilder buildLoad(unsigned Res, unsigned Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
The memory access always returns the same value (or traps).
MachineFunction & getMF()
Getter for the function we currently build.
unsigned getNumRegisters(LLVMContext &Context, EVT VT) const
Return the number of registers that this ValueType will eventually require.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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).
bool isTargetLinux() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
bool isCallingConvWin64(CallingConv::ID CC) const
MachineBasicBlock & getMBB()
Getter for the basic block we currently build.
X86CallLowering(const X86TargetLowering &TLI)
MachineInstrBuilder buildInstr(unsigned Opc, DstTy &&Ty, UseArgsTy &&... Args)
DAG like Generic method for building arbitrary instructions as above.
static MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
unsigned constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const MCInstrDesc &II, const MachineOperand &RegMO, unsigned OpIdx)
Try to constrain Reg so that it is usable by argument OpIdx of the provided MCInstrDesc II...
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
const MachineInstrBuilder & addDef(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineOperand & getOperand(unsigned i) const
iterator_range< arg_iterator > args()