blob: af61791b28212b84d47e9c0da1ab3eded8892bb5 [file] [log] [blame]
Chris Lattner56e91662002-08-12 21:25:05 +00001//===-- 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//===----------------------------------------------------------------------===//
Ruchira Sasankadfc6c882001-09-18 22:52:44 +00006
Chris Lattner56e91662002-08-12 21:25:05 +00007#ifndef SPARC_REG_CLASS_INFO_H
8#define SPARC_REG_CLASS_INFO_H
Ruchira Sasankadfc6c882001-09-18 22:52:44 +00009
Chris Lattnerf9781b52002-12-29 03:13:05 +000010#include "llvm/Target/TargetRegInfo.h"
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000011#include "llvm/CodeGen/IGNode.h"
12
13//-----------------------------------------------------------------------------
14// Integer Register Class
15//-----------------------------------------------------------------------------
16
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000017
Chris Lattnerf9781b52002-12-29 03:13:05 +000018struct SparcIntRegClass : public TargetRegClassInfo {
Chris Lattner56e91662002-08-12 21:25:05 +000019 SparcIntRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000020 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000021
Vikram S. Adve536b1922003-07-25 21:12:15 +000022 void colorIGNode(IGNode *Node,
23 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000024
Chris Lattner56e91662002-08-12 21:25:05 +000025 inline bool isRegVolatile(int Reg) const {
26 return (Reg < (int)StartOfNonVolatileRegs);
27 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000028
Anand Shuklabd2d0572003-07-20 15:39:30 +000029 inline bool modifiedByCall(int Reg) const {
30 return Reg==(int)ModifiedByCall;
31 }
32
Chris Lattner56e91662002-08-12 21:25:05 +000033 enum { // colors possible for a LR (in preferred order)
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000034 // --- following colors are volatile across function calls
35 // %g0 can't be used for coloring - always 0
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000036 o0, o1, o2, o3, o4, o5, o7, // %o0-%o5,
37
38 // %o6 is sp,
39 // all %0's can get modified by a call
40
41 // --- following colors are NON-volatile across function calls
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000042 l0, l1, l2, l3, l4, l5, l6, l7, // %l0-%l7
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +000043 i0, i1, i2, i3, i4, i5, // %i0-%i5: i's need not be preserved
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000044
45 // %i6 is the fp - so not allocated
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000046 // %i7 is the ret address by convention - can be used for others
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000047
48 // max # of colors reg coloring can allocate (NumOfAvailRegs)
49
50 // --- following colors are not available for allocation within this phase
51 // --- but can appear for pre-colored ranges
52
Chris Lattner56e91662002-08-12 21:25:05 +000053 i6, i7, g0, g1, g2, g3, g4, g5, g6, g7, o6,
54
55 NumOfAllRegs, // Must be first AFTER registers...
Vikram S. Adve5462dca2001-10-22 13:43:08 +000056
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000057 //*** NOTE: If we decide to use some %g regs, they are volatile
58 // (see sparc64ABI)
59 // Move the %g regs from the end of the enumeration to just above the
60 // enumeration of %o0 (change StartOfAllRegs below)
61 // change isRegVloatile method below
62 // Also change IntRegNames above.
Chris Lattner56e91662002-08-12 21:25:05 +000063
64 // max # of colors reg coloring can allocate
65 NumOfAvailRegs = i6,
66
67 StartOfNonVolatileRegs = l0,
68 StartOfAllRegs = o0,
Anand Shuklabd2d0572003-07-20 15:39:30 +000069
70 ModifiedByCall = o7,
Chris Lattner5216cc52002-02-04 05:59:25 +000071 };
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000072
Vikram S. Adve8adb9942003-05-27 00:02:22 +000073 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000074};
75
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000076
77
78
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000079//-----------------------------------------------------------------------------
80// Float Register Class
81//-----------------------------------------------------------------------------
82
Chris Lattnerf9781b52002-12-29 03:13:05 +000083class SparcFloatRegClass : public TargetRegClassInfo {
Chris Lattner56e91662002-08-12 21:25:05 +000084 int findFloatColor(const LiveRange *LR, unsigned Start,
Vikram S. Adve536b1922003-07-25 21:12:15 +000085 unsigned End,
86 const std::vector<bool> &IsColorUsedArr) const;
Chris Lattner56e91662002-08-12 21:25:05 +000087public:
88 SparcFloatRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000089 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) {}
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000090
Vikram S. Adve536b1922003-07-25 21:12:15 +000091 // This method marks the registers used for a given register number.
92 // This marks a single register for Float regs, but the R,R+1 pair
93 // for double-precision registers.
94 //
95 virtual void markColorsUsed(unsigned RegInClass,
96 int UserRegType,
97 int RegTypeWanted,
98 std::vector<bool> &IsColorUsedArr) const;
99
100 // This method finds unused registers of the specified register type,
101 // using the given "used" flag array IsColorUsedArr. It checks a single
102 // entry in the array directly for float regs, and checks the pair [R,R+1]
103 // for double-precision registers
104 // It returns -1 if no unused color is found.
105 //
106 virtual int findUnusedColor(int RegTypeWanted,
107 const std::vector<bool> &IsColorUsedArr) const;
108
109 void colorIGNode(IGNode *Node,
110 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000111
Chris Lattner56e91662002-08-12 21:25:05 +0000112 // according to Sparc 64 ABI, all %fp regs are volatile
113 inline bool isRegVolatile(int Reg) const { return true; }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000114
Chris Lattner56e91662002-08-12 21:25:05 +0000115 enum {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000116 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9,
117 f10, f11, f12, f13, f14, f15, f16, f17, f18, f19,
118 f20, f21, f22, f23, f24, f25, f26, f27, f28, f29,
119 f30, f31, f32, f33, f34, f35, f36, f37, f38, f39,
120 f40, f41, f42, f43, f44, f45, f46, f47, f48, f49,
121 f50, f51, f52, f53, f54, f55, f56, f57, f58, f59,
Chris Lattner56e91662002-08-12 21:25:05 +0000122 f60, f61, f62, f63,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000123
Chris Lattner56e91662002-08-12 21:25:05 +0000124 // there are 64 regs alltogether but only 32 regs can be allocated at
125 // a time.
126 //
127 NumOfAvailRegs = 32,
128 NumOfAllRegs = 64,
129
130 StartOfNonVolatileRegs = f32,
131 StartOfAllRegs = f0,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000132 };
133
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000134 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000135};
136
137
138
139
140//-----------------------------------------------------------------------------
141// Int CC Register Class
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000142// Only one integer cc register is available. However, this register is
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000143// referred to as %xcc or %icc when instructions like subcc are executed but
144// referred to as %ccr (i.e., %xcc . %icc") when this register is moved
145// into an integer register using RD or WR instrcutions. So, three ids are
146// allocated for the three names.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000147//-----------------------------------------------------------------------------
148
Chris Lattnerf9781b52002-12-29 03:13:05 +0000149struct SparcIntCCRegClass : public TargetRegClassInfo {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000150 SparcIntCCRegClass(unsigned ID)
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000151 : TargetRegClassInfo(ID, 1, 3) { }
Vikram S. Advee9327f02002-05-19 15:25:51 +0000152
Vikram S. Adve536b1922003-07-25 21:12:15 +0000153 void colorIGNode(IGNode *Node,
154 const std::vector<bool> &IsColorUsedArr) const;
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000155
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +0000156 // according to Sparc 64 ABI, %ccr is volatile
157 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000158 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000159
160 enum {
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000161 xcc, icc, ccr // only one is available - see the note above
Chris Lattner56e91662002-08-12 21:25:05 +0000162 };
163
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000164 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000165};
166
167
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000168//-----------------------------------------------------------------------------
169// Float CC Register Class
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000170// Only 4 Float CC registers are available for allocation.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000171//-----------------------------------------------------------------------------
172
Chris Lattnerf9781b52002-12-29 03:13:05 +0000173struct SparcFloatCCRegClass : public TargetRegClassInfo {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000174 SparcFloatCCRegClass(unsigned ID)
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000175 : TargetRegClassInfo(ID, 4, 5) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000176
Vikram S. Adve536b1922003-07-25 21:12:15 +0000177 void colorIGNode(IGNode *Node,
178 const std::vector<bool> &IsColorUsedArr) const {
Chris Lattnerabe98192002-05-23 15:50:03 +0000179 for(unsigned c = 0; c != 4; ++c)
180 if (!IsColorUsedArr[c]) { // find unused color
181 Node->setColor(c);
182 return;
183 }
184
185 Node->getParentLR()->markForSpill();
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000186 }
Vikram S. Advee9327f02002-05-19 15:25:51 +0000187
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +0000188 // according to Sparc 64 ABI, all %fp CC regs are volatile
189 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000190 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000191
192 enum {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000193 fcc0, fcc1, fcc2, fcc3, fsr // fsr is not used in allocation
194 }; // but has a name in getRegName()
195
196 const char * const getRegName(unsigned reg) const;
197};
198
199//-----------------------------------------------------------------------------
200// Sparc special register class. These registers are not used for allocation
201// but are used as arguments of some instructions.
202//-----------------------------------------------------------------------------
203
204struct SparcSpecialRegClass : public TargetRegClassInfo {
205 SparcSpecialRegClass(unsigned ID)
206 : TargetRegClassInfo(ID, 0, 1) { }
207
Vikram S. Adve536b1922003-07-25 21:12:15 +0000208 void colorIGNode(IGNode *Node,
209 const std::vector<bool> &IsColorUsedArr) const {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000210 assert(0 && "SparcSpecialRegClass should never be used for allocation");
211 }
212
213 // all currently included special regs are volatile
214 inline bool isRegVolatile(int Reg) const { return true; }
215
216 enum {
217 fsr // floating point state register
Chris Lattner56e91662002-08-12 21:25:05 +0000218 };
219
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000220 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000221};
222
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000223#endif