LLVM 22.0.0git
TargetCallingConv.h
Go to the documentation of this file.
1//===-- llvm/CodeGen/TargetCallingConv.h - Calling Convention ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines types for working with calling-convention information.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CODEGEN_TARGETCALLINGCONV_H
14#define LLVM_CODEGEN_TARGETCALLINGCONV_H
15
20#include <cassert>
21#include <climits>
22#include <cstdint>
23
24namespace llvm {
25namespace ISD {
26
27 struct ArgFlagsTy {
28 private:
29 unsigned IsZExt : 1; ///< Zero extended
30 unsigned IsSExt : 1; ///< Sign extended
31 unsigned IsNoExt : 1; ///< No extension
32 unsigned IsInReg : 1; ///< Passed in register
33 unsigned IsSRet : 1; ///< Hidden struct-ret ptr
34 unsigned IsByVal : 1; ///< Struct passed by value
35 unsigned IsByRef : 1; ///< Passed in memory
36 unsigned IsNest : 1; ///< Nested fn static chain
37 unsigned IsReturned : 1; ///< Always returned
38 unsigned IsSplit : 1;
39 unsigned IsInAlloca : 1; ///< Passed with inalloca
40 unsigned IsPreallocated : 1; ///< ByVal without the copy
41 unsigned IsSplitEnd : 1; ///< Last part of a split
42 unsigned IsSwiftSelf : 1; ///< Swift self parameter
43 unsigned IsSwiftAsync : 1; ///< Swift async context parameter
44 unsigned IsSwiftError : 1; ///< Swift error parameter
45 unsigned IsCFGuardTarget : 1; ///< Control Flow Guard target
46 unsigned IsHva : 1; ///< HVA field for
47 unsigned IsHvaStart : 1; ///< HVA structure start
48 unsigned IsSecArgPass : 1; ///< Second argument
49 unsigned MemAlign : 6; ///< Log 2 of alignment when arg is passed in memory
50 ///< (including byval/byref). The max alignment is
51 ///< verified in IR verification.
52 unsigned OrigAlign : 5; ///< Log 2 of original alignment
53 unsigned IsInConsecutiveRegsLast : 1;
54 unsigned IsInConsecutiveRegs : 1;
55 unsigned IsCopyElisionCandidate : 1; ///< Argument copy elision candidate
56 unsigned IsPointer : 1;
57 /// Whether this is part of a variable argument list (non-fixed).
58 unsigned IsVarArg : 1;
59
60 unsigned ByValOrByRefSize = 0; ///< Byval or byref struct size
61
62 unsigned PointerAddrSpace = 0; ///< Address space of pointer argument
63
64 public:
66 : IsZExt(0), IsSExt(0), IsNoExt(0), IsInReg(0), IsSRet(0), IsByVal(0),
67 IsByRef(0), IsNest(0), IsReturned(0), IsSplit(0), IsInAlloca(0),
68 IsPreallocated(0), IsSplitEnd(0), IsSwiftSelf(0), IsSwiftAsync(0),
69 IsSwiftError(0), IsCFGuardTarget(0), IsHva(0), IsHvaStart(0),
70 IsSecArgPass(0), MemAlign(0), OrigAlign(0),
71 IsInConsecutiveRegsLast(0), IsInConsecutiveRegs(0),
72 IsCopyElisionCandidate(0), IsPointer(0), IsVarArg(0) {
73 static_assert(sizeof(*this) == 4 * sizeof(unsigned), "flags are too big");
74 }
75
76 bool isZExt() const { return IsZExt; }
77 void setZExt() { IsZExt = 1; }
78
79 bool isSExt() const { return IsSExt; }
80 void setSExt() { IsSExt = 1; }
81
82 bool isNoExt() const { return IsNoExt; }
83 void setNoExt() { IsNoExt = 1; }
84
85 bool isInReg() const { return IsInReg; }
86 void setInReg() { IsInReg = 1; }
87
88 bool isSRet() const { return IsSRet; }
89 void setSRet() { IsSRet = 1; }
90
91 bool isByVal() const { return IsByVal; }
92 void setByVal() { IsByVal = 1; }
93
94 bool isByRef() const { return IsByRef; }
95 void setByRef() { IsByRef = 1; }
96
97 bool isInAlloca() const { return IsInAlloca; }
98 void setInAlloca() { IsInAlloca = 1; }
99
100 bool isPreallocated() const { return IsPreallocated; }
101 void setPreallocated() { IsPreallocated = 1; }
102
103 bool isSwiftSelf() const { return IsSwiftSelf; }
104 void setSwiftSelf() { IsSwiftSelf = 1; }
105
106 bool isSwiftAsync() const { return IsSwiftAsync; }
107 void setSwiftAsync() { IsSwiftAsync = 1; }
108
109 bool isSwiftError() const { return IsSwiftError; }
110 void setSwiftError() { IsSwiftError = 1; }
111
112 bool isCFGuardTarget() const { return IsCFGuardTarget; }
113 void setCFGuardTarget() { IsCFGuardTarget = 1; }
114
115 bool isHva() const { return IsHva; }
116 void setHva() { IsHva = 1; }
117
118 bool isHvaStart() const { return IsHvaStart; }
119 void setHvaStart() { IsHvaStart = 1; }
120
121 bool isSecArgPass() const { return IsSecArgPass; }
122 void setSecArgPass() { IsSecArgPass = 1; }
123
124 bool isNest() const { return IsNest; }
125 void setNest() { IsNest = 1; }
126
127 bool isReturned() const { return IsReturned; }
128 void setReturned(bool V = true) { IsReturned = V; }
129
130 bool isInConsecutiveRegs() const { return IsInConsecutiveRegs; }
131 void setInConsecutiveRegs(bool Flag = true) { IsInConsecutiveRegs = Flag; }
132
133 bool isInConsecutiveRegsLast() const { return IsInConsecutiveRegsLast; }
134 void setInConsecutiveRegsLast(bool Flag = true) {
135 IsInConsecutiveRegsLast = Flag;
136 }
137
138 bool isSplit() const { return IsSplit; }
139 void setSplit() { IsSplit = 1; }
140
141 bool isSplitEnd() const { return IsSplitEnd; }
142 void setSplitEnd() { IsSplitEnd = 1; }
143
144 bool isCopyElisionCandidate() const { return IsCopyElisionCandidate; }
145 void setCopyElisionCandidate() { IsCopyElisionCandidate = 1; }
146
147 bool isPointer() const { return IsPointer; }
148 void setPointer() { IsPointer = 1; }
149
150 bool isVarArg() const { return IsVarArg; }
151 void setVarArg() { IsVarArg = 1; }
152
154 return decodeMaybeAlign(MemAlign).valueOrOne();
155 }
156
158 MemAlign = encode(A);
159 assert(getNonZeroMemAlign() == A && "bitfield overflow");
160 }
161
163 assert(isByVal());
164 MaybeAlign A = decodeMaybeAlign(MemAlign);
165 assert(A && "ByValAlign must be defined");
166 return *A;
167 }
168
170 return decodeMaybeAlign(OrigAlign).valueOrOne();
171 }
172
174 OrigAlign = encode(A);
175 assert(getNonZeroOrigAlign() == A && "bitfield overflow");
176 }
177
178 unsigned getByValSize() const {
179 assert(isByVal() && !isByRef());
180 return ByValOrByRefSize;
181 }
182 void setByValSize(unsigned S) {
183 assert(isByVal() && !isByRef());
184 ByValOrByRefSize = S;
185 }
186
187 unsigned getByRefSize() const {
188 assert(!isByVal() && isByRef());
189 return ByValOrByRefSize;
190 }
191 void setByRefSize(unsigned S) {
192 assert(!isByVal() && isByRef());
193 ByValOrByRefSize = S;
194 }
195
196 unsigned getPointerAddrSpace() const { return PointerAddrSpace; }
197 void setPointerAddrSpace(unsigned AS) { PointerAddrSpace = AS; }
198};
199
200 /// InputArg - This struct carries flags and type information about a
201 /// single incoming (formal) argument or incoming (from the perspective
202 /// of the caller) return value virtual register.
203 ///
204 struct InputArg {
206 /// Legalized type of this argument part.
207 MVT VT = MVT::Other;
208 /// Usually the non-legalized type of the argument, which is the EVT
209 /// corresponding to the OrigTy IR type. However, for post-legalization
210 /// libcalls, this will be a legalized type.
212 /// Original IR type of the argument. For aggregates, this is the type of
213 /// an individual aggregate element, not the whole aggregate.
215 bool Used;
216
217 /// Index original Function's argument.
218 unsigned OrigArgIndex;
219 /// Sentinel value for implicit machine-level input arguments.
220 static const unsigned NoArgIndex = UINT_MAX;
221
222 /// Offset in bytes of current input value relative to the beginning of
223 /// original argument. E.g. if argument was splitted into four 32 bit
224 /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12.
225 unsigned PartOffset;
226
228 unsigned OrigArgIndex, unsigned PartOffset)
231
232 bool isOrigArg() const {
233 return OrigArgIndex != NoArgIndex;
234 }
235
236 unsigned getOrigArgIndex() const {
237 assert(OrigArgIndex != NoArgIndex && "Implicit machine-level argument");
238 return OrigArgIndex;
239 }
240 };
241
242 /// OutputArg - This struct carries flags and a value for a
243 /// single outgoing (actual) argument or outgoing (from the perspective
244 /// of the caller) return value virtual register.
245 ///
246 struct OutputArg {
248 // Legalized type of this argument part.
250 /// Non-legalized type of the argument. This is the EVT corresponding to
251 /// the OrigTy IR type.
253 /// Original IR type of the argument. For aggregates, this is the type of
254 /// an individual aggregate element, not the whole aggregate.
256
257 /// Index original Function's argument.
258 unsigned OrigArgIndex;
259
260 /// Offset in bytes of current output value relative to the beginning of
261 /// original argument. E.g. if argument was splitted into four 32 bit
262 /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12.
263 unsigned PartOffset;
264
266 unsigned OrigArgIndex, unsigned PartOffset)
269 };
270
271} // end namespace ISD
272} // end namespace llvm
273
274#endif // LLVM_CODEGEN_TARGETCALLINGCONV_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
Definition: Alignment.h:217
MaybeAlign decodeMaybeAlign(unsigned Value)
Dual operation of the encode function above.
Definition: Alignment.h:220
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Extended Value Type.
Definition: ValueTypes.h:35
bool isInConsecutiveRegs() const
void setInConsecutiveRegs(bool Flag=true)
bool isCopyElisionCandidate() const
Align getNonZeroOrigAlign() const
void setPointerAddrSpace(unsigned AS)
unsigned getPointerAddrSpace() const
unsigned getByRefSize() const
void setReturned(bool V=true)
void setByRefSize(unsigned S)
unsigned getByValSize() const
bool isInConsecutiveRegsLast() const
Align getNonZeroMemAlign() const
void setByValSize(unsigned S)
void setInConsecutiveRegsLast(bool Flag=true)
Align getNonZeroByValAlign() const
InputArg - This struct carries flags and type information about a single incoming (formal) argument o...
static const unsigned NoArgIndex
Sentinel value for implicit machine-level input arguments.
Type * OrigTy
Original IR type of the argument.
InputArg(ArgFlagsTy Flags, MVT VT, EVT ArgVT, Type *OrigTy, bool Used, unsigned OrigArgIndex, unsigned PartOffset)
MVT VT
Legalized type of this argument part.
unsigned PartOffset
Offset in bytes of current input value relative to the beginning of original argument.
EVT ArgVT
Usually the non-legalized type of the argument, which is the EVT corresponding to the OrigTy IR type.
unsigned getOrigArgIndex() const
unsigned OrigArgIndex
Index original Function's argument.
OutputArg - This struct carries flags and a value for a single outgoing (actual) argument or outgoing...
unsigned PartOffset
Offset in bytes of current output value relative to the beginning of original argument.
OutputArg(ArgFlagsTy Flags, MVT VT, EVT ArgVT, Type *OrigTy, unsigned OrigArgIndex, unsigned PartOffset)
Type * OrigTy
Original IR type of the argument.
EVT ArgVT
Non-legalized type of the argument.
unsigned OrigArgIndex
Index original Function's argument.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition: Alignment.h:141