26 #define DEBUG_TYPE "call-lowering" 30 void CallLowering::anchor() {}
77 template <
typename FuncInfoTy>
80 const FuncInfoTy &FuncInfo)
const {
81 auto &Flags = Arg.
Flags[0];
94 Flags.setSwiftError();
100 if (Flags.isByVal() || Flags.isInAlloca()) {
101 Type *ElementTy = cast<PointerType>(Arg.
Ty)->getElementType();
109 if (FuncInfo.getParamAlignment(OpIdx - 2))
110 FrameAlign = FuncInfo.getParamAlignment(OpIdx - 2);
113 Flags.setByValAlign(
Align(FrameAlign));
132 assert(SrcRegs.
size() > 1 &&
"Nothing to pack");
146 for (
unsigned i = 0; i < SrcRegs.
size(); ++i) {
148 MIRBuilder.
buildInsert(NewDst, Dst, SrcRegs[i], Offsets[i]);
158 assert(DstRegs.
size() > 1 &&
"Nothing to unpack");
167 for (
unsigned i = 0; i < DstRegs.
size(); ++i)
168 MIRBuilder.
buildExtract(DstRegs[i], SrcReg, Offsets[i]);
190 unsigned NumArgs = Args.
size();
191 for (
unsigned i = 0; i != NumArgs; ++i) {
194 Args[i].Flags[0], CCInfo)) {
222 Args[i].Flags[0], CCInfo))
228 Args[i].OrigRegs.
push_back(Args[i].Regs[0]);
229 Args[i].Regs.
clear();
230 Args[i].Flags.
clear();
235 for (
unsigned Part = 0; Part < NumParts; ++Part) {
243 if (Part == NumParts - 1)
249 Args[i], Args[i].Flags[Part], CCInfo)) {
262 Register LargeReg = Args[i].Regs[0];
264 auto Unmerge = MIRBuilder.
buildUnmerge(SmallTy, LargeReg);
265 assert(Unmerge->getNumOperands() == NumParts + 1);
268 Args[i].Regs.
clear();
269 Args[i].Flags.
clear();
270 for (
unsigned PartIdx = 0; PartIdx < NumParts; ++PartIdx) {
276 if (PartIdx == NumParts - 1)
279 Args[i].Regs.
push_back(Unmerge.getReg(PartIdx));
282 Args[i], Args[i].Flags[PartIdx], CCInfo))
289 for (
unsigned i = 0,
e = Args.
size(), j = 0; i !=
e; ++i, ++j) {
290 assert(j < ArgLocs.
size() &&
"Skipped too many arg locs");
293 assert(VA.getValNo() == i &&
"Location doesn't correspond to current arg");
295 if (VA.needsCustom()) {
304 MVT VAVT = VA.getValVT();
309 unsigned NumArgRegs = Args[i].Regs.
size();
313 assert((j + (NumArgRegs - 1)) < ArgLocs.
size() &&
314 "Too many regs for number of args");
315 for (
unsigned Part = 0; Part < NumArgRegs; ++Part) {
317 VA = ArgLocs[j + Part];
323 MIRBuilder.
buildMerge(Args[i].OrigRegs[0], Args[i].Regs);
326 const LLT VATy(VAVT);
334 const LLT OrigTy(OrigVT);
338 <<
"Incoming promoted vector arg has too many elts");
341 auto Unmerge = MIRBuilder.
buildUnmerge({OrigTy, OrigTy}, {NewReg});
342 MIRBuilder.
buildCopy(ArgReg, Unmerge.getReg(0));
348 "Too many regs for number of args");
350 for (
unsigned Part = 0; Part < Args[i].Regs.
size(); ++Part) {
352 VA = ArgLocs[j + Part];
355 j += Args[i].Regs.
size() - 1;
359 }
else if (VA.isMemLoc()) {
362 if (Args[i].Regs.
size() > 1) {
365 <<
"Load/store a split arg to/from the stack not implemented yet");
371 unsigned Offset = VA.getLocMemOffset();
387 for (
unsigned i = 0,
e = Args.
size(); i <
e; ++i) {
389 CCAssignFn &Fn = Args[i].IsFixed ? AssignFnFixed : AssignFnVarArg;
393 <<
" (arg number = " << i <<
"\n");
411 if (CallerCC == CalleeCC)
417 CalleeAssignFnVarArg))
423 CalleeAssignFnVarArg))
428 if (ArgLocs1.
size() != ArgLocs2.
size())
432 for (
unsigned i = 0,
e = ArgLocs1.
size(); i <
e; ++i) {
461 if (LocTy.getSizeInBits() ==
MRI.getType(ValReg).getSizeInBits())
475 Register NewReg =
MRI.createGenericVirtualRegister(LocTy);
480 Register NewReg =
MRI.createGenericVirtualRegister(LocTy);
488 void CallLowering::ValueHandler::anchor() {}
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
MachineOperand Callee
Destination of the call.
MachineInstrBuilder buildUnmerge(ArrayRef< LLT > Res, const SrcOp &Op)
Build and insert Res0, ...
This class represents lattice values for constants.
Register getLocReg() const
MachineInstrBuilder buildInsert(Register Res, Register Src, Register Op, unsigned Index)
void push_back(const T &Elt)
bool handleAssignments(MachineIRBuilder &MIRBuilder, SmallVectorImpl< ArgInfo > &Args, ValueHandler &Handler) const
Invoke Handler::assignArg on each of the given Args and then use Callback to move them to the assigne...
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
This class represents a function call, abstracting a target machine's calling convention.
bool IsMustTailCall
True if the call must be tail call optimized.
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...
unsigned getVectorNumElements() const
bool isTailCall() const
Tests if this call site is marked as a tail call.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
Register SwiftErrorVReg
Valid if the call has a swifterror inout parameter, and contains the vreg that the swifterror should ...
virtual void assignValueToAddress(Register ValVReg, Register Addr, uint64_t Size, MachinePointerInfo &MPO, CCValAssign &VA)=0
The specified value has been assigned to a stack location.
virtual unsigned getByValTypeAlignment(Type *Ty, const DataLayout &DL) const
Return the desired alignment for ByVal or InAlloca aggregate function arguments in the caller paramet...
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
bool isValid() const
Return true if this is a valid simple valuetype.
FunctionType * getFunctionType() const
virtual bool assignArg(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, const ArgInfo &Info, ISD::ArgFlagsTy Flags, CCState &State)
SmallVector< ISD::ArgFlagsTy, 4 > Flags
CallingConv::ID getCallingConv() const
Get the calling convention of the call.
MachineInstrBuilder buildExtract(const DstOp &Res, const SrcOp &Src, uint64_t Index)
Build and insert `Res0, ...
const TargetLowering * getTLI() const
Getter for generic TargetLowering class.
MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ANYEXT Op0.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
virtual MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
virtual bool lowerCall(MachineIRBuilder &MIRBuilder, CallLoweringInfo &Info) const
This hook must be implemented to lower the given call instruction, including argument and return valu...
Type * getType() const
Return the type of the instruction that generated this call site.
LocInfo getLocInfo() const
InstrTy * getInstruction() const
Type * getValueAsType() const
Return the attribute's value as a Type.
bool isMustTailCall() const
Tests if this call site must be tail call optimized.
MachineFunction & getMF()
Getter for the function we currently build.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool analyzeArgInfo(CCState &CCState, SmallVectorImpl< ArgInfo > &Args, CCAssignFn &AssignFnFixed, CCAssignFn &AssignFnVarArg) const
Analyze passed or returned values from a call, supplied in ArgInfo, incorporating info about the pass...
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Analysis containing CSE Info
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
bool isVoidTy() const
Return true if this is 'void'.
MachineInstrBuilder buildSExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_SEXT Op.
MachineRegisterInfo * getMRI()
Getter for MRI.
unsigned const MachineRegisterInfo * MRI
The instances of the Type class are immutable: once they are created, they are never changed...
LLT getLLTForMVT(MVT Ty)
Get a rough equivalent of an LLT for a given MVT.
MachineInstrBuilder buildZExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ZEXT Op.
size_t size() const
size - Get the array size.
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
bool resultsCompatible(CallLoweringInfo &Info, MachineFunction &MF, SmallVectorImpl< ArgInfo > &InArgs, CCAssignFn &CalleeAssignFnFixed, CCAssignFn &CalleeAssignFnVarArg, CCAssignFn &CallerAssignFnFixed, CCAssignFn &CallerAssignFnVarArg) const
void computeValueLLTs(const DataLayout &DL, Type &Ty, SmallVectorImpl< LLT > &ValueTys, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
computeValueLLTs - Given an LLVM IR type, compute a sequence of LLTs that represent all the individua...
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Helper class to build MachineInstr.
Register packRegs(ArrayRef< Register > SrcRegs, Type *PackedTy, MachineIRBuilder &MIRBuilder) const
Generate instructions for packing SrcRegs into one big register corresponding to the aggregate type P...
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static MVT getVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
void setArgFlags(ArgInfo &Arg, unsigned OpIdx, const DataLayout &DL, const FuncInfoTy &FuncInfo) const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
static unsigned NumFixedArgs
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_TRUNC Op.
static constexpr const Align None()
Returns a default constructed Align which corresponds to no alignment.
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
iterator_range< IterTy > args() const
bool isInTailCallPosition(ImmutableCallSite CS, const TargetMachine &TM)
Test if the given instruction is in a position to be optimized with a tail-call.
virtual unsigned assignCustomValue(const ArgInfo &Arg, ArrayRef< CCValAssign > VAs)
Handle custom values, which may be passed into one or more of VAs.
LLT getLLTForType(Type &Ty, const DataLayout &DL)
Construct a low-level type based on an LLVM type.
SmallVector< ArgInfo, 8 > OrigArgs
List of descriptors of the arguments passed to the function.
void unpackRegs(ArrayRef< Register > DstRegs, Register SrcReg, Type *PackedTy, MachineIRBuilder &MIRBuilder) const
Generate instructions for unpacking SrcReg into the DstRegs corresponding to the aggregate type Packe...
bool IsVarArg
True if the call is to a vararg function.
Register extendRegister(Register ValReg, CCValAssign &VA)
void setOrigAlign(Align A)
virtual unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const
Certain targets require unusual breakdowns of certain types.
CCState - This class holds information needed while lowering arguments and return values...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
CCValAssign - Represent assignment of one arg/retval to a location.
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
This file declares the MachineIRBuilder class.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
BBTy * getParent() const
Get the basic block containing the call site.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
virtual void assignValueToReg(Register ValVReg, Register PhysReg, CCValAssign &VA)=0
The specified value has been assigned to a physical register, handle the appropriate COPY (either to ...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
unsigned getLocMemOffset() const
StringRef getValueAsString() const
Return the attribute's value as a string.
CallingConv::ID CallConv
Calling convention to be used for the call.
Establish a view to a call site for examination.
const Function * getParent() const
Return the enclosing method, or null if none.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool IsTailCall
True if the call passes all target-independent checks for tail call optimization. ...
Module * getParent()
Get the module that this global value is contained inside of...
uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
This file describes how to lower LLVM calls to machine code calls.
virtual Register getStackAddress(uint64_t Size, int64_t Offset, MachinePointerInfo &MPO)=0
Materialize a VReg containing the address of the specified stack-based object.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
MachineInstrBuilder buildMerge(const DstOp &Res, ArrayRef< Register > Ops)
Build and insert Res = G_MERGE_VALUES Op0, ...
print Print MemDeps of function
MachineInstrBuilder buildUndef(const DstOp &Res)
Build and insert Res = IMPLICIT_DEF.
Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
virtual bool isIncomingArgumentHandler() const =0
Returns true if the handler is dealing with incoming arguments, i.e.
ArgInfo OrigRet
Descriptor for the return type of the function.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Wrapper class representing virtual and physical registers.
This file describes how to lower LLVM code to machine code.