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