blob: c6d559abdb930f7d4fc3201105e50d850967da16 [file] [log] [blame]
Chris Lattner95685682002-08-12 21:25:05 +00001//===-- SparcRegClassInfo.cpp - Register class def'ns for Sparc -----------===//
John Criswellb576c942003-10-20 19:43:21 +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 Lattner95685682002-08-12 21:25:05 +00009//
10// This file defines the register classes used by the Sparc target description.
11//
12//===----------------------------------------------------------------------===//
13
Misha Brukmand71295a2003-12-17 22:04:00 +000014#include "llvm/Type.h"
Chris Lattner699683c2002-02-04 05:59:25 +000015#include "SparcRegClassInfo.h"
Vikram S. Adve7dc7de52003-07-25 21:12:15 +000016#include "SparcInternals.h"
Misha Brukmand71295a2003-12-17 22:04:00 +000017#include "SparcRegInfo.h"
Chris Lattner0e104332003-01-15 19:50:44 +000018#include "../../CodeGen/RegAlloc/RegAllocCommon.h" // FIXME!
Chris Lattnerbcc6dec2003-09-01 20:00:08 +000019#include "../../CodeGen/RegAlloc/IGNode.h" // FIXME!
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000020
Brian Gaeked0fde302003-11-11 22:41:34 +000021namespace llvm {
22
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000023//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +000024// Int Register Class - method for coloring a node in the interference graph.
25//
26// Algorithm:
27// Record the colors/suggested colors of all neighbors.
28//
29// If there is a suggested color, try to allocate it
30// If there is no call interf, try to allocate volatile, then non volatile
31// If there is call interf, try to allocate non-volatile. If that fails
32// try to allocate a volatile and insert save across calls
33// If both above fail, spill.
34//
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000035//-----------------------------------------------------------------------------
Misha Brukmanee563cb2003-05-21 17:59:06 +000036void SparcIntRegClass::colorIGNode(IGNode * Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +000037 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +000038{
Chris Lattner699683c2002-02-04 05:59:25 +000039 LiveRange *LR = Node->getParentLR();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000040
Misha Brukman77c9fcb2003-05-21 18:05:35 +000041 if (DEBUG_RA) {
Misha Brukmanee563cb2003-05-21 17:59:06 +000042 std::cerr << "\nColoring LR [CallInt=" << LR->isCallInterference() <<"]:";
Chris Lattner296b7732002-02-05 02:52:05 +000043 printSet(*LR);
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000044 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000045
Misha Brukman77c9fcb2003-05-21 18:05:35 +000046 if (LR->hasSuggestedColor()) {
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000047 unsigned SugCol = LR->getSuggestedColor();
Chris Lattner85c54652002-05-23 15:50:03 +000048 if (!IsColorUsedArr[SugCol]) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +000049 if (LR->isSuggestedColorUsable()) {
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000050 // if the suggested color is volatile, we should use it only if
51 // there are no call interferences. Otherwise, it will get spilled.
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000052 if (DEBUG_RA)
Misha Brukmanee563cb2003-05-21 17:59:06 +000053 std::cerr << "\n -Coloring with sug color: " << SugCol;
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000054
Misha Brukman77c9fcb2003-05-21 18:05:35 +000055 LR->setColor(LR->getSuggestedColor());
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000056 return;
Misha Brukman77c9fcb2003-05-21 18:05:35 +000057 } else if(DEBUG_RA) {
Misha Brukmanc97a2072003-05-21 19:34:28 +000058 std::cerr << "\n Couldn't alloc Sug col - LR volatile & calls interf";
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000059 }
Misha Brukman77c9fcb2003-05-21 18:05:35 +000060 } else if (DEBUG_RA) { // can't allocate the suggested col
Misha Brukmanee563cb2003-05-21 17:59:06 +000061 std::cerr << "\n Could NOT allocate the suggested color (already used) ";
62 printSet(*LR); std::cerr << "\n";
Ruchira Sasanka91442282001-09-30 23:16:47 +000063 }
64 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000065
66 unsigned SearchStart; // start pos of color in pref-order
67 bool ColorFound= false; // have we found a color yet?
68
69 //if this Node is between calls
Misha Brukman77c9fcb2003-05-21 18:05:35 +000070 if (! LR->isCallInterference()) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000071 // start with volatiles (we can allocate volatiles safely)
Chris Lattner95685682002-08-12 21:25:05 +000072 SearchStart = SparcIntRegClass::StartOfAllRegs;
Misha Brukman77c9fcb2003-05-21 18:05:35 +000073 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000074 // start with non volatiles (no non-volatiles)
Chris Lattner95685682002-08-12 21:25:05 +000075 SearchStart = SparcIntRegClass::StartOfNonVolatileRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000076 }
77
78 unsigned c=0; // color
79
80 // find first unused color
Misha Brukman77c9fcb2003-05-21 18:05:35 +000081 for (c=SearchStart; c < SparcIntRegClass::NumOfAvailRegs; c++) {
82 if (!IsColorUsedArr[c]) {
83 ColorFound = true;
84 break;
85 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000086 }
87
Misha Brukman77c9fcb2003-05-21 18:05:35 +000088 if (ColorFound) {
Misha Brukman452db672003-09-23 17:28:11 +000089 LR->setColor(c); // first color found in preferred order
Misha Brukmanee563cb2003-05-21 17:59:06 +000090 if (DEBUG_RA) std::cerr << "\n Colored after first search with col " << c;
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000091 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000092
93 // if color is not found because of call interference
94 // try even finding a volatile color and insert save across calls
Ruchira Sasankad00982a2002-01-07 19:20:28 +000095 //
Misha Brukman77c9fcb2003-05-21 18:05:35 +000096 else if (LR->isCallInterference()) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000097 // start from 0 - try to find even a volatile this time
Chris Lattner95685682002-08-12 21:25:05 +000098 SearchStart = SparcIntRegClass::StartOfAllRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000099
100 // find first unused volatile color
Chris Lattner95685682002-08-12 21:25:05 +0000101 for(c=SearchStart; c < SparcIntRegClass::StartOfNonVolatileRegs; c++) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000102 if (! IsColorUsedArr[c]) {
103 ColorFound = true;
104 break;
105 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000106 }
107
Chris Lattner699683c2002-02-04 05:59:25 +0000108 if (ColorFound) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000109 LR->setColor(c);
110 // get the live range corresponding to live var
111 // since LR span across calls, must save across calls
112 //
113 LR->markForSaveAcrossCalls();
114 if (DEBUG_RA)
115 std::cerr << "\n Colored after SECOND search with col " << c;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000116 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000117 }
118
Ruchira Sasanka91442282001-09-30 23:16:47 +0000119
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000120 // If we couldn't find a color regardless of call interference - i.e., we
121 // don't have either a volatile or non-volatile color left
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000122 //
Chris Lattner699683c2002-02-04 05:59:25 +0000123 if (!ColorFound)
Ruchira Sasanka91442282001-09-30 23:16:47 +0000124 LR->markForSpill(); // no color found - must spill
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000125}
126
Vikram S. Adve786833a2003-07-06 20:13:59 +0000127//-----------------------------------------------------------------------------
128// Int CC Register Class - method for coloring a node in the interference graph.
129//
130// Algorithm:
131//
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000132// If (node has any interferences)
133// /* all interference operations can use only one register! */
Vikram S. Adve786833a2003-07-06 20:13:59 +0000134// mark the LR for spilling
135// else {
136// if (the LR is a 64-bit comparison) use %xcc
137// else /*32-bit or smaller*/ use %icc
138// }
139//
140// Note: The third name (%ccr) is essentially an assembly mnemonic and
141// depends solely on the opcode, so the name can be chosen in EmitAssembly.
142//-----------------------------------------------------------------------------
143void SparcIntCCRegClass::colorIGNode(IGNode *Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000144 const std::vector<bool> &IsColorUsedArr) const
Vikram S. Adve786833a2003-07-06 20:13:59 +0000145{
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000146 if (Node->getNumOfNeighbors() > 0)
Vikram S. Adve786833a2003-07-06 20:13:59 +0000147 Node->getParentLR()->markForSpill();
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000148
149 // Mark the appropriate register in any case (even if it needs to be spilled)
150 // because there is only one possible register, but more importantly, the
151 // spill algorithm cannot find it. In particular, we have to choose
152 // whether to use %xcc or %icc based on type of value compared
153 //
154 const LiveRange* ccLR = Node->getParentLR();
155 const Type* setCCType = (* ccLR->begin())->getType(); // any Value in LR
156 assert(setCCType->isIntegral() || isa<PointerType>(setCCType));
157 int ccReg = ((isa<PointerType>(setCCType) || setCCType == Type::LongTy)
158 ? xcc : icc);
Vikram S. Adve786833a2003-07-06 20:13:59 +0000159
160#ifndef NDEBUG
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000161 // Let's just make sure values of two different types have not been
162 // coalesced into this LR.
163 for (ValueSet::const_iterator I=ccLR->begin(), E=ccLR->end(); I!=E; ++I) {
164 const Type* ccType = (*I)->getType();
165 assert((ccReg == xcc && (isa<PointerType>(ccType)
166 || ccType == Type::LongTy)) ||
167 (ccReg == icc && ccType->isIntegral() && ccType != Type::LongTy)
168 && "Comparisons needing different intCC regs coalesced in LR!");
169 }
Vikram S. Adve786833a2003-07-06 20:13:59 +0000170#endif
171
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000172 Node->setColor(ccReg); // only one int cc reg is available
Vikram S. Adve786833a2003-07-06 20:13:59 +0000173}
174
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000175
Chris Lattner87d50f02003-09-01 19:56:48 +0000176void SparcFloatCCRegClass::colorIGNode(IGNode *Node,
177 const std::vector<bool> &IsColorUsedArr) const {
178 for(unsigned c = 0; c != 4; ++c)
179 if (!IsColorUsedArr[c]) { // find unused color
180 Node->setColor(c);
181 return;
182 }
183
184 Node->getParentLR()->markForSpill();
185}
186
187
188
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000189//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000190// Float Register Class - method for coloring a node in the interference graph.
191//
192// Algorithm:
193//
194// If the LR is a double try to allocate f32 - f63
195// If the above fails or LR is single precision
196// If the LR does not interfere with a call
197// start allocating from f0
198// Else start allocating from f6
199// If a color is still not found because LR interferes with a call
200// Search in f0 - f6. If found mark for spill across calls.
201// If a color is still not fond, mark for spilling
202//
203//----------------------------------------------------------------------------
Chris Lattner85c54652002-05-23 15:50:03 +0000204void SparcFloatRegClass::colorIGNode(IGNode * Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000205 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +0000206{
Chris Lattner37730942002-02-05 03:52:29 +0000207 LiveRange *LR = Node->getParentLR();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000208
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000209#ifndef NDEBUG
210 // Check that the correct colors have been are marked for fp-doubles.
211 //
212 // FIXME: This is old code that is no longer needed. Temporarily converting
213 // it into a big assertion just to check that the replacement logic
214 // (invoking SparcFloatRegClass::markColorsUsed() directly from
215 // RegClass::colorIGNode) works correctly.
216 //
217 // In fact, this entire function should be identical to
218 // SparcIntRegClass::colorIGNode(), and perhaps can be
219 // made into a general case in CodeGen/RegAlloc/RegClass.cpp.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000220 //
221 unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000222 for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh
223 IGNode *NeighIGNode = Node->getAdjIGNode(n);
Ruchira Sasanka91442282001-09-30 23:16:47 +0000224 LiveRange *NeighLR = NeighIGNode->getParentLR();
Vikram S. Adve242a8082002-05-19 15:25:51 +0000225
Vikram S. Adve4d436c12003-09-21 07:55:27 +0000226 if (NeighLR->hasColor()) {
227 assert(IsColorUsedArr[ NeighLR->getColor() ]);
228 if (NeighLR->getType() == Type::DoubleTy)
229 assert(IsColorUsedArr[ NeighLR->getColor()+1 ]);
Vikram S. Adve242a8082002-05-19 15:25:51 +0000230
231 } else if (NeighLR->hasSuggestedColor() &&
232 NeighLR-> isSuggestedColorUsable() ) {
Ruchira Sasanka91442282001-09-30 23:16:47 +0000233
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000234 // if the neighbour can use the suggested color
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000235 assert(IsColorUsedArr[ NeighLR->getSuggestedColor() ]);
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000236 if (NeighLR->getType() == Type::DoubleTy)
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000237 assert(IsColorUsedArr[ NeighLR->getSuggestedColor()+1 ]);
Vikram S. Adve242a8082002-05-19 15:25:51 +0000238 }
Ruchira Sasanka91442282001-09-30 23:16:47 +0000239 }
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000240#endif
Ruchira Sasanka91442282001-09-30 23:16:47 +0000241
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +0000242 // **NOTE: We don't check for call interferences in allocating suggested
243 // color in this class since ALL registers are volatile. If this fact
244 // changes, we should change the following part
245 //- see SparcIntRegClass::colorIGNode()
Vikram S. Adve242a8082002-05-19 15:25:51 +0000246 //
Ruchira Sasanka91442282001-09-30 23:16:47 +0000247 if( LR->hasSuggestedColor() ) {
248 if( ! IsColorUsedArr[ LR->getSuggestedColor() ] ) {
249 LR->setColor( LR->getSuggestedColor() );
250 return;
Chris Lattner296b7732002-02-05 02:52:05 +0000251 } else if (DEBUG_RA) { // can't allocate the suggested col
Misha Brukmanee563cb2003-05-21 17:59:06 +0000252 std::cerr << " Could NOT allocate the suggested color for LR ";
253 printSet(*LR); std::cerr << "\n";
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000254 }
255 }
256
Ruchira Sasanka91442282001-09-30 23:16:47 +0000257
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000258 int ColorFound = -1; // have we found a color yet?
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +0000259 bool isCallInterf = LR->isCallInterference();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000260
Chris Lattner85c54652002-05-23 15:50:03 +0000261 // if value is a double - search the double only region (f32 - f63)
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000262 // i.e. we try to allocate f32 - f63 first for doubles since singles
263 // cannot go there. By doing that, we provide more space for singles
264 // in f0 - f31
265 //
Chris Lattner37730942002-02-05 03:52:29 +0000266 if (LR->getType() == Type::DoubleTy)
Ruchira Sasanka91442282001-09-30 23:16:47 +0000267 ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr );
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000268
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000269 if (ColorFound >= 0) { // if we could find a color
Ruchira Sasanka91442282001-09-30 23:16:47 +0000270 LR->setColor(ColorFound);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000271 return;
Chris Lattner699683c2002-02-04 05:59:25 +0000272 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000273
Misha Brukmancf00c4a2003-10-10 17:57:28 +0000274 // if we didn't find a color because the LR was single precision or
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000275 // all f32-f63 range is filled, we try to allocate a register from
276 // the f0 - f31 region
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000277
278 unsigned SearchStart; // start pos of color in pref-order
279
280 //if this Node is between calls (i.e., no call interferences )
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000281 if (! isCallInterf) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000282 // start with volatiles (we can allocate volatiles safely)
Chris Lattner95685682002-08-12 21:25:05 +0000283 SearchStart = SparcFloatRegClass::StartOfAllRegs;
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000284 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000285 // start with non volatiles (no non-volatiles)
Chris Lattner95685682002-08-12 21:25:05 +0000286 SearchStart = SparcFloatRegClass::StartOfNonVolatileRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000287 }
288
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000289 ColorFound = findFloatColor(LR, SearchStart, 32, IsColorUsedArr);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000290 }
291
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000292 if (ColorFound >= 0) { // if we could find a color
Ruchira Sasanka91442282001-09-30 23:16:47 +0000293 LR->setColor(ColorFound);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000294 return;
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000295 } else if (isCallInterf) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000296 // We are here because there is a call interference and no non-volatile
297 // color could be found.
298 // Now try to allocate even a volatile color
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000299 ColorFound = findFloatColor(LR, SparcFloatRegClass::StartOfAllRegs,
Chris Lattner95685682002-08-12 21:25:05 +0000300 SparcFloatRegClass::StartOfNonVolatileRegs,
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000301 IsColorUsedArr);
302 }
303
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000304 if (ColorFound >= 0) {
Misha Brukmancf00c4a2003-10-10 17:57:28 +0000305 LR->setColor(ColorFound); // first color found in preferred order
Ruchira Sasanka91442282001-09-30 23:16:47 +0000306 LR->markForSaveAcrossCalls();
Chris Lattner699683c2002-02-04 05:59:25 +0000307 } else {
308 // we are here because no color could be found
309 LR->markForSpill(); // no color found - must spill
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000310 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000311}
312
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000313//-----------------------------------------------------------------------------
314// This method marks the registers used for a given register number.
315// This marks a single register for Float regs, but the R,R+1 pair
316// for double-precision registers.
317//-----------------------------------------------------------------------------
318
319void SparcFloatRegClass::markColorsUsed(unsigned RegInClass,
320 int UserRegType,
321 int RegTypeWanted,
322 std::vector<bool> &IsColorUsedArr) const
323{
Misha Brukmand71295a2003-12-17 22:04:00 +0000324 if (UserRegType == SparcRegInfo::FPDoubleRegType ||
325 RegTypeWanted == SparcRegInfo::FPDoubleRegType) {
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000326 // This register is used as or is needed as a double-precision reg.
327 // We need to mark the [even,odd] pair corresponding to this reg.
328 // Get the even numbered register corresponding to this reg.
329 unsigned EvenRegInClass = RegInClass & ~1u;
330 assert(EvenRegInClass+1 < NumOfAllRegs &&
331 EvenRegInClass+1 < IsColorUsedArr.size());
332 IsColorUsedArr[EvenRegInClass] = true;
333 IsColorUsedArr[EvenRegInClass+1] = true;
334 }
335 else {
336 assert(RegInClass < NumOfAllRegs && RegInClass < IsColorUsedArr.size());
337 assert(UserRegType == RegTypeWanted
338 && "Something other than FP single/double types share a reg class?");
339 IsColorUsedArr[RegInClass] = true;
340 }
341}
342
343// This method finds unused registers of the specified register type,
344// using the given "used" flag array IsColorUsedArr. It checks a single
345// entry in the array directly for float regs, and checks the pair [R,R+1]
346// for double-precision registers
347// It returns -1 if no unused color is found.
348//
349int SparcFloatRegClass::findUnusedColor(int RegTypeWanted,
350 const std::vector<bool> &IsColorUsedArr) const
351{
Misha Brukmand71295a2003-12-17 22:04:00 +0000352 if (RegTypeWanted == SparcRegInfo::FPDoubleRegType) {
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000353 unsigned NC = 2 * this->getNumOfAvailRegs();
354 assert(IsColorUsedArr.size() == NC && "Invalid colors-used array");
355 for (unsigned c = 0; c < NC; c+=2)
356 if (!IsColorUsedArr[c]) {
357 assert(!IsColorUsedArr[c+1] && "Incorrect used regs for FP double!");
358 return c;
359 }
360 return -1;
361 }
362 else
363 return TargetRegClassInfo::findUnusedColor(RegTypeWanted, IsColorUsedArr);
364}
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000365
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000366//-----------------------------------------------------------------------------
367// Helper method for coloring a node of Float Reg class.
368// Finds the first available color in the range [Start,End] depending on the
369// type of the Node (i.e., float/double)
370//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000371
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000372int SparcFloatRegClass::findFloatColor(const LiveRange *LR,
373 unsigned Start,
374 unsigned End,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000375 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +0000376{
Chris Lattner37730942002-02-05 03:52:29 +0000377 if (LR->getType() == Type::DoubleTy) {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000378 // find first unused color for a double
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000379 assert(Start % 2 == 0 && "Odd register number could be used for double!");
380 for (unsigned c=Start; c < End ; c+= 2)
381 if (!IsColorUsedArr[c]) {
382 assert(!IsColorUsedArr[c+1] &&
383 "Incorrect marking of used regs for Sparc FP double!");
Chris Lattner699683c2002-02-04 05:59:25 +0000384 return c;
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000385 }
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000386 } else {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000387 // find first unused color for a single
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000388 for (unsigned c = Start; c < End; c++)
Chris Lattner699683c2002-02-04 05:59:25 +0000389 if (!IsColorUsedArr[c])
390 return c;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000391 }
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000392
Chris Lattner699683c2002-02-04 05:59:25 +0000393 return -1;
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000394
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000395}
Brian Gaeked0fde302003-11-11 22:41:34 +0000396
397} // End llvm namespace