1 //===-- llvm/CodeGen/TargetCallingConv.h - Calling Convention ---*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines types for working with calling-convention information.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CODEGEN_TARGETCALLINGCONV_H
14 #define LLVM_CODEGEN_TARGETCALLINGCONV_H
16 #include "llvm/CodeGen/ValueTypes.h"
17 #include "llvm/Support/Alignment.h"
18 #include "llvm/Support/MachineValueType.h"
19 #include "llvm/Support/MathExtras.h"
29 unsigned IsZExt : 1; ///< Zero extended
30 unsigned IsSExt : 1; ///< Sign extended
31 unsigned IsInReg : 1; ///< Passed in register
32 unsigned IsSRet : 1; ///< Hidden struct-ret ptr
33 unsigned IsByVal : 1; ///< Struct passed by value
34 unsigned IsNest : 1; ///< Nested fn static chain
35 unsigned IsReturned : 1; ///< Always returned
37 unsigned IsInAlloca : 1; ///< Passed with inalloca
38 unsigned IsPreallocated : 1; ///< ByVal without the copy
39 unsigned IsSplitEnd : 1; ///< Last part of a split
40 unsigned IsSwiftSelf : 1; ///< Swift self parameter
41 unsigned IsSwiftError : 1; ///< Swift error parameter
42 unsigned IsCFGuardTarget : 1; ///< Control Flow Guard target
43 unsigned IsHva : 1; ///< HVA field for
44 unsigned IsHvaStart : 1; ///< HVA structure start
45 unsigned IsSecArgPass : 1; ///< Second argument
46 unsigned ByValAlign : 4; ///< Log 2 of byval alignment
47 unsigned OrigAlign : 5; ///< Log 2 of original alignment
48 unsigned IsInConsecutiveRegsLast : 1;
49 unsigned IsInConsecutiveRegs : 1;
50 unsigned IsCopyElisionCandidate : 1; ///< Argument copy elision candidate
51 unsigned IsPointer : 1;
53 unsigned ByValSize; ///< Byval struct size
55 unsigned PointerAddrSpace; ///< Address space of pointer argument
59 : IsZExt(0), IsSExt(0), IsInReg(0), IsSRet(0), IsByVal(0), IsNest(0),
60 IsReturned(0), IsSplit(0), IsInAlloca(0), IsPreallocated(0),
61 IsSplitEnd(0), IsSwiftSelf(0), IsSwiftError(0), IsCFGuardTarget(0),
62 IsHva(0), IsHvaStart(0), IsSecArgPass(0), ByValAlign(0), OrigAlign(0),
63 IsInConsecutiveRegsLast(0), IsInConsecutiveRegs(0),
64 IsCopyElisionCandidate(0), IsPointer(0), ByValSize(0),
66 static_assert(sizeof(*this) == 3 * sizeof(unsigned), "flags are too big");
69 bool isZExt() const { return IsZExt; }
70 void setZExt() { IsZExt = 1; }
72 bool isSExt() const { return IsSExt; }
73 void setSExt() { IsSExt = 1; }
75 bool isInReg() const { return IsInReg; }
76 void setInReg() { IsInReg = 1; }
78 bool isSRet() const { return IsSRet; }
79 void setSRet() { IsSRet = 1; }
81 bool isByVal() const { return IsByVal; }
82 void setByVal() { IsByVal = 1; }
84 bool isInAlloca() const { return IsInAlloca; }
85 void setInAlloca() { IsInAlloca = 1; }
87 bool isPreallocated() const { return IsPreallocated; }
88 void setPreallocated() { IsPreallocated = 1; }
90 bool isSwiftSelf() const { return IsSwiftSelf; }
91 void setSwiftSelf() { IsSwiftSelf = 1; }
93 bool isSwiftError() const { return IsSwiftError; }
94 void setSwiftError() { IsSwiftError = 1; }
96 bool isCFGuardTarget() const { return IsCFGuardTarget; }
97 void setCFGuardTarget() { IsCFGuardTarget = 1; }
99 bool isHva() const { return IsHva; }
100 void setHva() { IsHva = 1; }
102 bool isHvaStart() const { return IsHvaStart; }
103 void setHvaStart() { IsHvaStart = 1; }
105 bool isSecArgPass() const { return IsSecArgPass; }
106 void setSecArgPass() { IsSecArgPass = 1; }
108 bool isNest() const { return IsNest; }
109 void setNest() { IsNest = 1; }
111 bool isReturned() const { return IsReturned; }
112 void setReturned() { IsReturned = 1; }
114 bool isInConsecutiveRegs() const { return IsInConsecutiveRegs; }
115 void setInConsecutiveRegs() { IsInConsecutiveRegs = 1; }
117 bool isInConsecutiveRegsLast() const { return IsInConsecutiveRegsLast; }
118 void setInConsecutiveRegsLast() { IsInConsecutiveRegsLast = 1; }
120 bool isSplit() const { return IsSplit; }
121 void setSplit() { IsSplit = 1; }
123 bool isSplitEnd() const { return IsSplitEnd; }
124 void setSplitEnd() { IsSplitEnd = 1; }
126 bool isCopyElisionCandidate() const { return IsCopyElisionCandidate; }
127 void setCopyElisionCandidate() { IsCopyElisionCandidate = 1; }
129 bool isPointer() const { return IsPointer; }
130 void setPointer() { IsPointer = 1; }
132 LLVM_ATTRIBUTE_DEPRECATED(unsigned getByValAlign() const,
133 "Use getNonZeroByValAlign() instead") {
134 MaybeAlign A = decodeMaybeAlign(ByValAlign);
135 return A ? A->value() : 0;
137 Align getNonZeroByValAlign() const {
138 MaybeAlign A = decodeMaybeAlign(ByValAlign);
139 assert(A && "ByValAlign must be defined");
142 void setByValAlign(Align A) {
143 ByValAlign = encode(A);
144 assert(getNonZeroByValAlign() == A && "bitfield overflow");
147 LLVM_ATTRIBUTE_DEPRECATED(unsigned getOrigAlign() const,
148 "Use getNonZeroOrigAlign() instead") {
149 MaybeAlign A = decodeMaybeAlign(OrigAlign);
150 return A ? A->value() : 0;
152 Align getNonZeroOrigAlign() const {
153 return decodeMaybeAlign(OrigAlign).valueOrOne();
155 void setOrigAlign(Align A) {
156 OrigAlign = encode(A);
157 assert(getNonZeroOrigAlign() == A && "bitfield overflow");
160 unsigned getByValSize() const { return ByValSize; }
161 void setByValSize(unsigned S) { ByValSize = S; }
163 unsigned getPointerAddrSpace() const { return PointerAddrSpace; }
164 void setPointerAddrSpace(unsigned AS) { PointerAddrSpace = AS; }
167 /// InputArg - This struct carries flags and type information about a
168 /// single incoming (formal) argument or incoming (from the perspective
169 /// of the caller) return value virtual register.
177 /// Index original Function's argument.
178 unsigned OrigArgIndex;
179 /// Sentinel value for implicit machine-level input arguments.
180 static const unsigned NoArgIndex = UINT_MAX;
182 /// Offset in bytes of current input value relative to the beginning of
183 /// original argument. E.g. if argument was splitted into four 32 bit
184 /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12.
187 InputArg() = default;
188 InputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool used,
189 unsigned origIdx, unsigned partOffs)
190 : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) {
191 VT = vt.getSimpleVT();
195 bool isOrigArg() const {
196 return OrigArgIndex != NoArgIndex;
199 unsigned getOrigArgIndex() const {
200 assert(OrigArgIndex != NoArgIndex && "Implicit machine-level argument");
205 /// OutputArg - This struct carries flags and a value for a
206 /// single outgoing (actual) argument or outgoing (from the perspective
207 /// of the caller) return value virtual register.
214 /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
215 bool IsFixed = false;
217 /// Index original Function's argument.
218 unsigned OrigArgIndex;
220 /// Offset in bytes of current output value relative to the beginning of
221 /// original argument. E.g. if argument was splitted into four 32 bit
222 /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12.
225 OutputArg() = default;
226 OutputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool isfixed,
227 unsigned origIdx, unsigned partOffs)
228 : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx),
229 PartOffset(partOffs) {
230 VT = vt.getSimpleVT();
235 } // end namespace ISD
236 } // end namespace llvm
238 #endif // LLVM_CODEGEN_TARGETCALLINGCONV_H