1ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman//===-- llvm/Target/TargetCallingConv.h - Calling Convention ----*- C++ -*-===//
2ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman//
3ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman//                     The LLVM Compiler Infrastructure
4ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman//
5ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman// This file is distributed under the University of Illinois Open Source
6ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman// License. See LICENSE.TXT for details.
7ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman//
8ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman//===----------------------------------------------------------------------===//
9ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman//
10ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman// This file defines types for working with calling-convention information.
11ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman//
12ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman//===----------------------------------------------------------------------===//
13ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
14ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman#ifndef LLVM_TARGET_TARGETCALLINGCONV_H
15ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman#define LLVM_TARGET_TARGETCALLINGCONV_H
16ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
1784a61269370138b68ae2bcd6711a9ae8004fd77aEli Friedman#include "llvm/Support/DataTypes.h"
1884a61269370138b68ae2bcd6711a9ae8004fd77aEli Friedman#include "llvm/Support/MathExtras.h"
1984a61269370138b68ae2bcd6711a9ae8004fd77aEli Friedman#include <string>
2084a61269370138b68ae2bcd6711a9ae8004fd77aEli Friedman
21ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohmannamespace llvm {
22ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
23ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohmannamespace ISD {
24ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  struct ArgFlagsTy {
25ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  private:
26ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t NoFlagSet      = 0ULL;
27ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t ZExt           = 1ULL<<0;  ///< Zero extended
28ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t ZExtOffs       = 0;
29ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t SExt           = 1ULL<<1;  ///< Sign extended
30ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t SExtOffs       = 1;
31ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t InReg          = 1ULL<<2;  ///< Passed in register
32ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t InRegOffs      = 2;
33ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t SRet           = 1ULL<<3;  ///< Hidden struct-ret ptr
34ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t SRetOffs       = 3;
35ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t ByVal          = 1ULL<<4;  ///< Struct passed by value
36ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t ByValOffs      = 4;
37ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t Nest           = 1ULL<<5;  ///< Nested fn static chain
38ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t NestOffs       = 5;
3977592fe39c404f3c48b06fae48b965058b3a5ee8Dmitri Gribenko    static const uint64_t ByValAlign     = 0xFULL << 6; ///< Struct alignment
40ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t ByValAlignOffs = 6;
41ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t Split          = 1ULL << 10;
42ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t SplitOffs      = 10;
43ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t OrigAlign      = 0x1FULL<<27;
44ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t OrigAlignOffs  = 27;
4577592fe39c404f3c48b06fae48b965058b3a5ee8Dmitri Gribenko    static const uint64_t ByValSize      = 0xffffffffULL << 32; ///< Struct size
46ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    static const uint64_t ByValSizeOffs  = 32;
47ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
4877592fe39c404f3c48b06fae48b965058b3a5ee8Dmitri Gribenko    static const uint64_t One            = 1ULL; ///< 1 of this type, for shifts
49ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
50ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    uint64_t Flags;
51ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  public:
52ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    ArgFlagsTy() : Flags(0) { }
53ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
54ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    bool isZExt()   const { return Flags & ZExt; }
55ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    void setZExt()  { Flags |= One << ZExtOffs; }
56ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
57ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    bool isSExt()   const { return Flags & SExt; }
58ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    void setSExt()  { Flags |= One << SExtOffs; }
59ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
60ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    bool isInReg()  const { return Flags & InReg; }
61ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    void setInReg() { Flags |= One << InRegOffs; }
62ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
63ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    bool isSRet()   const { return Flags & SRet; }
64ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    void setSRet()  { Flags |= One << SRetOffs; }
65ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
66ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    bool isByVal()  const { return Flags & ByVal; }
67ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    void setByVal() { Flags |= One << ByValOffs; }
68ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
69ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    bool isNest()   const { return Flags & Nest; }
70ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    void setNest()  { Flags |= One << NestOffs; }
71ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
72ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    unsigned getByValAlign() const {
73ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman      return (unsigned)
74ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman        ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
75ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    }
76ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    void setByValAlign(unsigned A) {
77ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman      Flags = (Flags & ~ByValAlign) |
78ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman        (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
79ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    }
80ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
81ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    bool isSplit()   const { return Flags & Split; }
82ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    void setSplit()  { Flags |= One << SplitOffs; }
83ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
84ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    unsigned getOrigAlign() const {
85ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman      return (unsigned)
86ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman        ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
87ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    }
88ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    void setOrigAlign(unsigned A) {
89ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman      Flags = (Flags & ~OrigAlign) |
90ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman        (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
91ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    }
92ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
93ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    unsigned getByValSize() const {
94ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman      return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
95ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    }
96ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    void setByValSize(unsigned S) {
97ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman      Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
98ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    }
99ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
100ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
101ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    std::string getArgFlagsString();
102ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
103ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    /// getRawBits - Represent the flags as a bunch of bits.
104ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    uint64_t getRawBits() const { return Flags; }
105ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  };
106ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
107ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  /// InputArg - This struct carries flags and type information about a
108ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  /// single incoming (formal) argument or incoming (from the perspective
109ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  /// of the caller) return value virtual register.
110ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  ///
111ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  struct InputArg {
112ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    ArgFlagsTy Flags;
1131440e8b918d7116c3587cb95f4f7ac7a0a0b65adDuncan Sands    MVT VT;
114ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    bool Used;
115ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
116661afe75e81431a66de3ed8e22d5aa91443367b3Stepan Dyatkovskiy    /// Index original Function's argument.
117661afe75e81431a66de3ed8e22d5aa91443367b3Stepan Dyatkovskiy    unsigned OrigArgIndex;
118661afe75e81431a66de3ed8e22d5aa91443367b3Stepan Dyatkovskiy
119661afe75e81431a66de3ed8e22d5aa91443367b3Stepan Dyatkovskiy    /// Offset in bytes of current input value relative to the beginning of
120661afe75e81431a66de3ed8e22d5aa91443367b3Stepan Dyatkovskiy    /// original argument. E.g. if argument was splitted into four 32 bit
121661afe75e81431a66de3ed8e22d5aa91443367b3Stepan Dyatkovskiy    /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12.
122661afe75e81431a66de3ed8e22d5aa91443367b3Stepan Dyatkovskiy    unsigned PartOffset;
123661afe75e81431a66de3ed8e22d5aa91443367b3Stepan Dyatkovskiy
124ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    InputArg() : VT(MVT::Other), Used(false) {}
125661afe75e81431a66de3ed8e22d5aa91443367b3Stepan Dyatkovskiy    InputArg(ArgFlagsTy flags, EVT vt, bool used,
126661afe75e81431a66de3ed8e22d5aa91443367b3Stepan Dyatkovskiy             unsigned origIdx, unsigned partOffs)
127661afe75e81431a66de3ed8e22d5aa91443367b3Stepan Dyatkovskiy      : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) {
1281440e8b918d7116c3587cb95f4f7ac7a0a0b65adDuncan Sands      VT = vt.getSimpleVT();
129ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    }
130ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  };
131ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
132ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  /// OutputArg - This struct carries flags and a value for a
133ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  /// single outgoing (actual) argument or outgoing (from the perspective
134ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  /// of the caller) return value virtual register.
135ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  ///
136ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  struct OutputArg {
137ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    ArgFlagsTy Flags;
1381440e8b918d7116c3587cb95f4f7ac7a0a0b65adDuncan Sands    MVT VT;
139ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
140ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
141ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    bool IsFixed;
142ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
1430a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren    /// Index original Function's argument.
1440a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren    unsigned OrigArgIndex;
1450a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren
1460a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren    /// Offset in bytes of current output value relative to the beginning of
1470a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren    /// original argument. E.g. if argument was splitted into four 32 bit
1480a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren    /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12.
1490a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren    unsigned PartOffset;
1500a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren
151ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    OutputArg() : IsFixed(false) {}
1520a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren    OutputArg(ArgFlagsTy flags, EVT vt, bool isfixed,
1530a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren              unsigned origIdx, unsigned partOffs)
1540a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren      : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx),
1550a1544d2fd63d8101dc7d50974e65c95a0f6f98dManman Ren        PartOffset(partOffs) {
1561440e8b918d7116c3587cb95f4f7ac7a0a0b65adDuncan Sands      VT = vt.getSimpleVT();
157ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman    }
158ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman  };
159ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman}
160ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
161ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman} // end llvm namespace
162ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman
163ce5172098d5eaae22244c925b608fe62a23baaf2Dan Gohman#endif
164