blob: cc492e77c72c4b1089cfe7bad56ba66f66c05931 [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
Brian Gaeke960707c2003-11-11 22:41:34 +000019namespace llvm {
20
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000021//-----------------------------------------------------------------------------
22// Integer Register Class
23//-----------------------------------------------------------------------------
24
Chris Lattnerf9781b52002-12-29 03:13:05 +000025struct SparcIntRegClass : public TargetRegClassInfo {
Chris Lattner56e91662002-08-12 21:25:05 +000026 SparcIntRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000027 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000028
Vikram S. Adve536b1922003-07-25 21:12:15 +000029 void colorIGNode(IGNode *Node,
30 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000031
Chris Lattner56e91662002-08-12 21:25:05 +000032 inline bool isRegVolatile(int Reg) const {
33 return (Reg < (int)StartOfNonVolatileRegs);
34 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000035
Anand Shuklabd2d0572003-07-20 15:39:30 +000036 inline bool modifiedByCall(int Reg) const {
37 return Reg==(int)ModifiedByCall;
38 }
39
Chris Lattner56e91662002-08-12 21:25:05 +000040 enum { // colors possible for a LR (in preferred order)
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000041 // --- following colors are volatile across function calls
42 // %g0 can't be used for coloring - always 0
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000043 o0, o1, o2, o3, o4, o5, o7, // %o0-%o5,
44
45 // %o6 is sp,
46 // all %0's can get modified by a call
47
48 // --- following colors are NON-volatile across function calls
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000049 l0, l1, l2, l3, l4, l5, l6, l7, // %l0-%l7
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +000050 i0, i1, i2, i3, i4, i5, // %i0-%i5: i's need not be preserved
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000051
52 // %i6 is the fp - so not allocated
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000053 // %i7 is the ret address by convention - can be used for others
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000054
55 // max # of colors reg coloring can allocate (NumOfAvailRegs)
56
57 // --- following colors are not available for allocation within this phase
58 // --- but can appear for pre-colored ranges
59
Chris Lattner56e91662002-08-12 21:25:05 +000060 i6, i7, g0, g1, g2, g3, g4, g5, g6, g7, o6,
61
62 NumOfAllRegs, // Must be first AFTER registers...
Vikram S. Adve5462dca2001-10-22 13:43:08 +000063
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000064 //*** NOTE: If we decide to use some %g regs, they are volatile
65 // (see sparc64ABI)
66 // Move the %g regs from the end of the enumeration to just above the
67 // enumeration of %o0 (change StartOfAllRegs below)
68 // change isRegVloatile method below
69 // Also change IntRegNames above.
Chris Lattner56e91662002-08-12 21:25:05 +000070
71 // max # of colors reg coloring can allocate
72 NumOfAvailRegs = i6,
73
74 StartOfNonVolatileRegs = l0,
75 StartOfAllRegs = o0,
Anand Shuklabd2d0572003-07-20 15:39:30 +000076
77 ModifiedByCall = o7,
Chris Lattner5216cc52002-02-04 05:59:25 +000078 };
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000079
Vikram S. Adve8adb9942003-05-27 00:02:22 +000080 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000081};
82
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000083
84
85
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000086//-----------------------------------------------------------------------------
87// Float Register Class
88//-----------------------------------------------------------------------------
89
Chris Lattnerf9781b52002-12-29 03:13:05 +000090class SparcFloatRegClass : public TargetRegClassInfo {
Chris Lattner56e91662002-08-12 21:25:05 +000091 int findFloatColor(const LiveRange *LR, unsigned Start,
Vikram S. Adve536b1922003-07-25 21:12:15 +000092 unsigned End,
93 const std::vector<bool> &IsColorUsedArr) const;
Chris Lattner56e91662002-08-12 21:25:05 +000094public:
95 SparcFloatRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000096 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) {}
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000097
Vikram S. Adve536b1922003-07-25 21:12:15 +000098 // This method marks the registers used for a given register number.
99 // This marks a single register for Float regs, but the R,R+1 pair
100 // for double-precision registers.
101 //
102 virtual void markColorsUsed(unsigned RegInClass,
103 int UserRegType,
104 int RegTypeWanted,
105 std::vector<bool> &IsColorUsedArr) const;
106
107 // This method finds unused registers of the specified register type,
108 // using the given "used" flag array IsColorUsedArr. It checks a single
109 // entry in the array directly for float regs, and checks the pair [R,R+1]
110 // for double-precision registers
111 // It returns -1 if no unused color is found.
112 //
113 virtual int findUnusedColor(int RegTypeWanted,
114 const std::vector<bool> &IsColorUsedArr) const;
115
116 void colorIGNode(IGNode *Node,
117 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000118
Chris Lattner56e91662002-08-12 21:25:05 +0000119 // according to Sparc 64 ABI, all %fp regs are volatile
120 inline bool isRegVolatile(int Reg) const { return true; }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000121
Chris Lattner56e91662002-08-12 21:25:05 +0000122 enum {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000123 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9,
124 f10, f11, f12, f13, f14, f15, f16, f17, f18, f19,
125 f20, f21, f22, f23, f24, f25, f26, f27, f28, f29,
126 f30, f31, f32, f33, f34, f35, f36, f37, f38, f39,
127 f40, f41, f42, f43, f44, f45, f46, f47, f48, f49,
128 f50, f51, f52, f53, f54, f55, f56, f57, f58, f59,
Chris Lattner56e91662002-08-12 21:25:05 +0000129 f60, f61, f62, f63,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000130
Chris Lattner56e91662002-08-12 21:25:05 +0000131 // there are 64 regs alltogether but only 32 regs can be allocated at
132 // a time.
133 //
134 NumOfAvailRegs = 32,
135 NumOfAllRegs = 64,
136
137 StartOfNonVolatileRegs = f32,
138 StartOfAllRegs = f0,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000139 };
140
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000141 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000142};
143
144
145
146
147//-----------------------------------------------------------------------------
148// Int CC Register Class
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000149// Only one integer cc register is available. However, this register is
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000150// referred to as %xcc or %icc when instructions like subcc are executed but
151// referred to as %ccr (i.e., %xcc . %icc") when this register is moved
152// into an integer register using RD or WR instrcutions. So, three ids are
153// allocated for the three names.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000154//-----------------------------------------------------------------------------
155
Chris Lattnerf9781b52002-12-29 03:13:05 +0000156struct SparcIntCCRegClass : public TargetRegClassInfo {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000157 SparcIntCCRegClass(unsigned ID)
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000158 : TargetRegClassInfo(ID, 1, 3) { }
Vikram S. Advee9327f02002-05-19 15:25:51 +0000159
Vikram S. Adve536b1922003-07-25 21:12:15 +0000160 void colorIGNode(IGNode *Node,
161 const std::vector<bool> &IsColorUsedArr) const;
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000162
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +0000163 // according to Sparc 64 ABI, %ccr is volatile
164 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000165 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000166
167 enum {
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000168 xcc, icc, ccr // only one is available - see the note above
Chris Lattner56e91662002-08-12 21:25:05 +0000169 };
170
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000171 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000172};
173
174
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000175//-----------------------------------------------------------------------------
176// Float CC Register Class
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000177// Only 4 Float CC registers are available for allocation.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000178//-----------------------------------------------------------------------------
179
Chris Lattnerf9781b52002-12-29 03:13:05 +0000180struct SparcFloatCCRegClass : public TargetRegClassInfo {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000181 SparcFloatCCRegClass(unsigned ID)
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000182 : TargetRegClassInfo(ID, 4, 5) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000183
Vikram S. Adve536b1922003-07-25 21:12:15 +0000184 void colorIGNode(IGNode *Node,
Chris Lattner33238292003-09-01 19:56:48 +0000185 const std::vector<bool> &IsColorUsedArr) const;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000186
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +0000187 // according to Sparc 64 ABI, all %fp CC regs are volatile
188 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000189 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000190
191 enum {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000192 fcc0, fcc1, fcc2, fcc3, fsr // fsr is not used in allocation
193 }; // but has a name in getRegName()
194
195 const char * const getRegName(unsigned reg) const;
196};
197
198//-----------------------------------------------------------------------------
199// Sparc special register class. These registers are not used for allocation
200// but are used as arguments of some instructions.
201//-----------------------------------------------------------------------------
202
203struct SparcSpecialRegClass : public TargetRegClassInfo {
204 SparcSpecialRegClass(unsigned ID)
205 : TargetRegClassInfo(ID, 0, 1) { }
206
Vikram S. Adve536b1922003-07-25 21:12:15 +0000207 void colorIGNode(IGNode *Node,
208 const std::vector<bool> &IsColorUsedArr) const {
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000209 assert(0 && "SparcSpecialRegClass should never be used for allocation");
210 }
211
212 // all currently included special regs are volatile
213 inline bool isRegVolatile(int Reg) const { return true; }
214
215 enum {
216 fsr // floating point state register
Chris Lattner56e91662002-08-12 21:25:05 +0000217 };
218
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000219 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000220};
221
Brian Gaeke960707c2003-11-11 22:41:34 +0000222} // End llvm namespace
223
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000224#endif