[Alignment][NFC] Migrate Instructions to Align
[llvm-core.git] / include / llvm / CodeGen / TargetCallingConv.h
blobd25a9a24591fc9018bba0218acddd4c899eb51ac
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.
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"
20 #include <cassert>
21 #include <climits>
22 #include <cstdint>
24 namespace llvm {
25 namespace ISD {
27 struct ArgFlagsTy {
28 private:
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
36 unsigned IsSplit : 1;
37 unsigned IsInAlloca : 1; ///< Passed with inalloca
38 unsigned IsSplitEnd : 1; ///< Last part of a split
39 unsigned IsSwiftSelf : 1; ///< Swift self parameter
40 unsigned IsSwiftError : 1; ///< Swift error parameter
41 unsigned IsHva : 1; ///< HVA field for
42 unsigned IsHvaStart : 1; ///< HVA structure start
43 unsigned IsSecArgPass : 1; ///< Second argument
44 unsigned ByValAlign : 4; ///< Log 2 of byval alignment
45 unsigned OrigAlign : 5; ///< Log 2 of original alignment
46 unsigned IsInConsecutiveRegsLast : 1;
47 unsigned IsInConsecutiveRegs : 1;
48 unsigned IsCopyElisionCandidate : 1; ///< Argument copy elision candidate
49 unsigned IsPointer : 1;
51 unsigned ByValSize; ///< Byval struct size
53 unsigned PointerAddrSpace; ///< Address space of pointer argument
55 public:
56 ArgFlagsTy()
57 : IsZExt(0), IsSExt(0), IsInReg(0), IsSRet(0), IsByVal(0), IsNest(0),
58 IsReturned(0), IsSplit(0), IsInAlloca(0), IsSplitEnd(0),
59 IsSwiftSelf(0), IsSwiftError(0), IsHva(0), IsHvaStart(0),
60 IsSecArgPass(0), ByValAlign(0), OrigAlign(0),
61 IsInConsecutiveRegsLast(0), IsInConsecutiveRegs(0),
62 IsCopyElisionCandidate(0), IsPointer(0), ByValSize(0),
63 PointerAddrSpace(0) {
64 static_assert(sizeof(*this) == 3 * sizeof(unsigned), "flags are too big");
67 bool isZExt() const { return IsZExt; }
68 void setZExt() { IsZExt = 1; }
70 bool isSExt() const { return IsSExt; }
71 void setSExt() { IsSExt = 1; }
73 bool isInReg() const { return IsInReg; }
74 void setInReg() { IsInReg = 1; }
76 bool isSRet() const { return IsSRet; }
77 void setSRet() { IsSRet = 1; }
79 bool isByVal() const { return IsByVal; }
80 void setByVal() { IsByVal = 1; }
82 bool isInAlloca() const { return IsInAlloca; }
83 void setInAlloca() { IsInAlloca = 1; }
85 bool isSwiftSelf() const { return IsSwiftSelf; }
86 void setSwiftSelf() { IsSwiftSelf = 1; }
88 bool isSwiftError() const { return IsSwiftError; }
89 void setSwiftError() { IsSwiftError = 1; }
91 bool isHva() const { return IsHva; }
92 void setHva() { IsHva = 1; }
94 bool isHvaStart() const { return IsHvaStart; }
95 void setHvaStart() { IsHvaStart = 1; }
97 bool isSecArgPass() const { return IsSecArgPass; }
98 void setSecArgPass() { IsSecArgPass = 1; }
100 bool isNest() const { return IsNest; }
101 void setNest() { IsNest = 1; }
103 bool isReturned() const { return IsReturned; }
104 void setReturned() { IsReturned = 1; }
106 bool isInConsecutiveRegs() const { return IsInConsecutiveRegs; }
107 void setInConsecutiveRegs() { IsInConsecutiveRegs = 1; }
109 bool isInConsecutiveRegsLast() const { return IsInConsecutiveRegsLast; }
110 void setInConsecutiveRegsLast() { IsInConsecutiveRegsLast = 1; }
112 bool isSplit() const { return IsSplit; }
113 void setSplit() { IsSplit = 1; }
115 bool isSplitEnd() const { return IsSplitEnd; }
116 void setSplitEnd() { IsSplitEnd = 1; }
118 bool isCopyElisionCandidate() const { return IsCopyElisionCandidate; }
119 void setCopyElisionCandidate() { IsCopyElisionCandidate = 1; }
121 bool isPointer() const { return IsPointer; }
122 void setPointer() { IsPointer = 1; }
124 unsigned getByValAlign() const {
125 MaybeAlign A = decodeMaybeAlign(ByValAlign);
126 return A ? A->value() : 0;
128 void setByValAlign(unsigned A) {
129 ByValAlign = encode(llvm::Align(A));
130 assert(getByValAlign() == A && "bitfield overflow");
133 unsigned getOrigAlign() const {
134 MaybeAlign A = decodeMaybeAlign(OrigAlign);
135 return A ? A->value() : 0;
137 void setOrigAlign(unsigned A) {
138 OrigAlign = encode(llvm::Align(A));
139 assert(getOrigAlign() == A && "bitfield overflow");
142 unsigned getByValSize() const { return ByValSize; }
143 void setByValSize(unsigned S) { ByValSize = S; }
145 unsigned getPointerAddrSpace() const { return PointerAddrSpace; }
146 void setPointerAddrSpace(unsigned AS) { PointerAddrSpace = AS; }
149 /// InputArg - This struct carries flags and type information about a
150 /// single incoming (formal) argument or incoming (from the perspective
151 /// of the caller) return value virtual register.
153 struct InputArg {
154 ArgFlagsTy Flags;
155 MVT VT = MVT::Other;
156 EVT ArgVT;
157 bool Used = false;
159 /// Index original Function's argument.
160 unsigned OrigArgIndex;
161 /// Sentinel value for implicit machine-level input arguments.
162 static const unsigned NoArgIndex = UINT_MAX;
164 /// Offset in bytes of current input value relative to the beginning of
165 /// original argument. E.g. if argument was splitted into four 32 bit
166 /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12.
167 unsigned PartOffset;
169 InputArg() = default;
170 InputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool used,
171 unsigned origIdx, unsigned partOffs)
172 : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) {
173 VT = vt.getSimpleVT();
174 ArgVT = argvt;
177 bool isOrigArg() const {
178 return OrigArgIndex != NoArgIndex;
181 unsigned getOrigArgIndex() const {
182 assert(OrigArgIndex != NoArgIndex && "Implicit machine-level argument");
183 return OrigArgIndex;
187 /// OutputArg - This struct carries flags and a value for a
188 /// single outgoing (actual) argument or outgoing (from the perspective
189 /// of the caller) return value virtual register.
191 struct OutputArg {
192 ArgFlagsTy Flags;
193 MVT VT;
194 EVT ArgVT;
196 /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
197 bool IsFixed = false;
199 /// Index original Function's argument.
200 unsigned OrigArgIndex;
202 /// Offset in bytes of current output value relative to the beginning of
203 /// original argument. E.g. if argument was splitted into four 32 bit
204 /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12.
205 unsigned PartOffset;
207 OutputArg() = default;
208 OutputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool isfixed,
209 unsigned origIdx, unsigned partOffs)
210 : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx),
211 PartOffset(partOffs) {
212 VT = vt.getSimpleVT();
213 ArgVT = argvt;
217 } // end namespace ISD
218 } // end namespace llvm
220 #endif // LLVM_CODEGEN_TARGETCALLINGCONV_H