Home | History | Annotate | Download | only in Target
      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 <climits>
     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 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;
     62 
     63     static const uint64_t One            = 1ULL; ///< 1 of this type, for shifts
     64 
     65     uint64_t Flags;
     66 
     67   public:
     68     ArgFlagsTy() : Flags(0) { }
     69 
     70     bool isZExt()      const { return Flags & ZExt; }
     71     void setZExt()     { Flags |= One << ZExtOffs; }
     72 
     73     bool isSExt()      const { return Flags & SExt; }
     74     void setSExt()     { Flags |= One << SExtOffs; }
     75 
     76     bool isInReg()     const { return Flags & InReg; }
     77     void setInReg()    { Flags |= One << InRegOffs; }
     78 
     79     bool isSRet()      const { return Flags & SRet; }
     80     void setSRet()     { Flags |= One << SRetOffs; }
     81 
     82     bool isByVal()     const { return Flags & ByVal; }
     83     void setByVal()    { Flags |= One << ByValOffs; }
     84 
     85     bool isInAlloca()  const { return Flags & InAlloca; }
     86     void setInAlloca() { Flags |= One << InAllocaOffs; }
     87 
     88     bool isSwiftSelf() const { return Flags & SwiftSelf; }
     89     void setSwiftSelf() { Flags |= One << SwiftSelfOffs; }
     90 
     91     bool isSwiftError() const { return Flags & SwiftError; }
     92     void setSwiftError() { Flags |= One << SwiftErrorOffs; }
     93 
     94     bool isNest()      const { return Flags & Nest; }
     95     void setNest()     { Flags |= One << NestOffs; }
     96 
     97     bool isReturned()  const { return Flags & Returned; }
     98     void setReturned() { Flags |= One << ReturnedOffs; }
     99 
    100     bool isInConsecutiveRegs()  const { return Flags & InConsecutiveRegs; }
    101     void setInConsecutiveRegs() { Flags |= One << InConsecutiveRegsOffs; }
    102 
    103     bool isInConsecutiveRegsLast()  const { return Flags & InConsecutiveRegsLast; }
    104     void setInConsecutiveRegsLast() { Flags |= One << InConsecutiveRegsLastOffs; }
    105 
    106     unsigned getByValAlign() const {
    107       return (unsigned)
    108         ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
    109     }
    110     void setByValAlign(unsigned A) {
    111       Flags = (Flags & ~ByValAlign) |
    112         (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
    113     }
    114 
    115     bool isSplit()   const { return Flags & Split; }
    116     void setSplit()  { Flags |= One << SplitOffs; }
    117 
    118     bool isSplitEnd()   const { return Flags & SplitEnd; }
    119     void setSplitEnd()  { Flags |= One << SplitEndOffs; }
    120 
    121     unsigned getOrigAlign() const {
    122       return (unsigned)
    123         ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
    124     }
    125     void setOrigAlign(unsigned A) {
    126       Flags = (Flags & ~OrigAlign) |
    127         (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
    128     }
    129 
    130     unsigned getByValSize() const {
    131       return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
    132     }
    133     void setByValSize(unsigned S) {
    134       Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
    135     }
    136 
    137     /// getRawBits - Represent the flags as a bunch of bits.
    138     uint64_t getRawBits() const { return Flags; }
    139   };
    140 
    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.
    144   ///
    145   struct InputArg {
    146     ArgFlagsTy Flags;
    147     MVT VT;
    148     EVT ArgVT;
    149     bool Used;
    150 
    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;
    155 
    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.
    159     unsigned PartOffset;
    160 
    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();
    166       ArgVT = argvt;
    167     }
    168 
    169     bool isOrigArg() const {
    170       return OrigArgIndex != NoArgIndex;
    171     }
    172 
    173     unsigned getOrigArgIndex() const {
    174       assert(OrigArgIndex != NoArgIndex && "Implicit machine-level argument");
    175       return OrigArgIndex;
    176     }
    177   };
    178 
    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.
    182   ///
    183   struct OutputArg {
    184     ArgFlagsTy Flags;
    185     MVT VT;
    186     EVT ArgVT;
    187 
    188     /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
    189     bool IsFixed;
    190 
    191     /// Index original Function's argument.
    192     unsigned OrigArgIndex;
    193 
    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.
    197     unsigned PartOffset;
    198 
    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();
    205       ArgVT = argvt;
    206     }
    207   };
    208 } // end namespace ISD
    209 
    210 } // end llvm namespace
    211 
    212 #endif // LLVM_TARGET_TARGETCALLINGCONV_H
    213