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