blob: 33c7961403c631c1497d21afa6d9b3f25d781302 [file] [log] [blame]
Brian Gaeke03cac372004-04-25 07:04:49 +00001//===-- SparcV9RegClassInfo.h - Register class def'ns for SparcV9 -*- 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//
Brian Gaeke03cac372004-04-25 07:04:49 +000010// This file defines the register classes used by the SparcV9 target. It
11// implicitly defines (using enums) the "class register numbers" used in
Brian Gaekedca24dd2004-06-03 02:45:09 +000012// the SparcV9 target, which are converted using a formula in the SparcV9RegInfo
Brian Gaeke03cac372004-04-25 07:04:49 +000013// class to "unified register numbers".
Chris Lattner56e91662002-08-12 21:25:05 +000014//
15//===----------------------------------------------------------------------===//
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000016
Brian Gaeke85cb7772004-04-19 18:53:42 +000017#ifndef SPARCV9REGCLASSINFO_H
18#define SPARCV9REGCLASSINFO_H
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000019
Brian Gaeke71509a92004-04-23 18:15:47 +000020#include "SparcV9RegInfo.h"
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000021
Brian Gaeke960707c2003-11-11 22:41:34 +000022namespace llvm {
23
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000024//-----------------------------------------------------------------------------
25// Integer Register Class
26//-----------------------------------------------------------------------------
27
Brian Gaeke94e95d22004-02-25 18:44:15 +000028struct SparcV9IntRegClass : public TargetRegClassInfo {
29 SparcV9IntRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000030 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000031
Vikram S. Adve536b1922003-07-25 21:12:15 +000032 void colorIGNode(IGNode *Node,
33 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000034
Chris Lattner56e91662002-08-12 21:25:05 +000035 inline bool isRegVolatile(int Reg) const {
36 return (Reg < (int)StartOfNonVolatileRegs);
37 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000038
Anand Shuklabd2d0572003-07-20 15:39:30 +000039 inline bool modifiedByCall(int Reg) const {
40 return Reg==(int)ModifiedByCall;
41 }
42
Chris Lattner56e91662002-08-12 21:25:05 +000043 enum { // colors possible for a LR (in preferred order)
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000044 // --- following colors are volatile across function calls
45 // %g0 can't be used for coloring - always 0
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000046 o0, o1, o2, o3, o4, o5, o7, // %o0-%o5,
47
48 // %o6 is sp,
49 // all %0's can get modified by a call
50
51 // --- following colors are NON-volatile across function calls
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000052 l0, l1, l2, l3, l4, l5, l6, l7, // %l0-%l7
Ruchira Sasanka086bf0f2001-10-15 16:25:28 +000053 i0, i1, i2, i3, i4, i5, // %i0-%i5: i's need not be preserved
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000054
55 // %i6 is the fp - so not allocated
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000056 // %i7 is the ret address by convention - can be used for others
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000057
58 // max # of colors reg coloring can allocate (NumOfAvailRegs)
59
60 // --- following colors are not available for allocation within this phase
61 // --- but can appear for pre-colored ranges
62
Chris Lattner56e91662002-08-12 21:25:05 +000063 i6, i7, g0, g1, g2, g3, g4, g5, g6, g7, o6,
64
65 NumOfAllRegs, // Must be first AFTER registers...
Vikram S. Adve5462dca2001-10-22 13:43:08 +000066
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000067 //*** NOTE: If we decide to use some %g regs, they are volatile
68 // (see sparc64ABI)
69 // Move the %g regs from the end of the enumeration to just above the
70 // enumeration of %o0 (change StartOfAllRegs below)
71 // change isRegVloatile method below
72 // Also change IntRegNames above.
Chris Lattner56e91662002-08-12 21:25:05 +000073
74 // max # of colors reg coloring can allocate
75 NumOfAvailRegs = i6,
76
77 StartOfNonVolatileRegs = l0,
78 StartOfAllRegs = o0,
Anand Shuklabd2d0572003-07-20 15:39:30 +000079
80 ModifiedByCall = o7,
Chris Lattner5216cc52002-02-04 05:59:25 +000081 };
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000082
Vikram S. Adve8adb9942003-05-27 00:02:22 +000083 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000084};
85
Ruchira Sasankaf4c2ddd2002-01-07 21:03:42 +000086
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000087//-----------------------------------------------------------------------------
88// Float Register Class
89//-----------------------------------------------------------------------------
90
Brian Gaeke94e95d22004-02-25 18:44:15 +000091class SparcV9FloatRegClass : public TargetRegClassInfo {
Chris Lattner56e91662002-08-12 21:25:05 +000092 int findFloatColor(const LiveRange *LR, unsigned Start,
Vikram S. Adve536b1922003-07-25 21:12:15 +000093 unsigned End,
94 const std::vector<bool> &IsColorUsedArr) const;
Chris Lattner56e91662002-08-12 21:25:05 +000095public:
Brian Gaeke94e95d22004-02-25 18:44:15 +000096 SparcV9FloatRegClass(unsigned ID)
Chris Lattnerf9781b52002-12-29 03:13:05 +000097 : TargetRegClassInfo(ID, NumOfAvailRegs, NumOfAllRegs) {}
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000098
Vikram S. Adve536b1922003-07-25 21:12:15 +000099 // This method marks the registers used for a given register number.
100 // This marks a single register for Float regs, but the R,R+1 pair
101 // for double-precision registers.
102 //
103 virtual void markColorsUsed(unsigned RegInClass,
104 int UserRegType,
105 int RegTypeWanted,
106 std::vector<bool> &IsColorUsedArr) const;
107
108 // This method finds unused registers of the specified register type,
109 // using the given "used" flag array IsColorUsedArr. It checks a single
110 // entry in the array directly for float regs, and checks the pair [R,R+1]
111 // for double-precision registers
112 // It returns -1 if no unused color is found.
113 //
114 virtual int findUnusedColor(int RegTypeWanted,
115 const std::vector<bool> &IsColorUsedArr) const;
116
117 void colorIGNode(IGNode *Node,
118 const std::vector<bool> &IsColorUsedArr) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000119
Brian Gaeke94e95d22004-02-25 18:44:15 +0000120 // according to SparcV9 64 ABI, all %fp regs are volatile
Chris Lattner56e91662002-08-12 21:25:05 +0000121 inline bool isRegVolatile(int Reg) const { return true; }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000122
Chris Lattner56e91662002-08-12 21:25:05 +0000123 enum {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000124 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9,
125 f10, f11, f12, f13, f14, f15, f16, f17, f18, f19,
126 f20, f21, f22, f23, f24, f25, f26, f27, f28, f29,
127 f30, f31, f32, f33, f34, f35, f36, f37, f38, f39,
128 f40, f41, f42, f43, f44, f45, f46, f47, f48, f49,
129 f50, f51, f52, f53, f54, f55, f56, f57, f58, f59,
Chris Lattner56e91662002-08-12 21:25:05 +0000130 f60, f61, f62, f63,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000131
Chris Lattner56e91662002-08-12 21:25:05 +0000132 // there are 64 regs alltogether but only 32 regs can be allocated at
133 // a time.
134 //
135 NumOfAvailRegs = 32,
136 NumOfAllRegs = 64,
137
138 StartOfNonVolatileRegs = f32,
139 StartOfAllRegs = f0,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000140 };
141
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000142 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000143};
144
145
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000146//-----------------------------------------------------------------------------
147// Int CC Register Class
Ruchira Sasanka9d8950d2001-11-03 19:59:59 +0000148// Only one integer cc register is available. However, this register is
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000149// referred to as %xcc or %icc when instructions like subcc are executed but
150// referred to as %ccr (i.e., %xcc . %icc") when this register is moved
151// into an integer register using RD or WR instrcutions. So, three ids are
152// allocated for the three names.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000153//-----------------------------------------------------------------------------
154
Brian Gaeke94e95d22004-02-25 18:44:15 +0000155struct SparcV9IntCCRegClass : public TargetRegClassInfo {
156 SparcV9IntCCRegClass(unsigned ID)
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000157 : TargetRegClassInfo(ID, 1, 3) { }
Vikram S. Advee9327f02002-05-19 15:25:51 +0000158
Vikram S. Adve536b1922003-07-25 21:12:15 +0000159 void colorIGNode(IGNode *Node,
160 const std::vector<bool> &IsColorUsedArr) const;
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000161
Brian Gaeke85cb7772004-04-19 18:53:42 +0000162 // according to the 64-bit SparcV9 ABI, all integer CC regs are
163 // volatile.
Chris Lattner5216cc52002-02-04 05:59:25 +0000164 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000165
166 enum {
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000167 xcc, icc, ccr // only one is available - see the note above
Chris Lattner56e91662002-08-12 21:25:05 +0000168 };
169
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000170 const char * const getRegName(unsigned reg) const;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000171};
172
173
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000174//-----------------------------------------------------------------------------
175// Float CC Register Class
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000176// Only 4 Float CC registers are available for allocation.
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000177//-----------------------------------------------------------------------------
178
Brian Gaeke94e95d22004-02-25 18:44:15 +0000179struct SparcV9FloatCCRegClass : public TargetRegClassInfo {
180 SparcV9FloatCCRegClass(unsigned ID)
Brian Gaeke85cb7772004-04-19 18:53:42 +0000181 : TargetRegClassInfo(ID, 4, 4) { }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000182
Vikram S. Adve536b1922003-07-25 21:12:15 +0000183 void colorIGNode(IGNode *Node,
Chris Lattner33238292003-09-01 19:56:48 +0000184 const std::vector<bool> &IsColorUsedArr) const;
Vikram S. Advee9327f02002-05-19 15:25:51 +0000185
Brian Gaeke85cb7772004-04-19 18:53:42 +0000186 // according to the 64-bit SparcV9 ABI, all floating-point CC regs are
187 // volatile.
Chris Lattner5216cc52002-02-04 05:59:25 +0000188 inline bool isRegVolatile(int Reg) const { return true; }
Chris Lattner56e91662002-08-12 21:25:05 +0000189
190 enum {
Brian Gaeke85cb7772004-04-19 18:53:42 +0000191 fcc0, fcc1, fcc2, fcc3
192 };
193
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000194 const char * const getRegName(unsigned reg) const;
195};
196
Brian Gaeke85cb7772004-04-19 18:53:42 +0000197
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000198//-----------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000199// SparcV9 special register class. These registers are not used for allocation
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000200// but are used as arguments of some instructions.
201//-----------------------------------------------------------------------------
202
Brian Gaeke94e95d22004-02-25 18:44:15 +0000203struct SparcV9SpecialRegClass : public TargetRegClassInfo {
204 SparcV9SpecialRegClass(unsigned ID)
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000205 : 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 {
Brian Gaeke94e95d22004-02-25 18:44:15 +0000209 assert(0 && "SparcV9SpecialRegClass should never be used for allocation");
Vikram S. Adve8adb9942003-05-27 00:02:22 +0000210 }
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