blob: 17e94ae44c3dbfb9983b651339b5aa90517ee882 [file] [log] [blame]
Chris Lattner44d2c352003-10-13 03:32:08 +00001//===-- SparcRegClassInfo.h - Register class def'ns for Sparc ---*- C++ -*-===//
Chris Lattner56e91662002-08-12 21:25:05 +00002//
Chris Lattner44d2c352003-10-13 03:32:08 +00003// This file defines the register classes used by the Sparc target description.
Chris Lattner56e91662002-08-12 21:25:05 +00004//
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
Chris Lattnerf9781b52002-12-29 03:13:05 +000016struct SparcIntRegClass : public TargetRegClassInfo {
Chris Lattner56e91662002-08-12 21:25:05 +000017 SparcIntRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000018 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000019
Vikram S. Adve536b1922003-07-25 21:12:15 +000020 void colorIGNode(IGNode *Node,
21 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000022
Chris Lattner56e91662002-08-12 21:25:05 +000023 inline bool isRegVolatile(int Reg) const {
24 return (Reg < (int)StartOfNonVolatileRegs);
25 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000026
Anand Shuklabd2d0572003-07-20 15:39:30 +000027 inline bool modifiedByCall(int Reg) const {
28 return Reg==(int)ModifiedByCall;
29 }
30
Chris Lattner56e91662002-08-12 21:25:05 +000031 enum { // colors possible for a LR (in preferred order)
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000032 // --- following colors are volatile across function calls
33 // %g0 can't be used for coloring - always 0
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000034 o0, o1, o2, o3, o4, o5, o7, // %o0-%o5,
35
36 // %o6 is sp,
37 // all %0's can get modified by a call
38
39 // --- following colors are NON-volatile across function calls
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000040 l0, l1, l2, l3, l4, l5, l6, l7, // %l0-%l7
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +000041 i0, i1, i2, i3, i4, i5, // %i0-%i5: i's need not be preserved
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000042
43 // %i6 is the fp - so not allocated
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000044 // %i7 is the ret address by convention - can be used for others
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000045
46 // max # of colors reg coloring can allocate (NumOfAvailRegs)
47
48 // --- following colors are not available for allocation within this phase
49 // --- but can appear for pre-colored ranges
50
Chris Lattner56e91662002-08-12 21:25:05 +000051 i6, i7, g0, g1, g2, g3, g4, g5, g6, g7, o6,
52
53 NumOfAllRegs, // Must be first AFTER registers...
Vikram S. Adve5462dca2001-10-22 13:43:08 +000054
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000055 //*** NOTE: If we decide to use some %g regs, they are volatile
56 // (see sparc64ABI)
57 // Move the %g regs from the end of the enumeration to just above the
58 // enumeration of %o0 (change StartOfAllRegs below)
59 // change isRegVloatile method below
60 // Also change IntRegNames above.
Chris Lattner56e91662002-08-12 21:25:05 +000061
62 // max # of colors reg coloring can allocate
63 NumOfAvailRegs = i6,
64
65 StartOfNonVolatileRegs = l0,
66 StartOfAllRegs = o0,
Anand Shuklabd2d0572003-07-20 15:39:30 +000067
68 ModifiedByCall = o7,
Chris Lattner5216cc52002-02-04 05:59:25 +000069 };
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000070
Vikram S. Adve8adb9942003-05-27 00:02:22 +000071 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000072};
73
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000074
75
76
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000077//-----------------------------------------------------------------------------
78// Float Register Class
79//-----------------------------------------------------------------------------
80
Chris Lattnerf9781b52002-12-29 03:13:05 +000081class SparcFloatRegClass : public TargetRegClassInfo {
Chris Lattner56e91662002-08-12 21:25:05 +000082 int findFloatColor(const LiveRange *LR, unsigned Start,
Vikram S. Adve536b1922003-07-25 21:12:15 +000083 unsigned End,
84 const std::vector<bool> &IsColorUsedArr) const;
Chris Lattner56e91662002-08-12 21:25:05 +000085public:
86 SparcFloatRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000087 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) {}
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000088
Vikram S. Adve536b1922003-07-25 21:12:15 +000089 // This method marks the registers used for a given register number.
90 // This marks a single register for Float regs, but the R,R+1 pair
91 // for double-precision registers.
92 //
93 virtual void markColorsUsed(unsigned RegInClass,
94 int UserRegType,
95 int RegTypeWanted,
96 std::vector<bool> &IsColorUsedArr) const;
97
98 // This method finds unused registers of the specified register type,
99 // using the given "used" flag array IsColorUsedArr. It checks a single
100 // entry in the array directly for float regs, and checks the pair [R,R+1]
101 // for double-precision registers
102 // It returns -1 if no unused color is found.
103 //
104 virtual int findUnusedColor(int RegTypeWanted,
105 const std::vector<bool> &IsColorUsedArr) const;
106
107 void colorIGNode(IGNode *Node,
108 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000109
Chris Lattner56e91662002-08-12 21:25:05 +0000110 // according to Sparc 64 ABI, all %fp regs are volatile
111 inline bool isRegVolatile(int Reg) const { return true; }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000112
Chris Lattner56e91662002-08-12 21:25:05 +0000113 enum {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000114 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9,
115 f10, f11, f12, f13, f14, f15, f16, f17, f18, f19,
116 f20, f21, f22, f23, f24, f25, f26, f27, f28, f29,
117 f30, f31, f32, f33, f34, f35, f36, f37, f38, f39,
118 f40, f41, f42, f43, f44, f45, f46, f47, f48, f49,
119 f50, f51, f52, f53, f54, f55, f56, f57, f58, f59,
Chris Lattner56e91662002-08-12 21:25:05 +0000120 f60, f61, f62, f63,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000121
Chris Lattner56e91662002-08-12 21:25:05 +0000122 // there are 64 regs alltogether but only 32 regs can be allocated at
123 // a time.
124 //
125 NumOfAvailRegs = 32,
126 NumOfAllRegs = 64,
127
128 StartOfNonVolatileRegs = f32,
129 StartOfAllRegs = f0,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000130 };
131
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000132 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000133};
134
135
136
137
138//-----------------------------------------------------------------------------
139// Int CC Register Class
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000140// Only one integer cc register is available. However, this register is
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000141// referred to as %xcc or %icc when instructions like subcc are executed but
142// referred to as %ccr (i.e., %xcc . %icc") when this register is moved
143// into an integer register using RD or WR instrcutions. So, three ids are
144// allocated for the three names.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000145//-----------------------------------------------------------------------------
146
Chris Lattnerf9781b52002-12-29 03:13:05 +0000147struct SparcIntCCRegClass : public TargetRegClassInfo {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000148 SparcIntCCRegClass(unsigned ID)
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000149 : TargetRegClassInfo(ID, 1, 3) { }
Vikram S. Advee9327f02002-05-19 15:25:51 +0000150
Vikram S. Adve536b1922003-07-25 21:12:15 +0000151 void colorIGNode(IGNode *Node,
152 const std::vector<bool> &IsColorUsedArr) const;
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000153
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +0000154 // according to Sparc 64 ABI, %ccr is volatile
155 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000156 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000157
158 enum {
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000159 xcc, icc, ccr // only one is available - see the note above
Chris Lattner56e91662002-08-12 21:25:05 +0000160 };
161
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000162 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000163};
164
165
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000166//-----------------------------------------------------------------------------
167// Float CC Register Class
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000168// Only 4 Float CC registers are available for allocation.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000169//-----------------------------------------------------------------------------
170
Chris Lattnerf9781b52002-12-29 03:13:05 +0000171struct SparcFloatCCRegClass : public TargetRegClassInfo {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000172 SparcFloatCCRegClass(unsigned ID)
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000173 : TargetRegClassInfo(ID, 4, 5) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000174
Vikram S. Adve536b1922003-07-25 21:12:15 +0000175 void colorIGNode(IGNode *Node,
Chris Lattner33238292003-09-01 19:56:48 +0000176 const std::vector<bool> &IsColorUsedArr) const;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000177
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +0000178 // according to Sparc 64 ABI, all %fp CC regs are volatile
179 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000180 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000181
182 enum {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000183 fcc0, fcc1, fcc2, fcc3, fsr // fsr is not used in allocation
184 }; // but has a name in getRegName()
185
186 const char * const getRegName(unsigned reg) const;
187};
188
189//-----------------------------------------------------------------------------
190// Sparc special register class. These registers are not used for allocation
191// but are used as arguments of some instructions.
192//-----------------------------------------------------------------------------
193
194struct SparcSpecialRegClass : public TargetRegClassInfo {
195 SparcSpecialRegClass(unsigned ID)
196 : TargetRegClassInfo(ID, 0, 1) { }
197
Vikram S. Adve536b1922003-07-25 21:12:15 +0000198 void colorIGNode(IGNode *Node,
199 const std::vector<bool> &IsColorUsedArr) const {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000200 assert(0 && "SparcSpecialRegClass should never be used for allocation");
201 }
202
203 // all currently included special regs are volatile
204 inline bool isRegVolatile(int Reg) const { return true; }
205
206 enum {
207 fsr // floating point state register
Chris Lattner56e91662002-08-12 21:25:05 +0000208 };
209
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000210 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000211};
212
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000213#endif