LLVM API Documentation

TargetCallingConv.h
Go to the documentation of this file.
00001 //===-- llvm/Target/TargetCallingConv.h - Calling Convention ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines types for working with calling-convention information.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_TARGET_TARGETCALLINGCONV_H
00015 #define LLVM_TARGET_TARGETCALLINGCONV_H
00016 
00017 #include "llvm/CodeGen/ValueTypes.h"
00018 #include "llvm/Support/DataTypes.h"
00019 #include "llvm/Support/MathExtras.h"
00020 #include <string>
00021 
00022 namespace llvm {
00023 
00024 namespace ISD {
00025   struct ArgFlagsTy {
00026   private:
00027     static const uint64_t NoFlagSet      = 0ULL;
00028     static const uint64_t ZExt           = 1ULL<<0;  ///< Zero extended
00029     static const uint64_t ZExtOffs       = 0;
00030     static const uint64_t SExt           = 1ULL<<1;  ///< Sign extended
00031     static const uint64_t SExtOffs       = 1;
00032     static const uint64_t InReg          = 1ULL<<2;  ///< Passed in register
00033     static const uint64_t InRegOffs      = 2;
00034     static const uint64_t SRet           = 1ULL<<3;  ///< Hidden struct-ret ptr
00035     static const uint64_t SRetOffs       = 3;
00036     static const uint64_t ByVal          = 1ULL<<4;  ///< Struct passed by value
00037     static const uint64_t ByValOffs      = 4;
00038     static const uint64_t Nest           = 1ULL<<5;  ///< Nested fn static chain
00039     static const uint64_t NestOffs       = 5;
00040     static const uint64_t Returned       = 1ULL<<6;  ///< Always returned
00041     static const uint64_t ReturnedOffs   = 6;
00042     static const uint64_t ByValAlign     = 0xFULL<<7; ///< Struct alignment
00043     static const uint64_t ByValAlignOffs = 7;
00044     static const uint64_t Split          = 1ULL<<11;
00045     static const uint64_t SplitOffs      = 11;
00046     static const uint64_t InAlloca       = 1ULL<<12; ///< Passed with inalloca
00047     static const uint64_t InAllocaOffs   = 12;
00048     static const uint64_t OrigAlign      = 0x1FULL<<27;
00049     static const uint64_t OrigAlignOffs  = 27;
00050     static const uint64_t ByValSize      = 0x3fffffffULL<<32; ///< Struct size
00051     static const uint64_t ByValSizeOffs  = 32;
00052     static const uint64_t InConsecutiveRegsLast      = 0x1ULL<<62; ///< Struct size
00053     static const uint64_t InConsecutiveRegsLastOffs  = 62;
00054     static const uint64_t InConsecutiveRegs      = 0x1ULL<<63; ///< Struct size
00055     static const uint64_t InConsecutiveRegsOffs  = 63;
00056 
00057     static const uint64_t One            = 1ULL; ///< 1 of this type, for shifts
00058 
00059     uint64_t Flags;
00060   public:
00061     ArgFlagsTy() : Flags(0) { }
00062 
00063     bool isZExt()      const { return Flags & ZExt; }
00064     void setZExt()     { Flags |= One << ZExtOffs; }
00065 
00066     bool isSExt()      const { return Flags & SExt; }
00067     void setSExt()     { Flags |= One << SExtOffs; }
00068 
00069     bool isInReg()     const { return Flags & InReg; }
00070     void setInReg()    { Flags |= One << InRegOffs; }
00071 
00072     bool isSRet()      const { return Flags & SRet; }
00073     void setSRet()     { Flags |= One << SRetOffs; }
00074 
00075     bool isByVal()     const { return Flags & ByVal; }
00076     void setByVal()    { Flags |= One << ByValOffs; }
00077 
00078     bool isInAlloca()  const { return Flags & InAlloca; }
00079     void setInAlloca() { Flags |= One << InAllocaOffs; }
00080 
00081     bool isNest()      const { return Flags & Nest; }
00082     void setNest()     { Flags |= One << NestOffs; }
00083 
00084     bool isReturned()  const { return Flags & Returned; }
00085     void setReturned() { Flags |= One << ReturnedOffs; }
00086 
00087     bool isInConsecutiveRegs()  const { return Flags & InConsecutiveRegs; }
00088     void setInConsecutiveRegs() { Flags |= One << InConsecutiveRegsOffs; }
00089 
00090     bool isInConsecutiveRegsLast()  const { return Flags & InConsecutiveRegsLast; }
00091     void setInConsecutiveRegsLast() { Flags |= One << InConsecutiveRegsLastOffs; }
00092 
00093     unsigned getByValAlign() const {
00094       return (unsigned)
00095         ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
00096     }
00097     void setByValAlign(unsigned A) {
00098       Flags = (Flags & ~ByValAlign) |
00099         (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
00100     }
00101 
00102     bool isSplit()   const { return Flags & Split; }
00103     void setSplit()  { Flags |= One << SplitOffs; }
00104 
00105     unsigned getOrigAlign() const {
00106       return (unsigned)
00107         ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
00108     }
00109     void setOrigAlign(unsigned A) {
00110       Flags = (Flags & ~OrigAlign) |
00111         (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
00112     }
00113 
00114     unsigned getByValSize() const {
00115       return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
00116     }
00117     void setByValSize(unsigned S) {
00118       Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
00119     }
00120 
00121     /// getRawBits - Represent the flags as a bunch of bits.
00122     uint64_t getRawBits() const { return Flags; }
00123   };
00124 
00125   /// InputArg - This struct carries flags and type information about a
00126   /// single incoming (formal) argument or incoming (from the perspective
00127   /// of the caller) return value virtual register.
00128   ///
00129   struct InputArg {
00130     ArgFlagsTy Flags;
00131     MVT VT;
00132     EVT ArgVT;
00133     bool Used;
00134 
00135     /// Index original Function's argument.
00136     unsigned OrigArgIndex;
00137 
00138     /// Offset in bytes of current input value relative to the beginning of
00139     /// original argument. E.g. if argument was splitted into four 32 bit
00140     /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12.
00141     unsigned PartOffset;
00142 
00143     InputArg() : VT(MVT::Other), Used(false) {}
00144     InputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool used,
00145              unsigned origIdx, unsigned partOffs)
00146       : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) {
00147       VT = vt.getSimpleVT();
00148       ArgVT = argvt;
00149     }
00150   };
00151 
00152   /// OutputArg - This struct carries flags and a value for a
00153   /// single outgoing (actual) argument or outgoing (from the perspective
00154   /// of the caller) return value virtual register.
00155   ///
00156   struct OutputArg {
00157     ArgFlagsTy Flags;
00158     MVT VT;
00159     EVT ArgVT;
00160 
00161     /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
00162     bool IsFixed;
00163 
00164     /// Index original Function's argument.
00165     unsigned OrigArgIndex;
00166 
00167     /// Offset in bytes of current output value relative to the beginning of
00168     /// original argument. E.g. if argument was splitted into four 32 bit
00169     /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12.
00170     unsigned PartOffset;
00171 
00172     OutputArg() : IsFixed(false) {}
00173     OutputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool isfixed,
00174               unsigned origIdx, unsigned partOffs)
00175       : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx),
00176         PartOffset(partOffs) {
00177       VT = vt.getSimpleVT();
00178       ArgVT = argvt;
00179     }
00180   };
00181 }
00182 
00183 } // end llvm namespace
00184 
00185 #endif