Get rid of the old byte-at-a-time emission code used when the Sparc JIT was
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9RegClassInfo.h
1 //===-- SparcV9RegClassInfo.h - Register class def'ns for SparcV9 ---*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the register classes used by the SparcV9 target description.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SPARCV9REGCLASSINFO_H
15 #define SPARCV9REGCLASSINFO_H
16
17 #include "llvm/Target/TargetRegInfo.h"
18
19 namespace llvm {
20
21 //-----------------------------------------------------------------------------
22 // Integer Register Class
23 //-----------------------------------------------------------------------------
24
25 struct SparcV9IntRegClass : public TargetRegClassInfo {
26   SparcV9IntRegClass(unsigned ID) 
27     : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) {  }
28
29   void colorIGNode(IGNode *Node,
30                    const std::vector<bool> &IsColorUsedArr) const;
31
32   inline bool isRegVolatile(int Reg) const {
33     return (Reg < (int)StartOfNonVolatileRegs); 
34   }
35
36   inline bool modifiedByCall(int Reg) const {
37     return Reg==(int)ModifiedByCall;
38   }
39
40   enum {   // colors possible for a LR (in preferred order)
41      // --- following colors are volatile across function calls
42      // %g0 can't be used for coloring - always 0
43      o0, o1, o2, o3, o4, o5, o7,  // %o0-%o5, 
44
45      // %o6 is sp, 
46      // all %0's can get modified by a call
47
48      // --- following colors are NON-volatile across function calls
49      l0, l1, l2, l3, l4, l5, l6, l7,    //  %l0-%l7
50      i0, i1, i2, i3, i4, i5,         // %i0-%i5: i's need not be preserved 
51       
52      // %i6 is the fp - so not allocated
53      // %i7 is the ret address by convention - can be used for others
54
55      // max # of colors reg coloring  can allocate (NumOfAvailRegs)
56
57      // --- following colors are not available for allocation within this phase
58      // --- but can appear for pre-colored ranges 
59
60      i6, i7, g0,  g1, g2, g3, g4, g5, g6, g7, o6,
61
62      NumOfAllRegs,  // Must be first AFTER registers...
63      
64      //*** NOTE: If we decide to use some %g regs, they are volatile
65      // (see sparc64ABI)
66      // Move the %g regs from the end of the enumeration to just above the
67      // enumeration of %o0 (change StartOfAllRegs below)
68      // change isRegVloatile method below
69      // Also change IntRegNames above.
70
71      // max # of colors reg coloring  can allocate
72      NumOfAvailRegs = i6,
73
74      StartOfNonVolatileRegs = l0,
75      StartOfAllRegs = o0,
76      
77      ModifiedByCall = o7,
78   };
79
80   const char * const getRegName(unsigned reg) const;
81 };
82
83
84 //-----------------------------------------------------------------------------
85 // Float Register Class
86 //-----------------------------------------------------------------------------
87
88 class SparcV9FloatRegClass : public TargetRegClassInfo {
89   int findFloatColor(const LiveRange *LR, unsigned Start,
90                      unsigned End,
91                      const std::vector<bool> &IsColorUsedArr) const;
92 public:
93   SparcV9FloatRegClass(unsigned ID) 
94     : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) {}
95
96   // This method marks the registers used for a given register number.
97   // This marks a single register for Float regs, but the R,R+1 pair
98   // for double-precision registers.
99   // 
100   virtual void markColorsUsed(unsigned RegInClass,
101                               int UserRegType,
102                               int RegTypeWanted,
103                               std::vector<bool> &IsColorUsedArr) const;
104   
105   // This method finds unused registers of the specified register type,
106   // using the given "used" flag array IsColorUsedArr.  It checks a single
107   // entry in the array directly for float regs, and checks the pair [R,R+1]
108   // for double-precision registers
109   // It returns -1 if no unused color is found.
110   // 
111   virtual int findUnusedColor(int RegTypeWanted,
112                               const std::vector<bool> &IsColorUsedArr) const;
113
114   void colorIGNode(IGNode *Node,
115                    const std::vector<bool> &IsColorUsedArr) const;
116
117   // according to  SparcV9 64 ABI, all %fp regs are volatile
118   inline bool isRegVolatile(int Reg) const { return true; }
119
120   enum {
121     f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, 
122     f10, f11, f12, f13, f14, f15, f16, f17, f18, f19,
123     f20, f21, f22, f23, f24, f25, f26, f27, f28, f29,
124     f30, f31, f32, f33, f34, f35, f36, f37, f38, f39,
125     f40, f41, f42, f43, f44, f45, f46, f47, f48, f49,
126     f50, f51, f52, f53, f54, f55, f56, f57, f58, f59,
127     f60, f61, f62, f63,
128
129     // there are 64 regs alltogether but only 32 regs can be allocated at
130     // a time.
131     //
132     NumOfAvailRegs = 32,
133     NumOfAllRegs = 64,
134
135     StartOfNonVolatileRegs = f32,
136     StartOfAllRegs = f0,
137   };
138
139   const char * const getRegName(unsigned reg) const;
140 };
141
142
143 //-----------------------------------------------------------------------------
144 // Int CC Register Class
145 // Only one integer cc register is available. However, this register is
146 // referred to as %xcc or %icc when instructions like subcc are executed but 
147 // referred to as %ccr (i.e., %xcc . %icc") when this register is moved
148 // into an integer register using RD or WR instrcutions. So, three ids are
149 // allocated for the three names.
150 //-----------------------------------------------------------------------------
151
152 struct SparcV9IntCCRegClass : public TargetRegClassInfo {
153   SparcV9IntCCRegClass(unsigned ID) 
154     : TargetRegClassInfo(ID, 1, 3) {  }
155   
156   void colorIGNode(IGNode *Node,
157                    const std::vector<bool> &IsColorUsedArr) const;
158
159   // according to the 64-bit SparcV9 ABI, all integer CC regs are
160   // volatile.
161   inline bool isRegVolatile(int Reg) const { return true; }
162
163   enum {
164     xcc, icc, ccr   // only one is available - see the note above
165   };
166
167   const char * const getRegName(unsigned reg) const;
168 };
169
170
171 //-----------------------------------------------------------------------------
172 // Float CC Register Class
173 // Only 4 Float CC registers are available for allocation.
174 //-----------------------------------------------------------------------------
175
176 struct SparcV9FloatCCRegClass : public TargetRegClassInfo {
177   SparcV9FloatCCRegClass(unsigned ID) 
178     : TargetRegClassInfo(ID, 4, 4) {  }
179
180   void colorIGNode(IGNode *Node,
181                    const std::vector<bool> &IsColorUsedArr) const;
182   
183   // according to the 64-bit SparcV9 ABI, all floating-point CC regs are
184   // volatile.
185   inline bool isRegVolatile(int Reg) const { return true; }
186
187   enum {
188     fcc0, fcc1, fcc2, fcc3
189   };
190   
191   const char * const getRegName(unsigned reg) const;
192 };
193
194
195 //-----------------------------------------------------------------------------
196 // SparcV9 special register class.  These registers are not used for allocation
197 // but are used as arguments of some instructions.
198 //-----------------------------------------------------------------------------
199
200 struct SparcV9SpecialRegClass : public TargetRegClassInfo {
201   SparcV9SpecialRegClass(unsigned ID) 
202     : TargetRegClassInfo(ID, 0, 1) {  }
203
204   void colorIGNode(IGNode *Node,
205                    const std::vector<bool> &IsColorUsedArr) const {
206     assert(0 && "SparcV9SpecialRegClass should never be used for allocation");
207   }
208   
209   // all currently included special regs are volatile
210   inline bool isRegVolatile(int Reg) const { return true; }
211
212   enum {
213     fsr                                 // floating point state register
214   };
215
216   const char * const getRegName(unsigned reg) const;
217 };
218
219 } // End llvm namespace
220
221 #endif