Provide a target override for the latest regalloc heuristic.
[oota-llvm.git] / include / llvm / Target / TargetCallingConv.h
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 Returned       = 1ULL<<6;  ///< Always returned
40     static const uint64_t ReturnedOffs   = 6;
41     static const uint64_t ByValAlign     = 0xFULL<<7; ///< Struct alignment
42     static const uint64_t ByValAlignOffs = 7;
43     static const uint64_t Split          = 1ULL<<11;
44     static const uint64_t SplitOffs      = 11;
45     static const uint64_t InAlloca       = 1ULL<<12; ///< Passed with inalloca
46     static const uint64_t InAllocaOffs   = 12;
47     static const uint64_t OrigAlign      = 0x1FULL<<27;
48     static const uint64_t OrigAlignOffs  = 27;
49     static const uint64_t ByValSize      = 0xffffffffULL<<32; ///< Struct size
50     static const uint64_t ByValSizeOffs  = 32;
51
52     static const uint64_t One            = 1ULL; ///< 1 of this type, for shifts
53
54     uint64_t Flags;
55   public:
56     ArgFlagsTy() : Flags(0) { }
57
58     bool isZExt()      const { return Flags & ZExt; }
59     void setZExt()     { Flags |= One << ZExtOffs; }
60
61     bool isSExt()      const { return Flags & SExt; }
62     void setSExt()     { Flags |= One << SExtOffs; }
63
64     bool isInReg()     const { return Flags & InReg; }
65     void setInReg()    { Flags |= One << InRegOffs; }
66
67     bool isSRet()      const { return Flags & SRet; }
68     void setSRet()     { Flags |= One << SRetOffs; }
69
70     bool isByVal()     const { return Flags & ByVal; }
71     void setByVal()    { Flags |= One << ByValOffs; }
72
73     bool isInAlloca()  const { return Flags & InAlloca; }
74     void setInAlloca() { Flags |= One << InAllocaOffs; }
75
76     bool isNest()      const { return Flags & Nest; }
77     void setNest()     { Flags |= One << NestOffs; }
78
79     bool isReturned()  const { return Flags & Returned; }
80     void setReturned() { Flags |= One << ReturnedOffs; }
81
82     unsigned getByValAlign() const {
83       return (unsigned)
84         ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
85     }
86     void setByValAlign(unsigned A) {
87       Flags = (Flags & ~ByValAlign) |
88         (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
89     }
90
91     bool isSplit()   const { return Flags & Split; }
92     void setSplit()  { Flags |= One << SplitOffs; }
93
94     unsigned getOrigAlign() const {
95       return (unsigned)
96         ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
97     }
98     void setOrigAlign(unsigned A) {
99       Flags = (Flags & ~OrigAlign) |
100         (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
101     }
102
103     unsigned getByValSize() const {
104       return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
105     }
106     void setByValSize(unsigned S) {
107       Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
108     }
109
110     /// getRawBits - Represent the flags as a bunch of bits.
111     uint64_t getRawBits() const { return Flags; }
112   };
113
114   /// InputArg - This struct carries flags and type information about a
115   /// single incoming (formal) argument or incoming (from the perspective
116   /// of the caller) return value virtual register.
117   ///
118   struct InputArg {
119     ArgFlagsTy Flags;
120     MVT VT;
121     EVT ArgVT;
122     bool Used;
123
124     /// Index original Function's argument.
125     unsigned OrigArgIndex;
126
127     /// Offset in bytes of current input value relative to the beginning of
128     /// original argument. E.g. if argument was splitted into four 32 bit
129     /// registers, we got 4 InputArgs with PartOffsets 0, 4, 8 and 12.
130     unsigned PartOffset;
131
132     InputArg() : VT(MVT::Other), Used(false) {}
133     InputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool used,
134              unsigned origIdx, unsigned partOffs)
135       : Flags(flags), Used(used), OrigArgIndex(origIdx), PartOffset(partOffs) {
136       VT = vt.getSimpleVT();
137       ArgVT = argvt;
138     }
139   };
140
141   /// OutputArg - This struct carries flags and a value for a
142   /// single outgoing (actual) argument or outgoing (from the perspective
143   /// of the caller) return value virtual register.
144   ///
145   struct OutputArg {
146     ArgFlagsTy Flags;
147     MVT VT;
148     EVT ArgVT;
149
150     /// IsFixed - Is this a "fixed" value, ie not passed through a vararg "...".
151     bool IsFixed;
152
153     /// Index original Function's argument.
154     unsigned OrigArgIndex;
155
156     /// Offset in bytes of current output value relative to the beginning of
157     /// original argument. E.g. if argument was splitted into four 32 bit
158     /// registers, we got 4 OutputArgs with PartOffsets 0, 4, 8 and 12.
159     unsigned PartOffset;
160
161     OutputArg() : IsFixed(false) {}
162     OutputArg(ArgFlagsTy flags, EVT vt, EVT argvt, bool isfixed,
163               unsigned origIdx, unsigned partOffs)
164       : Flags(flags), IsFixed(isfixed), OrigArgIndex(origIdx),
165         PartOffset(partOffs) {
166       VT = vt.getSimpleVT();
167       ArgVT = argvt;
168     }
169   };
170 }
171
172 } // end llvm namespace
173
174 #endif