LLVM: lib/CodeGen/CallingConvLower.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
25
26using namespace llvm;
27
30 bool NegativeOffsets)
31 : CallingConv(CC), IsVarArg(IsVarArg), MF(MF),
32 TRI(*MF.getSubtarget().getRegisterInfo()), Locs(Locs), Context(Context),
33 NegativeOffsets(NegativeOffsets) {
34
35
36 StackSize = 0;
37
39 UsedRegs.resize((TRI.getNumRegs()+31)/32);
40}
41
42
43
44
50 if (MinSize > (int)Size)
51 Size = MinSize;
55 MF.getSubtarget().getTargetLowering()->HandleByVal(this, Size, Alignment);
59}
60
61
62void CCState::MarkAllocated(MCPhysReg Reg) {
64 UsedRegs[(*AI).id() / 32] |= 1 << ((*AI).id() & 31);
65}
66
69 UsedRegs[(*AI).id() / 32] &= ~(1 << ((*AI).id() & 31));
70}
71
74 return false;
75
76 for (auto const &ValAssign : Locs)
77 if (ValAssign.isRegLoc() && TRI.regsOverlap(ValAssign.getLocReg(), Reg))
78 return false;
79 return true;
80}
81
82
83
84void
87 unsigned NumArgs = Ins.size();
88
89 for (unsigned i = 0; i != NumArgs; ++i) {
90 MVT ArgVT = Ins[i].VT;
92 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, Ins[i].OrigTy, *this))
94 }
95}
96
97
98
101
102 for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
103 MVT VT = Outs[i].VT;
105 if (Fn(i, VT, VT, CCValAssign::Full, ArgFlags, Outs[i].OrigTy, *this))
106 return false;
107 }
108 return true;
109}
110
111
112
115
116 for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
117 MVT VT = Outs[i].VT;
119 if (Fn(i, VT, VT, CCValAssign::Full, ArgFlags, Outs[i].OrigTy, *this))
121 }
122}
123
124
125
129 for (unsigned i = 0; i != NumOps; ++i) {
130 MVT ArgVT = Outs[i].VT;
132 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, Outs[i].OrigTy,
133 *this)) {
134#ifndef NDEBUG
135 dbgs() << "Call operand #" << i << " has unhandled type "
136 << ArgVT << '\n';
137#endif
139 }
140 }
141}
142
143
149 for (unsigned i = 0; i != NumOps; ++i) {
150 MVT ArgVT = ArgVTs[i];
152 if (Fn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, OrigTys[i], *this)) {
153#ifndef NDEBUG
154 dbgs() << "Call operand #" << i << " has unhandled type "
155 << ArgVT << '\n';
156#endif
158 }
159 }
160}
161
162
163
166 for (unsigned i = 0, e = Ins.size(); i != e; ++i) {
167 MVT VT = Ins[i].VT;
169 if (Fn(i, VT, VT, CCValAssign::Full, Flags, Ins[i].OrigTy, *this)) {
170#ifndef NDEBUG
171 dbgs() << "Call result #" << i << " has unhandled type "
172 << VT << '\n';
173#endif
175 }
176 }
177}
178
179
182#ifndef NDEBUG
183 dbgs() << "Call result has unhandled type "
184 << VT << '\n';
185#endif
187 }
188}
189
191 if (!AnalyzingMustTailForwardedRegs)
192 MF.getFrameInfo().ensureMaxAlignment(Alignment);
193}
194
197 return true;
199 return false;
201}
202
205 uint64_t SavedStackSize = StackSize;
206 Align SavedMaxStackArgAlign = MaxStackArgAlign;
207 unsigned NumLocs = Locs.size();
208
209
213
214
215
216 bool HaveRegParm;
217 do {
220#ifndef NDEBUG
221 dbgs() << "Call has unhandled type " << VT
222 << " while computing remaining regparms\n";
223#endif
225 }
226 HaveRegParm = Locs.back().isRegLoc();
227 } while (HaveRegParm);
228
229
230 assert(NumLocs < Locs.size() && "CC assignment failed to add location");
231 for (unsigned I = NumLocs, E = Locs.size(); I != E; ++I)
232 if (Locs[I].isRegLoc())
234
235
236
237
238 StackSize = SavedStackSize;
239 MaxStackArgAlign = SavedMaxStackArgAlign;
240 Locs.truncate(NumLocs);
241}
242
246
247
248
250 SaveAndRestore SavedMustTail(AnalyzingMustTailForwardedRegs, true);
251
252 for (MVT RegVT : RegParmTypes) {
255 const TargetLowering *TL = MF.getSubtarget().getTargetLowering();
257 for (MCRegister PReg : RemainingRegs) {
258 Register VReg = MF.addLiveIn(PReg, RC);
260 }
261 }
262}
263
269 if (CalleeCC == CallerCC)
270 return true;
272 CCState CCInfo1(CalleeCC, false, MF, RVLocs1, C);
274
276 CCState CCInfo2(CallerCC, false, MF, RVLocs2, C);
278
281 "The location must have been decided by now");
282
283 if (Loc1.getLocInfo() != Loc2.getLocInfo())
284 return false;
285
286 if (Loc1.isRegLoc() && Loc2.isRegLoc())
287 return Loc1.getLocReg() == Loc2.getLocReg();
288 if (Loc1.isMemLoc() && Loc2.isMemLoc())
291 };
292
293 return llvm::equal(RVLocs1, RVLocs2, AreCompatible);
294}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isValueTypeInRegForCC(CallingConv::ID CC, MVT VT)
Definition CallingConvLower.cpp:195
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
Register const TargetRegisterInfo * TRI
This file provides utility classes that use RAII to save and restore values.
This file describes how to lower LLVM code to machine code.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM_ABI void HandleByVal(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, int MinSize, Align MinAlign, ISD::ArgFlagsTy ArgFlags)
Allocate space on the stack large enough to pass an argument by value.
Definition CallingConvLower.cpp:45
LLVM_ABI void analyzeMustTailForwardedRegisters(SmallVectorImpl< ForwardedRegister > &Forwards, ArrayRef< MVT > RegParmTypes, CCAssignFn Fn)
Compute the set of registers that need to be preserved and forwarded to any musttail calls.
Definition CallingConvLower.cpp:243
static LLVM_ABI bool resultsCompatible(CallingConv::ID CalleeCC, CallingConv::ID CallerCC, MachineFunction &MF, LLVMContext &C, const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn CalleeFn, CCAssignFn CallerFn)
Returns true if the results of the two calling conventions are compatible.
Definition CallingConvLower.cpp:264
LLVM_ABI void AnalyzeCallResult(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeCallResult - Analyze the return values of a call, incorporating info about the passed values i...
Definition CallingConvLower.cpp:164
LLVM_ABI void getRemainingRegParmsForType(SmallVectorImpl< MCRegister > &Regs, MVT VT, CCAssignFn Fn)
Compute the remaining unused register parameters that would be used for the given value type.
Definition CallingConvLower.cpp:203
LLVM_ABI bool IsShadowAllocatedReg(MCRegister Reg) const
A shadow allocated register is a register that was allocated but wasn't added to the location list (L...
Definition CallingConvLower.cpp:72
LLVM_ABI bool CheckReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
CheckReturn - Analyze the return values of a function, returning true if the return can be performed ...
Definition CallingConvLower.cpp:99
LLVM_ABI void AnalyzeReturn(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeReturn - Analyze the returned values of a return, incorporating info about the result values i...
Definition CallingConvLower.cpp:113
int64_t AllocateStack(unsigned Size, Align Alignment)
AllocateStack - Allocate a chunk of stack space with the specified size and alignment.
LLVM_ABI void AnalyzeCallOperands(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
AnalyzeCallOperands - Analyze the outgoing arguments to a call, incorporating info about the passed v...
Definition CallingConvLower.cpp:126
LLVM_ABI void ensureMaxAlignment(Align Alignment)
Definition CallingConvLower.cpp:190
LLVM_ABI CCState(CallingConv::ID CC, bool IsVarArg, MachineFunction &MF, SmallVectorImpl< CCValAssign > &Locs, LLVMContext &Context, bool NegativeOffsets=false)
Definition CallingConvLower.cpp:28
bool isAllocated(MCRegister Reg) const
isAllocated - Return true if the specified register (or an alias) is allocated.
LLVM_ABI void AnalyzeFormalArguments(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeFormalArguments - Analyze an array of argument values, incorporating info about the formals in...
Definition CallingConvLower.cpp:85
void addLoc(const CCValAssign &V)
void clearByValRegsInfo()
CCValAssign - Represent assignment of one arg/retval to a location.
Register getLocReg() const
bool isPendingLoc() const
LocInfo getLocInfo() const
static CCValAssign getMem(unsigned ValNo, MVT ValVT, int64_t Offset, MVT LocVT, LocInfo HTP, bool IsCustom=false)
int64_t getLocMemOffset() const
This is an important class for using LLVM in a threaded context.
MCRegAliasIterator enumerates all registers aliasing Reg.
Wrapper class representing physical registers. Should be passed by value.
bool isVector() const
Return true if this is a vector value type.
bool isInteger() const
Return true if this is an integer or a vector integer type.
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.
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ X86_VectorCall
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
@ C
The default llvm calling convention, compatible with C.
@ X86_FastCall
'fast' analog of X86_StdCall.
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.
constexpr T MinAlign(U A, V B)
A and B are either alignments or offsets.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
bool equal(L &&LRange, R &&RRange)
Wrapper function around std::equal to detect if pair-wise elements between two ranges are the same.
This struct is a compact representation of a valid (non-zero power of two) alignment.
LLVM_ABI Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Describes a register that needs to be forwarded from the prologue to a musttail call.
unsigned getByValSize() const
Align getNonZeroByValAlign() const
A utility class that uses RAII to save and restore the value of a variable.