14#ifndef LLVM_CODEGEN_GLOBALISEL_CALLLOWERING_H
15#define LLVM_CODEGEN_GLOBALISEL_CALLLOWERING_H
38class FunctionLoweringInfo;
39class MachineIRBuilder;
41struct MachinePointerInfo;
42class MachineRegisterInfo;
48 virtual void anchor();
56 : Ty(Ty), Flags(Flags) {}
72 const Value *OrigValue =
nullptr;
78 static const unsigned NoArgIndex = UINT_MAX;
82 const Value *OrigValue =
nullptr)
83 :
BaseArgInfo(Ty, Flags), Regs(Regs), OrigValue(OrigValue),
84 OrigArgIndex(OrigIndex) {
85 if (!Regs.
empty() && Flags.empty())
89 (Regs.
empty() || Regs[0] == 0)) &&
90 "only void types should have no register");
95 :
ArgInfo(Regs, OrigValue.
getType(), OrigIndex, Flags, &OrigValue) {}
132 std::optional<PtrAuthInfo>
PAI;
135 bool IsMustTailCall =
false;
139 bool IsTailCall =
false;
143 bool LoweredTailCall =
false;
146 bool IsVarArg =
false;
149 bool CanLowerReturn =
true;
161 bool IsConvergent =
true;
175 CCAssignFn *AssignFnVarArg_ =
nullptr)
176 : AssignFn(AssignFn_), AssignFnVarArg(AssignFnVarArg_),
177 IsIncomingArgumentHandler(IsIncoming) {
182 AssignFnVarArg = AssignFn;
190 return IsIncomingArgumentHandler;
200 if (getAssignFn(State.
isVarArg())(ValNo, ValVT, LocVT, LocInfo, Flags,
220 return IsVarArg ? AssignFnVarArg : AssignFn;
224 const bool IsIncomingArgumentHandler;
225 virtual void anchor();
230 CCAssignFn *AssignFnVarArg_ =
nullptr)
236 CCAssignFn *AssignFnVarArg_ =
nullptr)
247 : MIRBuilder(MIRBuilder),
MRI(
MRI),
248 IsIncomingArgumentHandler(IsIncoming) {}
255 return IsIncomingArgumentHandler;
296 assignValueToAddress(Arg.
Regs[ValRegIndex],
Addr, MemTy, MPO, VA);
307 std::function<
void()> *Thunk =
nullptr) {
324 unsigned MaxSizeBits = 0);
357 template <
class XXXTargetLowering>
358 const XXXTargetLowering *
getTLI()
const {
359 return static_cast<const XXXTargetLowering *
>(TLI);
365 unsigned ArgIdx)
const;
374 unsigned OpIdx)
const;
376 template <
typename FuncInfoTy>
378 const FuncInfoTy &FuncInfo)
const;
386 void splitToValueTypes(
const ArgInfo &OrigArgInfo,
402 bool determineAssignments(ValueAssigner &Assigner,
411 determineAndHandleAssignments(ValueHandler &Handler, ValueAssigner &Assigner,
420 bool handleAssignments(ValueHandler &Handler, SmallVectorImpl<ArgInfo> &Args,
422 SmallVectorImpl<CCValAssign> &ArgLocs,
423 MachineIRBuilder &MIRBuilder,
424 ArrayRef<Register> ThisReturnRegs = {})
const;
429 bool parametersInCSRMatch(
const MachineRegisterInfo &
MRI,
430 const uint32_t *CallerPreservedMask,
431 const SmallVectorImpl<CCValAssign> &ArgLocs,
432 const SmallVectorImpl<ArgInfo> &OutVals)
const;
444 bool resultsCompatible(CallLoweringInfo &
Info, MachineFunction &MF,
445 SmallVectorImpl<ArgInfo> &InArgs,
446 ValueAssigner &CalleeAssigner,
447 ValueAssigner &CallerAssigner)
const;
475 void insertSRetIncomingArgument(
const Function &
F,
484 CallLoweringInfo &
Info)
const;
489 CCAssignFn *Fn)
const;
507 bool IsVarArg)
const {
524 if (!supportSwiftError()) {
525 assert(SwiftErrorVReg == 0 &&
"attempt to use unsupported swifterror");
526 return lowerReturn(MIRBuilder, Val, VRegs, FLI);
597 std::optional<PtrAuthInfo> PAI,
Register ConvergenceCtrlToken,
598 std::function<
Register()> GetCalleeReg)
const;
610CallLowering::setArgFlags<Function>(CallLowering::ArgInfo &Arg,
unsigned OpIdx,
611 const DataLayout &
DL,
612 const Function &FuncInfo)
const;
615CallLowering::setArgFlags<CallBase>(CallLowering::ArgInfo &Arg,
unsigned OpIdx,
616 const DataLayout &
DL,
617 const CallBase &FuncInfo)
const;
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Analysis containing CSE Info
Implement a low-level type suitable for MachineInstr level instruction selection.
Promote Memory to Register
MachineInstr unsigned OpIdx
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),...
bool empty() const
empty - Check if the array is empty.
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
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...
virtual bool enableBigEndian() const
For targets which want to use big-endian can enable it with enableBigEndian() hook.
virtual bool supportSwiftError() 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...
virtual bool fallBackToDAGISel(const MachineFunction &MF) 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.
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.
LLVM_ABI 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.
This is an optimization pass for GlobalISel generic memory operations.
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, 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.
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 >(), const Value *OrigValue=nullptr)
ArgInfo(ArrayRef< Register > Regs, const Value &OrigValue, unsigned OrigIndex, ArrayRef< ISD::ArgFlagsTy > Flags=ArrayRef< ISD::ArgFlagsTy >())
SmallVector< ISD::ArgFlagsTy, 4 > Flags
BaseArgInfo(Type *Ty, ArrayRef< ISD::ArgFlagsTy > Flags=ArrayRef< ISD::ArgFlagsTy >())
ArgInfo OrigRet
Descriptor for the return type of the function.
Register ConvergenceCtrlToken
Valid if the call is a controlled convergent operation.
Register DemoteRegister
VReg to hold the hidden sret parameter.
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.
IncomingValueAssigner(CCAssignFn *AssignFn_, CCAssignFn *AssignFnVarArg_=nullptr)
Base class for ValueHandlers used for arguments coming into the current function, or for return value...
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).
virtual ~ValueAssigner()=default
MachineIRBuilder & MIRBuilder
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.
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.
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,...