Chris Lattner | 9568568 | 2002-08-12 21:25:05 +0000 | [diff] [blame] | 1 | //===-- 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 Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 7 | #include "SparcRegClassInfo.h" |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame] | 8 | #include "llvm/Type.h" |
Chris Lattner | 0e10433 | 2003-01-15 19:50:44 +0000 | [diff] [blame] | 9 | #include "../../CodeGen/RegAlloc/RegAllocCommon.h" // FIXME! |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 10 | |
| 11 | //----------------------------------------------------------------------------- |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 12 | // Int Register Class - method for coloring a node in the interference graph. |
| 13 | // |
| 14 | // Algorithm: |
| 15 | // Record the colors/suggested colors of all neighbors. |
| 16 | // |
| 17 | // If there is a suggested color, try to allocate it |
| 18 | // If there is no call interf, try to allocate volatile, then non volatile |
| 19 | // If there is call interf, try to allocate non-volatile. If that fails |
| 20 | // try to allocate a volatile and insert save across calls |
| 21 | // If both above fail, spill. |
| 22 | // |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 23 | //----------------------------------------------------------------------------- |
Misha Brukman | ee563cb | 2003-05-21 17:59:06 +0000 | [diff] [blame] | 24 | void SparcIntRegClass::colorIGNode(IGNode * Node, |
| 25 | std::vector<bool> &IsColorUsedArr) const |
| 26 | { |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 27 | LiveRange *LR = Node->getParentLR(); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 28 | |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 29 | if (DEBUG_RA) { |
Misha Brukman | ee563cb | 2003-05-21 17:59:06 +0000 | [diff] [blame] | 30 | std::cerr << "\nColoring LR [CallInt=" << LR->isCallInterference() <<"]:"; |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 31 | printSet(*LR); |
Ruchira Sasanka | 0f5e988 | 2001-10-19 17:23:43 +0000 | [diff] [blame] | 32 | } |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 33 | |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 34 | if (LR->hasSuggestedColor()) { |
Ruchira Sasanka | 0f5e988 | 2001-10-19 17:23:43 +0000 | [diff] [blame] | 35 | unsigned SugCol = LR->getSuggestedColor(); |
Chris Lattner | 85c5465 | 2002-05-23 15:50:03 +0000 | [diff] [blame] | 36 | if (!IsColorUsedArr[SugCol]) { |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 37 | if (LR->isSuggestedColorUsable()) { |
Ruchira Sasanka | 0f5e988 | 2001-10-19 17:23:43 +0000 | [diff] [blame] | 38 | // if the suggested color is volatile, we should use it only if |
| 39 | // there are no call interferences. Otherwise, it will get spilled. |
Ruchira Sasanka | 0f5e988 | 2001-10-19 17:23:43 +0000 | [diff] [blame] | 40 | if (DEBUG_RA) |
Misha Brukman | ee563cb | 2003-05-21 17:59:06 +0000 | [diff] [blame] | 41 | std::cerr << "\n -Coloring with sug color: " << SugCol; |
Ruchira Sasanka | 0f5e988 | 2001-10-19 17:23:43 +0000 | [diff] [blame] | 42 | |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 43 | LR->setColor(LR->getSuggestedColor()); |
Ruchira Sasanka | 0f5e988 | 2001-10-19 17:23:43 +0000 | [diff] [blame] | 44 | return; |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 45 | } else if(DEBUG_RA) { |
Misha Brukman | c97a207 | 2003-05-21 19:34:28 +0000 | [diff] [blame] | 46 | std::cerr << "\n Couldn't alloc Sug col - LR volatile & calls interf"; |
Ruchira Sasanka | 0f5e988 | 2001-10-19 17:23:43 +0000 | [diff] [blame] | 47 | } |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 48 | } else if (DEBUG_RA) { // can't allocate the suggested col |
Misha Brukman | ee563cb | 2003-05-21 17:59:06 +0000 | [diff] [blame] | 49 | std::cerr << "\n Could NOT allocate the suggested color (already used) "; |
| 50 | printSet(*LR); std::cerr << "\n"; |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 51 | } |
| 52 | } |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 53 | |
| 54 | unsigned SearchStart; // start pos of color in pref-order |
| 55 | bool ColorFound= false; // have we found a color yet? |
| 56 | |
| 57 | //if this Node is between calls |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 58 | if (! LR->isCallInterference()) { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 59 | // start with volatiles (we can allocate volatiles safely) |
Chris Lattner | 9568568 | 2002-08-12 21:25:05 +0000 | [diff] [blame] | 60 | SearchStart = SparcIntRegClass::StartOfAllRegs; |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 61 | } else { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 62 | // start with non volatiles (no non-volatiles) |
Chris Lattner | 9568568 | 2002-08-12 21:25:05 +0000 | [diff] [blame] | 63 | SearchStart = SparcIntRegClass::StartOfNonVolatileRegs; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | unsigned c=0; // color |
| 67 | |
| 68 | // find first unused color |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 69 | for (c=SearchStart; c < SparcIntRegClass::NumOfAvailRegs; c++) { |
| 70 | if (!IsColorUsedArr[c]) { |
| 71 | ColorFound = true; |
| 72 | break; |
| 73 | } |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 76 | if (ColorFound) { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 77 | LR->setColor(c); // first color found in preffered order |
Misha Brukman | ee563cb | 2003-05-21 17:59:06 +0000 | [diff] [blame] | 78 | if (DEBUG_RA) std::cerr << "\n Colored after first search with col " << c; |
Ruchira Sasanka | 0f5e988 | 2001-10-19 17:23:43 +0000 | [diff] [blame] | 79 | } |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 80 | |
| 81 | // if color is not found because of call interference |
| 82 | // try even finding a volatile color and insert save across calls |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 83 | // |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 84 | else if (LR->isCallInterference()) { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 85 | // start from 0 - try to find even a volatile this time |
Chris Lattner | 9568568 | 2002-08-12 21:25:05 +0000 | [diff] [blame] | 86 | SearchStart = SparcIntRegClass::StartOfAllRegs; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 87 | |
| 88 | // find first unused volatile color |
Chris Lattner | 9568568 | 2002-08-12 21:25:05 +0000 | [diff] [blame] | 89 | for(c=SearchStart; c < SparcIntRegClass::StartOfNonVolatileRegs; c++) { |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 90 | if (! IsColorUsedArr[c]) { |
| 91 | ColorFound = true; |
| 92 | break; |
| 93 | } |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 96 | if (ColorFound) { |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 97 | LR->setColor(c); |
| 98 | // get the live range corresponding to live var |
| 99 | // since LR span across calls, must save across calls |
| 100 | // |
| 101 | LR->markForSaveAcrossCalls(); |
| 102 | if (DEBUG_RA) |
| 103 | std::cerr << "\n Colored after SECOND search with col " << c; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 104 | } |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 107 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 108 | // If we couldn't find a color regardless of call interference - i.e., we |
| 109 | // don't have either a volatile or non-volatile color left |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 110 | // |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 111 | if (!ColorFound) |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 112 | LR->markForSpill(); // no color found - must spill |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Vikram S. Adve | 786833a | 2003-07-06 20:13:59 +0000 | [diff] [blame^] | 115 | //----------------------------------------------------------------------------- |
| 116 | // Int CC Register Class - method for coloring a node in the interference graph. |
| 117 | // |
| 118 | // Algorithm: |
| 119 | // |
| 120 | // If the single int CC register is used (either as icc or xcc) |
| 121 | // mark the LR for spilling |
| 122 | // else { |
| 123 | // if (the LR is a 64-bit comparison) use %xcc |
| 124 | // else /*32-bit or smaller*/ use %icc |
| 125 | // } |
| 126 | // |
| 127 | // Note: The third name (%ccr) is essentially an assembly mnemonic and |
| 128 | // depends solely on the opcode, so the name can be chosen in EmitAssembly. |
| 129 | //----------------------------------------------------------------------------- |
| 130 | void SparcIntCCRegClass::colorIGNode(IGNode *Node, |
| 131 | std::vector<bool> &IsColorUsedArr) const |
| 132 | { |
| 133 | if (IsColorUsedArr[xcc] && IsColorUsedArr[icc]) |
| 134 | Node->getParentLR()->markForSpill(); |
| 135 | else { |
| 136 | // Choose whether to use %xcc or %icc based on type of value compared |
| 137 | const LiveRange* ccLR = Node->getParentLR(); |
| 138 | const Type* setCCType = (* ccLR->begin())->getType(); // any Value in LR |
| 139 | assert(setCCType->isIntegral()); |
| 140 | int ccReg = (setCCType == Type::LongTy)? xcc : icc; |
| 141 | |
| 142 | #ifndef NDEBUG |
| 143 | // Let's just make sure values of two different types have not been |
| 144 | // coalesced into this LR. |
| 145 | for (ValueSet::const_iterator I=ccLR->begin(), E=ccLR->end(); I != E; ++I) |
| 146 | assert(setCCType->isIntegral() && |
| 147 | ((ccReg == xcc && (*I)->getType() == Type::LongTy) || |
| 148 | (ccReg == icc && (*I)->getType() != Type::LongTy)) |
| 149 | && "Comparisons needing different intCC regs coalesced in LR!"); |
| 150 | #endif |
| 151 | |
| 152 | Node->setColor(ccReg); // only one int cc reg is available |
| 153 | } |
| 154 | } |
| 155 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 156 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 157 | //----------------------------------------------------------------------------- |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 158 | // Float Register Class - method for coloring a node in the interference graph. |
| 159 | // |
| 160 | // Algorithm: |
| 161 | // |
| 162 | // If the LR is a double try to allocate f32 - f63 |
| 163 | // If the above fails or LR is single precision |
| 164 | // If the LR does not interfere with a call |
| 165 | // start allocating from f0 |
| 166 | // Else start allocating from f6 |
| 167 | // If a color is still not found because LR interferes with a call |
| 168 | // Search in f0 - f6. If found mark for spill across calls. |
| 169 | // If a color is still not fond, mark for spilling |
| 170 | // |
| 171 | //---------------------------------------------------------------------------- |
Chris Lattner | 85c5465 | 2002-05-23 15:50:03 +0000 | [diff] [blame] | 172 | void SparcFloatRegClass::colorIGNode(IGNode * Node, |
Misha Brukman | ee563cb | 2003-05-21 17:59:06 +0000 | [diff] [blame] | 173 | std::vector<bool> &IsColorUsedArr) const |
| 174 | { |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame] | 175 | LiveRange *LR = Node->getParentLR(); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 176 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 177 | // Mark the second color for double-precision registers: |
| 178 | // This is UGLY and should be merged into nearly identical code |
| 179 | // in RegClass::colorIGNode that handles the first color. |
| 180 | // |
| 181 | unsigned NumNeighbors = Node->getNumOfNeighbors(); // total # of neighbors |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 182 | for(unsigned n=0; n < NumNeighbors; n++) { // for each neigh |
| 183 | IGNode *NeighIGNode = Node->getAdjIGNode(n); |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 184 | LiveRange *NeighLR = NeighIGNode->getParentLR(); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 185 | |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 186 | if (NeighLR->hasColor() && |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 187 | NeighLR->getType() == Type::DoubleTy) { |
| 188 | IsColorUsedArr[ (NeighLR->getColor()) + 1 ] = true; |
| 189 | |
| 190 | } else if (NeighLR->hasSuggestedColor() && |
| 191 | NeighLR-> isSuggestedColorUsable() ) { |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 192 | |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 193 | // if the neighbour can use the suggested color |
| 194 | IsColorUsedArr[ NeighLR->getSuggestedColor() ] = true; |
| 195 | if (NeighLR->getType() == Type::DoubleTy) |
| 196 | IsColorUsedArr[ (NeighLR->getSuggestedColor()) + 1 ] = true; |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 197 | } |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Ruchira Sasanka | 0f5e988 | 2001-10-19 17:23:43 +0000 | [diff] [blame] | 200 | // **NOTE: We don't check for call interferences in allocating suggested |
| 201 | // color in this class since ALL registers are volatile. If this fact |
| 202 | // changes, we should change the following part |
| 203 | //- see SparcIntRegClass::colorIGNode() |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 204 | // |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 205 | if( LR->hasSuggestedColor() ) { |
| 206 | if( ! IsColorUsedArr[ LR->getSuggestedColor() ] ) { |
| 207 | LR->setColor( LR->getSuggestedColor() ); |
| 208 | return; |
Chris Lattner | 296b773 | 2002-02-05 02:52:05 +0000 | [diff] [blame] | 209 | } else if (DEBUG_RA) { // can't allocate the suggested col |
Misha Brukman | ee563cb | 2003-05-21 17:59:06 +0000 | [diff] [blame] | 210 | std::cerr << " Could NOT allocate the suggested color for LR "; |
| 211 | printSet(*LR); std::cerr << "\n"; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 215 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 216 | int ColorFound = -1; // have we found a color yet? |
Ruchira Sasanka | 0f5e988 | 2001-10-19 17:23:43 +0000 | [diff] [blame] | 217 | bool isCallInterf = LR->isCallInterference(); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 218 | |
Chris Lattner | 85c5465 | 2002-05-23 15:50:03 +0000 | [diff] [blame] | 219 | // if value is a double - search the double only region (f32 - f63) |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 220 | // i.e. we try to allocate f32 - f63 first for doubles since singles |
| 221 | // cannot go there. By doing that, we provide more space for singles |
| 222 | // in f0 - f31 |
| 223 | // |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame] | 224 | if (LR->getType() == Type::DoubleTy) |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 225 | ColorFound = findFloatColor( LR, 32, 64, IsColorUsedArr ); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 226 | |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 227 | if (ColorFound >= 0) { // if we could find a color |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 228 | LR->setColor(ColorFound); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 229 | return; |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 230 | } else { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 231 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 232 | // if we didn't find a color becuase the LR was single precision or |
| 233 | // all f32-f63 range is filled, we try to allocate a register from |
| 234 | // the f0 - f31 region |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 235 | |
| 236 | unsigned SearchStart; // start pos of color in pref-order |
| 237 | |
| 238 | //if this Node is between calls (i.e., no call interferences ) |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 239 | if (! isCallInterf) { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 240 | // start with volatiles (we can allocate volatiles safely) |
Chris Lattner | 9568568 | 2002-08-12 21:25:05 +0000 | [diff] [blame] | 241 | SearchStart = SparcFloatRegClass::StartOfAllRegs; |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 242 | } else { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 243 | // start with non volatiles (no non-volatiles) |
Chris Lattner | 9568568 | 2002-08-12 21:25:05 +0000 | [diff] [blame] | 244 | SearchStart = SparcFloatRegClass::StartOfNonVolatileRegs; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 247 | ColorFound = findFloatColor(LR, SearchStart, 32, IsColorUsedArr); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 250 | if (ColorFound >= 0) { // if we could find a color |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 251 | LR->setColor(ColorFound); |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 252 | return; |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 253 | } else if (isCallInterf) { |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 254 | // We are here because there is a call interference and no non-volatile |
| 255 | // color could be found. |
| 256 | // Now try to allocate even a volatile color |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 257 | ColorFound = findFloatColor(LR, SparcFloatRegClass::StartOfAllRegs, |
Chris Lattner | 9568568 | 2002-08-12 21:25:05 +0000 | [diff] [blame] | 258 | SparcFloatRegClass::StartOfNonVolatileRegs, |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 259 | IsColorUsedArr); |
| 260 | } |
| 261 | |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 262 | if (ColorFound >= 0) { |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 263 | LR->setColor(ColorFound); // first color found in prefered order |
Ruchira Sasanka | 9144228 | 2001-09-30 23:16:47 +0000 | [diff] [blame] | 264 | LR->markForSaveAcrossCalls(); |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 265 | } else { |
| 266 | // we are here because no color could be found |
| 267 | LR->markForSpill(); // no color found - must spill |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 268 | } |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 272 | //----------------------------------------------------------------------------- |
| 273 | // Helper method for coloring a node of Float Reg class. |
| 274 | // Finds the first available color in the range [Start,End] depending on the |
| 275 | // type of the Node (i.e., float/double) |
| 276 | //----------------------------------------------------------------------------- |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 277 | |
Misha Brukman | 77c9fcb | 2003-05-21 18:05:35 +0000 | [diff] [blame] | 278 | int SparcFloatRegClass::findFloatColor(const LiveRange *LR, |
| 279 | unsigned Start, |
| 280 | unsigned End, |
| 281 | std::vector<bool> &IsColorUsedArr) const |
Misha Brukman | ee563cb | 2003-05-21 17:59:06 +0000 | [diff] [blame] | 282 | { |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 283 | bool ColorFound = false; |
| 284 | unsigned c; |
| 285 | |
Chris Lattner | 3773094 | 2002-02-05 03:52:29 +0000 | [diff] [blame] | 286 | if (LR->getType() == Type::DoubleTy) { |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 287 | // find first unused color for a double |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 288 | for (c=Start; c < End ; c+= 2) |
| 289 | if (!IsColorUsedArr[c] && !IsColorUsedArr[c+1]) |
| 290 | return c; |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 291 | } else { |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 292 | // find first unused color for a single |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 293 | for (c = Start; c < End; c++) |
| 294 | if (!IsColorUsedArr[c]) |
| 295 | return c; |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Chris Lattner | 699683c | 2002-02-04 05:59:25 +0000 | [diff] [blame] | 298 | return -1; |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 299 | } |