LLVM: include/llvm/CodeGen/CallingConvLower.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CODEGEN_CALLINGCONVLOWER_H
15#define LLVM_CODEGEN_CALLINGCONVLOWER_H
16
24#include
25
26namespace llvm {
27
32
33
34class CCValAssign {
35public:
42
44
46
50
51
54
55 };
56
57private:
58
59
60
61
62
63 std::variant<Register, int64_t, unsigned> Data;
64
65
66 unsigned ValNo;
67
68
69 unsigned isCustom : 1;
70
71
72 LocInfo HTP : 6;
73
74
75 MVT ValVT;
76
77
78 MVT LocVT;
79
80 CCValAssign(LocInfo HTP, unsigned ValNo, MVT ValVT, MVT LocVT, bool IsCustom)
81 : ValNo(ValNo), isCustom(IsCustom), HTP(HTP), ValVT(ValVT), LocVT(LocVT) {
82 }
83
84public:
86 MVT LocVT, LocInfo HTP, bool IsCustom = false) {
87 CCValAssign Ret(HTP, ValNo, ValVT, LocVT, IsCustom);
89 return Ret;
90 }
91
94 return getReg(ValNo, ValVT, Reg, LocVT, HTP, true);
95 }
96
97 static CCValAssign getMem(unsigned ValNo, MVT ValVT, int64_t Offset,
98 MVT LocVT, LocInfo HTP, bool IsCustom = false) {
99 CCValAssign Ret(HTP, ValNo, ValVT, LocVT, IsCustom);
101 return Ret;
102 }
103
106 return getMem(ValNo, ValVT, Offset, LocVT, HTP, true);
107 }
108
110 LocInfo HTP, unsigned ExtraInfo = 0) {
111 CCValAssign Ret(HTP, ValNo, ValVT, LocVT, false);
112 Ret.Data = ExtraInfo;
113 return Ret;
114 }
115
117
119
120 unsigned getValNo() const { return ValNo; }
122
123 bool isRegLoc() const { return std::holds_alternative(Data); }
124 bool isMemLoc() const { return std::holds_alternative<int64_t>(Data); }
125 bool isPendingLoc() const { return std::holds_alternative(Data); }
126
128
131 unsigned getExtraInfo() const { return std::get(Data); }
132
134
137 return (HTP == AExt || HTP == SExt || HTP == ZExt);
138 }
139
143};
144
145
146
154
155
156
160
161
162
163
167
168
169
170
172private:
174 bool IsVarArg;
175 bool AnalyzingMustTailForwardedRegs = false;
180
181 bool NegativeOffsets;
182
184 Align MaxStackArgAlign;
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216 struct ByValInfo {
217 ByValInfo(unsigned B, unsigned E) : Begin(B), End(E) {}
218
219
220 unsigned Begin;
221
222
223 unsigned End;
224 };
226
227
228
229 unsigned InRegsParamsProcessed;
230
231public:
234 bool NegativeOffsets = false);
235
237 Locs.push_back(V);
238 }
239
243 bool isVarArg() const { return IsVarArg; }
244
245
247
248
249
250
252 return alignTo(StackSize, MaxStackArgAlign);
253 }
254
255
256
258 return UsedRegs[Reg.id() / 32] & (1 << (Reg.id() & 31));
259 }
260
261
262
266
267
272
273
274
277
278
279
280
283
284
285
288
289
290
295
296
301
302
303
306
307
308
309
311
312
313
315
316
317
319 for (unsigned i = 0; i < Regs.size(); ++i)
321 return i;
322 return Regs.size();
323 }
324
327 MarkUnallocated(Reg);
328 }
329
330
331
332
336 MarkAllocated(Reg);
337 return Reg;
338 }
339
340
344 MarkAllocated(Reg);
345 MarkAllocated(ShadowReg);
346 return Reg;
347 }
348
349
350
351
354 if (FirstUnalloc == Regs.size())
355 return MCRegister();
356
357
359 MarkAllocated(Reg);
360 return Reg;
361 }
362
363
364
365
367 unsigned RegsRequired) {
368 if (RegsRequired > Regs.size())
369 return {};
370
371 for (unsigned StartIdx = 0; StartIdx <= Regs.size() - RegsRequired;
372 ++StartIdx) {
373 bool BlockAvailable = true;
374
375 for (unsigned BlockIdx = 0; BlockIdx < RegsRequired; ++BlockIdx) {
376 if (isAllocated(Regs[StartIdx + BlockIdx])) {
377 BlockAvailable = false;
378 break;
379 }
380 }
381 if (BlockAvailable) {
382
383 for (unsigned BlockIdx = 0; BlockIdx < RegsRequired; ++BlockIdx) {
384 MarkAllocated(Regs[StartIdx + BlockIdx]);
385 }
386 return Regs.slice(StartIdx, RegsRequired);
387 }
388 }
389
390 return {};
391 }
392
393
396 if (FirstUnalloc == Regs.size())
397 return MCRegister();
398
399
400 MCRegister Reg = Regs[FirstUnalloc], ShadowReg = ShadowRegs[FirstUnalloc];
401 MarkAllocated(Reg);
402 MarkAllocated(ShadowReg);
403 return Reg;
404 }
405
406
407
410 if (NegativeOffsets) {
411 StackSize = alignTo(StackSize + Size, Alignment);
413 } else {
416 }
417 MaxStackArgAlign = std::max(Alignment, MaxStackArgAlign);
420 }
421
423
424
425
429 MarkAllocated(Reg);
431 }
432
433
434
435
439
440
441
443
444
446
447
448
450 unsigned& BeginReg, unsigned& EndReg) const {
451 assert(InRegsParamRecordIndex < ByValRegs.size() &&
452 "Wrong ByVal parameter index");
453
454 const ByValInfo& info = ByValRegs[InRegsParamRecordIndex];
455 BeginReg = info.Begin;
456 EndReg = info.End;
457 }
458
459
461 ByValRegs.push_back(ByValInfo(RegBegin, RegEnd));
462 }
463
464
465
466
468 unsigned e = ByValRegs.size();
469 if (InRegsParamsProcessed < e)
470 ++InRegsParamsProcessed;
471 return InRegsParamsProcessed < e;
472 }
473
474
476 InRegsParamsProcessed = 0;
477 ByValRegs.clear();
478 }
479
480
482 InRegsParamsProcessed = 0;
483 }
484
485
487 return PendingLocs;
488 }
489
490
492 return PendingArgFlags;
493 }
494
495
496
497
498
501
502
503
507
508
509
515
516
517
518
519 template
522 unsigned NumFirstPassLocs = Locs.size();
523
524
525
527
528 for (auto Arg : Args) {
529 Arg.Flags.setSecArgPass();
531 }
532
533
535
536
538 TmpArgLocs.swap(Locs);
539 auto B = TmpArgLocs.begin(), E = TmpArgLocs.end();
540 std::merge(B, B + NumFirstPassLocs, B + NumFirstPassLocs, E,
541 std::back_inserter(Locs),
543 return A.getValNo() < B.getValNo();
544 });
545 }
546
547private:
548
550
552};
553
554}
555
556#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Promote Memory to Register
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
CCState - This class holds information needed while lowering arguments and return values.
Definition CallingConvLower.h:171
void getInRegsParamInfo(unsigned InRegsParamRecordIndex, unsigned &BeginReg, unsigned &EndReg) const
Definition CallingConvLower.h:449
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.
MachineFunction & getMachineFunction() const
Definition CallingConvLower.h:241
unsigned getFirstUnallocated(ArrayRef< MCPhysReg > Regs) const
getFirstUnallocated - Return the index of the first unallocated register in the set,...
Definition CallingConvLower.h:318
void AnalyzeArguments(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
The function will invoke AnalyzeFormalArguments.
Definition CallingConvLower.h:268
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.
int64_t AllocateStack(unsigned Size, Align Alignment, ArrayRef< MCPhysReg > ShadowRegs)
Version of AllocateStack with list of extra registers to be shadowed.
Definition CallingConvLower.h:426
void AnalyzeArgumentsSecondPass(const SmallVectorImpl< T > &Args, CCAssignFn Fn)
The function runs an additional analysis pass over function arguments.
Definition CallingConvLower.h:520
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.
MCRegister AllocateReg(ArrayRef< MCPhysReg > Regs)
AllocateReg - Attempt to allocate one of the specified registers.
Definition CallingConvLower.h:352
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...
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.
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...
void AnalyzeArguments(const SmallVectorImpl< ISD::OutputArg > &Outs, CCAssignFn Fn)
The function will invoke AnalyzeCallOperands.
Definition CallingConvLower.h:297
CallingConv::ID getCallingConv() const
Definition CallingConvLower.h:242
SmallVectorImpl< ISD::ArgFlagsTy > & getPendingArgFlags()
Definition CallingConvLower.h:491
MCRegister AllocateReg(MCPhysReg Reg)
AllocateReg - Attempt to allocate one register.
Definition CallingConvLower.h:333
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 ...
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...
LLVMContext & getContext() const
Definition CallingConvLower.h:240
ArrayRef< MCPhysReg > AllocateRegBlock(ArrayRef< MCPhysReg > Regs, unsigned RegsRequired)
Attempt to allocate a block of RegsRequired consecutive registers.
Definition CallingConvLower.h:366
int64_t AllocateStack(unsigned Size, Align Alignment)
AllocateStack - Allocate a chunk of stack space with the specified size and alignment.
Definition CallingConvLower.h:408
bool nextInRegsParam()
Definition CallingConvLower.h:467
void rewindByValRegsInfo()
Definition CallingConvLower.h:481
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...
unsigned getInRegsParamsProcessed() const
Definition CallingConvLower.h:445
LLVM_ABI void ensureMaxAlignment(Align Alignment)
void DeallocateReg(MCPhysReg Reg)
Definition CallingConvLower.h:325
LLVM_ABI CCState(CallingConv::ID CC, bool IsVarArg, MachineFunction &MF, SmallVectorImpl< CCValAssign > &Locs, LLVMContext &Context, bool NegativeOffsets=false)
uint64_t getStackSize() const
Returns the size of the currently allocated portion of the stack.
Definition CallingConvLower.h:246
MCRegister AllocateReg(ArrayRef< MCPhysReg > Regs, const MCPhysReg *ShadowRegs)
Version of AllocateReg with list of registers to be shadowed.
Definition CallingConvLower.h:394
SmallVectorImpl< CCValAssign > & getPendingLocs()
Definition CallingConvLower.h:486
bool isVarArg() const
Definition CallingConvLower.h:243
uint64_t getAlignedCallFrameSize() const
getAlignedCallFrameSize - Return the size of the call frame needed to be able to store all arguments ...
Definition CallingConvLower.h:251
bool isAllocated(MCRegister Reg) const
isAllocated - Return true if the specified register (or an alias) is allocated.
Definition CallingConvLower.h:257
void addInRegsParamInfo(unsigned RegBegin, unsigned RegEnd)
Definition CallingConvLower.h:460
MCRegister AllocateReg(MCPhysReg Reg, MCPhysReg ShadowReg)
Version of AllocateReg with extra register to be shadowed.
Definition CallingConvLower.h:341
LLVM_ABI void AnalyzeFormalArguments(const SmallVectorImpl< ISD::InputArg > &Ins, CCAssignFn Fn)
AnalyzeFormalArguments - Analyze an array of argument values, incorporating info about the formals in...
void addLoc(const CCValAssign &V)
Definition CallingConvLower.h:236
unsigned getInRegsParamsCount() const
Definition CallingConvLower.h:442
void clearByValRegsInfo()
Definition CallingConvLower.h:475
CCValAssign - Represent assignment of one arg/retval to a location.
Definition CallingConvLower.h:34
bool isRegLoc() const
Definition CallingConvLower.h:123
void convertToReg(MCRegister Reg)
Definition CallingConvLower.h:116
static CCValAssign getPending(unsigned ValNo, MVT ValVT, MVT LocVT, LocInfo HTP, unsigned ExtraInfo=0)
Definition CallingConvLower.h:109
Register getLocReg() const
Definition CallingConvLower.h:129
bool isPendingLoc() const
Definition CallingConvLower.h:125
LocInfo getLocInfo() const
Definition CallingConvLower.h:135
static CCValAssign getReg(unsigned ValNo, MVT ValVT, MCRegister Reg, MVT LocVT, LocInfo HTP, bool IsCustom=false)
Definition CallingConvLower.h:85
LocInfo
Definition CallingConvLower.h:36
@ BCvt
Definition CallingConvLower.h:47
@ ZExtUpper
Definition CallingConvLower.h:43
@ Trunc
Definition CallingConvLower.h:48
@ SExt
Definition CallingConvLower.h:38
@ ZExt
Definition CallingConvLower.h:39
@ Full
Definition CallingConvLower.h:37
@ VExt
Definition CallingConvLower.h:49
@ Indirect
Definition CallingConvLower.h:53
@ FPExt
Definition CallingConvLower.h:52
@ AExt
Definition CallingConvLower.h:40
@ AExtUpper
Definition CallingConvLower.h:45
@ SExtUpper
Definition CallingConvLower.h:41
static CCValAssign getCustomReg(unsigned ValNo, MVT ValVT, MCRegister Reg, MVT LocVT, LocInfo HTP)
Definition CallingConvLower.h:92
bool isUpperBitsInLoc() const
Definition CallingConvLower.h:140
static CCValAssign getMem(unsigned ValNo, MVT ValVT, int64_t Offset, MVT LocVT, LocInfo HTP, bool IsCustom=false)
Definition CallingConvLower.h:97
bool needsCustom() const
Definition CallingConvLower.h:127
MVT getValVT() const
Definition CallingConvLower.h:121
bool isMemLoc() const
Definition CallingConvLower.h:124
unsigned getExtraInfo() const
Definition CallingConvLower.h:131
bool isExtInLoc() const
Definition CallingConvLower.h:136
int64_t getLocMemOffset() const
Definition CallingConvLower.h:130
unsigned getValNo() const
Definition CallingConvLower.h:120
static CCValAssign getCustomMem(unsigned ValNo, MVT ValVT, int64_t Offset, MVT LocVT, LocInfo HTP)
Definition CallingConvLower.h:104
MVT getLocVT() const
Definition CallingConvLower.h:133
void convertToMem(int64_t Offset)
Definition CallingConvLower.h:118
This is an important class for using LLVM in a threaded context.
Wrapper class representing physical registers. Should be passed by value.
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 swap(SmallVectorImpl &RHS)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ 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, Type *OrigTy, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
Definition CallingConvLower.h:157
bool CCCustomFn(unsigned &ValNo, MVT &ValVT, MVT &LocVT, CCValAssign::LocInfo &LocInfo, ISD::ArgFlagsTy &ArgFlags, CCState &State)
CCCustomFn - This function assigns a location for Val, possibly updating all args to reflect changes ...
Definition CallingConvLower.h:164
constexpr T MinAlign(U A, V B)
A and B are either alignments or offsets.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
ForwardedRegister(Register VReg, MCPhysReg PReg, MVT VT)
Definition CallingConvLower.h:148
MVT VT
Definition CallingConvLower.h:152
Register VReg
Definition CallingConvLower.h:150
MCPhysReg PReg
Definition CallingConvLower.h:151