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 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 22 | namespace art { |
| 23 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 24 | bool setFp(CompilationUnit* cUnit, int index, bool isFP) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 25 | bool change = false; |
| 26 | if (cUnit->regLocation[index].highWord) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 27 | return change; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 28 | } |
| 29 | if (isFP && !cUnit->regLocation[index].fp) { |
| 30 | cUnit->regLocation[index].fp = true; |
| 31 | cUnit->regLocation[index].defined = true; |
| 32 | change = true; |
| 33 | } |
| 34 | return change; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 35 | } |
| 36 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 37 | bool setCore(CompilationUnit* cUnit, int index, bool isCore) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 38 | bool change = false; |
| 39 | if (cUnit->regLocation[index].highWord) { |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 40 | return change; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 41 | } |
| 42 | if (isCore && !cUnit->regLocation[index].defined) { |
| 43 | cUnit->regLocation[index].core = true; |
| 44 | cUnit->regLocation[index].defined = true; |
| 45 | change = true; |
| 46 | } |
| 47 | return change; |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 48 | } |
| 49 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 50 | bool remapNames(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 51 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 52 | if (bb->blockType != kDalvikByteCode && bb->blockType != kEntryBlock && |
| 53 | bb->blockType != kExitBlock) |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 54 | return false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 55 | |
| 56 | for (MIR* mir = bb->firstMIRInsn; mir; mir = mir->next) { |
| 57 | SSARepresentation *ssaRep = mir->ssaRep; |
| 58 | if (ssaRep) { |
| 59 | for (int i = 0; i < ssaRep->numUses; i++) { |
| 60 | ssaRep->uses[i] = cUnit->phiAliasMap[ssaRep->uses[i]]; |
| 61 | } |
| 62 | for (int i = 0; i < ssaRep->numDefs; i++) { |
| 63 | ssaRep->defs[i] = cUnit->phiAliasMap[ssaRep->defs[i]]; |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | return false; |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 68 | } |
| 69 | |
buzbee | 769fde1 | 2012-01-05 17:35:23 -0800 | [diff] [blame] | 70 | // Try to find the next move result which might have an FP target |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 71 | SSARepresentation* findMoveResult(MIR* mir) |
buzbee | 769fde1 | 2012-01-05 17:35:23 -0800 | [diff] [blame] | 72 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 73 | SSARepresentation* res = NULL; |
| 74 | for (; mir; mir = mir->next) { |
| 75 | if ((mir->dalvikInsn.opcode == Instruction::MOVE_RESULT) || |
| 76 | (mir->dalvikInsn.opcode == Instruction::MOVE_RESULT_WIDE)) { |
| 77 | res = mir->ssaRep; |
| 78 | break; |
buzbee | 769fde1 | 2012-01-05 17:35:23 -0800 | [diff] [blame] | 79 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 80 | } |
| 81 | return res; |
buzbee | 769fde1 | 2012-01-05 17:35:23 -0800 | [diff] [blame] | 82 | } |
| 83 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 84 | /* |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 85 | * Infer types and sizes. We don't need to track change on sizes, |
| 86 | * as it doesn't propagate. We're guaranteed at least one pass through |
| 87 | * the cfg. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 88 | */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 89 | bool inferTypeAndSize(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 90 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 91 | MIR *mir; |
| 92 | bool changed = false; // Did anything change? |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 93 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 94 | if (bb->dataFlowInfo == NULL) return false; |
| 95 | if (bb->blockType != kDalvikByteCode && bb->blockType != kEntryBlock) |
| 96 | return false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 97 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 98 | for (mir = bb->firstMIRInsn; mir; mir = mir->next) { |
| 99 | SSARepresentation *ssaRep = mir->ssaRep; |
| 100 | if (ssaRep) { |
| 101 | int attrs = oatDataFlowAttributes[mir->dalvikInsn.opcode]; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 102 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 103 | // Handle defs |
| 104 | if (attrs & (DF_DA | DF_DA_WIDE)) { |
| 105 | if (attrs & DF_CORE_A) { |
| 106 | changed |= setCore(cUnit, ssaRep->defs[0], true); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 107 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 108 | if (attrs & DF_DA_WIDE) { |
| 109 | cUnit->regLocation[ssaRep->defs[0]].wide = true; |
| 110 | cUnit->regLocation[ssaRep->defs[1]].highWord = true; |
| 111 | DCHECK_EQ(SRegToVReg(cUnit, ssaRep->defs[0])+1, |
| 112 | SRegToVReg(cUnit, ssaRep->defs[1])); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Handles uses |
| 117 | int next = 0; |
| 118 | if (attrs & (DF_UA | DF_UA_WIDE)) { |
| 119 | if (attrs & DF_CORE_A) { |
| 120 | changed |= setCore(cUnit, ssaRep->uses[next], true); |
| 121 | } |
| 122 | if (attrs & DF_UA_WIDE) { |
| 123 | cUnit->regLocation[ssaRep->uses[next]].wide = true; |
| 124 | cUnit->regLocation[ssaRep->uses[next + 1]].highWord = true; |
| 125 | DCHECK_EQ(SRegToVReg(cUnit, ssaRep->uses[next])+1, |
| 126 | SRegToVReg(cUnit, ssaRep->uses[next + 1])); |
| 127 | next += 2; |
| 128 | } else { |
| 129 | next++; |
| 130 | } |
| 131 | } |
| 132 | if (attrs & (DF_UB | DF_UB_WIDE)) { |
| 133 | if (attrs & DF_CORE_B) { |
| 134 | changed |= setCore(cUnit, ssaRep->uses[next], true); |
| 135 | } |
| 136 | if (attrs & DF_UB_WIDE) { |
| 137 | cUnit->regLocation[ssaRep->uses[next]].wide = true; |
| 138 | cUnit->regLocation[ssaRep->uses[next + 1]].highWord = true; |
| 139 | DCHECK_EQ(SRegToVReg(cUnit, ssaRep->uses[next])+1, |
| 140 | SRegToVReg(cUnit, ssaRep->uses[next + 1])); |
| 141 | next += 2; |
| 142 | } else { |
| 143 | next++; |
| 144 | } |
| 145 | } |
| 146 | if (attrs & (DF_UC | DF_UC_WIDE)) { |
| 147 | if (attrs & DF_CORE_C) { |
| 148 | changed |= setCore(cUnit, ssaRep->uses[next], true); |
| 149 | } |
| 150 | if (attrs & DF_UC_WIDE) { |
| 151 | cUnit->regLocation[ssaRep->uses[next]].wide = true; |
| 152 | cUnit->regLocation[ssaRep->uses[next + 1]].highWord = true; |
| 153 | DCHECK_EQ(SRegToVReg(cUnit, ssaRep->uses[next])+1, |
| 154 | SRegToVReg(cUnit, ssaRep->uses[next + 1])); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // Special-case handling for format 35c/3rc invokes |
| 159 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
| 160 | int flags = (static_cast<int>(opcode) >= kNumPackedOpcodes) |
| 161 | ? 0 : Instruction::Flags(mir->dalvikInsn.opcode); |
| 162 | if ((flags & Instruction::kInvoke) && |
| 163 | (attrs & (DF_FORMAT_35C | DF_FORMAT_3RC))) { |
| 164 | DCHECK_EQ(next, 0); |
| 165 | int target_idx = mir->dalvikInsn.vB; |
| 166 | const char* shorty = oatGetShortyFromTargetIdx(cUnit, target_idx); |
| 167 | // Handle result type if floating point |
| 168 | if ((shorty[0] == 'F') || (shorty[0] == 'D')) { |
| 169 | // Find move-result that consumes this result |
| 170 | SSARepresentation* tgtRep = findMoveResult(mir->next); |
| 171 | // Might be in next basic block |
| 172 | if (!tgtRep) { |
| 173 | tgtRep = findMoveResult(bb->fallThrough->firstMIRInsn); |
| 174 | } |
| 175 | // Result might not be used at all, so no move-result |
| 176 | if (tgtRep) { |
| 177 | tgtRep->fpDef[0] = true; |
| 178 | changed |= setFp(cUnit, tgtRep->defs[0], true); |
| 179 | if (shorty[0] == 'D') { |
| 180 | tgtRep->fpDef[1] = true; |
| 181 | changed |= setFp(cUnit, tgtRep->defs[1], true); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | int numUses = mir->dalvikInsn.vA; |
| 186 | // If this is a non-static invoke, skip implicit "this" |
| 187 | if (((mir->dalvikInsn.opcode != Instruction::INVOKE_STATIC) && |
| 188 | (mir->dalvikInsn.opcode != Instruction::INVOKE_STATIC_RANGE))) { |
| 189 | cUnit->regLocation[ssaRep->uses[next]].defined = true; |
| 190 | cUnit->regLocation[ssaRep->uses[next]].core = true; |
| 191 | next++; |
| 192 | } |
| 193 | uint32_t cpos = 1; |
| 194 | if (strlen(shorty) > 1) { |
| 195 | for (int i = next; i < numUses;) { |
| 196 | DCHECK_LT(cpos, strlen(shorty)); |
| 197 | switch (shorty[cpos++]) { |
| 198 | case 'D': |
| 199 | ssaRep->fpUse[i] = true; |
| 200 | ssaRep->fpUse[i+1] = true; |
| 201 | cUnit->regLocation[ssaRep->uses[i]].wide = true; |
| 202 | cUnit->regLocation[ssaRep->uses[i+1]].highWord = true; |
| 203 | DCHECK_EQ(SRegToVReg(cUnit, ssaRep->uses[i])+1, |
| 204 | SRegToVReg(cUnit, ssaRep->uses[i+1])); |
| 205 | i++; |
| 206 | break; |
| 207 | case 'J': |
| 208 | cUnit->regLocation[ssaRep->uses[i]].wide = true; |
| 209 | cUnit->regLocation[ssaRep->uses[i+1]].highWord = true; |
| 210 | DCHECK_EQ(SRegToVReg(cUnit, ssaRep->uses[i])+1, |
| 211 | SRegToVReg(cUnit, ssaRep->uses[i+1])); |
| 212 | changed |= setCore(cUnit, ssaRep->uses[i],true); |
| 213 | i++; |
| 214 | break; |
| 215 | case 'F': |
| 216 | ssaRep->fpUse[i] = true; |
| 217 | break; |
| 218 | default: |
| 219 | changed |= setCore(cUnit,ssaRep->uses[i], true); |
| 220 | break; |
| 221 | } |
| 222 | i++; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | for (int i=0; ssaRep->fpUse && i< ssaRep->numUses; i++) { |
| 228 | if (ssaRep->fpUse[i]) |
| 229 | changed |= setFp(cUnit, ssaRep->uses[i], true); |
| 230 | } |
| 231 | for (int i=0; ssaRep->fpDef && i< ssaRep->numDefs; i++) { |
| 232 | if (ssaRep->fpDef[i]) |
| 233 | changed |= setFp(cUnit, ssaRep->defs[i], true); |
| 234 | } |
| 235 | // Special-case handling for moves & Phi |
| 236 | if (attrs & (DF_IS_MOVE | DF_NULL_TRANSFER_N)) { |
| 237 | // If any of our inputs or outputs is defined, set all |
| 238 | bool definedFP = false; |
| 239 | bool definedCore = false; |
| 240 | definedFP |= (cUnit->regLocation[ssaRep->defs[0]].defined && |
| 241 | cUnit->regLocation[ssaRep->defs[0]].fp); |
| 242 | definedCore |= (cUnit->regLocation[ssaRep->defs[0]].defined && |
| 243 | cUnit->regLocation[ssaRep->defs[0]].core); |
| 244 | for (int i = 0; i < ssaRep->numUses; i++) { |
| 245 | definedFP |= (cUnit->regLocation[ssaRep->uses[i]].defined && |
| 246 | cUnit->regLocation[ssaRep->uses[i]].fp); |
| 247 | definedCore |= (cUnit->regLocation[ssaRep->uses[i]].defined |
| 248 | && cUnit->regLocation[ssaRep->uses[i]].core); |
| 249 | } |
| 250 | /* |
| 251 | * TODO: cleaner fix |
| 252 | * We don't normally expect to see a Dalvik register |
| 253 | * definition used both as a floating point and core |
| 254 | * value. However, the instruction rewriting that occurs |
| 255 | * during verification can eliminate some type information, |
| 256 | * leaving us confused. The real fix here is either to |
| 257 | * add explicit type information to Dalvik byte codes, |
| 258 | * or to recognize THROW_VERIFICATION_ERROR as |
| 259 | * an unconditional branch and support dead code elimination. |
| 260 | * As a workaround we can detect this situation and |
| 261 | * disable register promotion (which is the only thing that |
| 262 | * relies on distinctions between core and fp usages. |
| 263 | */ |
| 264 | if ((definedFP && definedCore) && |
| 265 | ((cUnit->disableOpt & (1 << kPromoteRegs)) == 0)) { |
| 266 | LOG(WARNING) << PrettyMethod(cUnit->method_idx, *cUnit->dex_file) |
| 267 | << " op at block " << bb->id |
| 268 | << " has both fp and core uses for same def."; |
| 269 | cUnit->disableOpt |= (1 << kPromoteRegs); |
| 270 | } |
| 271 | changed |= setFp(cUnit, ssaRep->defs[0], definedFP); |
| 272 | changed |= setCore(cUnit, ssaRep->defs[0], definedCore); |
| 273 | for (int i = 0; i < ssaRep->numUses; i++) { |
| 274 | changed |= setFp(cUnit, ssaRep->uses[i], definedFP); |
| 275 | changed |= setCore(cUnit, ssaRep->uses[i], definedCore); |
| 276 | } |
| 277 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 278 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 279 | } |
| 280 | return changed; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | static const char* storageName[] = {" Frame ", "PhysReg", " Spill "}; |
| 284 | |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 285 | void oatDumpRegLocTable(RegLocation* table, int count) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 286 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 287 | for (int i = 0; i < count; i++) { |
| 288 | LOG(INFO) << StringPrintf("Loc[%02d] : %s, %c %c %c %c %c %c%d %c%d S%d", |
| 289 | i, storageName[table[i].location], table[i].wide ? 'W' : 'N', |
| 290 | table[i].defined ? 'D' : 'U', table[i].fp ? 'F' : 'C', |
| 291 | table[i].highWord ? 'H' : 'L', table[i].home ? 'h' : 't', |
| 292 | oatIsFpReg(table[i].lowReg) ? 's' : 'r', |
| 293 | table[i].lowReg & oatFpRegMask(), |
| 294 | oatIsFpReg(table[i].highReg) ? 's' : 'r', |
| 295 | table[i].highReg & oatFpRegMask(), table[i].sRegLow); |
| 296 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 297 | } |
| 298 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 299 | static const RegLocation freshLoc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, |
| 300 | INVALID_REG, INVALID_REG, INVALID_SREG}; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 301 | |
| 302 | /* |
| 303 | * Simple register allocation. Some Dalvik virtual registers may |
| 304 | * be promoted to physical registers. Most of the work for temp |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 305 | * allocation is done on the fly. We also do some initialization and |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 306 | * type inference here. |
| 307 | */ |
| 308 | void oatSimpleRegAlloc(CompilationUnit* cUnit) |
| 309 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 310 | int i; |
| 311 | RegLocation* loc; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 312 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 313 | /* Allocate the location map */ |
| 314 | loc = (RegLocation*)oatNew(cUnit, cUnit->numSSARegs * sizeof(*loc), true, |
| 315 | kAllocRegAlloc); |
| 316 | for (i=0; i< cUnit->numSSARegs; i++) { |
| 317 | loc[i] = freshLoc; |
| 318 | loc[i].sRegLow = i; |
| 319 | } |
| 320 | |
| 321 | /* Patch up the locations for Method* and the compiler temps */ |
| 322 | loc[cUnit->methodSReg].location = kLocCompilerTemp; |
| 323 | loc[cUnit->methodSReg].defined = true; |
| 324 | for (i = 0; i < cUnit->numCompilerTemps; i++) { |
| 325 | CompilerTemp* ct = (CompilerTemp*)cUnit->compilerTemps.elemList[i]; |
| 326 | loc[ct->sReg].location = kLocCompilerTemp; |
| 327 | loc[ct->sReg].defined = true; |
| 328 | } |
| 329 | |
| 330 | cUnit->regLocation = loc; |
| 331 | |
| 332 | /* Allocation the promotion map */ |
| 333 | int numRegs = cUnit->numDalvikRegisters; |
| 334 | cUnit->promotionMap = |
| 335 | (PromotionMap*)oatNew(cUnit, (numRegs + cUnit->numCompilerTemps + 1) * |
| 336 | sizeof(cUnit->promotionMap[0]), true, |
| 337 | kAllocRegAlloc); |
| 338 | |
| 339 | /* Add types of incoming arguments based on signature */ |
| 340 | int numIns = cUnit->numIns; |
| 341 | if (numIns > 0) { |
| 342 | int sReg = numRegs - numIns; |
| 343 | if ((cUnit->access_flags & kAccStatic) == 0) { |
| 344 | // For non-static, skip past "this" |
| 345 | cUnit->regLocation[sReg].defined = true; |
| 346 | cUnit->regLocation[sReg].core = true; |
| 347 | sReg++; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 348 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 349 | const char* shorty = cUnit->shorty; |
| 350 | int shorty_len = strlen(shorty); |
| 351 | for (int i = 1; i < shorty_len; i++) { |
| 352 | switch (shorty[i]) { |
| 353 | case 'D': |
| 354 | cUnit->regLocation[sReg].wide = true; |
| 355 | cUnit->regLocation[sReg+1].highWord = true; |
| 356 | cUnit->regLocation[sReg+1].fp = true; |
| 357 | DCHECK_EQ(SRegToVReg(cUnit, sReg)+1, SRegToVReg(cUnit, sReg+1)); |
| 358 | cUnit->regLocation[sReg].fp = true; |
| 359 | cUnit->regLocation[sReg].defined = true; |
| 360 | sReg++; |
| 361 | break; |
| 362 | case 'J': |
| 363 | cUnit->regLocation[sReg].wide = true; |
| 364 | cUnit->regLocation[sReg+1].highWord = true; |
| 365 | DCHECK_EQ(SRegToVReg(cUnit, sReg)+1, SRegToVReg(cUnit, sReg+1)); |
| 366 | cUnit->regLocation[sReg].core = true; |
| 367 | cUnit->regLocation[sReg].defined = true; |
| 368 | sReg++; |
| 369 | break; |
| 370 | case 'F': |
| 371 | cUnit->regLocation[sReg].fp = true; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 372 | cUnit->regLocation[sReg].defined = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 373 | break; |
| 374 | default: |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 375 | cUnit->regLocation[sReg].core = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 376 | cUnit->regLocation[sReg].defined = true; |
| 377 | break; |
buzbee | e9a72f6 | 2011-09-04 17:59:07 -0700 | [diff] [blame] | 378 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 379 | sReg++; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | /* Remap names */ |
| 384 | oatDataFlowAnalysisDispatcher(cUnit, remapNames, |
| 385 | kPreOrderDFSTraversal, |
| 386 | false /* isIterative */); |
| 387 | |
| 388 | /* Do type & size inference pass */ |
| 389 | oatDataFlowAnalysisDispatcher(cUnit, inferTypeAndSize, |
| 390 | kPreOrderDFSTraversal, |
| 391 | true /* isIterative */); |
| 392 | |
| 393 | /* |
| 394 | * Set the sRegLow field to refer to the pre-SSA name of the |
| 395 | * base Dalvik virtual register. Once we add a better register |
| 396 | * allocator, remove this remapping. |
| 397 | */ |
| 398 | for (i=0; i < cUnit->numSSARegs; i++) { |
| 399 | if (cUnit->regLocation[i].location != kLocCompilerTemp) { |
| 400 | cUnit->regLocation[i].sRegLow = SRegToVReg(cUnit, loc[i].sRegLow); |
buzbee | e9a72f6 | 2011-09-04 17:59:07 -0700 | [diff] [blame] | 401 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 402 | } |
buzbee | e9a72f6 | 2011-09-04 17:59:07 -0700 | [diff] [blame] | 403 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 404 | cUnit->coreSpillMask = 0; |
| 405 | cUnit->fpSpillMask = 0; |
| 406 | cUnit->numCoreSpills = 0; |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 407 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 408 | oatDoPromotion(cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 409 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 410 | if (cUnit->printMe && !(cUnit->disableOpt & (1 << kPromoteRegs))) { |
| 411 | LOG(INFO) << "After Promotion"; |
| 412 | oatDumpRegLocTable(cUnit->regLocation, cUnit->numSSARegs); |
| 413 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 414 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame^] | 415 | /* Figure out the frame size */ |
| 416 | static const uint32_t kAlignMask = kStackAlignment - 1; |
| 417 | uint32_t size = (cUnit->numCoreSpills + cUnit->numFPSpills + |
| 418 | 1 /* filler word */ + cUnit->numRegs + cUnit->numOuts + |
| 419 | cUnit->numCompilerTemps + 1 /* curMethod* */) |
| 420 | * sizeof(uint32_t); |
| 421 | /* Align and set */ |
| 422 | cUnit->frameSize = (size + kAlignMask) & ~(kAlignMask); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 423 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 424 | |
| 425 | } // namespace art |