1 //===-- llvm/Target/TargetCallingConv.h - Calling Convention ----*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines types for working with calling-convention information. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_TARGET_TARGETCALLINGCONV_H 15 #define LLVM_TARGET_TARGETCALLINGCONV_H 16 17 #include "llvm/CodeGen/ValueTypes.h" 18 #include "llvm/Support/DataTypes.h" 19 #include "llvm/Support/MathExtras.h" 20 #include <string> 21 22 namespace llvm { 23 24 namespace ISD { 25 struct ArgFlagsTy { 26 private: 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 OrigAlign = 0x1FULL<<27; 49 static const uint64_t OrigAlignOffs = 27; 50 static const uint64_t ByValSize = 0x3fffffffULL<<32; ///< Struct size 51 static const uint64_t ByValSizeOffs = 32; 52 static const uint64_t InConsecutiveRegsLast = 0x1ULL<<62; ///< Struct size 53 static const uint64_t InConsecutiveRegsLastOffs = 62; 54 static const uint64_t InConsecutiveRegs = 0x1ULL<<63; ///< Struct size 55 static const uint64_t InConsecutiveRegsOffs = 63; 56 57 static const uint64_t One = 1ULL; ///< 1 of this type, for shifts 58 59 uint64_t Flags; 60 public: ArgFlagsTyArgFlagsTy61 ArgFlagsTy() : Flags(0) { } 62 isZExtArgFlagsTy63 bool isZExt() const { return Flags & ZExt; } setZExtArgFlagsTy64 void setZExt() { Flags |= One << ZExtOffs; } 65 isSExtArgFlagsTy66 bool isSExt() const { return Flags & SExt; } setSExtArgFlagsTy67 void setSExt() { Flags |= One << SExtOffs; } 68 isInRegArgFlagsTy69 bool isInReg() const { return Flags & InReg; } setInRegArgFlagsTy70 void setInReg() { Flags |= One << InRegOffs; } 71 isSRetArgFlagsTy72 bool isSRet() const { return Flags & SRet; } setSRetArgFlagsTy73 void setSRet() { Flags |= One << SRetOffs; } 74 isByValArgFlagsTy75 bool isByVal() const { return Flags & ByVal; } setByValArgFlagsTy76 void setByVal() { Flags |= One << ByValOffs; } 77 isInAllocaArgFlagsTy78 bool isInAlloca() const { return Flags & InAlloca; } setInAllocaArgFlagsTy79 void setInAlloca() { Flags |= One << InAllocaOffs; } 80 isNestArgFlagsTy81 bool isNest() const { return Flags & Nest; } setNestArgFlagsTy82 void setNest() { Flags |= One << NestOffs; } 83 isReturnedArgFlagsTy84 bool isReturned() const { return Flags & Returned; } setReturnedArgFlagsTy85 void setReturned() { Flags |= One << ReturnedOffs; } 86 isInConsecutiveRegsArgFlagsTy87 bool isInConsecutiveRegs() const { return Flags & InConsecutiveRegs; } setInConsecutiveRegsArgFlagsTy88 void setInConsecutiveRegs() { Flags |= One << InConsecutiveRegsOffs; } 89 isInConsecutiveRegsLastArgFlagsTy90 bool isInConsecutiveRegsLast() const { return Flags & InConsecutiveRegsLast; } setInConsecutiveRegsLastArgFlagsTy91 void setInConsecutiveRegsLast() { Flags |= One << InConsecutiveRegsLastOffs; } 92 getByValAlignArgFlagsTy93 unsigned getByValAlign() const { 94 return (unsigned) 95 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2); 96 } setByValAlignArgFlagsTy97 void setByValAlign(unsigned A) { 98 Flags = (Flags & ~ByValAlign) | 99 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs); 100 } 101 isSplitArgFlagsTy102 bool isSplit() const { return Flags & Split; } setSplitArgFlagsTy103 void setSplit() { Flags |= One << SplitOffs; } 104 getOrigAlignArgFlagsTy105 unsigned getOrigAlign() const { 106 return (unsigned) 107 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2); 108 } setOrigAlignArgFlagsTy109 void setOrigAlign(unsigned A) { 110 Flags = (Flags & ~OrigAlign) | 111 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs); 112 } 113 getByValSizeArgFlagsTy114 unsigned getByValSize() const { 115 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs); 116 } setByValSizeArgFlagsTy117 void setByValSize(unsigned S) { 118 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs); 119 } 120 121 /// getRawBits - Represent the flags as a bunch of bits. getRawBitsArgFlagsTy122 uint64_t getRawBits() const { return Flags; } 123 }; 124 125 /// InputArg - This struct carries flags and type information about a 126 /// single incoming (formal) argument or incoming (from the perspective 127 /// of the caller) return value virtual register. 128 /// 129 struct InputArg { 130 ArgFlagsTy Flags; 131 MVT VT; 132 EVT ArgVT; 133 bool Used; 134 135 /// Index original Function's argument. 136 unsigned OrigArgIndex; 137 /// Sentinel value for implicit machine-level input arguments. 138 static const unsigned NoArgIndex = UINT_MAX; 139 140 /// Offset in bytes of current input value relative to the beginning of 141 /// original argument. E.g. if argument was splitted into four 32 bit 142 /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12. 143 unsigned PartOffset; 144 InputArgInputArg145 InputArg() : VT(MVT::Other), Used(false) {} InputArgInputArg146 InputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool used, 147 unsigned origIdx, unsigned partOffs) 148 : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) { 149 VT = vt.getSimpleVT(); 150 ArgVT = argvt; 151 } 152 isOrigArgInputArg153 bool isOrigArg() const { 154 return OrigArgIndex != NoArgIndex; 155 } 156 getOrigArgIndexInputArg157 unsigned getOrigArgIndex() const { 158 assert(OrigArgIndex != NoArgIndex && "Implicit machine-level argument"); 159 return OrigArgIndex; 160 } 161 }; 162 163 /// OutputArg - This struct carries flags and a value for a 164 /// single outgoing (actual) argument or outgoing (from the perspective 165 /// of the caller) return value virtual register. 166 /// 167 struct OutputArg { 168 ArgFlagsTy Flags; 169 MVT VT; 170 EVT ArgVT; 171 172 /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...". 173 bool IsFixed; 174 175 /// Index original Function's argument. 176 unsigned OrigArgIndex; 177 178 /// Offset in bytes of current output value relative to the beginning of 179 /// original argument. E.g. if argument was splitted into four 32 bit 180 /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12. 181 unsigned PartOffset; 182 OutputArgOutputArg183 OutputArg() : IsFixed(false) {} OutputArgOutputArg184 OutputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool isfixed, 185 unsigned origIdx, unsigned partOffs) 186 : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx), 187 PartOffset(partOffs) { 188 VT = vt.getSimpleVT(); 189 ArgVT = argvt; 190 } 191 }; 192 } 193 194 } // end llvm namespace 195 196 #endif 197