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