blob: ff04e3f9ce9c9f90b7a58e1edae7da57e787a45b [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",
Ruchira Sasanka990d8fb2001-10-09 23:36:13 +000026 "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +000027 "i6", "i7", "o6" };
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000028
29
30
31class SparcIntRegOrder{
32
33 public:
34
35 enum RegsInPrefOrder // colors possible for a LR (in preferred order)
36 {
37 // --- following colors are volatile across function calls
38 // %g0 can't be used for coloring - always 0
39
Ruchira Sasanka990d8fb2001-10-09 23:36:13 +000040 //%g1-%g5 (g6-7 are reserved for system)
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000041 o0, o1, o2, o3, o4, o5, o7, // %o0-%o5,
42
43 // %o6 is sp,
44 // all %0's can get modified by a call
45
46 // --- following colors are NON-volatile across function calls
47
48 l0, l1, l2, l3, l4, l5, l6, l7, // %l0-%l7
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +000049 i0, i1, i2, i3, i4, i5, // %i0-%i5: i's need not be preserved
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000050
51 // %i6 is the fp - so not allocated
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000052 // %i7 is the ret address by convention - can be used for others
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000053
54 // max # of colors reg coloring can allocate (NumOfAvailRegs)
55
56 // --- following colors are not available for allocation within this phase
57 // --- but can appear for pre-colored ranges
58
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +000059 g0, g1, g2, g3, g4, g5, g6, g7, i6, i7, o6
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000060
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +000061 //*** NOTE: If we decide to use globals, some of them are volatile
62 //**** see sparc64ABI (change isRegVloatile method below)
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000063
64
65 };
66
67 // max # of colors reg coloring can allocate
68 static unsigned int const NumOfAvailRegs = g0;
69
70 static unsigned int const StartOfNonVolatileRegs = l0;
Ruchira Sasanka990d8fb2001-10-09 23:36:13 +000071 static unsigned int const StartOfAllRegs = o0;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000072 static unsigned int const NumOfAllRegs = o6 + 1;
73
74
75 static const string getRegName(const unsigned reg) {
76 assert( reg < NumOfAllRegs );
77 return IntRegNames[reg];
78 }
79
80};
81
82
83
84class SparcIntRegClass : public MachineRegClassInfo
85{
86 public:
87
88 SparcIntRegClass(unsigned ID)
89 : MachineRegClassInfo(ID,
90 SparcIntRegOrder::NumOfAvailRegs,
91 SparcIntRegOrder::NumOfAllRegs)
92 { }
93
94 void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const;
95
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +000096 inline bool isRegVolatile(const int Reg) const {
97 return (Reg < (int) SparcIntRegOrder::StartOfNonVolatileRegs);
98 }
99
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000100};
101
102//-----------------------------------------------------------------------------
103// Float Register Class
104//-----------------------------------------------------------------------------
105
106static string const FloatRegNames[] =
107 {
108 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9",
109 "f10", "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19",
110 "f20", "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29",
111 "f30", "f31", "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39",
112 "f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47", "f48", "f49",
113 "f50", "f51", "f52", "f53", "f54", "f55", "f56", "f57", "f58", "f59",
114 "f60", "f61", "f62", "f63"
115 };
116
117
118class SparcFloatRegOrder{
119
120 public:
121
122 enum RegsInPrefOrder {
123
124 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9,
125 f10, f11, f12, f13, f14, f15, f16, f17, f18, f19,
126 f20, f21, f22, f23, f24, f25, f26, f27, f28, f29,
127 f30, f31, f32, f33, f34, f35, f36, f37, f38, f39,
128 f40, f41, f42, f43, f44, f45, f46, f47, f48, f49,
129 f50, f51, f52, f53, f54, f55, f56, f57, f58, f59,
130 f60, f61, f62, f63
131
132 };
133
134 // there are 64 regs alltogether but only 32 regs can be allocated at
135 // a time.
136
137 static unsigned int const NumOfAvailRegs = 32;
138 static unsigned int const NumOfAllRegs = 64;
139
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000140 static unsigned int const StartOfNonVolatileRegs = f32;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000141 static unsigned int const StartOfAllRegs = f0;
142
143
144 static const string getRegName(const unsigned reg) {
145 assert( reg < NumOfAllRegs );
146 return FloatRegNames[reg];
147 }
148
149
150
151};
152
153
154
155class SparcFloatRegClass : public MachineRegClassInfo
156{
157 private:
158
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000159 int findFloatColor(const LiveRange *const LR, unsigned Start,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000160 unsigned End, bool IsColorUsedArr[] ) const;
161
162 public:
163
164 SparcFloatRegClass(unsigned ID)
165 : MachineRegClassInfo(ID,
166 SparcFloatRegOrder::NumOfAvailRegs,
167 SparcFloatRegOrder::NumOfAllRegs)
168 { }
169
170 void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const;
171
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000172 // according to Sparc 64 ABI, all %fp regs are volatile
173 inline bool isRegVolatile(const int Reg) const { return true; }
174
175
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000176};
177
178
179
180
181//-----------------------------------------------------------------------------
182// Int CC Register Class
183// Only one integer cc register is available
184//-----------------------------------------------------------------------------
185
186
187class SparcIntCCRegClass : public MachineRegClassInfo
188{
189public:
190
191 SparcIntCCRegClass(unsigned ID)
192 : MachineRegClassInfo(ID,1, 1) { }
193
194 inline void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const {
195 Node->setColor(0); // only one int cc reg is available
196 }
197
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000198 // *** TODO: Check this
199 inline bool isRegVolatile(const int Reg) const { return true; }
200
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000201};
202
203
204
205//-----------------------------------------------------------------------------
206// Float CC Register Class
207// Only 4 Float CC registers are available
208//-----------------------------------------------------------------------------
209
210
211static string const FloatCCRegNames[] =
212 {
213 "fcc0", "fcc1", "fcc2", "fcc3"
214 };
215
216
217class SparcFloatCCRegOrder{
218
219 public:
220
221 enum RegsInPrefOrder {
222
223 fcc0, fcc1, fcc2, fcc3
224 };
225
226 static const string getRegName(const unsigned reg) {
227 assert( reg < 4 );
228 return FloatCCRegNames[reg];
229 }
230
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000231 // according to Sparc 64 ABI, all %fp regs are volatile
232 inline bool isRegVolatile(const int Reg) const { return true; }
233
234
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000235};
236
237
238
239class SparcFloatCCRegClass : public MachineRegClassInfo
240{
241public:
242
243 SparcFloatCCRegClass(unsigned ID)
244 : MachineRegClassInfo(ID, 4, 4) { }
245
246 void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const {
247 int c;
248 for(c=0; c < 4 && IsColorUsedArr[c] ; ++c) ; // find color
249 assert( (c < 4) && "Can allocate only 4 float cc registers");
250 Node->setColor(c);
251 }
252
Ruchira Sasanka5b8971f2001-10-16 01:23:19 +0000253 // *** TODO: Check this
254 inline bool isRegVolatile(const int Reg) const { return true; }
255
256
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000257};
258
259
260
261
262#endif