blob: fdd53bc18439320bd281a0a1dfc02a34e4070944 [file] [log] [blame]
Brian Gaeke03cac372004-04-25 07:04:49 +00001//===-- SparcV9RegClassInfo.cpp - Register class def'ns for SparcV9 -------===//
John Criswell482202a2003-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 Lattner56e91662002-08-12 21:25:05 +00009//
Brian Gaeke03cac372004-04-25 07:04:49 +000010// This file defines the methods used by the SparcV9 register allocator
11// to pick registers of various classes. Most of this code should be
12// considered part of the register allocator.
Chris Lattner56e91662002-08-12 21:25:05 +000013//
14//===----------------------------------------------------------------------===//
15
Misha Brukmanb01a80a2003-12-17 22:04:00 +000016#include "llvm/Type.h"
Brian Gaeke94e95d22004-02-25 18:44:15 +000017#include "SparcV9RegClassInfo.h"
18#include "SparcV9Internals.h"
19#include "SparcV9RegInfo.h"
Chris Lattnerbb6fa4b2004-01-09 16:17:09 +000020#include "RegAlloc/RegAllocCommon.h"
21#include "RegAlloc/IGNode.h"
Reid Spencereb04d9b2004-07-04 12:19:56 +000022#include <iostream>
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000023
Brian Gaeke960707c2003-11-11 22:41:34 +000024namespace llvm {
25
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000026//-----------------------------------------------------------------------------
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +000027// Int Register Class - method for coloring a node in the interference graph.
28//
29// Algorithm:
30// Record the colors/suggested colors of all neighbors.
31//
32// If there is a suggested color, try to allocate it
33// If there is no call interf, try to allocate volatile, then non volatile
34// If there is call interf, try to allocate non-volatile. If that fails
35// try to allocate a volatile and insert save across calls
36// If both above fail, spill.
37//
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000038//-----------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +000039void SparcV9IntRegClass::colorIGNode(IGNode * Node,
Vikram S. Adve536b1922003-07-25 21:12:15 +000040 const std::vector<bool> &IsColorUsedArr) const
Misha Brukman352f7ac2003-05-21 17:59:06 +000041{
Chris Lattner5216cc52002-02-04 05:59:25 +000042 LiveRange *LR = Node->getParentLR();
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000043
Brian Gaeke8f8a2ed2004-07-29 06:43:08 +000044 if (DEBUG_RA)
45 std::cerr << "\nColoring LR [CallInt=" << LR->isCallInterference() <<"]:"
46 << *LR << "\n";
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000047
Misha Brukman2a651d72003-05-21 18:05:35 +000048 if (LR->hasSuggestedColor()) {
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000049 unsigned SugCol = LR->getSuggestedColor();
Chris Lattnerabe98192002-05-23 15:50:03 +000050 if (!IsColorUsedArr[SugCol]) {
Misha Brukman2a651d72003-05-21 18:05:35 +000051 if (LR->isSuggestedColorUsable()) {
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000052 // if the suggested color is volatile, we should use it only if
53 // there are no call interferences. Otherwise, it will get spilled.
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000054 if (DEBUG_RA)
Misha Brukman352f7ac2003-05-21 17:59:06 +000055 std::cerr << "\n -Coloring with sug color: " << SugCol;
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000056
Misha Brukman2a651d72003-05-21 18:05:35 +000057 LR->setColor(LR->getSuggestedColor());
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000058 return;
Misha Brukman2a651d72003-05-21 18:05:35 +000059 } else if(DEBUG_RA) {
Misha Brukmanc42dc742003-05-21 19:34:28 +000060 std::cerr << "\n Couldn't alloc Sug col - LR volatile & calls interf";
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000061 }
Misha Brukman2a651d72003-05-21 18:05:35 +000062 } else if (DEBUG_RA) { // can't allocate the suggested col
Brian Gaeke8f8a2ed2004-07-29 06:43:08 +000063 std::cerr << "\n Could NOT allocate the suggested color (already used) "
64 << *LR << "\n";
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000065 }
66 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000067
68 unsigned SearchStart; // start pos of color in pref-order
69 bool ColorFound= false; // have we found a color yet?
70
71 //if this Node is between calls
Misha Brukman2a651d72003-05-21 18:05:35 +000072 if (! LR->isCallInterference()) {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000073 // start with volatiles (we can allocate volatiles safely)
Brian Gaeke94e95d22004-02-25 18:44:15 +000074 SearchStart = SparcV9IntRegClass::StartOfAllRegs;
Misha Brukman2a651d72003-05-21 18:05:35 +000075 } else {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000076 // start with non volatiles (no non-volatiles)
Brian Gaeke94e95d22004-02-25 18:44:15 +000077 SearchStart = SparcV9IntRegClass::StartOfNonVolatileRegs;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000078 }
79
80 unsigned c=0; // color
81
82 // find first unused color
Brian Gaeke94e95d22004-02-25 18:44:15 +000083 for (c=SearchStart; c < SparcV9IntRegClass::NumOfAvailRegs; c++) {
Misha Brukman2a651d72003-05-21 18:05:35 +000084 if (!IsColorUsedArr[c]) {
85 ColorFound = true;
86 break;
87 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000088 }
89
Misha Brukman2a651d72003-05-21 18:05:35 +000090 if (ColorFound) {
Misha Brukman427929a2003-09-23 17:28:11 +000091 LR->setColor(c); // first color found in preferred order
Misha Brukman352f7ac2003-05-21 17:59:06 +000092 if (DEBUG_RA) std::cerr << "\n Colored after first search with col " << c;
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000093 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000094
95 // if color is not found because of call interference
96 // try even finding a volatile color and insert save across calls
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +000097 //
Misha Brukman2a651d72003-05-21 18:05:35 +000098 else if (LR->isCallInterference()) {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000099 // start from 0 - try to find even a volatile this time
Brian Gaeke94e95d22004-02-25 18:44:15 +0000100 SearchStart = SparcV9IntRegClass::StartOfAllRegs;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000101
102 // find first unused volatile color
Brian Gaeke94e95d22004-02-25 18:44:15 +0000103 for(c=SearchStart; c < SparcV9IntRegClass::StartOfNonVolatileRegs; c++) {
Misha Brukman2a651d72003-05-21 18:05:35 +0000104 if (! IsColorUsedArr[c]) {
105 ColorFound = true;
106 break;
107 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000108 }
109
Chris Lattner5216cc52002-02-04 05:59:25 +0000110 if (ColorFound) {
Misha Brukman2a651d72003-05-21 18:05:35 +0000111 LR->setColor(c);
112 // get the live range corresponding to live var
113 // since LR span across calls, must save across calls
114 //
Misha Brukman2a651d72003-05-21 18:05:35 +0000115 if (DEBUG_RA)
116 std::cerr << "\n Colored after SECOND search with col " << c;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000117 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000118 }
119
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000120
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000121 // If we couldn't find a color regardless of call interference - i.e., we
122 // don't have either a volatile or non-volatile color left
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000123 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000124 if (!ColorFound)
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000125 LR->markForSpill(); // no color found - must spill
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000126}
127
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000128//-----------------------------------------------------------------------------
129// Int CC Register Class - method for coloring a node in the interference graph.
130//
131// Algorithm:
132//
Vikram S. Adve65280672003-07-10 19:42:11 +0000133// If (node has any interferences)
134// /* all interference operations can use only one register! */
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000135// mark the LR for spilling
136// else {
137// if (the LR is a 64-bit comparison) use %xcc
138// else /*32-bit or smaller*/ use %icc
139// }
140//
141// Note: The third name (%ccr) is essentially an assembly mnemonic and
142// depends solely on the opcode, so the name can be chosen in EmitAssembly.
143//-----------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000144void SparcV9IntCCRegClass::colorIGNode(IGNode *Node,
Vikram S. Adve536b1922003-07-25 21:12:15 +0000145 const std::vector<bool> &IsColorUsedArr) const
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000146{
Vikram S. Adve65280672003-07-10 19:42:11 +0000147 if (Node->getNumOfNeighbors() > 0)
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000148 Node->getParentLR()->markForSpill();
Vikram S. Adve65280672003-07-10 19:42:11 +0000149
150 // Mark the appropriate register in any case (even if it needs to be spilled)
151 // because there is only one possible register, but more importantly, the
152 // spill algorithm cannot find it. In particular, we have to choose
153 // whether to use %xcc or %icc based on type of value compared
154 //
155 const LiveRange* ccLR = Node->getParentLR();
156 const Type* setCCType = (* ccLR->begin())->getType(); // any Value in LR
157 assert(setCCType->isIntegral() || isa<PointerType>(setCCType));
158 int ccReg = ((isa<PointerType>(setCCType) || setCCType == Type::LongTy)
159 ? xcc : icc);
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000160
161#ifndef NDEBUG
Vikram S. Adve65280672003-07-10 19:42:11 +0000162 // Let's just make sure values of two different types have not been
163 // coalesced into this LR.
Brian Gaeke8f8a2ed2004-07-29 06:43:08 +0000164 for (LiveRange::const_iterator I=ccLR->begin(), E=ccLR->end(); I!=E; ++I) {
Vikram S. Adve65280672003-07-10 19:42:11 +0000165 const Type* ccType = (*I)->getType();
166 assert((ccReg == xcc && (isa<PointerType>(ccType)
167 || ccType == Type::LongTy)) ||
168 (ccReg == icc && ccType->isIntegral() && ccType != Type::LongTy)
169 && "Comparisons needing different intCC regs coalesced in LR!");
170 }
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000171#endif
172
Vikram S. Adve65280672003-07-10 19:42:11 +0000173 Node->setColor(ccReg); // only one int cc reg is available
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000174}
175
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000176
Brian Gaeke94e95d22004-02-25 18:44:15 +0000177void SparcV9FloatCCRegClass::colorIGNode(IGNode *Node,
Chris Lattner33238292003-09-01 19:56:48 +0000178 const std::vector<bool> &IsColorUsedArr) const {
179 for(unsigned c = 0; c != 4; ++c)
180 if (!IsColorUsedArr[c]) { // find unused color
181 Node->setColor(c);
182 return;
183 }
184
185 Node->getParentLR()->markForSpill();
186}
187
188
189
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000190//-----------------------------------------------------------------------------
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000191// Float Register Class - method for coloring a node in the interference graph.
192//
193// Algorithm:
194//
195// If the LR is a double try to allocate f32 - f63
196// If the above fails or LR is single precision
197// If the LR does not interfere with a call
198// start allocating from f0
199// Else start allocating from f6
200// If a color is still not found because LR interferes with a call
201// Search in f0 - f6. If found mark for spill across calls.
202// If a color is still not fond, mark for spilling
203//
204//----------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000205void SparcV9FloatRegClass::colorIGNode(IGNode * Node,
Vikram S. Adve536b1922003-07-25 21:12:15 +0000206 const std::vector<bool> &IsColorUsedArr) const
Misha Brukman352f7ac2003-05-21 17:59:06 +0000207{
Chris Lattnerd30f9892002-02-05 03:52:29 +0000208 LiveRange *LR = Node->getParentLR();
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000209
Vikram S. Adve536b1922003-07-25 21:12:15 +0000210#ifndef NDEBUG
211 // Check that the correct colors have been are marked for fp-doubles.
212 //
213 // FIXME: This is old code that is no longer needed. Temporarily converting
214 // it into a big assertion just to check that the replacement logic
Brian Gaeke94e95d22004-02-25 18:44:15 +0000215 // (invoking SparcV9FloatRegClass::markColorsUsed() directly from
Vikram S. Adve536b1922003-07-25 21:12:15 +0000216 // RegClass::colorIGNode) works correctly.
217 //
218 // In fact, this entire function should be identical to
Brian Gaeke94e95d22004-02-25 18:44:15 +0000219 // SparcV9IntRegClass::colorIGNode(), and perhaps can be
Vikram S. Adve536b1922003-07-25 21:12:15 +0000220 // made into a general case in CodeGen/RegAlloc/RegClass.cpp.
Vikram S. Advee9327f02002-05-19 15:25:51 +0000221 //
222 unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000223 for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh
224 IGNode *NeighIGNode = Node->getAdjIGNode(n);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000225 LiveRange *NeighLR = NeighIGNode->getParentLR();
Vikram S. Advee9327f02002-05-19 15:25:51 +0000226
Vikram S. Adve49cf0912003-09-21 07:55:27 +0000227 if (NeighLR->hasColor()) {
228 assert(IsColorUsedArr[ NeighLR->getColor() ]);
229 if (NeighLR->getType() == Type::DoubleTy)
230 assert(IsColorUsedArr[ NeighLR->getColor()+1 ]);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000231
232 } else if (NeighLR->hasSuggestedColor() &&
233 NeighLR-> isSuggestedColorUsable() ) {
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000234
Misha Brukman2a651d72003-05-21 18:05:35 +0000235 // if the neighbour can use the suggested color
Vikram S. Adve536b1922003-07-25 21:12:15 +0000236 assert(IsColorUsedArr[ NeighLR->getSuggestedColor() ]);
Misha Brukman2a651d72003-05-21 18:05:35 +0000237 if (NeighLR->getType() == Type::DoubleTy)
Vikram S. Adve536b1922003-07-25 21:12:15 +0000238 assert(IsColorUsedArr[ NeighLR->getSuggestedColor()+1 ]);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000239 }
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000240 }
Vikram S. Adve536b1922003-07-25 21:12:15 +0000241#endif
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000242
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +0000243 // **NOTE: We don't check for call interferences in allocating suggested
244 // color in this class since ALL registers are volatile. If this fact
245 // changes, we should change the following part
Brian Gaeke94e95d22004-02-25 18:44:15 +0000246 //- see SparcV9IntRegClass::colorIGNode()
Vikram S. Advee9327f02002-05-19 15:25:51 +0000247 //
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000248 if( LR->hasSuggestedColor() ) {
249 if( ! IsColorUsedArr[ LR->getSuggestedColor() ] ) {
250 LR->setColor( LR->getSuggestedColor() );
251 return;
Chris Lattnerb0af9cd2002-02-05 02:52:05 +0000252 } else if (DEBUG_RA) { // can't allocate the suggested col
Brian Gaeke8f8a2ed2004-07-29 06:43:08 +0000253 std::cerr << " Could NOT allocate the suggested color for LR " << *LR
254 << "\n";
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000255 }
256 }
257
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000258
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000259 int ColorFound = -1; // have we found a color yet?
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +0000260 bool isCallInterf = LR->isCallInterference();
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000261
Chris Lattnerabe98192002-05-23 15:50:03 +0000262 // if value is a double - search the double only region (f32 - f63)
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000263 // i.e. we try to allocate f32 - f63 first for doubles since singles
264 // cannot go there. By doing that, we provide more space for singles
265 // in f0 - f31
266 //
Chris Lattnerd30f9892002-02-05 03:52:29 +0000267 if (LR->getType() == Type::DoubleTy)
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000268 ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr );
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000269
Misha Brukman2a651d72003-05-21 18:05:35 +0000270 if (ColorFound >= 0) { // if we could find a color
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000271 LR->setColor(ColorFound);
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000272 return;
Chris Lattner5216cc52002-02-04 05:59:25 +0000273 } else {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000274
Misha Brukman8b2bd4e2003-10-10 17:57:28 +0000275 // if we didn't find a color because the LR was single precision or
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000276 // all f32-f63 range is filled, we try to allocate a register from
277 // the f0 - f31 region
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000278
279 unsigned SearchStart; // start pos of color in pref-order
280
281 //if this Node is between calls (i.e., no call interferences )
Misha Brukman2a651d72003-05-21 18:05:35 +0000282 if (! isCallInterf) {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000283 // start with volatiles (we can allocate volatiles safely)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000284 SearchStart = SparcV9FloatRegClass::StartOfAllRegs;
Misha Brukman2a651d72003-05-21 18:05:35 +0000285 } else {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000286 // start with non volatiles (no non-volatiles)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000287 SearchStart = SparcV9FloatRegClass::StartOfNonVolatileRegs;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000288 }
289
Misha Brukman2a651d72003-05-21 18:05:35 +0000290 ColorFound = findFloatColor(LR, SearchStart, 32, IsColorUsedArr);
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000291 }
292
Misha Brukman2a651d72003-05-21 18:05:35 +0000293 if (ColorFound >= 0) { // if we could find a color
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000294 LR->setColor(ColorFound);
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000295 return;
Misha Brukman2a651d72003-05-21 18:05:35 +0000296 } else if (isCallInterf) {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000297 // We are here because there is a call interference and no non-volatile
298 // color could be found.
299 // Now try to allocate even a volatile color
Brian Gaeke94e95d22004-02-25 18:44:15 +0000300 ColorFound = findFloatColor(LR, SparcV9FloatRegClass::StartOfAllRegs,
301 SparcV9FloatRegClass::StartOfNonVolatileRegs,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000302 IsColorUsedArr);
303 }
304
Misha Brukman2a651d72003-05-21 18:05:35 +0000305 if (ColorFound >= 0) {
Misha Brukman8b2bd4e2003-10-10 17:57:28 +0000306 LR->setColor(ColorFound); // first color found in preferred order
Chris Lattner5216cc52002-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 Sasankadfc6c882001-09-18 22:52:44 +0000310 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000311}
312
Vikram S. Adve536b1922003-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
Brian Gaeke94e95d22004-02-25 18:44:15 +0000319void SparcV9FloatRegClass::markColorsUsed(unsigned RegInClass,
Vikram S. Adve536b1922003-07-25 21:12:15 +0000320 int UserRegType,
321 int RegTypeWanted,
322 std::vector<bool> &IsColorUsedArr) const
323{
Brian Gaeke94e95d22004-02-25 18:44:15 +0000324 if (UserRegType == SparcV9RegInfo::FPDoubleRegType ||
325 RegTypeWanted == SparcV9RegInfo::FPDoubleRegType) {
Vikram S. Adve536b1922003-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//
Brian Gaeke94e95d22004-02-25 18:44:15 +0000349int SparcV9FloatRegClass::findUnusedColor(int RegTypeWanted,
Vikram S. Adve536b1922003-07-25 21:12:15 +0000350 const std::vector<bool> &IsColorUsedArr) const
351{
Brian Gaeke94e95d22004-02-25 18:44:15 +0000352 if (RegTypeWanted == SparcV9RegInfo::FPDoubleRegType) {
Vikram S. Adve536b1922003-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 Sasankadfc6c882001-09-18 22:52:44 +0000365
Ruchira Sasanka4cfbfd52002-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 Sasanka4cfbfd52002-01-07 19:20:28 +0000371
Brian Gaeke94e95d22004-02-25 18:44:15 +0000372int SparcV9FloatRegClass::findFloatColor(const LiveRange *LR,
Misha Brukman2a651d72003-05-21 18:05:35 +0000373 unsigned Start,
374 unsigned End,
Vikram S. Adve536b1922003-07-25 21:12:15 +0000375 const std::vector<bool> &IsColorUsedArr) const
Misha Brukman352f7ac2003-05-21 17:59:06 +0000376{
Chris Lattnerd30f9892002-02-05 03:52:29 +0000377 if (LR->getType() == Type::DoubleTy) {
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000378 // find first unused color for a double
Vikram S. Adve536b1922003-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] &&
Brian Gaeke94e95d22004-02-25 18:44:15 +0000383 "Incorrect marking of used regs for SparcV9 FP double!");
Chris Lattner5216cc52002-02-04 05:59:25 +0000384 return c;
Vikram S. Adve536b1922003-07-25 21:12:15 +0000385 }
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000386 } else {
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000387 // find first unused color for a single
Vikram S. Adve536b1922003-07-25 21:12:15 +0000388 for (unsigned c = Start; c < End; c++)
Chris Lattner5216cc52002-02-04 05:59:25 +0000389 if (!IsColorUsedArr[c])
390 return c;
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000391 }
Vikram S. Adve536b1922003-07-25 21:12:15 +0000392
Chris Lattner5216cc52002-02-04 05:59:25 +0000393 return -1;
Vikram S. Adve536b1922003-07-25 21:12:15 +0000394
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000395}
Brian Gaeke960707c2003-11-11 22:41:34 +0000396
397} // End llvm namespace