blob: 30ec42d764233697c9cd3c4e3048f76b064299b3 [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
12//-----------------------------------------------------------------------------
13// Integer Register Class
14//-----------------------------------------------------------------------------
15
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000016
Chris Lattnerf9781b52002-12-29 03:13:05 +000017struct SparcIntRegClass : public TargetRegClassInfo {
Chris Lattner56e91662002-08-12 21:25:05 +000018 SparcIntRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000019 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000020
Vikram S. Adve536b1922003-07-25 21:12:15 +000021 void colorIGNode(IGNode *Node,
22 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000023
Chris Lattner56e91662002-08-12 21:25:05 +000024 inline bool isRegVolatile(int Reg) const {
25 return (Reg < (int)StartOfNonVolatileRegs);
26 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000027
Anand Shuklabd2d0572003-07-20 15:39:30 +000028 inline bool modifiedByCall(int Reg) const {
29 return Reg==(int)ModifiedByCall;
30 }
31
Chris Lattner56e91662002-08-12 21:25:05 +000032 enum { // colors possible for a LR (in preferred order)
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000033 // --- following colors are volatile across function calls
34 // %g0 can't be used for coloring - always 0
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000035 o0, o1, o2, o3, o4, o5, o7, // %o0-%o5,
36
37 // %o6 is sp,
38 // all %0's can get modified by a call
39
40 // --- following colors are NON-volatile across function calls
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000041 l0, l1, l2, l3, l4, l5, l6, l7, // %l0-%l7
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +000042 i0, i1, i2, i3, i4, i5, // %i0-%i5: i's need not be preserved
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000043
44 // %i6 is the fp - so not allocated
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000045 // %i7 is the ret address by convention - can be used for others
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000046
47 // max # of colors reg coloring can allocate (NumOfAvailRegs)
48
49 // --- following colors are not available for allocation within this phase
50 // --- but can appear for pre-colored ranges
51
Chris Lattner56e91662002-08-12 21:25:05 +000052 i6, i7, g0, g1, g2, g3, g4, g5, g6, g7, o6,
53
54 NumOfAllRegs, // Must be first AFTER registers...
Vikram S. Adve5462dca2001-10-22 13:43:08 +000055
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000056 //*** NOTE: If we decide to use some %g regs, they are volatile
57 // (see sparc64ABI)
58 // Move the %g regs from the end of the enumeration to just above the
59 // enumeration of %o0 (change StartOfAllRegs below)
60 // change isRegVloatile method below
61 // Also change IntRegNames above.
Chris Lattner56e91662002-08-12 21:25:05 +000062
63 // max # of colors reg coloring can allocate
64 NumOfAvailRegs = i6,
65
66 StartOfNonVolatileRegs = l0,
67 StartOfAllRegs = o0,
Anand Shuklabd2d0572003-07-20 15:39:30 +000068
69 ModifiedByCall = o7,
Chris Lattner5216cc52002-02-04 05:59:25 +000070 };
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000071
Vikram S. Adve8adb9942003-05-27 00:02:22 +000072 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000073};
74
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000075
76
77
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000078//-----------------------------------------------------------------------------
79// Float Register Class
80//-----------------------------------------------------------------------------
81
Chris Lattnerf9781b52002-12-29 03:13:05 +000082class SparcFloatRegClass : public TargetRegClassInfo {
Chris Lattner56e91662002-08-12 21:25:05 +000083 int findFloatColor(const LiveRange *LR, unsigned Start,
Vikram S. Adve536b1922003-07-25 21:12:15 +000084 unsigned End,
85 const std::vector<bool> &IsColorUsedArr) const;
Chris Lattner56e91662002-08-12 21:25:05 +000086public:
87 SparcFloatRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000088 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) {}
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000089
Vikram S. Adve536b1922003-07-25 21:12:15 +000090 // This method marks the registers used for a given register number.
91 // This marks a single register for Float regs, but the R,R+1 pair
92 // for double-precision registers.
93 //
94 virtual void markColorsUsed(unsigned RegInClass,
95 int UserRegType,
96 int RegTypeWanted,
97 std::vector<bool> &IsColorUsedArr) const;
98
99 // This method finds unused registers of the specified register type,
100 // using the given "used" flag array IsColorUsedArr. It checks a single
101 // entry in the array directly for float regs, and checks the pair [R,R+1]
102 // for double-precision registers
103 // It returns -1 if no unused color is found.
104 //
105 virtual int findUnusedColor(int RegTypeWanted,
106 const std::vector<bool> &IsColorUsedArr) const;
107
108 void colorIGNode(IGNode *Node,
109 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000110
Chris Lattner56e91662002-08-12 21:25:05 +0000111 // according to Sparc 64 ABI, all %fp regs are volatile
112 inline bool isRegVolatile(int Reg) const { return true; }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000113
Chris Lattner56e91662002-08-12 21:25:05 +0000114 enum {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000115 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9,
116 f10, f11, f12, f13, f14, f15, f16, f17, f18, f19,
117 f20, f21, f22, f23, f24, f25, f26, f27, f28, f29,
118 f30, f31, f32, f33, f34, f35, f36, f37, f38, f39,
119 f40, f41, f42, f43, f44, f45, f46, f47, f48, f49,
120 f50, f51, f52, f53, f54, f55, f56, f57, f58, f59,
Chris Lattner56e91662002-08-12 21:25:05 +0000121 f60, f61, f62, f63,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000122
Chris Lattner56e91662002-08-12 21:25:05 +0000123 // there are 64 regs alltogether but only 32 regs can be allocated at
124 // a time.
125 //
126 NumOfAvailRegs = 32,
127 NumOfAllRegs = 64,
128
129 StartOfNonVolatileRegs = f32,
130 StartOfAllRegs = f0,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000131 };
132
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000133 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000134};
135
136
137
138
139//-----------------------------------------------------------------------------
140// Int CC Register Class
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000141// Only one integer cc register is available. However, this register is
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000142// referred to as %xcc or %icc when instructions like subcc are executed but
143// referred to as %ccr (i.e., %xcc . %icc") when this register is moved
144// into an integer register using RD or WR instrcutions. So, three ids are
145// allocated for the three names.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000146//-----------------------------------------------------------------------------
147
Chris Lattnerf9781b52002-12-29 03:13:05 +0000148struct SparcIntCCRegClass : public TargetRegClassInfo {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000149 SparcIntCCRegClass(unsigned ID)
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000150 : TargetRegClassInfo(ID, 1, 3) { }
Vikram S. Advee9327f02002-05-19 15:25:51 +0000151
Vikram S. Adve536b1922003-07-25 21:12:15 +0000152 void colorIGNode(IGNode *Node,
153 const std::vector<bool> &IsColorUsedArr) const;
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000154
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +0000155 // according to Sparc 64 ABI, %ccr is volatile
156 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000157 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000158
159 enum {
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000160 xcc, icc, ccr // only one is available - see the note above
Chris Lattner56e91662002-08-12 21:25:05 +0000161 };
162
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000163 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000164};
165
166
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000167//-----------------------------------------------------------------------------
168// Float CC Register Class
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000169// Only 4 Float CC registers are available for allocation.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000170//-----------------------------------------------------------------------------
171
Chris Lattnerf9781b52002-12-29 03:13:05 +0000172struct SparcFloatCCRegClass : public TargetRegClassInfo {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000173 SparcFloatCCRegClass(unsigned ID)
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000174 : TargetRegClassInfo(ID, 4, 5) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000175
Vikram S. Adve536b1922003-07-25 21:12:15 +0000176 void colorIGNode(IGNode *Node,
Chris Lattner33238292003-09-01 19:56:48 +0000177 const std::vector<bool> &IsColorUsedArr) const;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000178
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +0000179 // according to Sparc 64 ABI, all %fp CC regs are volatile
180 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000181 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000182
183 enum {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000184 fcc0, fcc1, fcc2, fcc3, fsr // fsr is not used in allocation
185 }; // but has a name in getRegName()
186
187 const char * const getRegName(unsigned reg) const;
188};
189
190//-----------------------------------------------------------------------------
191// Sparc special register class. These registers are not used for allocation
192// but are used as arguments of some instructions.
193//-----------------------------------------------------------------------------
194
195struct SparcSpecialRegClass : public TargetRegClassInfo {
196 SparcSpecialRegClass(unsigned ID)
197 : TargetRegClassInfo(ID, 0, 1) { }
198
Vikram S. Adve536b1922003-07-25 21:12:15 +0000199 void colorIGNode(IGNode *Node,
200 const std::vector<bool> &IsColorUsedArr) const {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000201 assert(0 && "SparcSpecialRegClass should never be used for allocation");
202 }
203
204 // all currently included special regs are volatile
205 inline bool isRegVolatile(int Reg) const { return true; }
206
207 enum {
208 fsr // floating point state register
Chris Lattner56e91662002-08-12 21:25:05 +0000209 };
210
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000211 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000212};
213
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000214#endif