1 //===-- llvm/Target/TargetCallingConv.h - Calling Convention ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines types for working with calling-convention information.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TARGET_TARGETCALLINGCONV_H
15 #define LLVM_TARGET_TARGETCALLINGCONV_H
17 #include "llvm/CodeGen/ValueTypes.h"
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/Support/MathExtras.h"
27 static const uint64_t NoFlagSet = 0ULL;
28 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
29 static const uint64_t ZExtOffs = 0;
30 static const uint64_t SExt = 1ULL<<1; ///< Sign extended
31 static const uint64_t SExtOffs = 1;
32 static const uint64_t InReg = 1ULL<<2; ///< Passed in register
33 static const uint64_t InRegOffs = 2;
34 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
35 static const uint64_t SRetOffs = 3;
36 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
37 static const uint64_t ByValOffs = 4;
38 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
39 static const uint64_t NestOffs = 5;
40 static const uint64_t Returned = 1ULL<<6; ///< Always returned
41 static const uint64_t ReturnedOffs = 6;
42 static const uint64_t ByValAlign = 0xFULL<<7; ///< Struct alignment
43 static const uint64_t ByValAlignOffs = 7;
44 static const uint64_t Split = 1ULL<<11;
45 static const uint64_t SplitOffs = 11;
46 static const uint64_t InAlloca = 1ULL<<12; ///< Passed with inalloca
47 static const uint64_t InAllocaOffs = 12;
48 static const uint64_t SplitEnd = 1ULL<<13; ///< Last part of a split
49 static const uint64_t SplitEndOffs = 13;
50 static const uint64_t SwiftSelf = 1ULL<<14; ///< Swift self parameter
51 static const uint64_t SwiftSelfOffs = 14;
52 static const uint64_t SwiftError = 1ULL<<15; ///< Swift error parameter
53 static const uint64_t SwiftErrorOffs = 15;
54 static const uint64_t OrigAlign = 0x1FULL<<27;
55 static const uint64_t OrigAlignOffs = 27;
56 static const uint64_t ByValSize = 0x3fffffffULL<<32; ///< Struct size
57 static const uint64_t ByValSizeOffs = 32;
58 static const uint64_t InConsecutiveRegsLast = 0x1ULL<<62; ///< Struct size
59 static const uint64_t InConsecutiveRegsLastOffs = 62;
60 static const uint64_t InConsecutiveRegs = 0x1ULL<<63; ///< Struct size
61 static const uint64_t InConsecutiveRegsOffs = 63;
63 static const uint64_t One = 1ULL; ///< 1 of this type, for shifts
68 ArgFlagsTy() : Flags(0) { }
70 bool isZExt() const { return Flags & ZExt; }
71 void setZExt() { Flags |= One << ZExtOffs; }
73 bool isSExt() const { return Flags & SExt; }
74 void setSExt() { Flags |= One << SExtOffs; }
76 bool isInReg() const { return Flags & InReg; }
77 void setInReg() { Flags |= One << InRegOffs; }
79 bool isSRet() const { return Flags & SRet; }
80 void setSRet() { Flags |= One << SRetOffs; }
82 bool isByVal() const { return Flags & ByVal; }
83 void setByVal() { Flags |= One << ByValOffs; }
85 bool isInAlloca() const { return Flags & InAlloca; }
86 void setInAlloca() { Flags |= One << InAllocaOffs; }
88 bool isSwiftSelf() const { return Flags & SwiftSelf; }
89 void setSwiftSelf() { Flags |= One << SwiftSelfOffs; }
91 bool isSwiftError() const { return Flags & SwiftError; }
92 void setSwiftError() { Flags |= One << SwiftErrorOffs; }
94 bool isNest() const { return Flags & Nest; }
95 void setNest() { Flags |= One << NestOffs; }
97 bool isReturned() const { return Flags & Returned; }
98 void setReturned() { Flags |= One << ReturnedOffs; }
100 bool isInConsecutiveRegs() const { return Flags & InConsecutiveRegs; }
101 void setInConsecutiveRegs() { Flags |= One << InConsecutiveRegsOffs; }
103 bool isInConsecutiveRegsLast() const { return Flags & InConsecutiveRegsLast; }
104 void setInConsecutiveRegsLast() { Flags |= One << InConsecutiveRegsLastOffs; }
106 unsigned getByValAlign() const {
108 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
110 void setByValAlign(unsigned A) {
111 Flags = (Flags & ~ByValAlign) |
112 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
115 bool isSplit() const { return Flags & Split; }
116 void setSplit() { Flags |= One << SplitOffs; }
118 bool isSplitEnd() const { return Flags & SplitEnd; }
119 void setSplitEnd() { Flags |= One << SplitEndOffs; }
121 unsigned getOrigAlign() const {
123 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
125 void setOrigAlign(unsigned A) {
126 Flags = (Flags & ~OrigAlign) |
127 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
130 unsigned getByValSize() const {
131 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
133 void setByValSize(unsigned S) {
134 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
137 /// getRawBits - Represent the flags as a bunch of bits.
138 uint64_t getRawBits() const { return Flags; }
141 /// InputArg - This struct carries flags and type information about a
142 /// single incoming (formal) argument or incoming (from the perspective
143 /// of the caller) return value virtual register.
151 /// Index original Function's argument.
152 unsigned OrigArgIndex;
153 /// Sentinel value for implicit machine-level input arguments.
154 static const unsigned NoArgIndex = UINT_MAX;
156 /// Offset in bytes of current input value relative to the beginning of
157 /// original argument. E.g. if argument was splitted into four 32 bit
158 /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12.
161 InputArg() : VT(MVT::Other), Used(false) {}
162 InputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool used,
163 unsigned origIdx, unsigned partOffs)
164 : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) {
165 VT = vt.getSimpleVT();
169 bool isOrigArg() const {
170 return OrigArgIndex != NoArgIndex;
173 unsigned getOrigArgIndex() const {
174 assert(OrigArgIndex != NoArgIndex && "Implicit machine-level argument");
179 /// OutputArg - This struct carries flags and a value for a
180 /// single outgoing (actual) argument or outgoing (from the perspective
181 /// of the caller) return value virtual register.
188 /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
191 /// Index original Function's argument.
192 unsigned OrigArgIndex;
194 /// Offset in bytes of current output value relative to the beginning of
195 /// original argument. E.g. if argument was splitted into four 32 bit
196 /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12.
199 OutputArg() : IsFixed(false) {}
200 OutputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool isfixed,
201 unsigned origIdx, unsigned partOffs)
202 : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx),
203 PartOffset(partOffs) {
204 VT = vt.getSimpleVT();
208 } // end namespace ISD
210 } // end llvm namespace
212 #endif // LLVM_TARGET_TARGETCALLINGCONV_H