blob: 321ce60ab0f27d9803688047cedf02e3e53986bb [file] [log] [blame]
Chris Lattner44d2c352003-10-13 03:32:08 +00001//===-- SparcRegClassInfo.h - Register class def'ns for Sparc ---*- C++ -*-===//
John Criswell29265fe2003-10-21 15:17:13 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner56e91662002-08-12 21:25:05 +00009//
Chris Lattner44d2c352003-10-13 03:32:08 +000010// This file defines the register classes used by the Sparc target description.
Chris Lattner56e91662002-08-12 21:25:05 +000011//
12//===----------------------------------------------------------------------===//
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000013
Chris Lattner56e91662002-08-12 21:25:05 +000014#ifndef SPARC_REG_CLASS_INFO_H
15#define SPARC_REG_CLASS_INFO_H
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000016
Chris Lattnerf9781b52002-12-29 03:13:05 +000017#include "llvm/Target/TargetRegInfo.h"
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000018
19//-----------------------------------------------------------------------------
20// Integer Register Class
21//-----------------------------------------------------------------------------
22
Chris Lattnerf9781b52002-12-29 03:13:05 +000023struct SparcIntRegClass : public TargetRegClassInfo {
Chris Lattner56e91662002-08-12 21:25:05 +000024 SparcIntRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000025 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000026
Vikram S. Adve536b1922003-07-25 21:12:15 +000027 void colorIGNode(IGNode *Node,
28 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000029
Chris Lattner56e91662002-08-12 21:25:05 +000030 inline bool isRegVolatile(int Reg) const {
31 return (Reg < (int)StartOfNonVolatileRegs);
32 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000033
Anand Shuklabd2d0572003-07-20 15:39:30 +000034 inline bool modifiedByCall(int Reg) const {
35 return Reg==(int)ModifiedByCall;
36 }
37
Chris Lattner56e91662002-08-12 21:25:05 +000038 enum { // colors possible for a LR (in preferred order)
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000039 // --- following colors are volatile across function calls
40 // %g0 can't be used for coloring - always 0
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
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000047 l0, l1, l2, l3, l4, l5, l6, l7, // %l0-%l7
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +000048 i0, i1, i2, i3, i4, i5, // %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
Chris Lattner56e91662002-08-12 21:25:05 +000058 i6, i7, g0, g1, g2, g3, g4, g5, g6, g7, o6,
59
60 NumOfAllRegs, // Must be first AFTER registers...
Vikram S. Adve5462dca2001-10-22 13:43:08 +000061
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000062 //*** NOTE: If we decide to use some %g regs, they are volatile
63 // (see sparc64ABI)
64 // Move the %g regs from the end of the enumeration to just above the
65 // enumeration of %o0 (change StartOfAllRegs below)
66 // change isRegVloatile method below
67 // Also change IntRegNames above.
Chris Lattner56e91662002-08-12 21:25:05 +000068
69 // max # of colors reg coloring can allocate
70 NumOfAvailRegs = i6,
71
72 StartOfNonVolatileRegs = l0,
73 StartOfAllRegs = o0,
Anand Shuklabd2d0572003-07-20 15:39:30 +000074
75 ModifiedByCall = o7,
Chris Lattner5216cc52002-02-04 05:59:25 +000076 };
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000077
Vikram S. Adve8adb9942003-05-27 00:02:22 +000078 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000079};
80
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000081
82
83
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000084//-----------------------------------------------------------------------------
85// Float Register Class
86//-----------------------------------------------------------------------------
87
Chris Lattnerf9781b52002-12-29 03:13:05 +000088class SparcFloatRegClass : public TargetRegClassInfo {
Chris Lattner56e91662002-08-12 21:25:05 +000089 int findFloatColor(const LiveRange *LR, unsigned Start,
Vikram S. Adve536b1922003-07-25 21:12:15 +000090 unsigned End,
91 const std::vector<bool> &IsColorUsedArr) const;
Chris Lattner56e91662002-08-12 21:25:05 +000092public:
93 SparcFloatRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000094 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) {}
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000095
Vikram S. Adve536b1922003-07-25 21:12:15 +000096 // This method marks the registers used for a given register number.
97 // This marks a single register for Float regs, but the R,R+1 pair
98 // for double-precision registers.
99 //
100 virtual void markColorsUsed(unsigned RegInClass,
101 int UserRegType,
102 int RegTypeWanted,
103 std::vector<bool> &IsColorUsedArr) const;
104
105 // This method finds unused registers of the specified register type,
106 // using the given "used" flag array IsColorUsedArr. It checks a single
107 // entry in the array directly for float regs, and checks the pair [R,R+1]
108 // for double-precision registers
109 // It returns -1 if no unused color is found.
110 //
111 virtual int findUnusedColor(int RegTypeWanted,
112 const std::vector<bool> &IsColorUsedArr) const;
113
114 void colorIGNode(IGNode *Node,
115 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000116
Chris Lattner56e91662002-08-12 21:25:05 +0000117 // according to Sparc 64 ABI, all %fp regs are volatile
118 inline bool isRegVolatile(int Reg) const { return true; }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000119
Chris Lattner56e91662002-08-12 21:25:05 +0000120 enum {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000121 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9,
122 f10, f11, f12, f13, f14, f15, f16, f17, f18, f19,
123 f20, f21, f22, f23, f24, f25, f26, f27, f28, f29,
124 f30, f31, f32, f33, f34, f35, f36, f37, f38, f39,
125 f40, f41, f42, f43, f44, f45, f46, f47, f48, f49,
126 f50, f51, f52, f53, f54, f55, f56, f57, f58, f59,
Chris Lattner56e91662002-08-12 21:25:05 +0000127 f60, f61, f62, f63,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000128
Chris Lattner56e91662002-08-12 21:25:05 +0000129 // there are 64 regs alltogether but only 32 regs can be allocated at
130 // a time.
131 //
132 NumOfAvailRegs = 32,
133 NumOfAllRegs = 64,
134
135 StartOfNonVolatileRegs = f32,
136 StartOfAllRegs = f0,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000137 };
138
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000139 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000140};
141
142
143
144
145//-----------------------------------------------------------------------------
146// Int CC Register Class
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000147// Only one integer cc register is available. However, this register is
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000148// referred to as %xcc or %icc when instructions like subcc are executed but
149// referred to as %ccr (i.e., %xcc . %icc") when this register is moved
150// into an integer register using RD or WR instrcutions. So, three ids are
151// allocated for the three names.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000152//-----------------------------------------------------------------------------
153
Chris Lattnerf9781b52002-12-29 03:13:05 +0000154struct SparcIntCCRegClass : public TargetRegClassInfo {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000155 SparcIntCCRegClass(unsigned ID)
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000156 : TargetRegClassInfo(ID, 1, 3) { }
Vikram S. Advee9327f02002-05-19 15:25:51 +0000157
Vikram S. Adve536b1922003-07-25 21:12:15 +0000158 void colorIGNode(IGNode *Node,
159 const std::vector<bool> &IsColorUsedArr) const;
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000160
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +0000161 // according to Sparc 64 ABI, %ccr is volatile
162 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000163 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000164
165 enum {
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000166 xcc, icc, ccr // only one is available - see the note above
Chris Lattner56e91662002-08-12 21:25:05 +0000167 };
168
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000169 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000170};
171
172
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000173//-----------------------------------------------------------------------------
174// Float CC Register Class
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000175// Only 4 Float CC registers are available for allocation.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000176//-----------------------------------------------------------------------------
177
Chris Lattnerf9781b52002-12-29 03:13:05 +0000178struct SparcFloatCCRegClass : public TargetRegClassInfo {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000179 SparcFloatCCRegClass(unsigned ID)
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000180 : TargetRegClassInfo(ID, 4, 5) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000181
Vikram S. Adve536b1922003-07-25 21:12:15 +0000182 void colorIGNode(IGNode *Node,
Chris Lattner33238292003-09-01 19:56:48 +0000183 const std::vector<bool> &IsColorUsedArr) const;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000184
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +0000185 // according to Sparc 64 ABI, all %fp CC regs are volatile
186 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000187 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000188
189 enum {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000190 fcc0, fcc1, fcc2, fcc3, fsr // fsr is not used in allocation
191 }; // but has a name in getRegName()
192
193 const char * const getRegName(unsigned reg) const;
194};
195
196//-----------------------------------------------------------------------------
197// Sparc special register class. These registers are not used for allocation
198// but are used as arguments of some instructions.
199//-----------------------------------------------------------------------------
200
201struct SparcSpecialRegClass : public TargetRegClassInfo {
202 SparcSpecialRegClass(unsigned ID)
203 : TargetRegClassInfo(ID, 0, 1) { }
204
Vikram S. Adve536b1922003-07-25 21:12:15 +0000205 void colorIGNode(IGNode *Node,
206 const std::vector<bool> &IsColorUsedArr) const {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000207 assert(0 && "SparcSpecialRegClass should never be used for allocation");
208 }
209
210 // all currently included special regs are volatile
211 inline bool isRegVolatile(int Reg) const { return true; }
212
213 enum {
214 fsr // floating point state register
Chris Lattner56e91662002-08-12 21:25:05 +0000215 };
216
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000217 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000218};
219
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000220#endif