14#ifndef LLVM_CODEGEN_GLOBALISEL_CALLLOWERING_H
15#define LLVM_CODEGEN_GLOBALISEL_CALLLOWERING_H
37class FunctionLoweringInfo;
38class MachineIRBuilder;
40struct MachinePointerInfo;
41class MachineRegisterInfo;
47 virtual void anchor();
91 "only void types should have no register");
134 std::optional<PtrAuthInfo>
PAI;
179 IsIncomingArgumentHandler(IsIncoming) {
192 return IsIncomingArgumentHandler;
226 const bool IsIncomingArgumentHandler;
227 virtual void anchor();
309 std::function<
void()> *Thunk =
nullptr) {
326 unsigned MaxSizeBits = 0);
359 template <
class XXXTargetLowering>
360 const XXXTargetLowering *
getTLI()
const {
361 return static_cast<const XXXTargetLowering *
>(TLI);
367 unsigned ArgIdx)
const;
376 unsigned OpIdx)
const;
378 template <
typename FuncInfoTy>
380 const FuncInfoTy &FuncInfo)
const;
413 ValueHandler &Handler, ValueAssigner &Assigner,
431 const uint32_t *CallerPreservedMask,
447 ValueAssigner &CalleeAssigner,
448 ValueAssigner &CallerAssigner)
const;
485 CallLoweringInfo &
Info)
const;
508 bool IsVarArg)
const {
526 assert(SwiftErrorVReg == 0 &&
"attempt to use unsupported swifterror");
598 std::optional<PtrAuthInfo> PAI,
Register ConvergenceCtrlToken,
599 std::function<
unsigned()> GetCalleeReg)
const;
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Analysis containing CSE Info
Implement a low-level type suitable for MachineInstr level instruction selection.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
CCState - This class holds information needed while lowering arguments and return values.
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.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
virtual ~CallLowering()=default
bool handleAssignments(ValueHandler &Handler, SmallVectorImpl< ArgInfo > &Args, CCState &CCState, SmallVectorImpl< CCValAssign > &ArgLocs, MachineIRBuilder &MIRBuilder, ArrayRef< Register > ThisReturnRegs=std::nullopt) const
Use Handler to insert code to handle the argument/return values represented by Args.
void insertSRetOutgoingArgument(MachineIRBuilder &MIRBuilder, const CallBase &CB, CallLoweringInfo &Info) const
For the call-base described by CB, insert the hidden sret ArgInfo to the OrigArgs field of Info.
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 checkReturnTypeForCallConv(MachineFunction &MF) const
Toplevel function to check the return type based on the target calling convention.
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...
bool resultsCompatible(CallLoweringInfo &Info, MachineFunction &MF, SmallVectorImpl< ArgInfo > &InArgs, ValueAssigner &CalleeAssigner, ValueAssigner &CallerAssigner) const
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.
virtual bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, ArrayRef< ArrayRef< Register > > VRegs, FunctionLoweringInfo &FLI) const
This hook must be implemented to lower the incoming (formal) arguments, described by VRegs,...
virtual bool canLowerReturn(MachineFunction &MF, CallingConv::ID CallConv, SmallVectorImpl< BaseArgInfo > &Outs, bool IsVarArg) const
This hook must be implemented to check whether the return values described by Outs can fit into the r...
virtual bool isTypeIsValidForThisReturn(EVT Ty) const
For targets which support the "returned" parameter attribute, returns true if the given type is a val...
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.
ISD::ArgFlagsTy getAttributesForArgIdx(const CallBase &Call, unsigned ArgIdx) const
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.
void addArgFlagsFromAttributes(ISD::ArgFlagsTy &Flags, const AttributeList &Attrs, unsigned OpIdx) const
Adds flags to Flags based off of the attributes in Attrs.
virtual bool enableBigEndian() const
For targets which want to use big-endian can enable it with enableBigEndian() hook.
virtual bool supportSwiftError() const
bool parametersInCSRMatch(const MachineRegisterInfo &MRI, const uint32_t *CallerPreservedMask, const SmallVectorImpl< CCValAssign > &ArgLocs, const SmallVectorImpl< ArgInfo > &OutVals) const
Check whether parameters to a call that are passed in callee saved registers are the same as from the...
void getReturnInfo(CallingConv::ID CallConv, Type *RetTy, AttributeList Attrs, SmallVectorImpl< BaseArgInfo > &Outs, const DataLayout &DL) const
Get the type and the ArgFlags for the split components of RetTy as returned by ComputeValueVTs.
bool determineAssignments(ValueAssigner &Assigner, SmallVectorImpl< ArgInfo > &Args, CCState &CCInfo) const
Analyze the argument list in Args, using Assigner to populate CCInfo.
bool checkReturn(CCState &CCInfo, SmallVectorImpl< BaseArgInfo > &Outs, CCAssignFn *Fn) const
CallLowering(const TargetLowering *TLI)
virtual bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, ArrayRef< Register > VRegs, FunctionLoweringInfo &FLI, Register SwiftErrorVReg) const
This hook must be implemented to lower outgoing return values, described by Val, into the specified v...
virtual bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, ArrayRef< Register > VRegs, FunctionLoweringInfo &FLI) const
This hook behaves as the extended lowerReturn function, but for targets that do not support swifterro...
const TargetLowering * getTLI() const
Getter for generic TargetLowering class.
const XXXTargetLowering * getTLI() const
Getter for target specific TargetLowering class.
virtual bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const
This hook must be implemented to lower the given call instruction, including argument and return valu...
void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
virtual bool fallBackToDAGISel(const MachineFunction &MF) const
ISD::ArgFlagsTy getAttributesForReturn(const CallBase &Call) const
This is the shared class of boolean and integer constants.
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...
Helper class to build MachineInstr.
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateImm(int64_t Val)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isEmptyTy() const
Return true if this type is empty, that is, it has no elements or all of its elements are empty.
bool isVoidTy() const
Return true if this is 'void'.
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Helper struct shared between Function Specialization and SCCP Solver.
const Value * OrigValue
Optionally track the original IR value for the argument.
SmallVector< Register, 4 > Regs
SmallVector< Register, 2 > OrigRegs
unsigned OrigArgIndex
Index original Function's argument.
ArgInfo(ArrayRef< Register > Regs, Type *Ty, unsigned OrigIndex, ArrayRef< ISD::ArgFlagsTy > Flags=ArrayRef< ISD::ArgFlagsTy >(), bool IsFixed=true, const Value *OrigValue=nullptr)
ArgInfo(ArrayRef< Register > Regs, const Value &OrigValue, unsigned OrigIndex, ArrayRef< ISD::ArgFlagsTy > Flags=ArrayRef< ISD::ArgFlagsTy >(), bool IsFixed=true)
static const unsigned NoArgIndex
Sentinel value for implicit machine-level input arguments.
SmallVector< ISD::ArgFlagsTy, 4 > Flags
BaseArgInfo(Type *Ty, ArrayRef< ISD::ArgFlagsTy > Flags=ArrayRef< ISD::ArgFlagsTy >(), bool IsFixed=true)
bool IsVarArg
True if the call is to a vararg function.
bool IsMustTailCall
True if the call must be tail call optimized.
bool IsTailCall
True if the call passes all target-independent checks for tail call optimization.
MachineOperand Callee
Destination of the call.
bool CanLowerReturn
True if the function's return value can be lowered to registers.
ArgInfo OrigRet
Descriptor for the return type of the function.
const ConstantInt * CFIType
Expected type identifier for indirect calls with a CFI check.
CallingConv::ID CallConv
Calling convention to be used for the call.
Register ConvergenceCtrlToken
Valid if the call is a controlled convergent operation.
const CallBase * CB
Original IR callsite corresponding to this call, if available.
Register DemoteRegister
VReg to hold the hidden sret parameter.
bool IsConvergent
True if this call results in convergent operations.
std::optional< PtrAuthInfo > PAI
The auth-call information in the "ptrauth" bundle, if present.
int DemoteStackIndex
The stack index for sret demotion.
Register SwiftErrorVReg
Valid if the call has a swifterror inout parameter, and contains the vreg that the swifterror should ...
SmallVector< ArgInfo, 32 > OrigArgs
List of descriptors of the arguments passed to the function.
bool LoweredTailCall
True if the call was lowered as a tail call.
IncomingValueAssigner(CCAssignFn *AssignFn_, CCAssignFn *AssignFnVarArg_=nullptr)
Base class for ValueHandlers used for arguments coming into the current function, or for return value...
void assignValueToReg(Register ValVReg, Register PhysReg, const CCValAssign &VA) override
Provides a default implementation for argument handling.
Register buildExtensionHint(const CCValAssign &VA, Register SrcReg, LLT NarrowTy)
Insert G_ASSERT_ZEXT/G_ASSERT_SEXT or other hint instruction based on VA, returning the new register ...
IncomingValueHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
OutgoingValueAssigner(CCAssignFn *AssignFn_, CCAssignFn *AssignFnVarArg_=nullptr)
Base class for ValueHandlers used for arguments passed to a function call, or for return values.
OutgoingValueHandler(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
Argument handling is mostly uniform between the four places that make these decisions: function forma...
CCAssignFn * getAssignFn(bool IsVarArg) const
Select the appropriate assignment function depending on whether this is a variadic call.
CCAssignFn * AssignFn
Assignment function to use for a general call.
bool isIncomingArgumentHandler() const
Returns true if the handler is dealing with incoming arguments, i.e.
ValueAssigner(bool IsIncoming, CCAssignFn *AssignFn_, CCAssignFn *AssignFnVarArg_=nullptr)
CCAssignFn * AssignFnVarArg
Assignment function to use for a variadic call.
virtual bool assignArg(unsigned ValNo, EVT OrigVT, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, const ArgInfo &Info, ISD::ArgFlagsTy Flags, CCState &State)
Wrap call to (typically tablegenerated CCAssignFn).
uint64_t StackSize
The size of the currently allocated portion of the stack.
virtual ~ValueAssigner()=default
MachineIRBuilder & MIRBuilder
void copyArgumentMemory(const ArgInfo &Arg, Register DstPtr, Register SrcPtr, const MachinePointerInfo &DstPtrInfo, Align DstAlign, const MachinePointerInfo &SrcPtrInfo, Align SrcAlign, uint64_t MemSize, CCValAssign &VA) const
Do a memory copy of MemSize bytes from SrcPtr to DstPtr.
virtual ~ValueHandler()=default
MachineRegisterInfo & MRI
const bool IsIncomingArgumentHandler
virtual Register getStackAddress(uint64_t MemSize, int64_t Offset, MachinePointerInfo &MPO, ISD::ArgFlagsTy Flags)=0
Materialize a VReg containing the address of the specified stack-based object.
virtual void assignValueToAddress(const ArgInfo &Arg, unsigned ValRegIndex, Register Addr, LLT MemTy, const MachinePointerInfo &MPO, const CCValAssign &VA)
An overload which takes an ArgInfo if additional information about the arg is needed.
virtual LLT getStackValueStoreType(const DataLayout &DL, const CCValAssign &VA, ISD::ArgFlagsTy Flags) const
Return the in-memory size to write for the argument at VA.
bool isIncomingArgumentHandler() const
Returns true if the handler is dealing with incoming arguments, i.e.
virtual void assignValueToAddress(Register ValVReg, Register Addr, LLT MemTy, const MachinePointerInfo &MPO, const CCValAssign &VA)=0
The specified value has been assigned to a stack location.
Register extendRegister(Register ValReg, const CCValAssign &VA, unsigned MaxSizeBits=0)
Extend a register to the location type given in VA, capped at extending to at most MaxSize bits.
virtual unsigned assignCustomValue(ArgInfo &Arg, ArrayRef< CCValAssign > VAs, std::function< void()> *Thunk=nullptr)
Handle custom values, which may be passed into one or more of VAs.
virtual void assignValueToReg(Register ValVReg, Register PhysReg, const CCValAssign &VA)=0
The specified value has been assigned to a physical register, handle the appropriate COPY (either to ...
ValueHandler(bool IsIncoming, MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI)
This class contains a discriminated union of information about pointers in memory operands,...