TargetCallingConv.h revision 263508
1238384Sjkim//===-- llvm/Target/TargetCallingConv.h - Calling Convention ----*- C++ -*-===// 2296341Sdelphij// 3296341Sdelphij// The LLVM Compiler Infrastructure 4296341Sdelphij// 5296341Sdelphij// This file is distributed under the University of Illinois Open Source 6238384Sjkim// License. See LICENSE.TXT for details. 7238384Sjkim// 8238384Sjkim//===----------------------------------------------------------------------===// 9238384Sjkim// 10238384Sjkim// This file defines types for working with calling-convention information. 11238384Sjkim// 12238384Sjkim//===----------------------------------------------------------------------===// 13238384Sjkim 14238384Sjkim#ifndef LLVM_TARGET_TARGETCALLINGCONV_H 15296341Sdelphij#define LLVM_TARGET_TARGETCALLINGCONV_H 16238384Sjkim 17238384Sjkim#include "llvm/Support/DataTypes.h" 18238384Sjkim#include "llvm/Support/MathExtras.h" 19238384Sjkim#include <string> 20238384Sjkim 21238384Sjkimnamespace llvm { 22238384Sjkim 23238384Sjkimnamespace ISD { 24238384Sjkim struct ArgFlagsTy { 25238384Sjkim private: 26238384Sjkim static const uint64_t NoFlagSet = 0ULL; 27238384Sjkim static const uint64_t ZExt = 1ULL<<0; ///< Zero extended 28238384Sjkim static const uint64_t ZExtOffs = 0; 29238384Sjkim static const uint64_t SExt = 1ULL<<1; ///< Sign extended 30238384Sjkim static const uint64_t SExtOffs = 1; 31238384Sjkim static const uint64_t InReg = 1ULL<<2; ///< Passed in register 32238384Sjkim static const uint64_t InRegOffs = 2; 33238384Sjkim static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr 34238384Sjkim static const uint64_t SRetOffs = 3; 35238384Sjkim static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value 36238384Sjkim static const uint64_t ByValOffs = 4; 37238384Sjkim static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain 38238384Sjkim static const uint64_t NestOffs = 5; 39238384Sjkim static const uint64_t Returned = 1ULL<<6; ///< Always returned 40238384Sjkim static const uint64_t ReturnedOffs = 6; 41238384Sjkim static const uint64_t ByValAlign = 0xFULL<<7; ///< Struct alignment 42238384Sjkim static const uint64_t ByValAlignOffs = 7; 43238384Sjkim static const uint64_t Split = 1ULL<<11; 44238384Sjkim static const uint64_t SplitOffs = 11; 45238384Sjkim static const uint64_t OrigAlign = 0x1FULL<<27; 46238384Sjkim static const uint64_t OrigAlignOffs = 27; 47238384Sjkim static const uint64_t ByValSize = 0xffffffffULL<<32; ///< Struct size 48238384Sjkim static const uint64_t ByValSizeOffs = 32; 49238384Sjkim 50238384Sjkim static const uint64_t One = 1ULL; ///< 1 of this type, for shifts 51238384Sjkim 52238384Sjkim uint64_t Flags; 53238384Sjkim public: 54238384Sjkim ArgFlagsTy() : Flags(0) { } 55238384Sjkim 56238384Sjkim bool isZExt() const { return Flags & ZExt; } 57238384Sjkim void setZExt() { Flags |= One << ZExtOffs; } 58238384Sjkim 59238384Sjkim bool isSExt() const { return Flags & SExt; } 60238384Sjkim void setSExt() { Flags |= One << SExtOffs; } 61296341Sdelphij 62238384Sjkim bool isInReg() const { return Flags & InReg; } 63296341Sdelphij void setInReg() { Flags |= One << InRegOffs; } 64238384Sjkim 65296341Sdelphij bool isSRet() const { return Flags & SRet; } 66296341Sdelphij void setSRet() { Flags |= One << SRetOffs; } 67238384Sjkim 68238384Sjkim bool isByVal() const { return Flags & ByVal; } 69238384Sjkim void setByVal() { Flags |= One << ByValOffs; } 70238384Sjkim 71238384Sjkim bool isNest() const { return Flags & Nest; } 72296341Sdelphij void setNest() { Flags |= One << NestOffs; } 73296341Sdelphij 74296341Sdelphij bool isReturned() const { return Flags & Returned; } 75238384Sjkim void setReturned() { Flags |= One << ReturnedOffs; } 76296341Sdelphij 77296341Sdelphij unsigned getByValAlign() const { 78296341Sdelphij return (unsigned) 79296341Sdelphij ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2); 80238384Sjkim } 81238384Sjkim void setByValAlign(unsigned A) { 82238384Sjkim Flags = (Flags & ~ByValAlign) | 83238384Sjkim (uint64_t(Log2_32(A) + 1) << ByValAlignOffs); 84296341Sdelphij } 85296341Sdelphij 86296341Sdelphij bool isSplit() const { return Flags & Split; } 87296341Sdelphij void setSplit() { Flags |= One << SplitOffs; } 88296341Sdelphij 89296341Sdelphij unsigned getOrigAlign() const { 90296341Sdelphij return (unsigned) 91296341Sdelphij ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2); 92296341Sdelphij } 93296341Sdelphij void setOrigAlign(unsigned A) { 94296341Sdelphij Flags = (Flags & ~OrigAlign) | 95238384Sjkim (uint64_t(Log2_32(A) + 1) << OrigAlignOffs); 96238384Sjkim } 97238384Sjkim 98296341Sdelphij unsigned getByValSize() const { 99296341Sdelphij return (unsigned)((Flags & ByValSize) >> ByValSizeOffs); 100296341Sdelphij } 101296341Sdelphij void setByValSize(unsigned S) { 102296341Sdelphij Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs); 103238384Sjkim } 104296341Sdelphij 105296341Sdelphij /// getRawBits - Represent the flags as a bunch of bits. 106296341Sdelphij uint64_t getRawBits() const { return Flags; } 107296341Sdelphij }; 108238384Sjkim 109296341Sdelphij /// InputArg - This struct carries flags and type information about a 110296341Sdelphij /// single incoming (formal) argument or incoming (from the perspective 111296341Sdelphij /// of the caller) return value virtual register. 112296341Sdelphij /// 113296341Sdelphij struct InputArg { 114296341Sdelphij ArgFlagsTy Flags; 115296341Sdelphij MVT VT; 116296341Sdelphij EVT ArgVT; 117238384Sjkim bool Used; 118238384Sjkim 119238384Sjkim /// Index original Function's argument. 120238384Sjkim unsigned OrigArgIndex; 121238384Sjkim 122296341Sdelphij /// Offset in bytes of current input value relative to the beginning of 123296341Sdelphij /// original argument. E.g. if argument was splitted into four 32 bit 124296341Sdelphij /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12. 125238384Sjkim unsigned PartOffset; 126296341Sdelphij 127296341Sdelphij InputArg() : VT(MVT::Other), Used(false) {} 128296341Sdelphij InputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool used, 129238384Sjkim unsigned origIdx, unsigned partOffs) 130296341Sdelphij : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) { 131296341Sdelphij VT = vt.getSimpleVT(); 132296341Sdelphij ArgVT = argvt; 133238384Sjkim } 134296341Sdelphij }; 135296341Sdelphij 136296341Sdelphij /// OutputArg - This struct carries flags and a value for a 137296341Sdelphij /// single outgoing (actual) argument or outgoing (from the perspective 138296341Sdelphij /// of the caller) return value virtual register. 139238384Sjkim /// 140296341Sdelphij struct OutputArg { 141296341Sdelphij ArgFlagsTy Flags; 142296341Sdelphij MVT VT; 143296341Sdelphij EVT ArgVT; 144296341Sdelphij 145296341Sdelphij /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...". 146296341Sdelphij bool IsFixed; 147296341Sdelphij 148238384Sjkim /// Index original Function's argument. 149296341Sdelphij unsigned OrigArgIndex; 150296341Sdelphij 151296341Sdelphij /// Offset in bytes of current output value relative to the beginning of 152296341Sdelphij /// original argument. E.g. if argument was splitted into four 32 bit 153238384Sjkim /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12. 154238384Sjkim unsigned PartOffset; 155296341Sdelphij 156296341Sdelphij OutputArg() : IsFixed(false) {} 157238384Sjkim OutputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool isfixed, 158238384Sjkim unsigned origIdx, unsigned partOffs) 159296341Sdelphij : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx), 160296341Sdelphij PartOffset(partOffs) { 161238384Sjkim VT = vt.getSimpleVT(); 162238384Sjkim ArgVT = argvt; 163296341Sdelphij } 164238384Sjkim }; 165238384Sjkim} 166238384Sjkim 167238384Sjkim} // end llvm namespace 168296341Sdelphij 169296341Sdelphij#endif 170238384Sjkim