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"
28 static const uint64_t NoFlagSet = 0ULL;
29 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
30 static const uint64_t ZExtOffs = 0;
31 static const uint64_t SExt = 1ULL<<1; ///< Sign extended
32 static const uint64_t SExtOffs = 1;
33 static const uint64_t InReg = 1ULL<<2; ///< Passed in register
34 static const uint64_t InRegOffs = 2;
35 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
36 static const uint64_t SRetOffs = 3;
37 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
38 static const uint64_t ByValOffs = 4;
39 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
40 static const uint64_t NestOffs = 5;
41 static const uint64_t Returned = 1ULL<<6; ///< Always returned
42 static const uint64_t ReturnedOffs = 6;
43 static const uint64_t ByValAlign = 0xFULL<<7; ///< Struct alignment
44 static const uint64_t ByValAlignOffs = 7;
45 static const uint64_t Split = 1ULL<<11;
46 static const uint64_t SplitOffs = 11;
47 static const uint64_t InAlloca = 1ULL<<12; ///< Passed with inalloca
48 static const uint64_t InAllocaOffs = 12;
49 static const uint64_t SplitEnd = 1ULL<<13; ///< Last part of a split
50 static const uint64_t SplitEndOffs = 13;
51 static const uint64_t OrigAlign = 0x1FULL<<27;
52 static const uint64_t OrigAlignOffs = 27;
53 static const uint64_t ByValSize = 0x3fffffffULL<<32; ///< Struct size
54 static const uint64_t ByValSizeOffs = 32;
55 static const uint64_t InConsecutiveRegsLast = 0x1ULL<<62; ///< Struct size
56 static const uint64_t InConsecutiveRegsLastOffs = 62;
57 static const uint64_t InConsecutiveRegs = 0x1ULL<<63; ///< Struct size
58 static const uint64_t InConsecutiveRegsOffs = 63;
60 static const uint64_t One = 1ULL; ///< 1 of this type, for shifts
64 ArgFlagsTy() : Flags(0) { }
66 bool isZExt() const { return Flags & ZExt; }
67 void setZExt() { Flags |= One << ZExtOffs; }
69 bool isSExt() const { return Flags & SExt; }
70 void setSExt() { Flags |= One << SExtOffs; }
72 bool isInReg() const { return Flags & InReg; }
73 void setInReg() { Flags |= One << InRegOffs; }
75 bool isSRet() const { return Flags & SRet; }
76 void setSRet() { Flags |= One << SRetOffs; }
78 bool isByVal() const { return Flags & ByVal; }
79 void setByVal() { Flags |= One << ByValOffs; }
81 bool isInAlloca() const { return Flags & InAlloca; }
82 void setInAlloca() { Flags |= One << InAllocaOffs; }
84 bool isNest() const { return Flags & Nest; }
85 void setNest() { Flags |= One << NestOffs; }
87 bool isReturned() const { return Flags & Returned; }
88 void setReturned() { Flags |= One << ReturnedOffs; }
90 bool isInConsecutiveRegs() const { return Flags & InConsecutiveRegs; }
91 void setInConsecutiveRegs() { Flags |= One << InConsecutiveRegsOffs; }
93 bool isInConsecutiveRegsLast() const { return Flags & InConsecutiveRegsLast; }
94 void setInConsecutiveRegsLast() { Flags |= One << InConsecutiveRegsLastOffs; }
96 unsigned getByValAlign() const {
98 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
100 void setByValAlign(unsigned A) {
101 Flags = (Flags & ~ByValAlign) |
102 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
105 bool isSplit() const { return Flags & Split; }
106 void setSplit() { Flags |= One << SplitOffs; }
108 bool isSplitEnd() const { return Flags & SplitEnd; }
109 void setSplitEnd() { Flags |= One << SplitEndOffs; }
111 unsigned getOrigAlign() const {
113 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
115 void setOrigAlign(unsigned A) {
116 Flags = (Flags & ~OrigAlign) |
117 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
120 unsigned getByValSize() const {
121 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
123 void setByValSize(unsigned S) {
124 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
127 /// getRawBits - Represent the flags as a bunch of bits.
128 uint64_t getRawBits() const { return Flags; }
131 /// InputArg - This struct carries flags and type information about a
132 /// single incoming (formal) argument or incoming (from the perspective
133 /// of the caller) return value virtual register.
141 /// Index original Function's argument.
142 unsigned OrigArgIndex;
143 /// Sentinel value for implicit machine-level input arguments.
144 static const unsigned NoArgIndex = UINT_MAX;
146 /// Offset in bytes of current input value relative to the beginning of
147 /// original argument. E.g. if argument was splitted into four 32 bit
148 /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12.
151 InputArg() : VT(MVT::Other), Used(false) {}
152 InputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool used,
153 unsigned origIdx, unsigned partOffs)
154 : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) {
155 VT = vt.getSimpleVT();
159 bool isOrigArg() const {
160 return OrigArgIndex != NoArgIndex;
163 unsigned getOrigArgIndex() const {
164 assert(OrigArgIndex != NoArgIndex && "Implicit machine-level argument");
169 /// OutputArg - This struct carries flags and a value for a
170 /// single outgoing (actual) argument or outgoing (from the perspective
171 /// of the caller) return value virtual register.
178 /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
181 /// Index original Function's argument.
182 unsigned OrigArgIndex;
184 /// Offset in bytes of current output value relative to the beginning of
185 /// original argument. E.g. if argument was splitted into four 32 bit
186 /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12.
189 OutputArg() : IsFixed(false) {}
190 OutputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool isfixed,
191 unsigned origIdx, unsigned partOffs)
192 : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx),
193 PartOffset(partOffs) {
194 VT = vt.getSimpleVT();
200 } // end llvm namespace