blob: c27c28b33f0fbd928d4beab266402e36d5482121 [file] [log] [blame]
Chris Lattner95685682002-08-12 21:25:05 +00001//===-- SparcRegClassInfo.cpp - Register class def'ns for Sparc -----------===//
2//
3// This file defines the register classes used by the Sparc target description.
4//
5//===----------------------------------------------------------------------===//
6
Chris Lattner699683c2002-02-04 05:59:25 +00007#include "SparcRegClassInfo.h"
Vikram S. Adve7dc7de52003-07-25 21:12:15 +00008#include "SparcInternals.h"
Chris Lattner37730942002-02-05 03:52:29 +00009#include "llvm/Type.h"
Chris Lattner0e104332003-01-15 19:50:44 +000010#include "../../CodeGen/RegAlloc/RegAllocCommon.h" // FIXME!
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000011
12//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +000013// Int Register Class - method for coloring a node in the interference graph.
14//
15// Algorithm:
16// Record the colors/suggested colors of all neighbors.
17//
18// If there is a suggested color, try to allocate it
19// If there is no call interf, try to allocate volatile, then non volatile
20// If there is call interf, try to allocate non-volatile. If that fails
21// try to allocate a volatile and insert save across calls
22// If both above fail, spill.
23//
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000024//-----------------------------------------------------------------------------
Misha Brukmanee563cb2003-05-21 17:59:06 +000025void SparcIntRegClass::colorIGNode(IGNode * Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +000026 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +000027{
Chris Lattner699683c2002-02-04 05:59:25 +000028 LiveRange *LR = Node->getParentLR();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000029
Misha Brukman77c9fcb2003-05-21 18:05:35 +000030 if (DEBUG_RA) {
Misha Brukmanee563cb2003-05-21 17:59:06 +000031 std::cerr << "\nColoring LR [CallInt=" << LR->isCallInterference() <<"]:";
Chris Lattner296b7732002-02-05 02:52:05 +000032 printSet(*LR);
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000033 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000034
Misha Brukman77c9fcb2003-05-21 18:05:35 +000035 if (LR->hasSuggestedColor()) {
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000036 unsigned SugCol = LR->getSuggestedColor();
Chris Lattner85c54652002-05-23 15:50:03 +000037 if (!IsColorUsedArr[SugCol]) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +000038 if (LR->isSuggestedColorUsable()) {
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000039 // if the suggested color is volatile, we should use it only if
40 // there are no call interferences. Otherwise, it will get spilled.
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000041 if (DEBUG_RA)
Misha Brukmanee563cb2003-05-21 17:59:06 +000042 std::cerr << "\n -Coloring with sug color: " << SugCol;
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000043
Misha Brukman77c9fcb2003-05-21 18:05:35 +000044 LR->setColor(LR->getSuggestedColor());
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000045 return;
Misha Brukman77c9fcb2003-05-21 18:05:35 +000046 } else if(DEBUG_RA) {
Misha Brukmanc97a2072003-05-21 19:34:28 +000047 std::cerr << "\n Couldn't alloc Sug col - LR volatile & calls interf";
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000048 }
Misha Brukman77c9fcb2003-05-21 18:05:35 +000049 } else if (DEBUG_RA) { // can't allocate the suggested col
Misha Brukmanee563cb2003-05-21 17:59:06 +000050 std::cerr << "\n Could NOT allocate the suggested color (already used) ";
51 printSet(*LR); std::cerr << "\n";
Ruchira Sasanka91442282001-09-30 23:16:47 +000052 }
53 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000054
55 unsigned SearchStart; // start pos of color in pref-order
56 bool ColorFound= false; // have we found a color yet?
57
58 //if this Node is between calls
Misha Brukman77c9fcb2003-05-21 18:05:35 +000059 if (! LR->isCallInterference()) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000060 // start with volatiles (we can allocate volatiles safely)
Chris Lattner95685682002-08-12 21:25:05 +000061 SearchStart = SparcIntRegClass::StartOfAllRegs;
Misha Brukman77c9fcb2003-05-21 18:05:35 +000062 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000063 // start with non volatiles (no non-volatiles)
Chris Lattner95685682002-08-12 21:25:05 +000064 SearchStart = SparcIntRegClass::StartOfNonVolatileRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000065 }
66
67 unsigned c=0; // color
68
69 // find first unused color
Misha Brukman77c9fcb2003-05-21 18:05:35 +000070 for (c=SearchStart; c < SparcIntRegClass::NumOfAvailRegs; c++) {
71 if (!IsColorUsedArr[c]) {
72 ColorFound = true;
73 break;
74 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000075 }
76
Misha Brukman77c9fcb2003-05-21 18:05:35 +000077 if (ColorFound) {
Ruchira Sasanka91442282001-09-30 23:16:47 +000078 LR->setColor(c); // first color found in preffered order
Misha Brukmanee563cb2003-05-21 17:59:06 +000079 if (DEBUG_RA) std::cerr << "\n Colored after first search with col " << c;
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000080 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000081
82 // if color is not found because of call interference
83 // try even finding a volatile color and insert save across calls
Ruchira Sasankad00982a2002-01-07 19:20:28 +000084 //
Misha Brukman77c9fcb2003-05-21 18:05:35 +000085 else if (LR->isCallInterference()) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000086 // start from 0 - try to find even a volatile this time
Chris Lattner95685682002-08-12 21:25:05 +000087 SearchStart = SparcIntRegClass::StartOfAllRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000088
89 // find first unused volatile color
Chris Lattner95685682002-08-12 21:25:05 +000090 for(c=SearchStart; c < SparcIntRegClass::StartOfNonVolatileRegs; c++) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +000091 if (! IsColorUsedArr[c]) {
92 ColorFound = true;
93 break;
94 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000095 }
96
Chris Lattner699683c2002-02-04 05:59:25 +000097 if (ColorFound) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +000098 LR->setColor(c);
99 // get the live range corresponding to live var
100 // since LR span across calls, must save across calls
101 //
102 LR->markForSaveAcrossCalls();
103 if (DEBUG_RA)
104 std::cerr << "\n Colored after SECOND search with col " << c;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000105 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000106 }
107
Ruchira Sasanka91442282001-09-30 23:16:47 +0000108
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000109 // If we couldn't find a color regardless of call interference - i.e., we
110 // don't have either a volatile or non-volatile color left
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000111 //
Chris Lattner699683c2002-02-04 05:59:25 +0000112 if (!ColorFound)
Ruchira Sasanka91442282001-09-30 23:16:47 +0000113 LR->markForSpill(); // no color found - must spill
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000114}
115
Vikram S. Adve786833a2003-07-06 20:13:59 +0000116//-----------------------------------------------------------------------------
117// Int CC Register Class - method for coloring a node in the interference graph.
118//
119// Algorithm:
120//
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000121// If (node has any interferences)
122// /* all interference operations can use only one register! */
Vikram S. Adve786833a2003-07-06 20:13:59 +0000123// mark the LR for spilling
124// else {
125// if (the LR is a 64-bit comparison) use %xcc
126// else /*32-bit or smaller*/ use %icc
127// }
128//
129// Note: The third name (%ccr) is essentially an assembly mnemonic and
130// depends solely on the opcode, so the name can be chosen in EmitAssembly.
131//-----------------------------------------------------------------------------
132void SparcIntCCRegClass::colorIGNode(IGNode *Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000133 const std::vector<bool> &IsColorUsedArr) const
Vikram S. Adve786833a2003-07-06 20:13:59 +0000134{
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000135 if (Node->getNumOfNeighbors() > 0)
Vikram S. Adve786833a2003-07-06 20:13:59 +0000136 Node->getParentLR()->markForSpill();
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000137
138 // Mark the appropriate register in any case (even if it needs to be spilled)
139 // because there is only one possible register, but more importantly, the
140 // spill algorithm cannot find it. In particular, we have to choose
141 // whether to use %xcc or %icc based on type of value compared
142 //
143 const LiveRange* ccLR = Node->getParentLR();
144 const Type* setCCType = (* ccLR->begin())->getType(); // any Value in LR
145 assert(setCCType->isIntegral() || isa<PointerType>(setCCType));
146 int ccReg = ((isa<PointerType>(setCCType) || setCCType == Type::LongTy)
147 ? xcc : icc);
Vikram S. Adve786833a2003-07-06 20:13:59 +0000148
149#ifndef NDEBUG
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000150 // Let's just make sure values of two different types have not been
151 // coalesced into this LR.
152 for (ValueSet::const_iterator I=ccLR->begin(), E=ccLR->end(); I!=E; ++I) {
153 const Type* ccType = (*I)->getType();
154 assert((ccReg == xcc && (isa<PointerType>(ccType)
155 || ccType == Type::LongTy)) ||
156 (ccReg == icc && ccType->isIntegral() && ccType != Type::LongTy)
157 && "Comparisons needing different intCC regs coalesced in LR!");
158 }
Vikram S. Adve786833a2003-07-06 20:13:59 +0000159#endif
160
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000161 Node->setColor(ccReg); // only one int cc reg is available
Vikram S. Adve786833a2003-07-06 20:13:59 +0000162}
163
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000164
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000165//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000166// Float Register Class - method for coloring a node in the interference graph.
167//
168// Algorithm:
169//
170// If the LR is a double try to allocate f32 - f63
171// If the above fails or LR is single precision
172// If the LR does not interfere with a call
173// start allocating from f0
174// Else start allocating from f6
175// If a color is still not found because LR interferes with a call
176// Search in f0 - f6. If found mark for spill across calls.
177// If a color is still not fond, mark for spilling
178//
179//----------------------------------------------------------------------------
Chris Lattner85c54652002-05-23 15:50:03 +0000180void SparcFloatRegClass::colorIGNode(IGNode * Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000181 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +0000182{
Chris Lattner37730942002-02-05 03:52:29 +0000183 LiveRange *LR = Node->getParentLR();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000184
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000185#ifndef NDEBUG
186 // Check that the correct colors have been are marked for fp-doubles.
187 //
188 // FIXME: This is old code that is no longer needed. Temporarily converting
189 // it into a big assertion just to check that the replacement logic
190 // (invoking SparcFloatRegClass::markColorsUsed() directly from
191 // RegClass::colorIGNode) works correctly.
192 //
193 // In fact, this entire function should be identical to
194 // SparcIntRegClass::colorIGNode(), and perhaps can be
195 // made into a general case in CodeGen/RegAlloc/RegClass.cpp.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000196 //
197 unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000198 for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh
199 IGNode *NeighIGNode = Node->getAdjIGNode(n);
Ruchira Sasanka91442282001-09-30 23:16:47 +0000200 LiveRange *NeighLR = NeighIGNode->getParentLR();
Vikram S. Adve242a8082002-05-19 15:25:51 +0000201
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000202 if (NeighLR->hasColor() &&
Vikram S. Adve242a8082002-05-19 15:25:51 +0000203 NeighLR->getType() == Type::DoubleTy) {
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000204 assert(IsColorUsedArr[ NeighLR->getColor() ] &&
205 IsColorUsedArr[ NeighLR->getColor()+1 ]);
Vikram S. Adve242a8082002-05-19 15:25:51 +0000206
207 } else if (NeighLR->hasSuggestedColor() &&
208 NeighLR-> isSuggestedColorUsable() ) {
Ruchira Sasanka91442282001-09-30 23:16:47 +0000209
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000210 // if the neighbour can use the suggested color
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000211 assert(IsColorUsedArr[ NeighLR->getSuggestedColor() ]);
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000212 if (NeighLR->getType() == Type::DoubleTy)
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000213 assert(IsColorUsedArr[ NeighLR->getSuggestedColor()+1 ]);
Vikram S. Adve242a8082002-05-19 15:25:51 +0000214 }
Ruchira Sasanka91442282001-09-30 23:16:47 +0000215 }
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000216#endif
Ruchira Sasanka91442282001-09-30 23:16:47 +0000217
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +0000218 // **NOTE: We don't check for call interferences in allocating suggested
219 // color in this class since ALL registers are volatile. If this fact
220 // changes, we should change the following part
221 //- see SparcIntRegClass::colorIGNode()
Vikram S. Adve242a8082002-05-19 15:25:51 +0000222 //
Ruchira Sasanka91442282001-09-30 23:16:47 +0000223 if( LR->hasSuggestedColor() ) {
224 if( ! IsColorUsedArr[ LR->getSuggestedColor() ] ) {
225 LR->setColor( LR->getSuggestedColor() );
226 return;
Chris Lattner296b7732002-02-05 02:52:05 +0000227 } else if (DEBUG_RA) { // can't allocate the suggested col
Misha Brukmanee563cb2003-05-21 17:59:06 +0000228 std::cerr << " Could NOT allocate the suggested color for LR ";
229 printSet(*LR); std::cerr << "\n";
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000230 }
231 }
232
Ruchira Sasanka91442282001-09-30 23:16:47 +0000233
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000234 int ColorFound = -1; // have we found a color yet?
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +0000235 bool isCallInterf = LR->isCallInterference();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000236
Chris Lattner85c54652002-05-23 15:50:03 +0000237 // if value is a double - search the double only region (f32 - f63)
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000238 // i.e. we try to allocate f32 - f63 first for doubles since singles
239 // cannot go there. By doing that, we provide more space for singles
240 // in f0 - f31
241 //
Chris Lattner37730942002-02-05 03:52:29 +0000242 if (LR->getType() == Type::DoubleTy)
Ruchira Sasanka91442282001-09-30 23:16:47 +0000243 ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr );
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000244
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000245 if (ColorFound >= 0) { // if we could find a color
Ruchira Sasanka91442282001-09-30 23:16:47 +0000246 LR->setColor(ColorFound);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000247 return;
Chris Lattner699683c2002-02-04 05:59:25 +0000248 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000249
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000250 // if we didn't find a color becuase the LR was single precision or
251 // all f32-f63 range is filled, we try to allocate a register from
252 // the f0 - f31 region
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000253
254 unsigned SearchStart; // start pos of color in pref-order
255
256 //if this Node is between calls (i.e., no call interferences )
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000257 if (! isCallInterf) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000258 // start with volatiles (we can allocate volatiles safely)
Chris Lattner95685682002-08-12 21:25:05 +0000259 SearchStart = SparcFloatRegClass::StartOfAllRegs;
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000260 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000261 // start with non volatiles (no non-volatiles)
Chris Lattner95685682002-08-12 21:25:05 +0000262 SearchStart = SparcFloatRegClass::StartOfNonVolatileRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000263 }
264
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000265 ColorFound = findFloatColor(LR, SearchStart, 32, IsColorUsedArr);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000266 }
267
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;
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000271 } else if (isCallInterf) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000272 // We are here because there is a call interference and no non-volatile
273 // color could be found.
274 // Now try to allocate even a volatile color
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000275 ColorFound = findFloatColor(LR, SparcFloatRegClass::StartOfAllRegs,
Chris Lattner95685682002-08-12 21:25:05 +0000276 SparcFloatRegClass::StartOfNonVolatileRegs,
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000277 IsColorUsedArr);
278 }
279
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000280 if (ColorFound >= 0) {
Vikram S. Adve242a8082002-05-19 15:25:51 +0000281 LR->setColor(ColorFound); // first color found in prefered order
Ruchira Sasanka91442282001-09-30 23:16:47 +0000282 LR->markForSaveAcrossCalls();
Chris Lattner699683c2002-02-04 05:59:25 +0000283 } else {
284 // we are here because no color could be found
285 LR->markForSpill(); // no color found - must spill
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000286 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000287}
288
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000289//-----------------------------------------------------------------------------
290// This method marks the registers used for a given register number.
291// This marks a single register for Float regs, but the R,R+1 pair
292// for double-precision registers.
293//-----------------------------------------------------------------------------
294
295void SparcFloatRegClass::markColorsUsed(unsigned RegInClass,
296 int UserRegType,
297 int RegTypeWanted,
298 std::vector<bool> &IsColorUsedArr) const
299{
300 if (UserRegType == UltraSparcRegInfo::FPDoubleRegType ||
301 RegTypeWanted == UltraSparcRegInfo::FPDoubleRegType) {
302 // This register is used as or is needed as a double-precision reg.
303 // We need to mark the [even,odd] pair corresponding to this reg.
304 // Get the even numbered register corresponding to this reg.
305 unsigned EvenRegInClass = RegInClass & ~1u;
306 assert(EvenRegInClass+1 < NumOfAllRegs &&
307 EvenRegInClass+1 < IsColorUsedArr.size());
308 IsColorUsedArr[EvenRegInClass] = true;
309 IsColorUsedArr[EvenRegInClass+1] = true;
310 }
311 else {
312 assert(RegInClass < NumOfAllRegs && RegInClass < IsColorUsedArr.size());
313 assert(UserRegType == RegTypeWanted
314 && "Something other than FP single/double types share a reg class?");
315 IsColorUsedArr[RegInClass] = true;
316 }
317}
318
319// This method finds unused registers of the specified register type,
320// using the given "used" flag array IsColorUsedArr. It checks a single
321// entry in the array directly for float regs, and checks the pair [R,R+1]
322// for double-precision registers
323// It returns -1 if no unused color is found.
324//
325int SparcFloatRegClass::findUnusedColor(int RegTypeWanted,
326 const std::vector<bool> &IsColorUsedArr) const
327{
328 if (RegTypeWanted == UltraSparcRegInfo::FPDoubleRegType) {
329 unsigned NC = 2 * this->getNumOfAvailRegs();
330 assert(IsColorUsedArr.size() == NC && "Invalid colors-used array");
331 for (unsigned c = 0; c < NC; c+=2)
332 if (!IsColorUsedArr[c]) {
333 assert(!IsColorUsedArr[c+1] && "Incorrect used regs for FP double!");
334 return c;
335 }
336 return -1;
337 }
338 else
339 return TargetRegClassInfo::findUnusedColor(RegTypeWanted, IsColorUsedArr);
340}
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000341
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000342//-----------------------------------------------------------------------------
343// Helper method for coloring a node of Float Reg class.
344// Finds the first available color in the range [Start,End] depending on the
345// type of the Node (i.e., float/double)
346//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000347
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000348int SparcFloatRegClass::findFloatColor(const LiveRange *LR,
349 unsigned Start,
350 unsigned End,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000351 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +0000352{
Chris Lattner37730942002-02-05 03:52:29 +0000353 if (LR->getType() == Type::DoubleTy) {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000354 // find first unused color for a double
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000355 assert(Start % 2 == 0 && "Odd register number could be used for double!");
356 for (unsigned c=Start; c < End ; c+= 2)
357 if (!IsColorUsedArr[c]) {
358 assert(!IsColorUsedArr[c+1] &&
359 "Incorrect marking of used regs for Sparc FP double!");
Chris Lattner699683c2002-02-04 05:59:25 +0000360 return c;
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000361 }
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000362 } else {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000363 // find first unused color for a single
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000364 for (unsigned c = Start; c < End; c++)
Chris Lattner699683c2002-02-04 05:59:25 +0000365 if (!IsColorUsedArr[c])
366 return c;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000367 }
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000368
Chris Lattner699683c2002-02-04 05:59:25 +0000369 return -1;
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000370
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000371}