blob: df4e44c7ee77ea9c277556b2db06a881aa07e8d8 [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
Misha Brukman2a651d72003-05-21 18:05:35 +000044 if (DEBUG_RA) {
Misha Brukman352f7ac2003-05-21 17:59:06 +000045 std::cerr << "\nColoring LR [CallInt=" << LR->isCallInterference() <<"]:";
Chris Lattnerb0af9cd2002-02-05 02:52:05 +000046 printSet(*LR);
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000047 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000048
Misha Brukman2a651d72003-05-21 18:05:35 +000049 if (LR->hasSuggestedColor()) {
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000050 unsigned SugCol = LR->getSuggestedColor();
Chris Lattnerabe98192002-05-23 15:50:03 +000051 if (!IsColorUsedArr[SugCol]) {
Misha Brukman2a651d72003-05-21 18:05:35 +000052 if (LR->isSuggestedColorUsable()) {
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000053 // if the suggested color is volatile, we should use it only if
54 // there are no call interferences. Otherwise, it will get spilled.
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000055 if (DEBUG_RA)
Misha Brukman352f7ac2003-05-21 17:59:06 +000056 std::cerr << "\n -Coloring with sug color: " << SugCol;
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000057
Misha Brukman2a651d72003-05-21 18:05:35 +000058 LR->setColor(LR->getSuggestedColor());
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000059 return;
Misha Brukman2a651d72003-05-21 18:05:35 +000060 } else if(DEBUG_RA) {
Misha Brukmanc42dc742003-05-21 19:34:28 +000061 std::cerr << "\n Couldn't alloc Sug col - LR volatile & calls interf";
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000062 }
Misha Brukman2a651d72003-05-21 18:05:35 +000063 } else if (DEBUG_RA) { // can't allocate the suggested col
Misha Brukman352f7ac2003-05-21 17:59:06 +000064 std::cerr << "\n Could NOT allocate the suggested color (already used) ";
65 printSet(*LR); std::cerr << "\n";
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +000066 }
67 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000068
69 unsigned SearchStart; // start pos of color in pref-order
70 bool ColorFound= false; // have we found a color yet?
71
72 //if this Node is between calls
Misha Brukman2a651d72003-05-21 18:05:35 +000073 if (! LR->isCallInterference()) {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000074 // start with volatiles (we can allocate volatiles safely)
Brian Gaeke94e95d22004-02-25 18:44:15 +000075 SearchStart = SparcV9IntRegClass::StartOfAllRegs;
Misha Brukman2a651d72003-05-21 18:05:35 +000076 } else {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000077 // start with non volatiles (no non-volatiles)
Brian Gaeke94e95d22004-02-25 18:44:15 +000078 SearchStart = SparcV9IntRegClass::StartOfNonVolatileRegs;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000079 }
80
81 unsigned c=0; // color
82
83 // find first unused color
Brian Gaeke94e95d22004-02-25 18:44:15 +000084 for (c=SearchStart; c < SparcV9IntRegClass::NumOfAvailRegs; c++) {
Misha Brukman2a651d72003-05-21 18:05:35 +000085 if (!IsColorUsedArr[c]) {
86 ColorFound = true;
87 break;
88 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000089 }
90
Misha Brukman2a651d72003-05-21 18:05:35 +000091 if (ColorFound) {
Misha Brukman427929a2003-09-23 17:28:11 +000092 LR->setColor(c); // first color found in preferred order
Misha Brukman352f7ac2003-05-21 17:59:06 +000093 if (DEBUG_RA) std::cerr << "\n Colored after first search with col " << c;
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +000094 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +000095
96 // if color is not found because of call interference
97 // try even finding a volatile color and insert save across calls
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +000098 //
Misha Brukman2a651d72003-05-21 18:05:35 +000099 else if (LR->isCallInterference()) {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000100 // start from 0 - try to find even a volatile this time
Brian Gaeke94e95d22004-02-25 18:44:15 +0000101 SearchStart = SparcV9IntRegClass::StartOfAllRegs;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000102
103 // find first unused volatile color
Brian Gaeke94e95d22004-02-25 18:44:15 +0000104 for(c=SearchStart; c < SparcV9IntRegClass::StartOfNonVolatileRegs; c++) {
Misha Brukman2a651d72003-05-21 18:05:35 +0000105 if (! IsColorUsedArr[c]) {
106 ColorFound = true;
107 break;
108 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000109 }
110
Chris Lattner5216cc52002-02-04 05:59:25 +0000111 if (ColorFound) {
Misha Brukman2a651d72003-05-21 18:05:35 +0000112 LR->setColor(c);
113 // get the live range corresponding to live var
114 // since LR span across calls, must save across calls
115 //
116 LR->markForSaveAcrossCalls();
117 if (DEBUG_RA)
118 std::cerr << "\n Colored after SECOND search with col " << c;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000119 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000120 }
121
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000122
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000123 // If we couldn't find a color regardless of call interference - i.e., we
124 // don't have either a volatile or non-volatile color left
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000125 //
Chris Lattner5216cc52002-02-04 05:59:25 +0000126 if (!ColorFound)
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000127 LR->markForSpill(); // no color found - must spill
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000128}
129
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000130//-----------------------------------------------------------------------------
131// Int CC Register Class - method for coloring a node in the interference graph.
132//
133// Algorithm:
134//
Vikram S. Adve65280672003-07-10 19:42:11 +0000135// If (node has any interferences)
136// /* all interference operations can use only one register! */
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000137// mark the LR for spilling
138// else {
139// if (the LR is a 64-bit comparison) use %xcc
140// else /*32-bit or smaller*/ use %icc
141// }
142//
143// Note: The third name (%ccr) is essentially an assembly mnemonic and
144// depends solely on the opcode, so the name can be chosen in EmitAssembly.
145//-----------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000146void SparcV9IntCCRegClass::colorIGNode(IGNode *Node,
Vikram S. Adve536b1922003-07-25 21:12:15 +0000147 const std::vector<bool> &IsColorUsedArr) const
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000148{
Vikram S. Adve65280672003-07-10 19:42:11 +0000149 if (Node->getNumOfNeighbors() > 0)
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000150 Node->getParentLR()->markForSpill();
Vikram S. Adve65280672003-07-10 19:42:11 +0000151
152 // Mark the appropriate register in any case (even if it needs to be spilled)
153 // because there is only one possible register, but more importantly, the
154 // spill algorithm cannot find it. In particular, we have to choose
155 // whether to use %xcc or %icc based on type of value compared
156 //
157 const LiveRange* ccLR = Node->getParentLR();
158 const Type* setCCType = (* ccLR->begin())->getType(); // any Value in LR
159 assert(setCCType->isIntegral() || isa<PointerType>(setCCType));
160 int ccReg = ((isa<PointerType>(setCCType) || setCCType == Type::LongTy)
161 ? xcc : icc);
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000162
163#ifndef NDEBUG
Vikram S. Adve65280672003-07-10 19:42:11 +0000164 // Let's just make sure values of two different types have not been
165 // coalesced into this LR.
166 for (ValueSet::const_iterator I=ccLR->begin(), E=ccLR->end(); I!=E; ++I) {
167 const Type* ccType = (*I)->getType();
168 assert((ccReg == xcc && (isa<PointerType>(ccType)
169 || ccType == Type::LongTy)) ||
170 (ccReg == icc && ccType->isIntegral() && ccType != Type::LongTy)
171 && "Comparisons needing different intCC regs coalesced in LR!");
172 }
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000173#endif
174
Vikram S. Adve65280672003-07-10 19:42:11 +0000175 Node->setColor(ccReg); // only one int cc reg is available
Vikram S. Adved09c4c32003-07-06 20:13:59 +0000176}
177
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000178
Brian Gaeke94e95d22004-02-25 18:44:15 +0000179void SparcV9FloatCCRegClass::colorIGNode(IGNode *Node,
Chris Lattner33238292003-09-01 19:56:48 +0000180 const std::vector<bool> &IsColorUsedArr) const {
181 for(unsigned c = 0; c != 4; ++c)
182 if (!IsColorUsedArr[c]) { // find unused color
183 Node->setColor(c);
184 return;
185 }
186
187 Node->getParentLR()->markForSpill();
188}
189
190
191
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000192//-----------------------------------------------------------------------------
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000193// Float Register Class - method for coloring a node in the interference graph.
194//
195// Algorithm:
196//
197// If the LR is a double try to allocate f32 - f63
198// If the above fails or LR is single precision
199// If the LR does not interfere with a call
200// start allocating from f0
201// Else start allocating from f6
202// If a color is still not found because LR interferes with a call
203// Search in f0 - f6. If found mark for spill across calls.
204// If a color is still not fond, mark for spilling
205//
206//----------------------------------------------------------------------------
Brian Gaeke94e95d22004-02-25 18:44:15 +0000207void SparcV9FloatRegClass::colorIGNode(IGNode * Node,
Vikram S. Adve536b1922003-07-25 21:12:15 +0000208 const std::vector<bool> &IsColorUsedArr) const
Misha Brukman352f7ac2003-05-21 17:59:06 +0000209{
Chris Lattnerd30f9892002-02-05 03:52:29 +0000210 LiveRange *LR = Node->getParentLR();
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000211
Vikram S. Adve536b1922003-07-25 21:12:15 +0000212#ifndef NDEBUG
213 // Check that the correct colors have been are marked for fp-doubles.
214 //
215 // FIXME: This is old code that is no longer needed. Temporarily converting
216 // it into a big assertion just to check that the replacement logic
Brian Gaeke94e95d22004-02-25 18:44:15 +0000217 // (invoking SparcV9FloatRegClass::markColorsUsed() directly from
Vikram S. Adve536b1922003-07-25 21:12:15 +0000218 // RegClass::colorIGNode) works correctly.
219 //
220 // In fact, this entire function should be identical to
Brian Gaeke94e95d22004-02-25 18:44:15 +0000221 // SparcV9IntRegClass::colorIGNode(), and perhaps can be
Vikram S. Adve536b1922003-07-25 21:12:15 +0000222 // made into a general case in CodeGen/RegAlloc/RegClass.cpp.
Vikram S. Advee9327f02002-05-19 15:25:51 +0000223 //
224 unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000225 for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh
226 IGNode *NeighIGNode = Node->getAdjIGNode(n);
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000227 LiveRange *NeighLR = NeighIGNode->getParentLR();
Vikram S. Advee9327f02002-05-19 15:25:51 +0000228
Vikram S. Adve49cf0912003-09-21 07:55:27 +0000229 if (NeighLR->hasColor()) {
230 assert(IsColorUsedArr[ NeighLR->getColor() ]);
231 if (NeighLR->getType() == Type::DoubleTy)
232 assert(IsColorUsedArr[ NeighLR->getColor()+1 ]);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000233
234 } else if (NeighLR->hasSuggestedColor() &&
235 NeighLR-> isSuggestedColorUsable() ) {
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000236
Misha Brukman2a651d72003-05-21 18:05:35 +0000237 // if the neighbour can use the suggested color
Vikram S. Adve536b1922003-07-25 21:12:15 +0000238 assert(IsColorUsedArr[ NeighLR->getSuggestedColor() ]);
Misha Brukman2a651d72003-05-21 18:05:35 +0000239 if (NeighLR->getType() == Type::DoubleTy)
Vikram S. Adve536b1922003-07-25 21:12:15 +0000240 assert(IsColorUsedArr[ NeighLR->getSuggestedColor()+1 ]);
Vikram S. Advee9327f02002-05-19 15:25:51 +0000241 }
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000242 }
Vikram S. Adve536b1922003-07-25 21:12:15 +0000243#endif
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000244
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +0000245 // **NOTE: We don't check for call interferences in allocating suggested
246 // color in this class since ALL registers are volatile. If this fact
247 // changes, we should change the following part
Brian Gaeke94e95d22004-02-25 18:44:15 +0000248 //- see SparcV9IntRegClass::colorIGNode()
Vikram S. Advee9327f02002-05-19 15:25:51 +0000249 //
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000250 if( LR->hasSuggestedColor() ) {
251 if( ! IsColorUsedArr[ LR->getSuggestedColor() ] ) {
252 LR->setColor( LR->getSuggestedColor() );
253 return;
Chris Lattnerb0af9cd2002-02-05 02:52:05 +0000254 } else if (DEBUG_RA) { // can't allocate the suggested col
Misha Brukman352f7ac2003-05-21 17:59:06 +0000255 std::cerr << " Could NOT allocate the suggested color for LR ";
256 printSet(*LR); std::cerr << "\n";
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000257 }
258 }
259
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000260
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000261 int ColorFound = -1; // have we found a color yet?
Ruchira Sasankad77a1bb2001-10-19 17:23:43 +0000262 bool isCallInterf = LR->isCallInterference();
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000263
Chris Lattnerabe98192002-05-23 15:50:03 +0000264 // if value is a double - search the double only region (f32 - f63)
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000265 // i.e. we try to allocate f32 - f63 first for doubles since singles
266 // cannot go there. By doing that, we provide more space for singles
267 // in f0 - f31
268 //
Chris Lattnerd30f9892002-02-05 03:52:29 +0000269 if (LR->getType() == Type::DoubleTy)
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000270 ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr );
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000271
Misha Brukman2a651d72003-05-21 18:05:35 +0000272 if (ColorFound >= 0) { // if we could find a color
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000273 LR->setColor(ColorFound);
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000274 return;
Chris Lattner5216cc52002-02-04 05:59:25 +0000275 } else {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000276
Misha Brukman8b2bd4e2003-10-10 17:57:28 +0000277 // if we didn't find a color because the LR was single precision or
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000278 // all f32-f63 range is filled, we try to allocate a register from
279 // the f0 - f31 region
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000280
281 unsigned SearchStart; // start pos of color in pref-order
282
283 //if this Node is between calls (i.e., no call interferences )
Misha Brukman2a651d72003-05-21 18:05:35 +0000284 if (! isCallInterf) {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000285 // start with volatiles (we can allocate volatiles safely)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000286 SearchStart = SparcV9FloatRegClass::StartOfAllRegs;
Misha Brukman2a651d72003-05-21 18:05:35 +0000287 } else {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000288 // start with non volatiles (no non-volatiles)
Brian Gaeke94e95d22004-02-25 18:44:15 +0000289 SearchStart = SparcV9FloatRegClass::StartOfNonVolatileRegs;
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000290 }
291
Misha Brukman2a651d72003-05-21 18:05:35 +0000292 ColorFound = findFloatColor(LR, SearchStart, 32, IsColorUsedArr);
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000293 }
294
Misha Brukman2a651d72003-05-21 18:05:35 +0000295 if (ColorFound >= 0) { // if we could find a color
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000296 LR->setColor(ColorFound);
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000297 return;
Misha Brukman2a651d72003-05-21 18:05:35 +0000298 } else if (isCallInterf) {
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000299 // We are here because there is a call interference and no non-volatile
300 // color could be found.
301 // Now try to allocate even a volatile color
Brian Gaeke94e95d22004-02-25 18:44:15 +0000302 ColorFound = findFloatColor(LR, SparcV9FloatRegClass::StartOfAllRegs,
303 SparcV9FloatRegClass::StartOfNonVolatileRegs,
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000304 IsColorUsedArr);
305 }
306
Misha Brukman2a651d72003-05-21 18:05:35 +0000307 if (ColorFound >= 0) {
Misha Brukman8b2bd4e2003-10-10 17:57:28 +0000308 LR->setColor(ColorFound); // first color found in preferred order
Ruchira Sasanka5867c7a2001-09-30 23:16:47 +0000309 LR->markForSaveAcrossCalls();
Chris Lattner5216cc52002-02-04 05:59:25 +0000310 } else {
311 // we are here because no color could be found
312 LR->markForSpill(); // no color found - must spill
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000313 }
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000314}
315
Vikram S. Adve536b1922003-07-25 21:12:15 +0000316//-----------------------------------------------------------------------------
317// This method marks the registers used for a given register number.
318// This marks a single register for Float regs, but the R,R+1 pair
319// for double-precision registers.
320//-----------------------------------------------------------------------------
321
Brian Gaeke94e95d22004-02-25 18:44:15 +0000322void SparcV9FloatRegClass::markColorsUsed(unsigned RegInClass,
Vikram S. Adve536b1922003-07-25 21:12:15 +0000323 int UserRegType,
324 int RegTypeWanted,
325 std::vector<bool> &IsColorUsedArr) const
326{
Brian Gaeke94e95d22004-02-25 18:44:15 +0000327 if (UserRegType == SparcV9RegInfo::FPDoubleRegType ||
328 RegTypeWanted == SparcV9RegInfo::FPDoubleRegType) {
Vikram S. Adve536b1922003-07-25 21:12:15 +0000329 // This register is used as or is needed as a double-precision reg.
330 // We need to mark the [even,odd] pair corresponding to this reg.
331 // Get the even numbered register corresponding to this reg.
332 unsigned EvenRegInClass = RegInClass & ~1u;
333 assert(EvenRegInClass+1 < NumOfAllRegs &&
334 EvenRegInClass+1 < IsColorUsedArr.size());
335 IsColorUsedArr[EvenRegInClass] = true;
336 IsColorUsedArr[EvenRegInClass+1] = true;
337 }
338 else {
339 assert(RegInClass < NumOfAllRegs && RegInClass < IsColorUsedArr.size());
340 assert(UserRegType == RegTypeWanted
341 && "Something other than FP single/double types share a reg class?");
342 IsColorUsedArr[RegInClass] = true;
343 }
344}
345
346// This method finds unused registers of the specified register type,
347// using the given "used" flag array IsColorUsedArr. It checks a single
348// entry in the array directly for float regs, and checks the pair [R,R+1]
349// for double-precision registers
350// It returns -1 if no unused color is found.
351//
Brian Gaeke94e95d22004-02-25 18:44:15 +0000352int SparcV9FloatRegClass::findUnusedColor(int RegTypeWanted,
Vikram S. Adve536b1922003-07-25 21:12:15 +0000353 const std::vector<bool> &IsColorUsedArr) const
354{
Brian Gaeke94e95d22004-02-25 18:44:15 +0000355 if (RegTypeWanted == SparcV9RegInfo::FPDoubleRegType) {
Vikram S. Adve536b1922003-07-25 21:12:15 +0000356 unsigned NC = 2 * this->getNumOfAvailRegs();
357 assert(IsColorUsedArr.size() == NC && "Invalid colors-used array");
358 for (unsigned c = 0; c < NC; c+=2)
359 if (!IsColorUsedArr[c]) {
360 assert(!IsColorUsedArr[c+1] && "Incorrect used regs for FP double!");
361 return c;
362 }
363 return -1;
364 }
365 else
366 return TargetRegClassInfo::findUnusedColor(RegTypeWanted, IsColorUsedArr);
367}
Ruchira Sasankadfc6c882001-09-18 22:52:44 +0000368
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000369//-----------------------------------------------------------------------------
370// Helper method for coloring a node of Float Reg class.
371// Finds the first available color in the range [Start,End] depending on the
372// type of the Node (i.e., float/double)
373//-----------------------------------------------------------------------------
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000374
Brian Gaeke94e95d22004-02-25 18:44:15 +0000375int SparcV9FloatRegClass::findFloatColor(const LiveRange *LR,
Misha Brukman2a651d72003-05-21 18:05:35 +0000376 unsigned Start,
377 unsigned End,
Vikram S. Adve536b1922003-07-25 21:12:15 +0000378 const std::vector<bool> &IsColorUsedArr) const
Misha Brukman352f7ac2003-05-21 17:59:06 +0000379{
Chris Lattnerd30f9892002-02-05 03:52:29 +0000380 if (LR->getType() == Type::DoubleTy) {
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000381 // find first unused color for a double
Vikram S. Adve536b1922003-07-25 21:12:15 +0000382 assert(Start % 2 == 0 && "Odd register number could be used for double!");
383 for (unsigned c=Start; c < End ; c+= 2)
384 if (!IsColorUsedArr[c]) {
385 assert(!IsColorUsedArr[c+1] &&
Brian Gaeke94e95d22004-02-25 18:44:15 +0000386 "Incorrect marking of used regs for SparcV9 FP double!");
Chris Lattner5216cc52002-02-04 05:59:25 +0000387 return c;
Vikram S. Adve536b1922003-07-25 21:12:15 +0000388 }
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000389 } else {
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000390 // find first unused color for a single
Vikram S. Adve536b1922003-07-25 21:12:15 +0000391 for (unsigned c = Start; c < End; c++)
Chris Lattner5216cc52002-02-04 05:59:25 +0000392 if (!IsColorUsedArr[c])
393 return c;
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000394 }
Vikram S. Adve536b1922003-07-25 21:12:15 +0000395
Chris Lattner5216cc52002-02-04 05:59:25 +0000396 return -1;
Vikram S. Adve536b1922003-07-25 21:12:15 +0000397
Ruchira Sasanka4cfbfd52002-01-07 19:20:28 +0000398}
Brian Gaeke960707c2003-11-11 22:41:34 +0000399
400} // End llvm namespace