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