blob: d6de5f9c0df27184e5459607e5a74b62199be873 [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
20//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +000021// Int Register Class - method for coloring a node in the interference graph.
22//
23// Algorithm:
24// Record the colors/suggested colors of all neighbors.
25//
26// If there is a suggested color, try to allocate it
27// If there is no call interf, try to allocate volatile, then non volatile
28// If there is call interf, try to allocate non-volatile. If that fails
29// try to allocate a volatile and insert save across calls
30// If both above fail, spill.
31//
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000032//-----------------------------------------------------------------------------
Misha Brukmanee563cb2003-05-21 17:59:06 +000033void SparcIntRegClass::colorIGNode(IGNode * Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +000034 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +000035{
Chris Lattner699683c2002-02-04 05:59:25 +000036 LiveRange *LR = Node->getParentLR();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000037
Misha Brukman77c9fcb2003-05-21 18:05:35 +000038 if (DEBUG_RA) {
Misha Brukmanee563cb2003-05-21 17:59:06 +000039 std::cerr << "\nColoring LR [CallInt=" << LR->isCallInterference() <<"]:";
Chris Lattner296b7732002-02-05 02:52:05 +000040 printSet(*LR);
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000041 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000042
Misha Brukman77c9fcb2003-05-21 18:05:35 +000043 if (LR->hasSuggestedColor()) {
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000044 unsigned SugCol = LR->getSuggestedColor();
Chris Lattner85c54652002-05-23 15:50:03 +000045 if (!IsColorUsedArr[SugCol]) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +000046 if (LR->isSuggestedColorUsable()) {
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000047 // if the suggested color is volatile, we should use it only if
48 // there are no call interferences. Otherwise, it will get spilled.
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000049 if (DEBUG_RA)
Misha Brukmanee563cb2003-05-21 17:59:06 +000050 std::cerr << "\n -Coloring with sug color: " << SugCol;
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000051
Misha Brukman77c9fcb2003-05-21 18:05:35 +000052 LR->setColor(LR->getSuggestedColor());
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000053 return;
Misha Brukman77c9fcb2003-05-21 18:05:35 +000054 } else if(DEBUG_RA) {
Misha Brukmanc97a2072003-05-21 19:34:28 +000055 std::cerr << "\n Couldn't alloc Sug col - LR volatile & calls interf";
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000056 }
Misha Brukman77c9fcb2003-05-21 18:05:35 +000057 } else if (DEBUG_RA) { // can't allocate the suggested col
Misha Brukmanee563cb2003-05-21 17:59:06 +000058 std::cerr << "\n Could NOT allocate the suggested color (already used) ";
59 printSet(*LR); std::cerr << "\n";
Ruchira Sasanka91442282001-09-30 23:16:47 +000060 }
61 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000062
63 unsigned SearchStart; // start pos of color in pref-order
64 bool ColorFound= false; // have we found a color yet?
65
66 //if this Node is between calls
Misha Brukman77c9fcb2003-05-21 18:05:35 +000067 if (! LR->isCallInterference()) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000068 // start with volatiles (we can allocate volatiles safely)
Chris Lattner95685682002-08-12 21:25:05 +000069 SearchStart = SparcIntRegClass::StartOfAllRegs;
Misha Brukman77c9fcb2003-05-21 18:05:35 +000070 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000071 // start with non volatiles (no non-volatiles)
Chris Lattner95685682002-08-12 21:25:05 +000072 SearchStart = SparcIntRegClass::StartOfNonVolatileRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000073 }
74
75 unsigned c=0; // color
76
77 // find first unused color
Misha Brukman77c9fcb2003-05-21 18:05:35 +000078 for (c=SearchStart; c < SparcIntRegClass::NumOfAvailRegs; c++) {
79 if (!IsColorUsedArr[c]) {
80 ColorFound = true;
81 break;
82 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000083 }
84
Misha Brukman77c9fcb2003-05-21 18:05:35 +000085 if (ColorFound) {
Misha Brukman452db672003-09-23 17:28:11 +000086 LR->setColor(c); // first color found in preferred order
Misha Brukmanee563cb2003-05-21 17:59:06 +000087 if (DEBUG_RA) std::cerr << "\n Colored after first search with col " << c;
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +000088 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000089
90 // if color is not found because of call interference
91 // try even finding a volatile color and insert save across calls
Ruchira Sasankad00982a2002-01-07 19:20:28 +000092 //
Misha Brukman77c9fcb2003-05-21 18:05:35 +000093 else if (LR->isCallInterference()) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000094 // start from 0 - try to find even a volatile this time
Chris Lattner95685682002-08-12 21:25:05 +000095 SearchStart = SparcIntRegClass::StartOfAllRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +000096
97 // find first unused volatile color
Chris Lattner95685682002-08-12 21:25:05 +000098 for(c=SearchStart; c < SparcIntRegClass::StartOfNonVolatileRegs; c++) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +000099 if (! IsColorUsedArr[c]) {
100 ColorFound = true;
101 break;
102 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000103 }
104
Chris Lattner699683c2002-02-04 05:59:25 +0000105 if (ColorFound) {
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000106 LR->setColor(c);
107 // get the live range corresponding to live var
108 // since LR span across calls, must save across calls
109 //
110 LR->markForSaveAcrossCalls();
111 if (DEBUG_RA)
112 std::cerr << "\n Colored after SECOND search with col " << c;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000113 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000114 }
115
Ruchira Sasanka91442282001-09-30 23:16:47 +0000116
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000117 // If we couldn't find a color regardless of call interference - i.e., we
118 // don't have either a volatile or non-volatile color left
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000119 //
Chris Lattner699683c2002-02-04 05:59:25 +0000120 if (!ColorFound)
Ruchira Sasanka91442282001-09-30 23:16:47 +0000121 LR->markForSpill(); // no color found - must spill
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000122}
123
Vikram S. Adve786833a2003-07-06 20:13:59 +0000124//-----------------------------------------------------------------------------
125// Int CC Register Class - method for coloring a node in the interference graph.
126//
127// Algorithm:
128//
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000129// If (node has any interferences)
130// /* all interference operations can use only one register! */
Vikram S. Adve786833a2003-07-06 20:13:59 +0000131// mark the LR for spilling
132// else {
133// if (the LR is a 64-bit comparison) use %xcc
134// else /*32-bit or smaller*/ use %icc
135// }
136//
137// Note: The third name (%ccr) is essentially an assembly mnemonic and
138// depends solely on the opcode, so the name can be chosen in EmitAssembly.
139//-----------------------------------------------------------------------------
140void SparcIntCCRegClass::colorIGNode(IGNode *Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000141 const std::vector<bool> &IsColorUsedArr) const
Vikram S. Adve786833a2003-07-06 20:13:59 +0000142{
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000143 if (Node->getNumOfNeighbors() > 0)
Vikram S. Adve786833a2003-07-06 20:13:59 +0000144 Node->getParentLR()->markForSpill();
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000145
146 // Mark the appropriate register in any case (even if it needs to be spilled)
147 // because there is only one possible register, but more importantly, the
148 // spill algorithm cannot find it. In particular, we have to choose
149 // whether to use %xcc or %icc based on type of value compared
150 //
151 const LiveRange* ccLR = Node->getParentLR();
152 const Type* setCCType = (* ccLR->begin())->getType(); // any Value in LR
153 assert(setCCType->isIntegral() || isa<PointerType>(setCCType));
154 int ccReg = ((isa<PointerType>(setCCType) || setCCType == Type::LongTy)
155 ? xcc : icc);
Vikram S. Adve786833a2003-07-06 20:13:59 +0000156
157#ifndef NDEBUG
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000158 // Let's just make sure values of two different types have not been
159 // coalesced into this LR.
160 for (ValueSet::const_iterator I=ccLR->begin(), E=ccLR->end(); I!=E; ++I) {
161 const Type* ccType = (*I)->getType();
162 assert((ccReg == xcc && (isa<PointerType>(ccType)
163 || ccType == Type::LongTy)) ||
164 (ccReg == icc && ccType->isIntegral() && ccType != Type::LongTy)
165 && "Comparisons needing different intCC regs coalesced in LR!");
166 }
Vikram S. Adve786833a2003-07-06 20:13:59 +0000167#endif
168
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000169 Node->setColor(ccReg); // only one int cc reg is available
Vikram S. Adve786833a2003-07-06 20:13:59 +0000170}
171
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000172
Chris Lattner87d50f02003-09-01 19:56:48 +0000173void SparcFloatCCRegClass::colorIGNode(IGNode *Node,
174 const std::vector<bool> &IsColorUsedArr) const {
175 for(unsigned c = 0; c != 4; ++c)
176 if (!IsColorUsedArr[c]) { // find unused color
177 Node->setColor(c);
178 return;
179 }
180
181 Node->getParentLR()->markForSpill();
182}
183
184
185
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000186//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000187// Float Register Class - method for coloring a node in the interference graph.
188//
189// Algorithm:
190//
191// If the LR is a double try to allocate f32 - f63
192// If the above fails or LR is single precision
193// If the LR does not interfere with a call
194// start allocating from f0
195// Else start allocating from f6
196// If a color is still not found because LR interferes with a call
197// Search in f0 - f6. If found mark for spill across calls.
198// If a color is still not fond, mark for spilling
199//
200//----------------------------------------------------------------------------
Chris Lattner85c54652002-05-23 15:50:03 +0000201void SparcFloatRegClass::colorIGNode(IGNode * Node,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000202 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +0000203{
Chris Lattner37730942002-02-05 03:52:29 +0000204 LiveRange *LR = Node->getParentLR();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000205
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000206#ifndef NDEBUG
207 // Check that the correct colors have been are marked for fp-doubles.
208 //
209 // FIXME: This is old code that is no longer needed. Temporarily converting
210 // it into a big assertion just to check that the replacement logic
211 // (invoking SparcFloatRegClass::markColorsUsed() directly from
212 // RegClass::colorIGNode) works correctly.
213 //
214 // In fact, this entire function should be identical to
215 // SparcIntRegClass::colorIGNode(), and perhaps can be
216 // made into a general case in CodeGen/RegAlloc/RegClass.cpp.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000217 //
218 unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000219 for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh
220 IGNode *NeighIGNode = Node->getAdjIGNode(n);
Ruchira Sasanka91442282001-09-30 23:16:47 +0000221 LiveRange *NeighLR = NeighIGNode->getParentLR();
Vikram S. Adve242a8082002-05-19 15:25:51 +0000222
Vikram S. Adve4d436c12003-09-21 07:55:27 +0000223 if (NeighLR->hasColor()) {
224 assert(IsColorUsedArr[ NeighLR->getColor() ]);
225 if (NeighLR->getType() == Type::DoubleTy)
226 assert(IsColorUsedArr[ NeighLR->getColor()+1 ]);
Vikram S. Adve242a8082002-05-19 15:25:51 +0000227
228 } else if (NeighLR->hasSuggestedColor() &&
229 NeighLR-> isSuggestedColorUsable() ) {
Ruchira Sasanka91442282001-09-30 23:16:47 +0000230
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000231 // if the neighbour can use the suggested color
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000232 assert(IsColorUsedArr[ NeighLR->getSuggestedColor() ]);
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000233 if (NeighLR->getType() == Type::DoubleTy)
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000234 assert(IsColorUsedArr[ NeighLR->getSuggestedColor()+1 ]);
Vikram S. Adve242a8082002-05-19 15:25:51 +0000235 }
Ruchira Sasanka91442282001-09-30 23:16:47 +0000236 }
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000237#endif
Ruchira Sasanka91442282001-09-30 23:16:47 +0000238
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +0000239 // **NOTE: We don't check for call interferences in allocating suggested
240 // color in this class since ALL registers are volatile. If this fact
241 // changes, we should change the following part
242 //- see SparcIntRegClass::colorIGNode()
Vikram S. Adve242a8082002-05-19 15:25:51 +0000243 //
Ruchira Sasanka91442282001-09-30 23:16:47 +0000244 if( LR->hasSuggestedColor() ) {
245 if( ! IsColorUsedArr[ LR->getSuggestedColor() ] ) {
246 LR->setColor( LR->getSuggestedColor() );
247 return;
Chris Lattner296b7732002-02-05 02:52:05 +0000248 } else if (DEBUG_RA) { // can't allocate the suggested col
Misha Brukmanee563cb2003-05-21 17:59:06 +0000249 std::cerr << " Could NOT allocate the suggested color for LR ";
250 printSet(*LR); std::cerr << "\n";
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000251 }
252 }
253
Ruchira Sasanka91442282001-09-30 23:16:47 +0000254
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000255 int ColorFound = -1; // have we found a color yet?
Ruchira Sasanka0f5e9882001-10-19 17:23:43 +0000256 bool isCallInterf = LR->isCallInterference();
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000257
Chris Lattner85c54652002-05-23 15:50:03 +0000258 // if value is a double - search the double only region (f32 - f63)
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000259 // i.e. we try to allocate f32 - f63 first for doubles since singles
260 // cannot go there. By doing that, we provide more space for singles
261 // in f0 - f31
262 //
Chris Lattner37730942002-02-05 03:52:29 +0000263 if (LR->getType() == Type::DoubleTy)
Ruchira Sasanka91442282001-09-30 23:16:47 +0000264 ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr );
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000265
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000266 if (ColorFound >= 0) { // if we could find a color
Ruchira Sasanka91442282001-09-30 23:16:47 +0000267 LR->setColor(ColorFound);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000268 return;
Chris Lattner699683c2002-02-04 05:59:25 +0000269 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000270
Misha Brukmancf00c4a2003-10-10 17:57:28 +0000271 // if we didn't find a color because the LR was single precision or
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000272 // all f32-f63 range is filled, we try to allocate a register from
273 // the f0 - f31 region
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000274
275 unsigned SearchStart; // start pos of color in pref-order
276
277 //if this Node is between calls (i.e., no call interferences )
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000278 if (! isCallInterf) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000279 // start with volatiles (we can allocate volatiles safely)
Chris Lattner95685682002-08-12 21:25:05 +0000280 SearchStart = SparcFloatRegClass::StartOfAllRegs;
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000281 } else {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000282 // start with non volatiles (no non-volatiles)
Chris Lattner95685682002-08-12 21:25:05 +0000283 SearchStart = SparcFloatRegClass::StartOfNonVolatileRegs;
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000284 }
285
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000286 ColorFound = findFloatColor(LR, SearchStart, 32, IsColorUsedArr);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000287 }
288
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000289 if (ColorFound >= 0) { // if we could find a color
Ruchira Sasanka91442282001-09-30 23:16:47 +0000290 LR->setColor(ColorFound);
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000291 return;
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000292 } else if (isCallInterf) {
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000293 // We are here because there is a call interference and no non-volatile
294 // color could be found.
295 // Now try to allocate even a volatile color
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000296 ColorFound = findFloatColor(LR, SparcFloatRegClass::StartOfAllRegs,
Chris Lattner95685682002-08-12 21:25:05 +0000297 SparcFloatRegClass::StartOfNonVolatileRegs,
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000298 IsColorUsedArr);
299 }
300
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000301 if (ColorFound >= 0) {
Misha Brukmancf00c4a2003-10-10 17:57:28 +0000302 LR->setColor(ColorFound); // first color found in preferred order
Ruchira Sasanka91442282001-09-30 23:16:47 +0000303 LR->markForSaveAcrossCalls();
Chris Lattner699683c2002-02-04 05:59:25 +0000304 } else {
305 // we are here because no color could be found
306 LR->markForSpill(); // no color found - must spill
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000307 }
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000308}
309
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000310//-----------------------------------------------------------------------------
311// This method marks the registers used for a given register number.
312// This marks a single register for Float regs, but the R,R+1 pair
313// for double-precision registers.
314//-----------------------------------------------------------------------------
315
316void SparcFloatRegClass::markColorsUsed(unsigned RegInClass,
317 int UserRegType,
318 int RegTypeWanted,
319 std::vector<bool> &IsColorUsedArr) const
320{
321 if (UserRegType == UltraSparcRegInfo::FPDoubleRegType ||
322 RegTypeWanted == UltraSparcRegInfo::FPDoubleRegType) {
323 // This register is used as or is needed as a double-precision reg.
324 // We need to mark the [even,odd] pair corresponding to this reg.
325 // Get the even numbered register corresponding to this reg.
326 unsigned EvenRegInClass = RegInClass & ~1u;
327 assert(EvenRegInClass+1 < NumOfAllRegs &&
328 EvenRegInClass+1 < IsColorUsedArr.size());
329 IsColorUsedArr[EvenRegInClass] = true;
330 IsColorUsedArr[EvenRegInClass+1] = true;
331 }
332 else {
333 assert(RegInClass < NumOfAllRegs && RegInClass < IsColorUsedArr.size());
334 assert(UserRegType == RegTypeWanted
335 && "Something other than FP single/double types share a reg class?");
336 IsColorUsedArr[RegInClass] = true;
337 }
338}
339
340// This method finds unused registers of the specified register type,
341// using the given "used" flag array IsColorUsedArr. It checks a single
342// entry in the array directly for float regs, and checks the pair [R,R+1]
343// for double-precision registers
344// It returns -1 if no unused color is found.
345//
346int SparcFloatRegClass::findUnusedColor(int RegTypeWanted,
347 const std::vector<bool> &IsColorUsedArr) const
348{
349 if (RegTypeWanted == UltraSparcRegInfo::FPDoubleRegType) {
350 unsigned NC = 2 * this->getNumOfAvailRegs();
351 assert(IsColorUsedArr.size() == NC && "Invalid colors-used array");
352 for (unsigned c = 0; c < NC; c+=2)
353 if (!IsColorUsedArr[c]) {
354 assert(!IsColorUsedArr[c+1] && "Incorrect used regs for FP double!");
355 return c;
356 }
357 return -1;
358 }
359 else
360 return TargetRegClassInfo::findUnusedColor(RegTypeWanted, IsColorUsedArr);
361}
Ruchira Sasanka89fb46b2001-09-18 22:52:44 +0000362
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000363//-----------------------------------------------------------------------------
364// Helper method for coloring a node of Float Reg class.
365// Finds the first available color in the range [Start,End] depending on the
366// type of the Node (i.e., float/double)
367//-----------------------------------------------------------------------------
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000368
Misha Brukman77c9fcb2003-05-21 18:05:35 +0000369int SparcFloatRegClass::findFloatColor(const LiveRange *LR,
370 unsigned Start,
371 unsigned End,
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000372 const std::vector<bool> &IsColorUsedArr) const
Misha Brukmanee563cb2003-05-21 17:59:06 +0000373{
Chris Lattner37730942002-02-05 03:52:29 +0000374 if (LR->getType() == Type::DoubleTy) {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000375 // find first unused color for a double
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000376 assert(Start % 2 == 0 && "Odd register number could be used for double!");
377 for (unsigned c=Start; c < End ; c+= 2)
378 if (!IsColorUsedArr[c]) {
379 assert(!IsColorUsedArr[c+1] &&
380 "Incorrect marking of used regs for Sparc FP double!");
Chris Lattner699683c2002-02-04 05:59:25 +0000381 return c;
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000382 }
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000383 } else {
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000384 // find first unused color for a single
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000385 for (unsigned c = Start; c < End; c++)
Chris Lattner699683c2002-02-04 05:59:25 +0000386 if (!IsColorUsedArr[c])
387 return c;
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000388 }
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000389
Chris Lattner699683c2002-02-04 05:59:25 +0000390 return -1;
Vikram S. Adve7dc7de52003-07-25 21:12:15 +0000391
Ruchira Sasankad00982a2002-01-07 19:20:28 +0000392}