blob: d613582c87afa91355a4346864f685e130c8f5fb [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 Sasanka5867c7a2001-09-30 23:16:47 +000022 { "g1", "g2", "g3", "g4", "g5",
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 Sasanka5867c7a2001-09-30 23:16:47 +000025 "i0", "i1", "i2", "i3", "i4", "i5", "i7",
26 "g0", "g6", "g7", "i6", "o6" };
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000027
28
29
30class SparcIntRegOrder{
31
32 public:
33
34 enum RegsInPrefOrder // colors possible for a LR (in preferred order)
35 {
36 // --- following colors are volatile across function calls
37 // %g0 can't be used for coloring - always 0
38
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000039 g1, g2, g3, g4, g5, //%g1-%g5 (g6-7 are reserved for system)
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000040 o0, o1, o2, o3, o4, o5, o7, // %o0-%o5,
41
42 // %o6 is sp,
43 // all %0's can get modified by a call
44
45 // --- following colors are NON-volatile across function calls
46
47 l0, l1, l2, l3, l4, l5, l6, l7, // %l0-%l7
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000048 i0, i1, i2, i3, i4, i5, i7, // %i0-%i5: i's need not be preserved
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000049
50 // %i6 is the fp - so not allocated
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000051 // %i7 is the ret address by convention - can be used for others
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000052
53 // max # of colors reg coloring can allocate (NumOfAvailRegs)
54
55 // --- following colors are not available for allocation within this phase
56 // --- but can appear for pre-colored ranges
57
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000058 g0, g6, g7, i6, o6
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000059
60
61
62 };
63
64 // max # of colors reg coloring can allocate
65 static unsigned int const NumOfAvailRegs = g0;
66
67 static unsigned int const StartOfNonVolatileRegs = l0;
68 static unsigned int const StartOfAllRegs = g1;
69 static unsigned int const NumOfAllRegs = o6 + 1;
70
71
72 static const string getRegName(const unsigned reg) {
73 assert( reg < NumOfAllRegs );
74 return IntRegNames[reg];
75 }
76
77};
78
79
80
81class SparcIntRegClass : public MachineRegClassInfo
82{
83 public:
84
85 SparcIntRegClass(unsigned ID)
86 : MachineRegClassInfo(ID,
87 SparcIntRegOrder::NumOfAvailRegs,
88 SparcIntRegOrder::NumOfAllRegs)
89 { }
90
91 void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const;
92
93};
94
95//-----------------------------------------------------------------------------
96// Float Register Class
97//-----------------------------------------------------------------------------
98
99static string const FloatRegNames[] =
100 {
101 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9",
102 "f10", "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19",
103 "f20", "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29",
104 "f30", "f31", "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39",
105 "f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47", "f48", "f49",
106 "f50", "f51", "f52", "f53", "f54", "f55", "f56", "f57", "f58", "f59",
107 "f60", "f61", "f62", "f63"
108 };
109
110
111class SparcFloatRegOrder{
112
113 public:
114
115 enum RegsInPrefOrder {
116
117 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9,
118 f10, f11, f12, f13, f14, f15, f16, f17, f18, f19,
119 f20, f21, f22, f23, f24, f25, f26, f27, f28, f29,
120 f30, f31, f32, f33, f34, f35, f36, f37, f38, f39,
121 f40, f41, f42, f43, f44, f45, f46, f47, f48, f49,
122 f50, f51, f52, f53, f54, f55, f56, f57, f58, f59,
123 f60, f61, f62, f63
124
125 };
126
127 // there are 64 regs alltogether but only 32 regs can be allocated at
128 // a time.
129
130 static unsigned int const NumOfAvailRegs = 32;
131 static unsigned int const NumOfAllRegs = 64;
132
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000133 static unsigned int const StartOfNonVolatileRegs = f32;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000134 static unsigned int const StartOfAllRegs = f0;
135
136
137 static const string getRegName(const unsigned reg) {
138 assert( reg < NumOfAllRegs );
139 return FloatRegNames[reg];
140 }
141
142
143
144};
145
146
147
148class SparcFloatRegClass : public MachineRegClassInfo
149{
150 private:
151
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000152 int findFloatColor(const LiveRange *const LR, unsigned Start,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000153 unsigned End, bool IsColorUsedArr[] ) const;
154
155 public:
156
157 SparcFloatRegClass(unsigned ID)
158 : MachineRegClassInfo(ID,
159 SparcFloatRegOrder::NumOfAvailRegs,
160 SparcFloatRegOrder::NumOfAllRegs)
161 { }
162
163 void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const;
164
165};
166
167
168
169
170//-----------------------------------------------------------------------------
171// Int CC Register Class
172// Only one integer cc register is available
173//-----------------------------------------------------------------------------
174
175
176class SparcIntCCRegClass : public MachineRegClassInfo
177{
178public:
179
180 SparcIntCCRegClass(unsigned ID)
181 : MachineRegClassInfo(ID,1, 1) { }
182
183 inline void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const {
184 Node->setColor(0); // only one int cc reg is available
185 }
186
187};
188
189
190
191//-----------------------------------------------------------------------------
192// Float CC Register Class
193// Only 4 Float CC registers are available
194//-----------------------------------------------------------------------------
195
196
197static string const FloatCCRegNames[] =
198 {
199 "fcc0", "fcc1", "fcc2", "fcc3"
200 };
201
202
203class SparcFloatCCRegOrder{
204
205 public:
206
207 enum RegsInPrefOrder {
208
209 fcc0, fcc1, fcc2, fcc3
210 };
211
212 static const string getRegName(const unsigned reg) {
213 assert( reg < 4 );
214 return FloatCCRegNames[reg];
215 }
216
217};
218
219
220
221class SparcFloatCCRegClass : public MachineRegClassInfo
222{
223public:
224
225 SparcFloatCCRegClass(unsigned ID)
226 : MachineRegClassInfo(ID, 4, 4) { }
227
228 void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const {
229 int c;
230 for(c=0; c < 4 && IsColorUsedArr[c] ; ++c) ; // find color
231 assert( (c < 4) && "Can allocate only 4 float cc registers");
232 Node->setColor(c);
233 }
234
235};
236
237
238
239
240#endif