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