blob: 564e59cd70ec1d52238f0bd3eab1070c234b16ab [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
Chris Lattner699683c2002-02-04 05:59:25 +000014#include "SparcRegClassInfo.h"
Vikram S. Adve7dc7de52003-07-25 21:12:15 +000015#include "SparcInternals.h"
Chris Lattner37730942002-02-05 03:52:29 +000016#include "llvm/Type.h"
Chris Lattner0e104332003-01-15 19:50:44 +000017#include "../../CodeGen/RegAlloc/RegAllocCommon.h" // FIXME!
Chris Lattnerbcc6dec2003-09-01 20:00:08 +000018#include "../../CodeGen/RegAlloc/IGNode.h" // FIXME!
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000019
Brian Gaeked0fde302003-11-11 22:41:34 +000020namespace llvm {
21
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000022//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +000023// Int Register Class - method for coloring a node in the interference graph.
24//
25// Algorithm:
26// Record the colors/suggested colors of all neighbors.
27//
28// If there is a suggested color, try to allocate it
29// If there is no call interf, try to allocate volatile, then non volatile
30// If there is call interf, try to allocate non-volatile. If that fails
31// try to allocate a volatile and insert save across calls
32// If both above fail, spill.
33//
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000034//-----------------------------------------------------------------------------
Misha Brukmanee563cb2003-05-21 17:59:06 +000035void SparcIntRegClass::colorIGNode(IGNode * Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +000036 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +000037{
Chris Lattner699683c2002-02-04 05:59:25 +000038 LiveRange *LR = Node->getParentLR();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000039
Misha Brukman77c9fcb2003-05-21 18:05:35 +000040 if (DEBUG_RA) {
Misha Brukmanee563cb2003-05-21 17:59:06 +000041 std::cerr << "\nColoring LR [CallInt=" << LR->isCallInterference() <<"]:";
Chris Lattner296b7732002-02-05 02:52:05 +000042 printSet(*LR);
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000043 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000044
Misha Brukman77c9fcb2003-05-21 18:05:35 +000045 if (LR->hasSuggestedColor()) {
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000046 unsigned SugCol = LR->getSuggestedColor();
Chris Lattner85c54652002-05-23 15:50:03 +000047 if (!IsColorUsedArr[SugCol]) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +000048 if (LR->isSuggestedColorUsable()) {
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000049 // if the suggested color is volatile, we should use it only if
50 // there are no call interferences. Otherwise, it will get spilled.
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000051 if (DEBUG_RA)
Misha Brukmanee563cb2003-05-21 17:59:06 +000052 std::cerr << "\n -Coloring with sug color: " << SugCol;
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000053
Misha Brukman77c9fcb2003-05-21 18:05:35 +000054 LR->setColor(LR->getSuggestedColor());
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000055 return;
Misha Brukman77c9fcb2003-05-21 18:05:35 +000056 } else if(DEBUG_RA) {
Misha Brukmanc97a2072003-05-21 19:34:28 +000057 std::cerr << "\n Couldn't alloc Sug col - LR volatile & calls interf";
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000058 }
Misha Brukman77c9fcb2003-05-21 18:05:35 +000059 } else if (DEBUG_RA) { // can't allocate the suggested col
Misha Brukmanee563cb2003-05-21 17:59:06 +000060 std::cerr << "\n Could NOT allocate the suggested color (already used) ";
61 printSet(*LR); std::cerr << "\n";
Ruchira Sasanka91442282001-09-30 23:16:47 +000062 }
63 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000064
65 unsigned SearchStart; // start pos of color in pref-order
66 bool ColorFound= false; // have we found a color yet?
67
68 //if this Node is between calls
Misha Brukman77c9fcb2003-05-21 18:05:35 +000069 if (! LR->isCallInterference()) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000070 // start with volatiles (we can allocate volatiles safely)
Chris Lattner95685682002-08-12 21:25:05 +000071 SearchStart = SparcIntRegClass::StartOfAllRegs;
Misha Brukman77c9fcb2003-05-21 18:05:35 +000072 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000073 // start with non volatiles (no non-volatiles)
Chris Lattner95685682002-08-12 21:25:05 +000074 SearchStart = SparcIntRegClass::StartOfNonVolatileRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000075 }
76
77 unsigned c=0; // color
78
79 // find first unused color
Misha Brukman77c9fcb2003-05-21 18:05:35 +000080 for (c=SearchStart; c < SparcIntRegClass::NumOfAvailRegs; c++) {
81 if (!IsColorUsedArr[c]) {
82 ColorFound = true;
83 break;
84 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000085 }
86
Misha Brukman77c9fcb2003-05-21 18:05:35 +000087 if (ColorFound) {
Misha Brukman452db672003-09-23 17:28:11 +000088 LR->setColor(c); // first color found in preferred order
Misha Brukmanee563cb2003-05-21 17:59:06 +000089 if (DEBUG_RA) std::cerr << "\n Colored after first search with col " << c;
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000090 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000091
92 // if color is not found because of call interference
93 // try even finding a volatile color and insert save across calls
Ruchira Sasankad00982a2002-01-07 19:20:28 +000094 //
Misha Brukman77c9fcb2003-05-21 18:05:35 +000095 else if (LR->isCallInterference()) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000096 // start from 0 - try to find even a volatile this time
Chris Lattner95685682002-08-12 21:25:05 +000097 SearchStart = SparcIntRegClass::StartOfAllRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000098
99 // find first unused volatile color
Chris Lattner95685682002-08-12 21:25:05 +0000100 for(c=SearchStart; c < SparcIntRegClass::StartOfNonVolatileRegs; c++) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000101 if (! IsColorUsedArr[c]) {
102 ColorFound = true;
103 break;
104 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000105 }
106
Chris Lattner699683c2002-02-04 05:59:25 +0000107 if (ColorFound) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000108 LR->setColor(c);
109 // get the live range corresponding to live var
110 // since LR span across calls, must save across calls
111 //
112 LR->markForSaveAcrossCalls();
113 if (DEBUG_RA)
114 std::cerr << "\n Colored after SECOND search with col " << c;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000115 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000116 }
117
Ruchira Sasanka91442282001-09-30 23:16:47 +0000118
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000119 // If we couldn't find a color regardless of call interference - i.e., we
120 // don't have either a volatile or non-volatile color left
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000121 //
Chris Lattner699683c2002-02-04 05:59:25 +0000122 if (!ColorFound)
Ruchira Sasanka91442282001-09-30 23:16:47 +0000123 LR->markForSpill(); // no color found - must spill
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000124}
125
Vikram S. Adve786833a2003-07-06 20:13:59 +0000126//-----------------------------------------------------------------------------
127// Int CC Register Class - method for coloring a node in the interference graph.
128//
129// Algorithm:
130//
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000131// If (node has any interferences)
132// /* all interference operations can use only one register! */
Vikram S. Adve786833a2003-07-06 20:13:59 +0000133// mark the LR for spilling
134// else {
135// if (the LR is a 64-bit comparison) use %xcc
136// else /*32-bit or smaller*/ use %icc
137// }
138//
139// Note: The third name (%ccr) is essentially an assembly mnemonic and
140// depends solely on the opcode, so the name can be chosen in EmitAssembly.
141//-----------------------------------------------------------------------------
142void SparcIntCCRegClass::colorIGNode(IGNode *Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000143 const std::vector<bool> &IsColorUsedArr) const
Vikram S. Adve786833a2003-07-06 20:13:59 +0000144{
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000145 if (Node->getNumOfNeighbors() > 0)
Vikram S. Adve786833a2003-07-06 20:13:59 +0000146 Node->getParentLR()->markForSpill();
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000147
148 // Mark the appropriate register in any case (even if it needs to be spilled)
149 // because there is only one possible register, but more importantly, the
150 // spill algorithm cannot find it. In particular, we have to choose
151 // whether to use %xcc or %icc based on type of value compared
152 //
153 const LiveRange* ccLR = Node->getParentLR();
154 const Type* setCCType = (* ccLR->begin())->getType(); // any Value in LR
155 assert(setCCType->isIntegral() || isa<PointerType>(setCCType));
156 int ccReg = ((isa<PointerType>(setCCType) || setCCType == Type::LongTy)
157 ? xcc : icc);
Vikram S. Adve786833a2003-07-06 20:13:59 +0000158
159#ifndef NDEBUG
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000160 // Let's just make sure values of two different types have not been
161 // coalesced into this LR.
162 for (ValueSet::const_iterator I=ccLR->begin(), E=ccLR->end(); I!=E; ++I) {
163 const Type* ccType = (*I)->getType();
164 assert((ccReg == xcc && (isa<PointerType>(ccType)
165 || ccType == Type::LongTy)) ||
166 (ccReg == icc && ccType->isIntegral() && ccType != Type::LongTy)
167 && "Comparisons needing different intCC regs coalesced in LR!");
168 }
Vikram S. Adve786833a2003-07-06 20:13:59 +0000169#endif
170
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000171 Node->setColor(ccReg); // only one int cc reg is available
Vikram S. Adve786833a2003-07-06 20:13:59 +0000172}
173
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000174
Chris Lattner87d50f02003-09-01 19:56:48 +0000175void SparcFloatCCRegClass::colorIGNode(IGNode *Node,
176 const std::vector<bool> &IsColorUsedArr) const {
177 for(unsigned c = 0; c != 4; ++c)
178 if (!IsColorUsedArr[c]) { // find unused color
179 Node->setColor(c);
180 return;
181 }
182
183 Node->getParentLR()->markForSpill();
184}
185
186
187
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000188//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000189// Float Register Class - method for coloring a node in the interference graph.
190//
191// Algorithm:
192//
193// If the LR is a double try to allocate f32 - f63
194// If the above fails or LR is single precision
195// If the LR does not interfere with a call
196// start allocating from f0
197// Else start allocating from f6
198// If a color is still not found because LR interferes with a call
199// Search in f0 - f6. If found mark for spill across calls.
200// If a color is still not fond, mark for spilling
201//
202//----------------------------------------------------------------------------
Chris Lattner85c54652002-05-23 15:50:03 +0000203void SparcFloatRegClass::colorIGNode(IGNode * Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000204 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +0000205{
Chris Lattner37730942002-02-05 03:52:29 +0000206 LiveRange *LR = Node->getParentLR();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000207
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000208#ifndef NDEBUG
209 // Check that the correct colors have been are marked for fp-doubles.
210 //
211 // FIXME: This is old code that is no longer needed. Temporarily converting
212 // it into a big assertion just to check that the replacement logic
213 // (invoking SparcFloatRegClass::markColorsUsed() directly from
214 // RegClass::colorIGNode) works correctly.
215 //
216 // In fact, this entire function should be identical to
217 // SparcIntRegClass::colorIGNode(), and perhaps can be
218 // made into a general case in CodeGen/RegAlloc/RegClass.cpp.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000219 //
220 unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000221 for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh
222 IGNode *NeighIGNode = Node->getAdjIGNode(n);
Ruchira Sasanka91442282001-09-30 23:16:47 +0000223 LiveRange *NeighLR = NeighIGNode->getParentLR();
Vikram S. Adve242a8082002-05-19 15:25:51 +0000224
Vikram S. Adve4d436c12003-09-21 07:55:27 +0000225 if (NeighLR->hasColor()) {
226 assert(IsColorUsedArr[ NeighLR->getColor() ]);
227 if (NeighLR->getType() == Type::DoubleTy)
228 assert(IsColorUsedArr[ NeighLR->getColor()+1 ]);
Vikram S. Adve242a8082002-05-19 15:25:51 +0000229
230 } else if (NeighLR->hasSuggestedColor() &&
231 NeighLR-> isSuggestedColorUsable() ) {
Ruchira Sasanka91442282001-09-30 23:16:47 +0000232
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000233 // if the neighbour can use the suggested color
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000234 assert(IsColorUsedArr[ NeighLR->getSuggestedColor() ]);
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000235 if (NeighLR->getType() == Type::DoubleTy)
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000236 assert(IsColorUsedArr[ NeighLR->getSuggestedColor()+1 ]);
Vikram S. Adve242a8082002-05-19 15:25:51 +0000237 }
Ruchira Sasanka91442282001-09-30 23:16:47 +0000238 }
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000239#endif
Ruchira Sasanka91442282001-09-30 23:16:47 +0000240
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +0000241 // **NOTE: We don't check for call interferences in allocating suggested
242 // color in this class since ALL registers are volatile. If this fact
243 // changes, we should change the following part
244 //- see SparcIntRegClass::colorIGNode()
Vikram S. Adve242a8082002-05-19 15:25:51 +0000245 //
Ruchira Sasanka91442282001-09-30 23:16:47 +0000246 if( LR->hasSuggestedColor() ) {
247 if( ! IsColorUsedArr[ LR->getSuggestedColor() ] ) {
248 LR->setColor( LR->getSuggestedColor() );
249 return;
Chris Lattner296b7732002-02-05 02:52:05 +0000250 } else if (DEBUG_RA) { // can't allocate the suggested col
Misha Brukmanee563cb2003-05-21 17:59:06 +0000251 std::cerr << " Could NOT allocate the suggested color for LR ";
252 printSet(*LR); std::cerr << "\n";
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000253 }
254 }
255
Ruchira Sasanka91442282001-09-30 23:16:47 +0000256
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000257 int ColorFound = -1; // have we found a color yet?
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +0000258 bool isCallInterf = LR->isCallInterference();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000259
Chris Lattner85c54652002-05-23 15:50:03 +0000260 // if value is a double - search the double only region (f32 - f63)
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000261 // i.e. we try to allocate f32 - f63 first for doubles since singles
262 // cannot go there. By doing that, we provide more space for singles
263 // in f0 - f31
264 //
Chris Lattner37730942002-02-05 03:52:29 +0000265 if (LR->getType() == Type::DoubleTy)
Ruchira Sasanka91442282001-09-30 23:16:47 +0000266 ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr );
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000267
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000268 if (ColorFound >= 0) { // if we could find a color
Ruchira Sasanka91442282001-09-30 23:16:47 +0000269 LR->setColor(ColorFound);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000270 return;
Chris Lattner699683c2002-02-04 05:59:25 +0000271 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000272
Misha Brukmancf00c4a2003-10-10 17:57:28 +0000273 // if we didn't find a color because the LR was single precision or
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000274 // all f32-f63 range is filled, we try to allocate a register from
275 // the f0 - f31 region
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000276
277 unsigned SearchStart; // start pos of color in pref-order
278
279 //if this Node is between calls (i.e., no call interferences )
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000280 if (! isCallInterf) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000281 // start with volatiles (we can allocate volatiles safely)
Chris Lattner95685682002-08-12 21:25:05 +0000282 SearchStart = SparcFloatRegClass::StartOfAllRegs;
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000283 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000284 // start with non volatiles (no non-volatiles)
Chris Lattner95685682002-08-12 21:25:05 +0000285 SearchStart = SparcFloatRegClass::StartOfNonVolatileRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000286 }
287
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000288 ColorFound = findFloatColor(LR, SearchStart, 32, IsColorUsedArr);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000289 }
290
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000291 if (ColorFound >= 0) { // if we could find a color
Ruchira Sasanka91442282001-09-30 23:16:47 +0000292 LR->setColor(ColorFound);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000293 return;
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000294 } else if (isCallInterf) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000295 // We are here because there is a call interference and no non-volatile
296 // color could be found.
297 // Now try to allocate even a volatile color
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000298 ColorFound = findFloatColor(LR, SparcFloatRegClass::StartOfAllRegs,
Chris Lattner95685682002-08-12 21:25:05 +0000299 SparcFloatRegClass::StartOfNonVolatileRegs,
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000300 IsColorUsedArr);
301 }
302
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000303 if (ColorFound >= 0) {
Misha Brukmancf00c4a2003-10-10 17:57:28 +0000304 LR->setColor(ColorFound); // first color found in preferred order
Ruchira Sasanka91442282001-09-30 23:16:47 +0000305 LR->markForSaveAcrossCalls();
Chris Lattner699683c2002-02-04 05:59:25 +0000306 } else {
307 // we are here because no color could be found
308 LR->markForSpill(); // no color found - must spill
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000309 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000310}
311
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000312//-----------------------------------------------------------------------------
313// This method marks the registers used for a given register number.
314// This marks a single register for Float regs, but the R,R+1 pair
315// for double-precision registers.
316//-----------------------------------------------------------------------------
317
318void SparcFloatRegClass::markColorsUsed(unsigned RegInClass,
319 int UserRegType,
320 int RegTypeWanted,
321 std::vector<bool> &IsColorUsedArr) const
322{
323 if (UserRegType == UltraSparcRegInfo::FPDoubleRegType ||
324 RegTypeWanted == UltraSparcRegInfo::FPDoubleRegType) {
325 // This register is used as or is needed as a double-precision reg.
326 // We need to mark the [even,odd] pair corresponding to this reg.
327 // Get the even numbered register corresponding to this reg.
328 unsigned EvenRegInClass = RegInClass & ~1u;
329 assert(EvenRegInClass+1 < NumOfAllRegs &&
330 EvenRegInClass+1 < IsColorUsedArr.size());
331 IsColorUsedArr[EvenRegInClass] = true;
332 IsColorUsedArr[EvenRegInClass+1] = true;
333 }
334 else {
335 assert(RegInClass < NumOfAllRegs && RegInClass < IsColorUsedArr.size());
336 assert(UserRegType == RegTypeWanted
337 && "Something other than FP single/double types share a reg class?");
338 IsColorUsedArr[RegInClass] = true;
339 }
340}
341
342// This method finds unused registers of the specified register type,
343// using the given "used" flag array IsColorUsedArr. It checks a single
344// entry in the array directly for float regs, and checks the pair [R,R+1]
345// for double-precision registers
346// It returns -1 if no unused color is found.
347//
348int SparcFloatRegClass::findUnusedColor(int RegTypeWanted,
349 const std::vector<bool> &IsColorUsedArr) const
350{
351 if (RegTypeWanted == UltraSparcRegInfo::FPDoubleRegType) {
352 unsigned NC = 2 * this->getNumOfAvailRegs();
353 assert(IsColorUsedArr.size() == NC && "Invalid colors-used array");
354 for (unsigned c = 0; c < NC; c+=2)
355 if (!IsColorUsedArr[c]) {
356 assert(!IsColorUsedArr[c+1] && "Incorrect used regs for FP double!");
357 return c;
358 }
359 return -1;
360 }
361 else
362 return TargetRegClassInfo::findUnusedColor(RegTypeWanted, IsColorUsedArr);
363}
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000364
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000365//-----------------------------------------------------------------------------
366// Helper method for coloring a node of Float Reg class.
367// Finds the first available color in the range [Start,End] depending on the
368// type of the Node (i.e., float/double)
369//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000370
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000371int SparcFloatRegClass::findFloatColor(const LiveRange *LR,
372 unsigned Start,
373 unsigned End,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000374 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +0000375{
Chris Lattner37730942002-02-05 03:52:29 +0000376 if (LR->getType() == Type::DoubleTy) {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000377 // find first unused color for a double
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000378 assert(Start % 2 == 0 && "Odd register number could be used for double!");
379 for (unsigned c=Start; c < End ; c+= 2)
380 if (!IsColorUsedArr[c]) {
381 assert(!IsColorUsedArr[c+1] &&
382 "Incorrect marking of used regs for Sparc FP double!");
Chris Lattner699683c2002-02-04 05:59:25 +0000383 return c;
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000384 }
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000385 } else {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000386 // find first unused color for a single
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000387 for (unsigned c = Start; c < End; c++)
Chris Lattner699683c2002-02-04 05:59:25 +0000388 if (!IsColorUsedArr[c])
389 return c;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000390 }
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000391
Chris Lattner699683c2002-02-04 05:59:25 +0000392 return -1;
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000393
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000394}
Brian Gaeked0fde302003-11-11 22:41:34 +0000395
396} // End llvm namespace