blob: 311d035c296ee935bc504099f6244345f038cd0e [file] [log] [blame]
Ruchira Sasankadfc6c882001-09-18 22:52:44 +00001/* Title: SparcRegClassInfo.h -*- C++ -*-
2 Author: Ruchira Sasanka
3 Date: Aug 20, 01
4 Purpose: Contains the description of integer register class of Sparc
5*/
6
7
8#ifndef SPARC_REG_INFO_CLASS_H
9#define SPARC_REG_INFO_CLASS_H
10
11#include "llvm/Target/MachineRegInfo.h"
12#include "llvm/CodeGen/IGNode.h"
13
14//-----------------------------------------------------------------------------
15// Integer Register Class
16//-----------------------------------------------------------------------------
17
18
19// Int register names in same order as enum in class SparcIntRegOrder
20
21static string const IntRegNames[] =
Ruchira Sasanka990d8fb2001-10-09 23:36:13 +000022 {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000023 "o0", "o1", "o2", "o3", "o4", "o5", "o7",
24 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +000025 "i0", "i1", "i2", "i3", "i4", "i5",
Vikram S. Adve5462dca2001-10-22 13:43:08 +000026 "i6", "i7",
Ruchira Sasanka990d8fb2001-10-09 23:36:13 +000027 "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
Vikram S. Adve5462dca2001-10-22 13:43:08 +000028 "o6" };
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000029
30
31
32class SparcIntRegOrder{
33
34 public:
35
36 enum RegsInPrefOrder // colors possible for a LR (in preferred order)
37 {
38 // --- following colors are volatile across function calls
39 // %g0 can't be used for coloring - always 0
40
Ruchira Sasanka990d8fb2001-10-09 23:36:13 +000041 //%g1-%g5 (g6-7 are reserved for system)
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000042 o0, o1, o2, o3, o4, o5, o7, // %o0-%o5,
43
44 // %o6 is sp,
45 // all %0's can get modified by a call
46
47 // --- following colors are NON-volatile across function calls
48
49 l0, l1, l2, l3, l4, l5, l6, l7, // %l0-%l7
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +000050 i0, i1, i2, i3, i4, i5, // %i0-%i5: i's need not be preserved
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000051
52 // %i6 is the fp - so not allocated
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000053 // %i7 is the ret address by convention - can be used for others
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000054
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
Vikram S. Adve5462dca2001-10-22 13:43:08 +000060 i6, i7, g0, g1, g2, g3, g4, g5, g6, g7, o6
61
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +000062 //*** NOTE: If we decide to use globals, some of them are volatile
63 //**** see sparc64ABI (change isRegVloatile method below)
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000064
65
66 };
67
68 // max # of colors reg coloring can allocate
69 static unsigned int const NumOfAvailRegs = g0;
70
71 static unsigned int const StartOfNonVolatileRegs = l0;
Ruchira Sasanka990d8fb2001-10-09 23:36:13 +000072 static unsigned int const StartOfAllRegs = o0;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000073 static unsigned int const NumOfAllRegs = o6 + 1;
74
75
76 static const string getRegName(const unsigned reg) {
77 assert( reg < NumOfAllRegs );
78 return IntRegNames[reg];
79 }
80
Vikram S. Adve5462dca2001-10-22 13:43:08 +000081 static unsigned int getRegNumInCallersWindow(const unsigned reg) {
82 if (reg <= l7 || reg == o6) {
83 assert(0 && "registers o0-o7 and l0-l7 are not visible in caller");
84 return reg;
85 }
86 if (reg <= i7)
87 return reg - (i0 - o0);
88 assert((reg >= g0 || reg <= g7) && "Unrecognized integer register number");
89 return reg;
90 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000091};
92
93
94
95class SparcIntRegClass : public MachineRegClassInfo
96{
97 public:
98
99 SparcIntRegClass(unsigned ID)
100 : MachineRegClassInfo(ID,
101 SparcIntRegOrder::NumOfAvailRegs,
102 SparcIntRegOrder::NumOfAllRegs)
103 { }
104
105 void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const;
106
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000107 inline bool isRegVolatile(const int Reg) const {
108 return (Reg < (int) SparcIntRegOrder::StartOfNonVolatileRegs);
109 }
110
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000111};
112
113//-----------------------------------------------------------------------------
114// Float Register Class
115//-----------------------------------------------------------------------------
116
117static string const FloatRegNames[] =
118 {
119 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9",
120 "f10", "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19",
121 "f20", "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29",
122 "f30", "f31", "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39",
123 "f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47", "f48", "f49",
124 "f50", "f51", "f52", "f53", "f54", "f55", "f56", "f57", "f58", "f59",
125 "f60", "f61", "f62", "f63"
126 };
127
128
129class SparcFloatRegOrder{
130
131 public:
132
133 enum RegsInPrefOrder {
134
135 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9,
136 f10, f11, f12, f13, f14, f15, f16, f17, f18, f19,
137 f20, f21, f22, f23, f24, f25, f26, f27, f28, f29,
138 f30, f31, f32, f33, f34, f35, f36, f37, f38, f39,
139 f40, f41, f42, f43, f44, f45, f46, f47, f48, f49,
140 f50, f51, f52, f53, f54, f55, f56, f57, f58, f59,
141 f60, f61, f62, f63
142
143 };
144
145 // there are 64 regs alltogether but only 32 regs can be allocated at
146 // a time.
147
148 static unsigned int const NumOfAvailRegs = 32;
149 static unsigned int const NumOfAllRegs = 64;
150
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000151 static unsigned int const StartOfNonVolatileRegs = f32;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000152 static unsigned int const StartOfAllRegs = f0;
153
154
155 static const string getRegName(const unsigned reg) {
156 assert( reg < NumOfAllRegs );
157 return FloatRegNames[reg];
158 }
159
160
161
162};
163
164
165
166class SparcFloatRegClass : public MachineRegClassInfo
167{
168 private:
169
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000170 int findFloatColor(const LiveRange *const LR, unsigned Start,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000171 unsigned End, bool IsColorUsedArr[] ) const;
172
173 public:
174
175 SparcFloatRegClass(unsigned ID)
176 : MachineRegClassInfo(ID,
177 SparcFloatRegOrder::NumOfAvailRegs,
178 SparcFloatRegOrder::NumOfAllRegs)
179 { }
180
181 void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const;
182
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000183 // according to Sparc 64 ABI, all %fp regs are volatile
184 inline bool isRegVolatile(const int Reg) const { return true; }
185
186
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000187};
188
189
190
191
192//-----------------------------------------------------------------------------
193// Int CC Register Class
194// Only one integer cc register is available
195//-----------------------------------------------------------------------------
196
197
198class SparcIntCCRegClass : public MachineRegClassInfo
199{
200public:
201
202 SparcIntCCRegClass(unsigned ID)
203 : MachineRegClassInfo(ID,1, 1) { }
204
205 inline void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const {
206 Node->setColor(0); // only one int cc reg is available
207 }
208
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000209 // *** TODO: Check this
210 inline bool isRegVolatile(const int Reg) const { return true; }
211
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000212};
213
214
215
216//-----------------------------------------------------------------------------
217// Float CC Register Class
218// Only 4 Float CC registers are available
219//-----------------------------------------------------------------------------
220
221
222static string const FloatCCRegNames[] =
223 {
224 "fcc0", "fcc1", "fcc2", "fcc3"
225 };
226
227
228class SparcFloatCCRegOrder{
229
230 public:
231
232 enum RegsInPrefOrder {
233
234 fcc0, fcc1, fcc2, fcc3
235 };
236
237 static const string getRegName(const unsigned reg) {
238 assert( reg < 4 );
239 return FloatCCRegNames[reg];
240 }
241
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000242 // according to Sparc 64 ABI, all %fp regs are volatile
243 inline bool isRegVolatile(const int Reg) const { return true; }
244
245
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000246};
247
248
249
250class SparcFloatCCRegClass : public MachineRegClassInfo
251{
252public:
253
254 SparcFloatCCRegClass(unsigned ID)
255 : MachineRegClassInfo(ID, 4, 4) { }
256
257 void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const {
258 int c;
259 for(c=0; c < 4 && IsColorUsedArr[c] ; ++c) ; // find color
260 assert( (c < 4) && "Can allocate only 4 float cc registers");
261 Node->setColor(c);
262 }
263
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000264 // *** TODO: Check this
265 inline bool isRegVolatile(const int Reg) const { return true; }
266
267
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000268};
269
270
271
272
273#endif