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