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/Support/DataTypes.h"
     18 #include "llvm/Support/MathExtras.h"
     19 #include <string>
     20 
     21 namespace llvm {
     22 
     23 namespace ISD {
     24   struct ArgFlagsTy {
     25   private:
     26     static const uint64_t NoFlagSet      = 0ULL;
     27     static const uint64_t ZExt           = 1ULL<<0;  ///< Zero extended
     28     static const uint64_t ZExtOffs       = 0;
     29     static const uint64_t SExt           = 1ULL<<1;  ///< Sign extended
     30     static const uint64_t SExtOffs       = 1;
     31     static const uint64_t InReg          = 1ULL<<2;  ///< Passed in register
     32     static const uint64_t InRegOffs      = 2;
     33     static const uint64_t SRet           = 1ULL<<3;  ///< Hidden struct-ret ptr
     34     static const uint64_t SRetOffs       = 3;
     35     static const uint64_t ByVal          = 1ULL<<4;  ///< Struct passed by value
     36     static const uint64_t ByValOffs      = 4;
     37     static const uint64_t Nest           = 1ULL<<5;  ///< Nested fn static chain
     38     static const uint64_t NestOffs       = 5;
     39     static const uint64_t ByValAlign     = 0xFULL << 6; ///< Struct alignment
     40     static const uint64_t ByValAlignOffs = 6;
     41     static const uint64_t Split          = 1ULL << 10;
     42     static const uint64_t SplitOffs      = 10;
     43     static const uint64_t OrigAlign      = 0x1FULL<<27;
     44     static const uint64_t OrigAlignOffs  = 27;
     45     static const uint64_t ByValSize      = 0xffffffffULL << 32; ///< Struct size
     46     static const uint64_t ByValSizeOffs  = 32;
     47 
     48     static const uint64_t One            = 1ULL; ///< 1 of this type, for shifts
     49 
     50     uint64_t Flags;
     51   public:
     52     ArgFlagsTy() : Flags(0) { }
     53 
     54     bool isZExt()   const { return Flags & ZExt; }
     55     void setZExt()  { Flags |= One << ZExtOffs; }
     56 
     57     bool isSExt()   const { return Flags & SExt; }
     58     void setSExt()  { Flags |= One << SExtOffs; }
     59 
     60     bool isInReg()  const { return Flags & InReg; }
     61     void setInReg() { Flags |= One << InRegOffs; }
     62 
     63     bool isSRet()   const { return Flags & SRet; }
     64     void setSRet()  { Flags |= One << SRetOffs; }
     65 
     66     bool isByVal()  const { return Flags & ByVal; }
     67     void setByVal() { Flags |= One << ByValOffs; }
     68 
     69     bool isNest()   const { return Flags & Nest; }
     70     void setNest()  { Flags |= One << NestOffs; }
     71 
     72     unsigned getByValAlign() const {
     73       return (unsigned)
     74         ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
     75     }
     76     void setByValAlign(unsigned A) {
     77       Flags = (Flags & ~ByValAlign) |
     78         (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
     79     }
     80 
     81     bool isSplit()   const { return Flags & Split; }
     82     void setSplit()  { Flags |= One << SplitOffs; }
     83 
     84     unsigned getOrigAlign() const {
     85       return (unsigned)
     86         ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
     87     }
     88     void setOrigAlign(unsigned A) {
     89       Flags = (Flags & ~OrigAlign) |
     90         (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
     91     }
     92 
     93     unsigned getByValSize() const {
     94       return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
     95     }
     96     void setByValSize(unsigned S) {
     97       Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
     98     }
     99 
    100     /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
    101     std::string getArgFlagsString();
    102 
    103     /// getRawBits - Represent the flags as a bunch of bits.
    104     uint64_t getRawBits() const { return Flags; }
    105   };
    106 
    107   /// InputArg - This struct carries flags and type information about a
    108   /// single incoming (formal) argument or incoming (from the perspective
    109   /// of the caller) return value virtual register.
    110   ///
    111   struct InputArg {
    112     ArgFlagsTy Flags;
    113     MVT VT;
    114     bool Used;
    115 
    116     /// Index original Function's argument.
    117     unsigned OrigArgIndex;
    118 
    119     /// Offset in bytes of current input value relative to the beginning of
    120     /// original argument. E.g. if argument was splitted into four 32 bit
    121     /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12.
    122     unsigned PartOffset;
    123 
    124     InputArg() : VT(MVT::Other), Used(false) {}
    125     InputArg(ArgFlagsTy flags, EVT vt, bool used,
    126              unsigned origIdx, unsigned partOffs)
    127       : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) {
    128       VT = vt.getSimpleVT();
    129     }
    130   };
    131 
    132   /// OutputArg - This struct carries flags and a value for a
    133   /// single outgoing (actual) argument or outgoing (from the perspective
    134   /// of the caller) return value virtual register.
    135   ///
    136   struct OutputArg {
    137     ArgFlagsTy Flags;
    138     MVT VT;
    139 
    140     /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
    141     bool IsFixed;
    142 
    143     /// Index original Function's argument.
    144     unsigned OrigArgIndex;
    145 
    146     /// Offset in bytes of current output value relative to the beginning of
    147     /// original argument. E.g. if argument was splitted into four 32 bit
    148     /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12.
    149     unsigned PartOffset;
    150 
    151     OutputArg() : IsFixed(false) {}
    152     OutputArg(ArgFlagsTy flags, EVT vt, bool isfixed,
    153               unsigned origIdx, unsigned partOffs)
    154       : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx),
    155         PartOffset(partOffs) {
    156       VT = vt.getSimpleVT();
    157     }
    158   };
    159 }
    160 
    161 } // end llvm namespace
    162 
    163 #endif
    164