buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "Dalvik.h" |
| 18 | #include "CompilerInternals.h" |
| 19 | #include "Dataflow.h" |
| 20 | #include "codegen/Ralloc.h" |
| 21 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 22 | STATIC bool setFp(CompilationUnit* cUnit, int index, bool isFP) { |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 23 | bool change = false; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 24 | if (cUnit->regLocation[index].highWord) { |
| 25 | return change; |
| 26 | } |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 27 | if (isFP && !cUnit->regLocation[index].fp) { |
| 28 | cUnit->regLocation[index].fp = true; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 29 | cUnit->regLocation[index].defined = true; |
| 30 | change = true; |
| 31 | } |
| 32 | return change; |
| 33 | } |
| 34 | |
| 35 | STATIC bool setCore(CompilationUnit* cUnit, int index, bool isCore) { |
| 36 | bool change = false; |
| 37 | if (cUnit->regLocation[index].highWord) { |
| 38 | return change; |
| 39 | } |
| 40 | if (isCore && !cUnit->regLocation[index].defined) { |
| 41 | cUnit->regLocation[index].core = true; |
| 42 | cUnit->regLocation[index].defined = true; |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 43 | change = true; |
| 44 | } |
| 45 | return change; |
| 46 | } |
| 47 | |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 48 | STATIC bool remapNames(CompilationUnit* cUnit, BasicBlock* bb) |
| 49 | { |
| 50 | if (bb->blockType != kDalvikByteCode && bb->blockType != kEntryBlock && |
| 51 | bb->blockType != kExitBlock) |
| 52 | return false; |
| 53 | |
| 54 | for (MIR* mir = bb->firstMIRInsn; mir; mir = mir->next) { |
| 55 | SSARepresentation *ssaRep = mir->ssaRep; |
| 56 | if (ssaRep) { |
| 57 | for (int i = 0; i < ssaRep->numUses; i++) { |
| 58 | ssaRep->uses[i] = cUnit->phiAliasMap[ssaRep->uses[i]]; |
| 59 | } |
| 60 | for (int i = 0; i < ssaRep->numDefs; i++) { |
| 61 | ssaRep->defs[i] = cUnit->phiAliasMap[ssaRep->defs[i]]; |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | return false; |
| 66 | } |
| 67 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 68 | /* |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 69 | * Infer types and sizes. We don't need to track change on sizes, |
| 70 | * as it doesn't propagate. We're guaranteed at least one pass through |
| 71 | * the cfg. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 72 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 73 | STATIC bool inferTypeAndSize(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 74 | { |
| 75 | MIR *mir; |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 76 | bool changed = false; // Did anything change? |
| 77 | |
| 78 | if (bb->dataFlowInfo == NULL) return false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 79 | if (bb->blockType != kDalvikByteCode && bb->blockType != kEntryBlock) |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 80 | return false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 81 | |
| 82 | for (mir = bb->firstMIRInsn; mir; mir = mir->next) { |
| 83 | SSARepresentation *ssaRep = mir->ssaRep; |
| 84 | if (ssaRep) { |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 85 | int attrs = oatDataFlowAttributes[mir->dalvikInsn.opcode]; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 86 | |
| 87 | // Handle defs |
| 88 | if (attrs & (DF_DA | DF_DA_WIDE)) { |
| 89 | if (attrs & DF_CORE_A) { |
| 90 | changed |= setCore(cUnit, ssaRep->defs[0], true); |
| 91 | } |
| 92 | if (attrs & DF_DA_WIDE) { |
| 93 | cUnit->regLocation[ssaRep->defs[0]].wide = true; |
| 94 | cUnit->regLocation[ssaRep->defs[1]].highWord = true; |
| 95 | DCHECK_EQ(oatS2VReg(cUnit, ssaRep->defs[0])+1, |
| 96 | oatS2VReg(cUnit, ssaRep->defs[1])); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // Handles uses |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 101 | int next = 0; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 102 | if (attrs & (DF_UA | DF_UA_WIDE)) { |
| 103 | if (attrs & DF_CORE_A) { |
| 104 | changed |= setCore(cUnit, ssaRep->uses[next], true); |
| 105 | } |
| 106 | if (attrs & DF_UA_WIDE) { |
| 107 | cUnit->regLocation[ssaRep->uses[next]].wide = true; |
| 108 | cUnit->regLocation[ssaRep->uses[next + 1]].highWord = true; |
| 109 | DCHECK_EQ(oatS2VReg(cUnit, ssaRep->uses[next])+1, |
| 110 | oatS2VReg(cUnit, ssaRep->uses[next + 1])); |
| 111 | next += 2; |
| 112 | } else { |
| 113 | next++; |
| 114 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 115 | } |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 116 | if (attrs & (DF_UB | DF_UB_WIDE)) { |
| 117 | if (attrs & DF_CORE_B) { |
| 118 | changed |= setCore(cUnit, ssaRep->uses[next], true); |
| 119 | } |
| 120 | if (attrs & DF_UB_WIDE) { |
| 121 | cUnit->regLocation[ssaRep->uses[next]].wide = true; |
| 122 | cUnit->regLocation[ssaRep->uses[next + 1]].highWord = true; |
| 123 | DCHECK_EQ(oatS2VReg(cUnit, ssaRep->uses[next])+1, |
| 124 | oatS2VReg(cUnit, ssaRep->uses[next + 1])); |
| 125 | next += 2; |
| 126 | } else { |
| 127 | next++; |
| 128 | } |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 129 | } |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 130 | if (attrs & (DF_UC | DF_UC_WIDE)) { |
| 131 | if (attrs & DF_CORE_C) { |
| 132 | changed |= setCore(cUnit, ssaRep->uses[next], true); |
| 133 | } |
| 134 | if (attrs & DF_UC_WIDE) { |
| 135 | cUnit->regLocation[ssaRep->uses[next]].wide = true; |
| 136 | cUnit->regLocation[ssaRep->uses[next + 1]].highWord = true; |
| 137 | DCHECK_EQ(oatS2VReg(cUnit, ssaRep->uses[next])+1, |
| 138 | oatS2VReg(cUnit, ssaRep->uses[next + 1])); |
| 139 | } |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 140 | } |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 141 | |
| 142 | // Special-case handling for format 35c/3rc invokes |
| 143 | Opcode opcode = mir->dalvikInsn.opcode; |
| 144 | int flags = (opcode >= kNumPackedOpcodes) ? 0 : |
| 145 | dexGetFlagsFromOpcode(opcode); |
| 146 | if ((flags & kInstrInvoke) && |
| 147 | (attrs & (DF_FORMAT_35C | DF_FORMAT_3RC))) { |
| 148 | DCHECK_EQ(next, 0); |
| 149 | int target_idx = mir->dalvikInsn.vB; |
| 150 | const char* shorty = |
| 151 | oatGetShortyFromTargetIdx(cUnit, target_idx); |
| 152 | int numUses = mir->dalvikInsn.vA; |
| 153 | // If this is a non-static invoke, skip implicit "this" |
| 154 | if (((mir->dalvikInsn.opcode != OP_INVOKE_STATIC) && |
| 155 | (mir->dalvikInsn.opcode != OP_INVOKE_STATIC_RANGE))) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 156 | cUnit->regLocation[ssaRep->uses[next]].defined = true; |
| 157 | cUnit->regLocation[ssaRep->uses[next]].core = true; |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 158 | next++; |
| 159 | } |
| 160 | uint32_t cpos = 1; |
| 161 | if (strlen(shorty) > 1) { |
| 162 | for (int i = next; i < numUses;) { |
| 163 | DCHECK_LT(cpos, strlen(shorty)); |
| 164 | switch(shorty[cpos++]) { |
| 165 | case 'D': |
| 166 | ssaRep->fpUse[i] = true; |
| 167 | ssaRep->fpUse[i+1] = true; |
| 168 | cUnit->regLocation[ssaRep->uses[i]].wide = true; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 169 | cUnit->regLocation[ssaRep->uses[i+1]].highWord |
| 170 | = true; |
| 171 | DCHECK_EQ(oatS2VReg(cUnit, ssaRep->uses[i])+1, |
| 172 | oatS2VReg(cUnit, ssaRep->uses[i+1])); |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 173 | i++; |
| 174 | break; |
| 175 | case 'J': |
| 176 | cUnit->regLocation[ssaRep->uses[i]].wide = true; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 177 | cUnit->regLocation[ssaRep->uses[i+1]].highWord |
| 178 | = true; |
| 179 | DCHECK_EQ(oatS2VReg(cUnit, ssaRep->uses[i])+1, |
| 180 | oatS2VReg(cUnit, ssaRep->uses[i+1])); |
| 181 | changed |= setCore(cUnit, ssaRep->uses[i],true); |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 182 | i++; |
| 183 | break; |
| 184 | case 'F': |
| 185 | ssaRep->fpUse[i] = true; |
| 186 | break; |
| 187 | default: |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 188 | changed |= setCore(cUnit,ssaRep->uses[i], true); |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 189 | break; |
| 190 | } |
| 191 | i++; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 196 | for (int i=0; ssaRep->fpUse && i< ssaRep->numUses; i++) { |
| 197 | if (ssaRep->fpUse[i]) |
| 198 | changed |= setFp(cUnit, ssaRep->uses[i], true); |
| 199 | } |
| 200 | for (int i=0; ssaRep->fpDef && i< ssaRep->numDefs; i++) { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 201 | if (ssaRep->fpDef[i]) |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 202 | changed |= setFp(cUnit, ssaRep->defs[i], true); |
| 203 | } |
| 204 | // Special-case handling for moves & Phi |
| 205 | if (attrs & (DF_IS_MOVE | DF_NULL_TRANSFER_N)) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 206 | // If any of our inputs or outputs is defined, set all |
| 207 | bool definedFP = false; |
| 208 | bool definedCore = false; |
| 209 | definedFP |= (cUnit->regLocation[ssaRep->defs[0]].defined && |
| 210 | cUnit->regLocation[ssaRep->defs[0]].fp); |
| 211 | definedCore |= (cUnit->regLocation[ssaRep->defs[0]].defined && |
| 212 | cUnit->regLocation[ssaRep->defs[0]].core); |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 213 | for (int i = 0; i < ssaRep->numUses; i++) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 214 | definedFP |= (cUnit->regLocation[ssaRep->uses[i]].defined && |
| 215 | cUnit->regLocation[ssaRep->uses[i]].fp); |
| 216 | definedCore |= (cUnit->regLocation[ssaRep->uses[i]].defined |
| 217 | && cUnit->regLocation[ssaRep->uses[i]].core); |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 218 | } |
buzbee | 23d5bc9 | 2011-10-31 12:41:02 -0700 | [diff] [blame^] | 219 | /* |
| 220 | * TODO: cleaner fix |
| 221 | * We don't normally expect to see a Dalvik register |
| 222 | * definition used both as a floating point and core |
| 223 | * value. However, the instruction rewriting that occurs |
| 224 | * during verification can eliminate some type information, |
| 225 | * leaving us confused. The real fix here is either to |
| 226 | * add explicit type information to Dalvik byte codes, |
| 227 | * or to recognize OP_THROW_VERIFICATION_ERROR as |
| 228 | * an unconditional branch and support dead code elimination. |
| 229 | * As a workaround we can detect this situation and |
| 230 | * disable register promotion (which is the only thing that |
| 231 | * relies on distinctions between core and fp usages. |
| 232 | */ |
| 233 | if ((definedFP && definedCore) && |
| 234 | ((cUnit->disableOpt & (1 << kPromoteRegs)) == 0)) { |
| 235 | LOG(WARNING) << art::PrettyMethod(cUnit->method) |
| 236 | << " op at block " << bb->id |
| 237 | << " has both fp and core uses for same def."; |
| 238 | cUnit->disableOpt |= (1 << kPromoteRegs); |
| 239 | } |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 240 | changed |= setFp(cUnit, ssaRep->defs[0], definedFP); |
| 241 | changed |= setCore(cUnit, ssaRep->defs[0], definedCore); |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 242 | for (int i = 0; i < ssaRep->numUses; i++) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 243 | changed |= setFp(cUnit, ssaRep->uses[i], definedFP); |
| 244 | changed |= setCore(cUnit, ssaRep->uses[i], definedCore); |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 245 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | } |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 249 | return changed; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | static const char* storageName[] = {" Frame ", "PhysReg", " Spill "}; |
| 253 | |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 254 | void oatDumpRegLocTable(RegLocation* table, int count) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 255 | { |
| 256 | for (int i = 0; i < count; i++) { |
| 257 | char buf[100]; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 258 | snprintf(buf, 100, "Loc[%02d] : %s, %c %c %c %c %c %c%d %c%d S%d", |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 259 | i, storageName[table[i].location], table[i].wide ? 'W' : 'N', |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 260 | table[i].defined ? 'D' : 'U', table[i].fp ? 'F' : 'C', |
| 261 | table[i].highWord ? 'H' : 'L', table[i].home ? 'h' : 't', |
| 262 | FPREG(table[i].lowReg) ? 's' : 'r', table[i].lowReg & FP_REG_MASK, |
| 263 | FPREG(table[i].highReg) ? 's' : 'r', table[i].highReg & FP_REG_MASK, |
| 264 | table[i].sRegLow); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 265 | LOG(INFO) << buf; |
| 266 | } |
| 267 | } |
| 268 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 269 | static const RegLocation freshLoc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, |
| 270 | INVALID_REG, INVALID_REG, INVALID_SREG}; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 271 | |
| 272 | /* |
| 273 | * Simple register allocation. Some Dalvik virtual registers may |
| 274 | * be promoted to physical registers. Most of the work for temp |
| 275 | * allocation is done on the fly. We also do some initilization and |
| 276 | * type inference here. |
| 277 | */ |
| 278 | void oatSimpleRegAlloc(CompilationUnit* cUnit) |
| 279 | { |
| 280 | int i; |
| 281 | RegLocation* loc; |
| 282 | |
| 283 | /* Allocate the location map */ |
| 284 | loc = (RegLocation*)oatNew(cUnit->numSSARegs * sizeof(*loc), true); |
| 285 | for (i=0; i< cUnit->numSSARegs; i++) { |
| 286 | loc[i] = freshLoc; |
| 287 | loc[i].sRegLow = i; |
| 288 | } |
| 289 | cUnit->regLocation = loc; |
| 290 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 291 | /* Allocation the promotion map */ |
| 292 | cUnit->promotionMap = (PromotionMap*)oatNew( cUnit->method->NumRegisters() |
| 293 | * sizeof(cUnit->promotionMap[0]), true); |
| 294 | |
buzbee | e9a72f6 | 2011-09-04 17:59:07 -0700 | [diff] [blame] | 295 | /* Add types of incoming arguments based on signature */ |
| 296 | int numRegs = cUnit->method->NumRegisters(); |
| 297 | int numIns = cUnit->method->NumIns(); |
| 298 | if (numIns > 0) { |
| 299 | int sReg = numRegs - numIns; |
| 300 | if (!cUnit->method->IsStatic()) { |
| 301 | // Skip past "this" |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 302 | cUnit->regLocation[sReg].defined = true; |
| 303 | cUnit->regLocation[sReg].core = true; |
buzbee | e9a72f6 | 2011-09-04 17:59:07 -0700 | [diff] [blame] | 304 | sReg++; |
| 305 | } |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 306 | const String* shorty = cUnit->method->GetShorty(); |
Brian Carlstrom | 2ed6739 | 2011-09-09 14:53:28 -0700 | [diff] [blame] | 307 | for (int i = 1; i < shorty->GetLength(); i++) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 308 | switch(shorty->CharAt(i)) { |
| 309 | case 'D': |
| 310 | cUnit->regLocation[sReg].wide = true; |
| 311 | cUnit->regLocation[sReg+1].highWord = true; |
| 312 | DCHECK_EQ(oatS2VReg(cUnit, sReg)+1, |
| 313 | oatS2VReg(cUnit, sReg+1)); |
| 314 | cUnit->regLocation[sReg].fp = true; |
| 315 | cUnit->regLocation[sReg].defined = true; |
| 316 | sReg++; |
| 317 | break; |
| 318 | case 'J': |
| 319 | cUnit->regLocation[sReg].wide = true; |
| 320 | cUnit->regLocation[sReg+1].highWord = true; |
| 321 | DCHECK_EQ(oatS2VReg(cUnit, sReg)+1, |
| 322 | oatS2VReg(cUnit, sReg+1)); |
| 323 | cUnit->regLocation[sReg].core = true; |
| 324 | cUnit->regLocation[sReg].defined = true; |
| 325 | sReg++; |
| 326 | break; |
| 327 | case 'F': |
| 328 | cUnit->regLocation[sReg].fp = true; |
| 329 | cUnit->regLocation[sReg].defined = true; |
| 330 | break; |
| 331 | default: |
| 332 | cUnit->regLocation[sReg].core = true; |
| 333 | cUnit->regLocation[sReg].defined = true; |
| 334 | break; |
buzbee | e9a72f6 | 2011-09-04 17:59:07 -0700 | [diff] [blame] | 335 | } |
| 336 | sReg++; |
| 337 | } |
| 338 | } |
| 339 | |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 340 | /* Remap names */ |
| 341 | oatDataFlowAnalysisDispatcher(cUnit, remapNames, |
| 342 | kPreOrderDFSTraversal, |
| 343 | false /* isIterative */); |
| 344 | |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 345 | /* Do type & size inference pass */ |
| 346 | oatDataFlowAnalysisDispatcher(cUnit, inferTypeAndSize, |
| 347 | kPreOrderDFSTraversal, |
| 348 | true /* isIterative */); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 349 | |
| 350 | /* |
| 351 | * Set the sRegLow field to refer to the pre-SSA name of the |
| 352 | * base Dalvik virtual register. Once we add a better register |
| 353 | * allocator, remove this remapping. |
| 354 | */ |
| 355 | for (i=0; i < cUnit->numSSARegs; i++) { |
| 356 | cUnit->regLocation[i].sRegLow = |
| 357 | DECODE_REG(oatConvertSSARegToDalvik(cUnit, loc[i].sRegLow)); |
| 358 | } |
| 359 | |
| 360 | cUnit->coreSpillMask = 0; |
| 361 | cUnit->fpSpillMask = 0; |
buzbee | bbaf894 | 2011-10-02 13:08:29 -0700 | [diff] [blame] | 362 | cUnit->numCoreSpills = 0; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 363 | |
| 364 | oatDoPromotion(cUnit); |
| 365 | |
| 366 | if (cUnit->printMe && !(cUnit->disableOpt & (1 << kPromoteRegs))) { |
| 367 | LOG(INFO) << "After Promotion"; |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 368 | oatDumpRegLocTable(cUnit->regLocation, cUnit->numSSARegs); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /* Figure out the frame size */ |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 372 | cUnit->numIns = cUnit->method->NumIns(); |
| 373 | cUnit->numRegs = cUnit->method->NumRegisters() - cUnit->numIns; |
| 374 | cUnit->numOuts = cUnit->method->NumOuts(); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 375 | cUnit->numPadding = (STACK_ALIGN_WORDS - |
buzbee | bbaf894 | 2011-10-02 13:08:29 -0700 | [diff] [blame] | 376 | (cUnit->numCoreSpills + cUnit->numFPSpills + cUnit->numRegs + |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 377 | cUnit->numOuts + 2)) & (STACK_ALIGN_WORDS-1); |
buzbee | bbaf894 | 2011-10-02 13:08:29 -0700 | [diff] [blame] | 378 | cUnit->frameSize = (cUnit->numCoreSpills + cUnit->numFPSpills + |
| 379 | cUnit->numRegs + cUnit->numOuts + |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 380 | cUnit->numPadding + 2) * 4; |
| 381 | cUnit->insOffset = cUnit->frameSize + 4; |
| 382 | cUnit->regsOffset = (cUnit->numOuts + cUnit->numPadding + 1) * 4; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 383 | } |