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 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 17 | #include "object_utils.h" |
| 18 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 19 | namespace art { |
| 20 | |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 21 | #define DISPLAY_MISSING_TARGETS (cUnit->enableDebug & \ |
| 22 | (1 << kDebugDisplayMissingTargets)) |
Elliott Hughes | 1240dad | 2011-09-09 16:24:50 -0700 | [diff] [blame] | 23 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 24 | STATIC const RegLocation badLoc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, INVALID_REG, |
| 25 | INVALID_REG, INVALID_SREG}; |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 26 | |
| 27 | /* Mark register usage state and return long retloc */ |
| 28 | STATIC RegLocation getRetLocWide(CompilationUnit* cUnit) |
| 29 | { |
| 30 | RegLocation res = LOC_DALVIK_RETURN_VAL_WIDE; |
| 31 | oatLockTemp(cUnit, res.lowReg); |
| 32 | oatLockTemp(cUnit, res.highReg); |
| 33 | oatMarkPair(cUnit, res.lowReg, res.highReg); |
| 34 | return res; |
| 35 | } |
| 36 | |
| 37 | STATIC RegLocation getRetLoc(CompilationUnit* cUnit) |
| 38 | { |
| 39 | RegLocation res = LOC_DALVIK_RETURN_VAL; |
| 40 | oatLockTemp(cUnit, res.lowReg); |
| 41 | return res; |
| 42 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 43 | |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 44 | /* |
| 45 | * Let helper function take care of everything. Will call |
| 46 | * Array::AllocFromCode(type_idx, method, count); |
| 47 | * Note: AllocFromCode will handle checks for errNegativeArraySize. |
| 48 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 49 | STATIC void genNewArray(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 50 | RegLocation rlSrc) |
| 51 | { |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 52 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 53 | uint32_t type_idx = mir->dalvikInsn.vC; |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 54 | if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
| 55 | cUnit->dex_cache, |
| 56 | *cUnit->dex_file, |
| 57 | type_idx)) { |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 58 | loadWordDisp(cUnit, rSELF, |
| 59 | OFFSETOF_MEMBER(Thread, pAllocArrayFromCode), rLR); |
| 60 | } else { |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 61 | loadWordDisp(cUnit, rSELF, |
Ian Rogers | 0eb7d7e | 2012-01-31 21:12:32 -0800 | [diff] [blame] | 62 | OFFSETOF_MEMBER(Thread, pAllocArrayFromCodeWithAccessCheck), rLR); |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 63 | } |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 64 | loadCurrMethodDirect(cUnit, r1); // arg1 <- Method* |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 65 | loadConstant(cUnit, r0, type_idx); // arg0 <- type_id |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 66 | loadValueDirectFixed(cUnit, rlSrc, r2); // arg2 <- count |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 67 | callRuntimeHelper(cUnit, rLR); |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 68 | RegLocation rlResult = oatGetReturn(cUnit); |
| 69 | storeValue(cUnit, rlDest, rlResult); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /* |
| 73 | * Similar to genNewArray, but with post-allocation initialization. |
| 74 | * Verifier guarantees we're dealing with an array class. Current |
| 75 | * code throws runtime exception "bad Filled array req" for 'D' and 'J'. |
| 76 | * Current code also throws internal unimp if not 'L', '[' or 'I'. |
| 77 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 78 | STATIC void genFilledNewArray(CompilationUnit* cUnit, MIR* mir, bool isRange) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 79 | { |
| 80 | DecodedInstruction* dInsn = &mir->dalvikInsn; |
buzbee | 81eccc0 | 2011-09-17 13:42:21 -0700 | [diff] [blame] | 81 | int elems = dInsn->vA; |
| 82 | int typeId = dInsn->vB; |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 83 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
Ian Rogers | 0eb7d7e | 2012-01-31 21:12:32 -0800 | [diff] [blame] | 84 | if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
| 85 | cUnit->dex_cache, |
| 86 | *cUnit->dex_file, |
| 87 | typeId)) { |
| 88 | loadWordDisp(cUnit, rSELF, |
| 89 | OFFSETOF_MEMBER(Thread, pCheckAndAllocArrayFromCode), rLR); |
| 90 | } else { |
| 91 | loadWordDisp(cUnit, rSELF, |
| 92 | OFFSETOF_MEMBER(Thread, pCheckAndAllocArrayFromCodeWithAccessCheck), rLR); |
Ian Rogers | 28ad40d | 2011-10-27 15:19:26 -0700 | [diff] [blame] | 93 | } |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 94 | loadCurrMethodDirect(cUnit, r1); // arg1 <- Method* |
| 95 | loadConstant(cUnit, r0, typeId); // arg0 <- type_id |
| 96 | loadConstant(cUnit, r2, elems); // arg2 <- count |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 97 | callRuntimeHelper(cUnit, rLR); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 98 | /* |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 99 | * NOTE: the implicit target for OP_FILLED_NEW_ARRAY is the |
| 100 | * return region. Because AllocFromCode placed the new array |
| 101 | * in r0, we'll just lock it into place. When debugger support is |
| 102 | * added, it may be necessary to additionally copy all return |
| 103 | * values to a home location in thread-local storage |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 104 | */ |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 105 | oatLockTemp(cUnit, r0); |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 106 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 107 | // Having a range of 0 is legal |
| 108 | if (isRange && (dInsn->vA > 0)) { |
| 109 | /* |
| 110 | * Bit of ugliness here. We're going generate a mem copy loop |
| 111 | * on the register range, but it is possible that some regs |
| 112 | * in the range have been promoted. This is unlikely, but |
| 113 | * before generating the copy, we'll just force a flush |
| 114 | * of any regs in the source range that have been promoted to |
| 115 | * home location. |
| 116 | */ |
| 117 | for (unsigned int i = 0; i < dInsn->vA; i++) { |
| 118 | RegLocation loc = oatUpdateLoc(cUnit, |
| 119 | oatGetSrc(cUnit, mir, i)); |
| 120 | if (loc.location == kLocPhysReg) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 121 | storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow), |
| 122 | loc.lowReg, kWord); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | /* |
| 126 | * TUNING note: generated code here could be much improved, but |
| 127 | * this is an uncommon operation and isn't especially performance |
| 128 | * critical. |
| 129 | */ |
| 130 | int rSrc = oatAllocTemp(cUnit); |
| 131 | int rDst = oatAllocTemp(cUnit); |
| 132 | int rIdx = oatAllocTemp(cUnit); |
| 133 | int rVal = rLR; // Using a lot of temps, rLR is known free here |
| 134 | // Set up source pointer |
| 135 | RegLocation rlFirst = oatGetSrc(cUnit, mir, 0); |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 136 | opRegRegImm(cUnit, kOpAdd, rSrc, rSP, |
| 137 | oatSRegOffset(cUnit, rlFirst.sRegLow)); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 138 | // Set up the target pointer |
| 139 | opRegRegImm(cUnit, kOpAdd, rDst, r0, |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 140 | Array::DataOffset().Int32Value()); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 141 | // Set up the loop counter (known to be > 0) |
buzbee | 3181345 | 2011-10-16 14:33:08 -0700 | [diff] [blame] | 142 | loadConstant(cUnit, rIdx, dInsn->vA - 1); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 143 | // Generate the copy loop. Going backwards for convenience |
| 144 | ArmLIR* target = newLIR0(cUnit, kArmPseudoTargetLabel); |
| 145 | target->defMask = ENCODE_ALL; |
| 146 | // Copy next element |
| 147 | loadBaseIndexed(cUnit, rSrc, rIdx, rVal, 2, kWord); |
| 148 | storeBaseIndexed(cUnit, rDst, rIdx, rVal, 2, kWord); |
| 149 | // Use setflags encoding here |
| 150 | newLIR3(cUnit, kThumb2SubsRRI12, rIdx, rIdx, 1); |
buzbee | 3181345 | 2011-10-16 14:33:08 -0700 | [diff] [blame] | 151 | ArmLIR* branch = opCondBranch(cUnit, kArmCondGe); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 152 | branch->generic.target = (LIR*)target; |
| 153 | } else if (!isRange) { |
| 154 | // TUNING: interleave |
| 155 | for (unsigned int i = 0; i < dInsn->vA; i++) { |
| 156 | RegLocation rlArg = loadValue(cUnit, |
| 157 | oatGetSrc(cUnit, mir, i), kCoreReg); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 158 | storeBaseDisp(cUnit, r0, |
| 159 | Array::DataOffset().Int32Value() + |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 160 | i * 4, rlArg.lowReg, kWord); |
| 161 | // If the loadValue caused a temp to be allocated, free it |
| 162 | if (oatIsTemp(cUnit, rlArg.lowReg)) { |
| 163 | oatFreeTemp(cUnit, rlArg.lowReg); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 169 | STATIC void genSput(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc, |
| 170 | bool isLongOrDouble, bool isObject) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 171 | { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 172 | int fieldOffset; |
| 173 | int ssbIndex; |
| 174 | bool isVolatile; |
| 175 | bool isReferrersClass; |
| 176 | uint32_t fieldIdx = mir->dalvikInsn.vB; |
| 177 | bool fastPath = |
| 178 | cUnit->compiler->ComputeStaticFieldInfo(fieldIdx, cUnit, |
| 179 | fieldOffset, ssbIndex, |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 180 | isReferrersClass, isVolatile, true); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 181 | if (fastPath && !SLOW_FIELD_PATH) { |
| 182 | DCHECK_GE(fieldOffset, 0); |
| 183 | int rBase; |
| 184 | int rMethod; |
| 185 | if (isReferrersClass) { |
| 186 | // Fast path, static storage base is this method's class |
| 187 | rMethod = loadCurrMethod(cUnit); |
| 188 | rBase = oatAllocTemp(cUnit); |
| 189 | loadWordDisp(cUnit, rMethod, |
| 190 | Method::DeclaringClassOffset().Int32Value(), rBase); |
| 191 | } else { |
| 192 | // Medium path, static storage base in a different class which |
| 193 | // requires checks that the other class is initialized. |
| 194 | DCHECK_GE(ssbIndex, 0); |
| 195 | // May do runtime call so everything to home locations. |
| 196 | oatFlushAllRegs(cUnit); |
| 197 | // Using fixed register to sync with possible call to runtime |
| 198 | // support. |
| 199 | rMethod = r1; |
| 200 | oatLockTemp(cUnit, rMethod); |
| 201 | loadCurrMethodDirect(cUnit, rMethod); |
| 202 | rBase = r0; |
| 203 | oatLockTemp(cUnit, rBase); |
| 204 | loadWordDisp(cUnit, rMethod, |
| 205 | Method::DexCacheInitializedStaticStorageOffset().Int32Value(), |
| 206 | rBase); |
| 207 | loadWordDisp(cUnit, rBase, |
| 208 | Array::DataOffset().Int32Value() + sizeof(int32_t*) * ssbIndex, |
| 209 | rBase); |
| 210 | // rBase now points at appropriate static storage base (Class*) |
| 211 | // or NULL if not initialized. Check for NULL and call helper if NULL. |
| 212 | // TUNING: fast path should fall through |
| 213 | ArmLIR* branchOver = genCmpImmBranch(cUnit, kArmCondNe, rBase, 0); |
| 214 | loadWordDisp(cUnit, rSELF, |
| 215 | OFFSETOF_MEMBER(Thread, pInitializeStaticStorage), rLR); |
| 216 | loadConstant(cUnit, r0, ssbIndex); |
| 217 | callRuntimeHelper(cUnit, rLR); |
| 218 | ArmLIR* skipTarget = newLIR0(cUnit, kArmPseudoTargetLabel); |
| 219 | skipTarget->defMask = ENCODE_ALL; |
| 220 | branchOver->generic.target = (LIR*)skipTarget; |
| 221 | } |
| 222 | // rBase now holds static storage base |
| 223 | oatFreeTemp(cUnit, rMethod); |
| 224 | if (isLongOrDouble) { |
| 225 | rlSrc = oatGetSrcWide(cUnit, mir, 0, 1); |
| 226 | rlSrc = loadValueWide(cUnit, rlSrc, kAnyReg); |
| 227 | } else { |
| 228 | rlSrc = oatGetSrc(cUnit, mir, 0); |
| 229 | rlSrc = loadValue(cUnit, rlSrc, kAnyReg); |
| 230 | } |
| 231 | if (isVolatile) { |
buzbee | 12246b8 | 2011-09-29 14:15:05 -0700 | [diff] [blame] | 232 | oatGenMemBarrier(cUnit, kST); |
| 233 | } |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 234 | if (isLongOrDouble) { |
| 235 | storeBaseDispWide(cUnit, rBase, fieldOffset, rlSrc.lowReg, |
| 236 | rlSrc.highReg); |
| 237 | } else { |
| 238 | storeWordDisp(cUnit, rBase, fieldOffset, rlSrc.lowReg); |
| 239 | } |
| 240 | if (isVolatile) { |
buzbee | 1da522d | 2011-09-04 11:22:20 -0700 | [diff] [blame] | 241 | oatGenMemBarrier(cUnit, kSY); |
| 242 | } |
buzbee | 1da522d | 2011-09-04 11:22:20 -0700 | [diff] [blame] | 243 | if (isObject) { |
| 244 | markGCCard(cUnit, rlSrc.lowReg, rBase); |
| 245 | } |
| 246 | oatFreeTemp(cUnit, rBase); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 247 | } else { |
| 248 | oatFlushAllRegs(cUnit); // Everything to home locations |
| 249 | int setterOffset = isLongOrDouble ? OFFSETOF_MEMBER(Thread, pSet64Static) : |
| 250 | (isObject ? OFFSETOF_MEMBER(Thread, pSetObjStatic) |
| 251 | : OFFSETOF_MEMBER(Thread, pSet32Static)); |
| 252 | loadWordDisp(cUnit, rSELF, setterOffset, rLR); |
| 253 | loadConstant(cUnit, r0, fieldIdx); |
| 254 | if (isLongOrDouble) { |
| 255 | loadValueDirectWideFixed(cUnit, rlSrc, r2, r3); |
| 256 | } else { |
| 257 | loadValueDirect(cUnit, rlSrc, r1); |
| 258 | } |
| 259 | callRuntimeHelper(cUnit, rLR); |
buzbee | e193174 | 2011-08-28 21:15:53 -0700 | [diff] [blame] | 260 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 263 | STATIC void genSget(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 264 | bool isLongOrDouble, bool isObject) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 265 | { |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 266 | int fieldOffset; |
| 267 | int ssbIndex; |
| 268 | bool isVolatile; |
| 269 | bool isReferrersClass; |
| 270 | uint32_t fieldIdx = mir->dalvikInsn.vB; |
| 271 | bool fastPath = |
| 272 | cUnit->compiler->ComputeStaticFieldInfo(fieldIdx, cUnit, |
| 273 | fieldOffset, ssbIndex, |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 274 | isReferrersClass, isVolatile, false); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 275 | if (fastPath && !SLOW_FIELD_PATH) { |
| 276 | DCHECK_GE(fieldOffset, 0); |
| 277 | int rBase; |
| 278 | int rMethod; |
| 279 | if (isReferrersClass) { |
| 280 | // Fast path, static storage base is this method's class |
| 281 | rMethod = loadCurrMethod(cUnit); |
| 282 | rBase = oatAllocTemp(cUnit); |
| 283 | loadWordDisp(cUnit, rMethod, |
| 284 | Method::DeclaringClassOffset().Int32Value(), rBase); |
| 285 | } else { |
| 286 | // Medium path, static storage base in a different class which |
| 287 | // requires checks that the other class is initialized |
| 288 | DCHECK_GE(ssbIndex, 0); |
| 289 | // May do runtime call so everything to home locations. |
| 290 | oatFlushAllRegs(cUnit); |
| 291 | // Using fixed register to sync with possible call to runtime |
| 292 | // support |
| 293 | rMethod = r1; |
| 294 | oatLockTemp(cUnit, rMethod); |
| 295 | loadCurrMethodDirect(cUnit, rMethod); |
| 296 | rBase = r0; |
| 297 | oatLockTemp(cUnit, rBase); |
| 298 | loadWordDisp(cUnit, rMethod, |
| 299 | Method::DexCacheInitializedStaticStorageOffset().Int32Value(), |
| 300 | rBase); |
| 301 | loadWordDisp(cUnit, rBase, |
| 302 | Array::DataOffset().Int32Value() + sizeof(int32_t*) * ssbIndex, |
| 303 | rBase); |
| 304 | // rBase now points at appropriate static storage base (Class*) |
| 305 | // or NULL if not initialized. Check for NULL and call helper if NULL. |
| 306 | // TUNING: fast path should fall through |
| 307 | ArmLIR* branchOver = genCmpImmBranch(cUnit, kArmCondNe, rBase, 0); |
| 308 | loadWordDisp(cUnit, rSELF, |
| 309 | OFFSETOF_MEMBER(Thread, pInitializeStaticStorage), rLR); |
| 310 | loadConstant(cUnit, r0, ssbIndex); |
| 311 | callRuntimeHelper(cUnit, rLR); |
| 312 | ArmLIR* skipTarget = newLIR0(cUnit, kArmPseudoTargetLabel); |
| 313 | skipTarget->defMask = ENCODE_ALL; |
| 314 | branchOver->generic.target = (LIR*)skipTarget; |
| 315 | } |
| 316 | // rBase now holds static storage base |
| 317 | oatFreeTemp(cUnit, rMethod); |
| 318 | rlDest = isLongOrDouble ? oatGetDestWide(cUnit, mir, 0, 1) |
| 319 | : oatGetDest(cUnit, mir, 0); |
buzbee | 1da522d | 2011-09-04 11:22:20 -0700 | [diff] [blame] | 320 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 321 | if (isVolatile) { |
buzbee | 1da522d | 2011-09-04 11:22:20 -0700 | [diff] [blame] | 322 | oatGenMemBarrier(cUnit, kSY); |
| 323 | } |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 324 | if (isLongOrDouble) { |
| 325 | loadBaseDispWide(cUnit, NULL, rBase, fieldOffset, rlResult.lowReg, |
| 326 | rlResult.highReg, INVALID_SREG); |
| 327 | } else { |
| 328 | loadWordDisp(cUnit, rBase, fieldOffset, rlResult.lowReg); |
| 329 | } |
buzbee | 1da522d | 2011-09-04 11:22:20 -0700 | [diff] [blame] | 330 | oatFreeTemp(cUnit, rBase); |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 331 | if (isLongOrDouble) { |
| 332 | storeValueWide(cUnit, rlDest, rlResult); |
| 333 | } else { |
| 334 | storeValue(cUnit, rlDest, rlResult); |
| 335 | } |
| 336 | } else { |
| 337 | oatFlushAllRegs(cUnit); // Everything to home locations |
| 338 | int getterOffset = isLongOrDouble ? OFFSETOF_MEMBER(Thread, pGet64Static) : |
| 339 | (isObject ? OFFSETOF_MEMBER(Thread, pGetObjStatic) |
| 340 | : OFFSETOF_MEMBER(Thread, pGet32Static)); |
| 341 | loadWordDisp(cUnit, rSELF, getterOffset, rLR); |
| 342 | loadConstant(cUnit, r0, fieldIdx); |
| 343 | callRuntimeHelper(cUnit, rLR); |
| 344 | if (isLongOrDouble) { |
| 345 | RegLocation rlResult = oatGetReturnWide(cUnit); |
| 346 | storeValueWide(cUnit, rlDest, rlResult); |
| 347 | } else { |
| 348 | RegLocation rlResult = oatGetReturn(cUnit); |
| 349 | storeValue(cUnit, rlDest, rlResult); |
| 350 | } |
buzbee | e193174 | 2011-08-28 21:15:53 -0700 | [diff] [blame] | 351 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 354 | typedef int (*NextCallInsn)(CompilationUnit*, MIR*, int, uint32_t dexIdx, |
| 355 | uint32_t methodIdx); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * Bit of a hack here - in leiu of a real scheduling pass, |
| 359 | * emit the next instruction in static & direct invoke sequences. |
| 360 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 361 | STATIC int nextSDCallInsn(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 362 | int state, uint32_t dexIdx, uint32_t unused) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 363 | { |
| 364 | switch(state) { |
| 365 | case 0: // Get the current Method* [sets r0] |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 366 | loadCurrMethodDirect(cUnit, r0); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 367 | break; |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 368 | case 1: // Get method->code_and_direct_methods_ |
| 369 | loadWordDisp(cUnit, r0, |
| 370 | Method::GetDexCacheCodeAndDirectMethodsOffset().Int32Value(), |
| 371 | r0); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 372 | break; |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 373 | case 2: // Grab target method* and target code_ |
| 374 | loadWordDisp(cUnit, r0, |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 375 | CodeAndDirectMethods::CodeOffsetInBytes(dexIdx), rLR); |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 376 | loadWordDisp(cUnit, r0, |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 377 | CodeAndDirectMethods::MethodOffsetInBytes(dexIdx), r0); |
buzbee | c5ef046 | 2011-08-25 18:44:49 -0700 | [diff] [blame] | 378 | break; |
| 379 | default: |
| 380 | return -1; |
| 381 | } |
| 382 | return state + 1; |
| 383 | } |
| 384 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 385 | /* |
| 386 | * Bit of a hack here - in leiu of a real scheduling pass, |
| 387 | * emit the next instruction in a virtual invoke sequence. |
| 388 | * We can use rLR as a temp prior to target address loading |
| 389 | * Note also that we'll load the first argument ("this") into |
| 390 | * r1 here rather than the standard loadArgRegs. |
| 391 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 392 | STATIC int nextVCallInsn(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 393 | int state, uint32_t dexIdx, uint32_t methodIdx) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 394 | { |
| 395 | RegLocation rlArg; |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 396 | /* |
| 397 | * This is the fast path in which the target virtual method is |
| 398 | * fully resolved at compile time. |
| 399 | */ |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 400 | switch(state) { |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 401 | case 0: // Get "this" [set r1] |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 402 | rlArg = oatGetSrc(cUnit, mir, 0); |
| 403 | loadValueDirectFixed(cUnit, rlArg, r1); |
| 404 | break; |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 405 | case 1: // Is "this" null? [use r1] |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 406 | genNullCheck(cUnit, oatSSASrc(mir,0), r1, mir); |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 407 | // get this->klass_ [use r1, set rLR] |
| 408 | loadWordDisp(cUnit, r1, Object::ClassOffset().Int32Value(), rLR); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 409 | break; |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 410 | case 2: // Get this->klass_->vtable [usr rLR, set rLR] |
| 411 | loadWordDisp(cUnit, rLR, Class::VTableOffset().Int32Value(), rLR); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 412 | break; |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 413 | case 3: // Get target method [use rLR, set r0] |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 414 | loadWordDisp(cUnit, rLR, (methodIdx * 4) + |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 415 | Array::DataOffset().Int32Value(), r0); |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 416 | break; |
| 417 | case 4: // Get the target compiled code address [uses r0, sets rLR] |
| 418 | loadWordDisp(cUnit, r0, Method::GetCodeOffset().Int32Value(), rLR); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 419 | break; |
| 420 | default: |
| 421 | return -1; |
| 422 | } |
| 423 | return state + 1; |
| 424 | } |
| 425 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 426 | /* |
| 427 | * Interleave launch code for INVOKE_SUPER. See comments |
| 428 | * for nextVCallIns. |
| 429 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 430 | STATIC int nextSuperCallInsn(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 431 | int state, uint32_t dexIdx, uint32_t methodIdx) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 432 | { |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 433 | /* |
| 434 | * This is the fast path in which the target virtual method is |
| 435 | * fully resolved at compile time. Note also that this path assumes |
| 436 | * that the check to verify that the target method index falls |
| 437 | * within the size of the super's vtable has been done at compile-time. |
| 438 | */ |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 439 | RegLocation rlArg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 440 | switch(state) { |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 441 | case 0: // Get current Method* [set r0] |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 442 | loadCurrMethodDirect(cUnit, r0); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 443 | // Load "this" [set r1] |
| 444 | rlArg = oatGetSrc(cUnit, mir, 0); |
| 445 | loadValueDirectFixed(cUnit, rlArg, r1); |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 446 | // Get method->declaring_class_ [use r0, set rLR] |
| 447 | loadWordDisp(cUnit, r0, Method::DeclaringClassOffset().Int32Value(), |
| 448 | rLR); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 449 | // Is "this" null? [use r1] |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 450 | genNullCheck(cUnit, oatSSASrc(mir,0), r1, mir); |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 451 | break; |
| 452 | case 1: // Get method->declaring_class_->super_class [usr rLR, set rLR] |
| 453 | loadWordDisp(cUnit, rLR, Class::SuperClassOffset().Int32Value(), |
| 454 | rLR); |
| 455 | break; |
| 456 | case 2: // Get ...->super_class_->vtable [u/s rLR] |
| 457 | loadWordDisp(cUnit, rLR, Class::VTableOffset().Int32Value(), rLR); |
| 458 | break; |
| 459 | case 3: // Get target method [use rLR, set r0] |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 460 | loadWordDisp(cUnit, rLR, (methodIdx * 4) + |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 461 | Array::DataOffset().Int32Value(), r0); |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 462 | break; |
| 463 | case 4: // Get the target compiled code address [uses r0, sets rLR] |
| 464 | loadWordDisp(cUnit, r0, Method::GetCodeOffset().Int32Value(), rLR); |
| 465 | break; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 466 | default: |
| 467 | return -1; |
| 468 | } |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 469 | return state + 1; |
| 470 | } |
| 471 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 472 | STATIC int nextInvokeInsnSP(CompilationUnit* cUnit, MIR* mir, int trampoline, |
| 473 | int state, uint32_t dexIdx, uint32_t methodIdx) |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 474 | { |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 475 | /* |
| 476 | * This handles the case in which the base method is not fully |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 477 | * resolved at compile time, we bail to a runtime helper. |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 478 | */ |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 479 | if (state == 0) { |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 480 | // Load trampoline target |
| 481 | loadWordDisp(cUnit, rSELF, trampoline, rLR); |
| 482 | // Load r0 with method index |
| 483 | loadConstant(cUnit, r0, dexIdx); |
| 484 | return 1; |
buzbee | 4a3164f | 2011-09-03 11:25:10 -0700 | [diff] [blame] | 485 | } |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 486 | return -1; |
| 487 | } |
| 488 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 489 | STATIC int nextStaticCallInsnSP(CompilationUnit* cUnit, MIR* mir, |
| 490 | int state, uint32_t dexIdx, uint32_t methodIdx) |
| 491 | { |
| 492 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeStaticTrampolineWithAccessCheck); |
| 493 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 494 | } |
| 495 | |
| 496 | STATIC int nextDirectCallInsnSP(CompilationUnit* cUnit, MIR* mir, |
| 497 | int state, uint32_t dexIdx, uint32_t methodIdx) |
| 498 | { |
| 499 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeDirectTrampolineWithAccessCheck); |
| 500 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 501 | } |
| 502 | |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 503 | STATIC int nextSuperCallInsnSP(CompilationUnit* cUnit, MIR* mir, |
| 504 | int state, uint32_t dexIdx, uint32_t methodIdx) |
| 505 | { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 506 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeSuperTrampolineWithAccessCheck); |
| 507 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | STATIC int nextVCallInsnSP(CompilationUnit* cUnit, MIR* mir, |
| 511 | int state, uint32_t dexIdx, uint32_t methodIdx) |
| 512 | { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 513 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeVirtualTrampolineWithAccessCheck); |
| 514 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | /* |
| 518 | * All invoke-interface calls bounce off of art_invoke_interface_trampoline, |
| 519 | * which will locate the target and continue on via a tail call. |
| 520 | */ |
| 521 | STATIC int nextInterfaceCallInsn(CompilationUnit* cUnit, MIR* mir, |
| 522 | int state, uint32_t dexIdx, uint32_t unused) |
| 523 | { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 524 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeInterfaceTrampoline); |
| 525 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | STATIC int nextInterfaceCallInsnWithAccessCheck(CompilationUnit* cUnit, |
| 529 | MIR* mir, int state, |
| 530 | uint32_t dexIdx, |
| 531 | uint32_t unused) |
| 532 | { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 533 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeInterfaceTrampolineWithAccessCheck); |
| 534 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | STATIC int loadArgRegs(CompilationUnit* cUnit, MIR* mir, |
| 538 | DecodedInstruction* dInsn, int callState, |
| 539 | NextCallInsn nextCallInsn, uint32_t dexIdx, |
| 540 | uint32_t methodIdx, bool skipThis) |
| 541 | { |
| 542 | int nextReg = r1; |
| 543 | int nextArg = 0; |
| 544 | if (skipThis) { |
| 545 | nextReg++; |
| 546 | nextArg++; |
| 547 | } |
| 548 | for (; (nextReg <= r3) && (nextArg < mir->ssaRep->numUses); nextReg++) { |
| 549 | RegLocation rlArg = oatGetRawSrc(cUnit, mir, nextArg++); |
| 550 | rlArg = oatUpdateRawLoc(cUnit, rlArg); |
| 551 | if (rlArg.wide && (nextReg <= r2)) { |
| 552 | loadValueDirectWideFixed(cUnit, rlArg, nextReg, nextReg + 1); |
| 553 | nextReg++; |
| 554 | nextArg++; |
| 555 | } else { |
| 556 | rlArg.wide = false; |
| 557 | loadValueDirectFixed(cUnit, rlArg, nextReg); |
| 558 | } |
| 559 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx); |
| 560 | } |
| 561 | return callState; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /* |
| 565 | * Load up to 5 arguments, the first three of which will be in |
| 566 | * r1 .. r3. On entry r0 contains the current method pointer, |
| 567 | * and as part of the load sequence, it must be replaced with |
| 568 | * the target method pointer. Note, this may also be called |
| 569 | * for "range" variants if the number of arguments is 5 or fewer. |
| 570 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 571 | STATIC int genDalvikArgsNoRange(CompilationUnit* cUnit, MIR* mir, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 572 | DecodedInstruction* dInsn, int callState, |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 573 | ArmLIR** pcrLabel, NextCallInsn nextCallInsn, |
| 574 | uint32_t dexIdx, uint32_t methodIdx, |
| 575 | bool skipThis) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 576 | { |
| 577 | RegLocation rlArg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 578 | |
| 579 | /* If no arguments, just return */ |
| 580 | if (dInsn->vA == 0) |
| 581 | return callState; |
| 582 | |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 583 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 584 | |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 585 | DCHECK_LE(dInsn->vA, 5U); |
| 586 | if (dInsn->vA > 3) { |
| 587 | uint32_t nextUse = 3; |
| 588 | //Detect special case of wide arg spanning arg3/arg4 |
| 589 | RegLocation rlUse0 = oatGetRawSrc(cUnit, mir, 0); |
| 590 | RegLocation rlUse1 = oatGetRawSrc(cUnit, mir, 1); |
| 591 | RegLocation rlUse2 = oatGetRawSrc(cUnit, mir, 2); |
| 592 | if (((!rlUse0.wide && !rlUse1.wide) || rlUse0.wide) && |
| 593 | rlUse2.wide) { |
| 594 | int reg; |
| 595 | // Wide spans, we need the 2nd half of uses[2]. |
| 596 | rlArg = oatUpdateLocWide(cUnit, rlUse2); |
| 597 | if (rlArg.location == kLocPhysReg) { |
| 598 | reg = rlArg.highReg; |
| 599 | } else { |
| 600 | // r2 & r3 can safely be used here |
| 601 | reg = r3; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 602 | loadWordDisp(cUnit, rSP, |
| 603 | oatSRegOffset(cUnit, rlArg.sRegLow) + 4, reg); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 604 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, |
| 605 | methodIdx); |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 606 | } |
| 607 | storeBaseDisp(cUnit, rSP, (nextUse + 1) * 4, reg, kWord); |
| 608 | storeBaseDisp(cUnit, rSP, 16 /* (3+1)*4 */, reg, kWord); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 609 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx); |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 610 | nextUse++; |
| 611 | } |
| 612 | // Loop through the rest |
| 613 | while (nextUse < dInsn->vA) { |
| 614 | int lowReg; |
| 615 | int highReg; |
| 616 | rlArg = oatGetRawSrc(cUnit, mir, nextUse); |
| 617 | rlArg = oatUpdateRawLoc(cUnit, rlArg); |
| 618 | if (rlArg.location == kLocPhysReg) { |
| 619 | lowReg = rlArg.lowReg; |
| 620 | highReg = rlArg.highReg; |
| 621 | } else { |
| 622 | lowReg = r2; |
| 623 | highReg = r3; |
| 624 | if (rlArg.wide) { |
| 625 | loadValueDirectWideFixed(cUnit, rlArg, lowReg, highReg); |
| 626 | } else { |
| 627 | loadValueDirectFixed(cUnit, rlArg, lowReg); |
| 628 | } |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 629 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, |
| 630 | methodIdx); |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 631 | } |
| 632 | int outsOffset = (nextUse + 1) * 4; |
| 633 | if (rlArg.wide) { |
| 634 | storeBaseDispWide(cUnit, rSP, outsOffset, lowReg, highReg); |
| 635 | nextUse += 2; |
| 636 | } else { |
| 637 | storeWordDisp(cUnit, rSP, outsOffset, lowReg); |
| 638 | nextUse++; |
| 639 | } |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 640 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 641 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 642 | } |
| 643 | |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 644 | callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn, |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 645 | dexIdx, methodIdx, skipThis); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 646 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 647 | if (pcrLabel) { |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 648 | *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), r1, mir); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 649 | } |
| 650 | return callState; |
| 651 | } |
| 652 | |
| 653 | /* |
| 654 | * May have 0+ arguments (also used for jumbo). Note that |
| 655 | * source virtual registers may be in physical registers, so may |
| 656 | * need to be flushed to home location before copying. This |
| 657 | * applies to arg3 and above (see below). |
| 658 | * |
| 659 | * Two general strategies: |
| 660 | * If < 20 arguments |
| 661 | * Pass args 3-18 using vldm/vstm block copy |
| 662 | * Pass arg0, arg1 & arg2 in r1-r3 |
| 663 | * If 20+ arguments |
| 664 | * Pass args arg19+ using memcpy block copy |
| 665 | * Pass arg0, arg1 & arg2 in r1-r3 |
| 666 | * |
| 667 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 668 | STATIC int genDalvikArgsRange(CompilationUnit* cUnit, MIR* mir, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 669 | DecodedInstruction* dInsn, int callState, |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 670 | ArmLIR** pcrLabel, NextCallInsn nextCallInsn, |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 671 | uint32_t dexIdx, uint32_t methodIdx, |
| 672 | bool skipThis) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 673 | { |
| 674 | int firstArg = dInsn->vC; |
| 675 | int numArgs = dInsn->vA; |
buzbee | e9a72f6 | 2011-09-04 17:59:07 -0700 | [diff] [blame] | 676 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 677 | // If we can treat it as non-range (Jumbo ops will use range form) |
| 678 | if (numArgs <= 5) |
| 679 | return genDalvikArgsNoRange(cUnit, mir, dInsn, callState, pcrLabel, |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 680 | nextCallInsn, dexIdx, methodIdx, |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 681 | skipThis); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 682 | /* |
| 683 | * Make sure range list doesn't span the break between in normal |
| 684 | * Dalvik vRegs and the ins. |
| 685 | */ |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 686 | int highestArg = oatGetSrc(cUnit, mir, numArgs-1).sRegLow; |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 687 | int boundaryReg = cUnit->numDalvikRegisters - cUnit->numIns; |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 688 | if ((firstArg < boundaryReg) && (highestArg >= boundaryReg)) { |
| 689 | LOG(FATAL) << "Argument list spanned locals & args"; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /* |
| 693 | * First load the non-register arguments. Both forms expect all |
| 694 | * of the source arguments to be in their home frame location, so |
| 695 | * scan the sReg names and flush any that have been promoted to |
| 696 | * frame backing storage. |
| 697 | */ |
| 698 | // Scan the rest of the args - if in physReg flush to memory |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 699 | for (int nextArg = 0; nextArg < numArgs;) { |
| 700 | RegLocation loc = oatGetRawSrc(cUnit, mir, nextArg); |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 701 | if (loc.wide) { |
| 702 | loc = oatUpdateLocWide(cUnit, loc); |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 703 | if ((nextArg >= 2) && (loc.location == kLocPhysReg)) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 704 | storeBaseDispWide(cUnit, rSP, |
| 705 | oatSRegOffset(cUnit, loc.sRegLow), |
| 706 | loc.lowReg, loc.highReg); |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 707 | } |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 708 | nextArg += 2; |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 709 | } else { |
| 710 | loc = oatUpdateLoc(cUnit, loc); |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 711 | if ((nextArg >= 3) && (loc.location == kLocPhysReg)) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 712 | storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow), |
| 713 | loc.lowReg, kWord); |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 714 | } |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 715 | nextArg++; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 719 | int startOffset = oatSRegOffset(cUnit, |
| 720 | cUnit->regLocation[mir->ssaRep->uses[3]].sRegLow); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 721 | int outsOffset = 4 /* Method* */ + (3 * 4); |
| 722 | if (numArgs >= 20) { |
buzbee | c0fe6c7 | 2011-09-18 20:19:14 -0700 | [diff] [blame] | 723 | // Generate memcpy |
| 724 | opRegRegImm(cUnit, kOpAdd, r0, rSP, outsOffset); |
| 725 | opRegRegImm(cUnit, kOpAdd, r1, rSP, startOffset); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 726 | loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pMemcpy), rLR); |
| 727 | loadConstant(cUnit, r2, (numArgs - 3) * 4); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 728 | callRuntimeHelper(cUnit, rLR); |
buzbee | 010cffc | 2011-09-21 18:28:43 -0700 | [diff] [blame] | 729 | // Restore Method* |
| 730 | loadCurrMethodDirect(cUnit, r0); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 731 | } else { |
| 732 | // Use vldm/vstm pair using r3 as a temp |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 733 | int regsLeft = std::min(numArgs - 3, 16); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 734 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 735 | opRegRegImm(cUnit, kOpAdd, r3, rSP, startOffset); |
buzbee | f48e971 | 2011-09-15 17:54:28 -0700 | [diff] [blame] | 736 | ArmLIR* ld = newLIR3(cUnit, kThumb2Vldms, r3, fr0, regsLeft); |
| 737 | //TUNING: loosen barrier |
| 738 | ld->defMask = ENCODE_ALL; |
| 739 | setMemRefType(ld, true /* isLoad */, kDalvikReg); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 740 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 741 | opRegRegImm(cUnit, kOpAdd, r3, rSP, 4 /* Method* */ + (3 * 4)); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 742 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx); |
buzbee | f48e971 | 2011-09-15 17:54:28 -0700 | [diff] [blame] | 743 | ArmLIR* st = newLIR3(cUnit, kThumb2Vstms, r3, fr0, regsLeft); |
| 744 | setMemRefType(st, false /* isLoad */, kDalvikReg); |
| 745 | st->defMask = ENCODE_ALL; |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 746 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 747 | } |
| 748 | |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 749 | callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn, |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 750 | dexIdx, methodIdx, skipThis); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 751 | |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 752 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx); |
buzbee | 99f2723 | 2011-10-05 12:56:36 -0700 | [diff] [blame] | 753 | if (pcrLabel) { |
| 754 | *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), r1, mir); |
| 755 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 756 | return callState; |
| 757 | } |
| 758 | |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 759 | // Debugging routine - if null target, branch to DebugMe |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 760 | STATIC void genShowTarget(CompilationUnit* cUnit) |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 761 | { |
| 762 | ArmLIR* branchOver = genCmpImmBranch(cUnit, kArmCondNe, rLR, 0); |
| 763 | loadWordDisp(cUnit, rSELF, |
| 764 | OFFSETOF_MEMBER(Thread, pDebugMe), rLR); |
| 765 | ArmLIR* target = newLIR0(cUnit, kArmPseudoTargetLabel); |
| 766 | target->defMask = -1; |
| 767 | branchOver->generic.target = (LIR*)target; |
| 768 | } |
buzbee | 2a475e7 | 2011-09-07 17:19:17 -0700 | [diff] [blame] | 769 | |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 770 | STATIC void genInvoke(CompilationUnit* cUnit, MIR* mir, |
| 771 | InvokeType type, bool isRange) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 772 | { |
| 773 | DecodedInstruction* dInsn = &mir->dalvikInsn; |
| 774 | int callState = 0; |
| 775 | ArmLIR* nullCk; |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 776 | ArmLIR** pNullCk = NULL; |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 777 | NextCallInsn nextCallInsn; |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 778 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
buzbee | 109bd6a | 2011-09-06 13:58:41 -0700 | [diff] [blame] | 779 | // Explicit register usage |
| 780 | oatLockCallTemps(cUnit); |
buzbee | 34c77ad | 2012-01-11 13:01:32 -0800 | [diff] [blame] | 781 | |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 782 | uint32_t dexMethodIdx = dInsn->vB; |
| 783 | int vtableIdx; |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 784 | bool skipThis; |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 785 | bool fastPath = |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 786 | cUnit->compiler->ComputeInvokeInfo(dexMethodIdx, cUnit, type, |
| 787 | vtableIdx) |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 788 | && !SLOW_INVOKE_PATH; |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 789 | if (type == kInterface) { |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 790 | nextCallInsn = fastPath ? nextInterfaceCallInsn |
| 791 | : nextInterfaceCallInsnWithAccessCheck; |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 792 | skipThis = false; |
| 793 | } else if (type == kDirect) { |
| 794 | if (fastPath) { |
| 795 | pNullCk = &nullCk; |
| 796 | } |
| 797 | nextCallInsn = fastPath ? nextSDCallInsn : nextDirectCallInsnSP; |
| 798 | skipThis = false; |
| 799 | } else if (type == kStatic) { |
| 800 | nextCallInsn = fastPath ? nextSDCallInsn : nextStaticCallInsnSP; |
| 801 | skipThis = false; |
| 802 | } else if (type == kSuper) { |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 803 | nextCallInsn = fastPath ? nextSuperCallInsn : nextSuperCallInsnSP; |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 804 | skipThis = fastPath; |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 805 | } else { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 806 | DCHECK_EQ(type, kVirtual); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 807 | nextCallInsn = fastPath ? nextVCallInsn : nextVCallInsnSP; |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 808 | skipThis = fastPath; |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 809 | } |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 810 | if (!isRange) { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 811 | callState = genDalvikArgsNoRange(cUnit, mir, dInsn, callState, pNullCk, |
| 812 | nextCallInsn, dexMethodIdx, |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 813 | vtableIdx, skipThis); |
| 814 | } else { |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 815 | callState = genDalvikArgsRange(cUnit, mir, dInsn, callState, pNullCk, |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 816 | nextCallInsn, dexMethodIdx, vtableIdx, |
| 817 | skipThis); |
| 818 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 819 | // Finish up any of the call sequence not interleaved in arg loading |
| 820 | while (callState >= 0) { |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 821 | callState = nextCallInsn(cUnit, mir, callState, dexMethodIdx, |
| 822 | vtableIdx); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 823 | } |
buzbee | ce30293 | 2011-10-04 14:32:18 -0700 | [diff] [blame] | 824 | if (DISPLAY_MISSING_TARGETS) { |
| 825 | genShowTarget(cUnit); |
| 826 | } |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 827 | opReg(cUnit, kOpBlx, rLR); |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 828 | oatClobberCalleeSave(cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 829 | } |
| 830 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 831 | STATIC bool compileDalvikInstruction(CompilationUnit* cUnit, MIR* mir, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 832 | BasicBlock* bb, ArmLIR* labelList) |
| 833 | { |
| 834 | bool res = false; // Assume success |
| 835 | RegLocation rlSrc[3]; |
| 836 | RegLocation rlDest = badLoc; |
| 837 | RegLocation rlResult = badLoc; |
| 838 | Opcode opcode = mir->dalvikInsn.opcode; |
| 839 | |
| 840 | /* Prep Src and Dest locations */ |
| 841 | int nextSreg = 0; |
| 842 | int nextLoc = 0; |
| 843 | int attrs = oatDataFlowAttributes[opcode]; |
| 844 | rlSrc[0] = rlSrc[1] = rlSrc[2] = badLoc; |
| 845 | if (attrs & DF_UA) { |
| 846 | rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg); |
| 847 | nextSreg++; |
| 848 | } else if (attrs & DF_UA_WIDE) { |
| 849 | rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg, |
| 850 | nextSreg + 1); |
| 851 | nextSreg+= 2; |
| 852 | } |
| 853 | if (attrs & DF_UB) { |
| 854 | rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg); |
| 855 | nextSreg++; |
| 856 | } else if (attrs & DF_UB_WIDE) { |
| 857 | rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg, |
| 858 | nextSreg + 1); |
| 859 | nextSreg+= 2; |
| 860 | } |
| 861 | if (attrs & DF_UC) { |
| 862 | rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg); |
| 863 | } else if (attrs & DF_UC_WIDE) { |
| 864 | rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg, |
| 865 | nextSreg + 1); |
| 866 | } |
| 867 | if (attrs & DF_DA) { |
| 868 | rlDest = oatGetDest(cUnit, mir, 0); |
| 869 | } else if (attrs & DF_DA_WIDE) { |
| 870 | rlDest = oatGetDestWide(cUnit, mir, 0, 1); |
| 871 | } |
| 872 | |
| 873 | switch(opcode) { |
| 874 | case OP_NOP: |
| 875 | break; |
| 876 | |
| 877 | case OP_MOVE_EXCEPTION: |
| 878 | int exOffset; |
| 879 | int resetReg; |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 880 | exOffset = Thread::ExceptionOffset().Int32Value(); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 881 | resetReg = oatAllocTemp(cUnit); |
| 882 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 883 | loadWordDisp(cUnit, rSELF, exOffset, rlResult.lowReg); |
| 884 | loadConstant(cUnit, resetReg, 0); |
| 885 | storeWordDisp(cUnit, rSELF, exOffset, resetReg); |
| 886 | storeValue(cUnit, rlDest, rlResult); |
| 887 | break; |
| 888 | |
| 889 | case OP_RETURN_VOID: |
buzbee | fe2e17f | 2011-10-10 09:35:02 -0700 | [diff] [blame] | 890 | genSuspendTest(cUnit, mir); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 891 | break; |
| 892 | |
| 893 | case OP_RETURN: |
| 894 | case OP_RETURN_OBJECT: |
buzbee | fe2e17f | 2011-10-10 09:35:02 -0700 | [diff] [blame] | 895 | genSuspendTest(cUnit, mir); |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 896 | storeValue(cUnit, getRetLoc(cUnit), rlSrc[0]); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 897 | break; |
| 898 | |
| 899 | case OP_RETURN_WIDE: |
buzbee | fe2e17f | 2011-10-10 09:35:02 -0700 | [diff] [blame] | 900 | genSuspendTest(cUnit, mir); |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 901 | storeValueWide(cUnit, getRetLocWide(cUnit), rlSrc[0]); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 902 | break; |
| 903 | |
| 904 | case OP_MOVE_RESULT_WIDE: |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 905 | if (mir->optimizationFlags & MIR_INLINED) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 906 | break; // Nop - combined w/ previous invoke |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 907 | storeValueWide(cUnit, rlDest, getRetLocWide(cUnit)); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 908 | break; |
| 909 | |
| 910 | case OP_MOVE_RESULT: |
| 911 | case OP_MOVE_RESULT_OBJECT: |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 912 | if (mir->optimizationFlags & MIR_INLINED) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 913 | break; // Nop - combined w/ previous invoke |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 914 | storeValue(cUnit, rlDest, getRetLoc(cUnit)); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 915 | break; |
| 916 | |
| 917 | case OP_MOVE: |
| 918 | case OP_MOVE_OBJECT: |
| 919 | case OP_MOVE_16: |
| 920 | case OP_MOVE_OBJECT_16: |
| 921 | case OP_MOVE_FROM16: |
| 922 | case OP_MOVE_OBJECT_FROM16: |
| 923 | storeValue(cUnit, rlDest, rlSrc[0]); |
| 924 | break; |
| 925 | |
| 926 | case OP_MOVE_WIDE: |
| 927 | case OP_MOVE_WIDE_16: |
| 928 | case OP_MOVE_WIDE_FROM16: |
| 929 | storeValueWide(cUnit, rlDest, rlSrc[0]); |
| 930 | break; |
| 931 | |
| 932 | case OP_CONST: |
| 933 | case OP_CONST_4: |
| 934 | case OP_CONST_16: |
| 935 | rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 936 | loadConstantNoClobber(cUnit, rlResult.lowReg, mir->dalvikInsn.vB); |
| 937 | storeValue(cUnit, rlDest, rlResult); |
| 938 | break; |
| 939 | |
| 940 | case OP_CONST_HIGH16: |
| 941 | rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 942 | loadConstantNoClobber(cUnit, rlResult.lowReg, |
| 943 | mir->dalvikInsn.vB << 16); |
| 944 | storeValue(cUnit, rlDest, rlResult); |
| 945 | break; |
| 946 | |
| 947 | case OP_CONST_WIDE_16: |
| 948 | case OP_CONST_WIDE_32: |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 949 | rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 950 | loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg, |
| 951 | mir->dalvikInsn.vB, |
| 952 | (mir->dalvikInsn.vB & 0x80000000) ? -1 : 0); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 953 | storeValueWide(cUnit, rlDest, rlResult); |
| 954 | break; |
| 955 | |
| 956 | case OP_CONST_WIDE: |
| 957 | rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 958 | loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg, |
buzbee | 5433072 | 2011-08-23 16:46:55 -0700 | [diff] [blame] | 959 | mir->dalvikInsn.vB_wide & 0xffffffff, |
| 960 | (mir->dalvikInsn.vB_wide >> 32) & 0xffffffff); |
buzbee | 3ea4ec5 | 2011-08-22 17:37:19 -0700 | [diff] [blame] | 961 | storeValueWide(cUnit, rlDest, rlResult); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 962 | break; |
| 963 | |
| 964 | case OP_CONST_WIDE_HIGH16: |
| 965 | rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 966 | loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg, |
| 967 | 0, mir->dalvikInsn.vB << 16); |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 968 | storeValueWide(cUnit, rlDest, rlResult); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 969 | break; |
| 970 | |
| 971 | case OP_MONITOR_ENTER: |
| 972 | genMonitorEnter(cUnit, mir, rlSrc[0]); |
| 973 | break; |
| 974 | |
| 975 | case OP_MONITOR_EXIT: |
| 976 | genMonitorExit(cUnit, mir, rlSrc[0]); |
| 977 | break; |
| 978 | |
| 979 | case OP_CHECK_CAST: |
| 980 | genCheckCast(cUnit, mir, rlSrc[0]); |
| 981 | break; |
| 982 | |
| 983 | case OP_INSTANCE_OF: |
| 984 | genInstanceof(cUnit, mir, rlDest, rlSrc[0]); |
| 985 | break; |
| 986 | |
| 987 | case OP_NEW_INSTANCE: |
| 988 | genNewInstance(cUnit, mir, rlDest); |
| 989 | break; |
| 990 | |
| 991 | case OP_THROW: |
| 992 | genThrow(cUnit, mir, rlSrc[0]); |
| 993 | break; |
| 994 | |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 995 | case OP_THROW_VERIFICATION_ERROR: |
| 996 | loadWordDisp(cUnit, rSELF, |
| 997 | OFFSETOF_MEMBER(Thread, pThrowVerificationErrorFromCode), rLR); |
| 998 | loadConstant(cUnit, r0, mir->dalvikInsn.vA); |
| 999 | loadConstant(cUnit, r1, mir->dalvikInsn.vB); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 1000 | callRuntimeHelper(cUnit, rLR); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 1001 | break; |
| 1002 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1003 | case OP_ARRAY_LENGTH: |
| 1004 | int lenOffset; |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 1005 | lenOffset = Array::LengthOffset().Int32Value(); |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 1006 | rlSrc[0] = loadValue(cUnit, rlSrc[0], kCoreReg); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 1007 | genNullCheck(cUnit, rlSrc[0].sRegLow, rlSrc[0].lowReg, mir); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1008 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1009 | loadWordDisp(cUnit, rlSrc[0].lowReg, lenOffset, |
| 1010 | rlResult.lowReg); |
| 1011 | storeValue(cUnit, rlDest, rlResult); |
| 1012 | break; |
| 1013 | |
| 1014 | case OP_CONST_STRING: |
| 1015 | case OP_CONST_STRING_JUMBO: |
| 1016 | genConstString(cUnit, mir, rlDest, rlSrc[0]); |
| 1017 | break; |
| 1018 | |
| 1019 | case OP_CONST_CLASS: |
| 1020 | genConstClass(cUnit, mir, rlDest, rlSrc[0]); |
| 1021 | break; |
| 1022 | |
| 1023 | case OP_FILL_ARRAY_DATA: |
| 1024 | genFillArrayData(cUnit, mir, rlSrc[0]); |
| 1025 | break; |
| 1026 | |
| 1027 | case OP_FILLED_NEW_ARRAY: |
| 1028 | genFilledNewArray(cUnit, mir, false /* not range */); |
| 1029 | break; |
| 1030 | |
| 1031 | case OP_FILLED_NEW_ARRAY_RANGE: |
| 1032 | genFilledNewArray(cUnit, mir, true /* range */); |
| 1033 | break; |
| 1034 | |
| 1035 | case OP_NEW_ARRAY: |
| 1036 | genNewArray(cUnit, mir, rlDest, rlSrc[0]); |
| 1037 | break; |
| 1038 | |
| 1039 | case OP_GOTO: |
| 1040 | case OP_GOTO_16: |
| 1041 | case OP_GOTO_32: |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 1042 | if (bb->taken->startOffset <= mir->offset) { |
| 1043 | genSuspendTest(cUnit, mir); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1044 | } |
| 1045 | genUnconditionalBranch(cUnit, &labelList[bb->taken->id]); |
| 1046 | break; |
| 1047 | |
| 1048 | case OP_PACKED_SWITCH: |
| 1049 | genPackedSwitch(cUnit, mir, rlSrc[0]); |
| 1050 | break; |
| 1051 | |
| 1052 | case OP_SPARSE_SWITCH: |
| 1053 | genSparseSwitch(cUnit, mir, rlSrc[0]); |
| 1054 | break; |
| 1055 | |
| 1056 | case OP_CMPL_FLOAT: |
| 1057 | case OP_CMPG_FLOAT: |
| 1058 | case OP_CMPL_DOUBLE: |
| 1059 | case OP_CMPG_DOUBLE: |
| 1060 | res = genCmpFP(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 1061 | break; |
| 1062 | |
| 1063 | case OP_CMP_LONG: |
| 1064 | genCmpLong(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 1065 | break; |
| 1066 | |
| 1067 | case OP_IF_EQ: |
| 1068 | case OP_IF_NE: |
| 1069 | case OP_IF_LT: |
| 1070 | case OP_IF_GE: |
| 1071 | case OP_IF_GT: |
| 1072 | case OP_IF_LE: { |
| 1073 | bool backwardBranch; |
| 1074 | ArmConditionCode cond; |
| 1075 | backwardBranch = (bb->taken->startOffset <= mir->offset); |
| 1076 | if (backwardBranch) { |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 1077 | genSuspendTest(cUnit, mir); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1078 | } |
| 1079 | rlSrc[0] = loadValue(cUnit, rlSrc[0], kCoreReg); |
| 1080 | rlSrc[1] = loadValue(cUnit, rlSrc[1], kCoreReg); |
| 1081 | opRegReg(cUnit, kOpCmp, rlSrc[0].lowReg, rlSrc[1].lowReg); |
| 1082 | switch(opcode) { |
| 1083 | case OP_IF_EQ: |
| 1084 | cond = kArmCondEq; |
| 1085 | break; |
| 1086 | case OP_IF_NE: |
| 1087 | cond = kArmCondNe; |
| 1088 | break; |
| 1089 | case OP_IF_LT: |
| 1090 | cond = kArmCondLt; |
| 1091 | break; |
| 1092 | case OP_IF_GE: |
| 1093 | cond = kArmCondGe; |
| 1094 | break; |
| 1095 | case OP_IF_GT: |
| 1096 | cond = kArmCondGt; |
| 1097 | break; |
| 1098 | case OP_IF_LE: |
| 1099 | cond = kArmCondLe; |
| 1100 | break; |
| 1101 | default: |
| 1102 | cond = (ArmConditionCode)0; |
| 1103 | LOG(FATAL) << "Unexpected opcode " << (int)opcode; |
| 1104 | } |
| 1105 | genConditionalBranch(cUnit, cond, &labelList[bb->taken->id]); |
| 1106 | genUnconditionalBranch(cUnit, &labelList[bb->fallThrough->id]); |
| 1107 | break; |
| 1108 | } |
| 1109 | |
| 1110 | case OP_IF_EQZ: |
| 1111 | case OP_IF_NEZ: |
| 1112 | case OP_IF_LTZ: |
| 1113 | case OP_IF_GEZ: |
| 1114 | case OP_IF_GTZ: |
| 1115 | case OP_IF_LEZ: { |
| 1116 | bool backwardBranch; |
| 1117 | ArmConditionCode cond; |
| 1118 | backwardBranch = (bb->taken->startOffset <= mir->offset); |
| 1119 | if (backwardBranch) { |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 1120 | genSuspendTest(cUnit, mir); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1121 | } |
| 1122 | rlSrc[0] = loadValue(cUnit, rlSrc[0], kCoreReg); |
| 1123 | opRegImm(cUnit, kOpCmp, rlSrc[0].lowReg, 0); |
| 1124 | switch(opcode) { |
| 1125 | case OP_IF_EQZ: |
| 1126 | cond = kArmCondEq; |
| 1127 | break; |
| 1128 | case OP_IF_NEZ: |
| 1129 | cond = kArmCondNe; |
| 1130 | break; |
| 1131 | case OP_IF_LTZ: |
| 1132 | cond = kArmCondLt; |
| 1133 | break; |
| 1134 | case OP_IF_GEZ: |
| 1135 | cond = kArmCondGe; |
| 1136 | break; |
| 1137 | case OP_IF_GTZ: |
| 1138 | cond = kArmCondGt; |
| 1139 | break; |
| 1140 | case OP_IF_LEZ: |
| 1141 | cond = kArmCondLe; |
| 1142 | break; |
| 1143 | default: |
| 1144 | cond = (ArmConditionCode)0; |
| 1145 | LOG(FATAL) << "Unexpected opcode " << (int)opcode; |
| 1146 | } |
| 1147 | genConditionalBranch(cUnit, cond, &labelList[bb->taken->id]); |
| 1148 | genUnconditionalBranch(cUnit, &labelList[bb->fallThrough->id]); |
| 1149 | break; |
| 1150 | } |
| 1151 | |
| 1152 | case OP_AGET_WIDE: |
| 1153 | genArrayGet(cUnit, mir, kLong, rlSrc[0], rlSrc[1], rlDest, 3); |
| 1154 | break; |
| 1155 | case OP_AGET: |
| 1156 | case OP_AGET_OBJECT: |
| 1157 | genArrayGet(cUnit, mir, kWord, rlSrc[0], rlSrc[1], rlDest, 2); |
| 1158 | break; |
| 1159 | case OP_AGET_BOOLEAN: |
| 1160 | genArrayGet(cUnit, mir, kUnsignedByte, rlSrc[0], rlSrc[1], |
| 1161 | rlDest, 0); |
| 1162 | break; |
| 1163 | case OP_AGET_BYTE: |
| 1164 | genArrayGet(cUnit, mir, kSignedByte, rlSrc[0], rlSrc[1], rlDest, 0); |
| 1165 | break; |
| 1166 | case OP_AGET_CHAR: |
| 1167 | genArrayGet(cUnit, mir, kUnsignedHalf, rlSrc[0], rlSrc[1], |
| 1168 | rlDest, 1); |
| 1169 | break; |
| 1170 | case OP_AGET_SHORT: |
| 1171 | genArrayGet(cUnit, mir, kSignedHalf, rlSrc[0], rlSrc[1], rlDest, 1); |
| 1172 | break; |
| 1173 | case OP_APUT_WIDE: |
| 1174 | genArrayPut(cUnit, mir, kLong, rlSrc[1], rlSrc[2], rlSrc[0], 3); |
| 1175 | break; |
| 1176 | case OP_APUT: |
| 1177 | genArrayPut(cUnit, mir, kWord, rlSrc[1], rlSrc[2], rlSrc[0], 2); |
| 1178 | break; |
| 1179 | case OP_APUT_OBJECT: |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 1180 | genArrayObjPut(cUnit, mir, rlSrc[1], rlSrc[2], rlSrc[0], 2); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1181 | break; |
| 1182 | case OP_APUT_SHORT: |
| 1183 | case OP_APUT_CHAR: |
| 1184 | genArrayPut(cUnit, mir, kUnsignedHalf, rlSrc[1], rlSrc[2], |
| 1185 | rlSrc[0], 1); |
| 1186 | break; |
| 1187 | case OP_APUT_BYTE: |
| 1188 | case OP_APUT_BOOLEAN: |
| 1189 | genArrayPut(cUnit, mir, kUnsignedByte, rlSrc[1], rlSrc[2], |
| 1190 | rlSrc[0], 0); |
| 1191 | break; |
| 1192 | |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1193 | case OP_IGET_OBJECT: |
| 1194 | case OP_IGET_OBJECT_VOLATILE: |
| 1195 | genIGet(cUnit, mir, kWord, rlDest, rlSrc[0], false, true); |
| 1196 | break; |
| 1197 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1198 | case OP_IGET_WIDE: |
| 1199 | case OP_IGET_WIDE_VOLATILE: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1200 | genIGet(cUnit, mir, kLong, rlDest, rlSrc[0], true, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1201 | break; |
| 1202 | |
| 1203 | case OP_IGET: |
| 1204 | case OP_IGET_VOLATILE: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1205 | genIGet(cUnit, mir, kWord, rlDest, rlSrc[0], false, false); |
| 1206 | break; |
| 1207 | |
| 1208 | case OP_IGET_CHAR: |
| 1209 | genIGet(cUnit, mir, kUnsignedHalf, rlDest, rlSrc[0], false, false); |
| 1210 | break; |
| 1211 | |
| 1212 | case OP_IGET_SHORT: |
| 1213 | genIGet(cUnit, mir, kSignedHalf, rlDest, rlSrc[0], false, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1214 | break; |
| 1215 | |
| 1216 | case OP_IGET_BOOLEAN: |
| 1217 | case OP_IGET_BYTE: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1218 | genIGet(cUnit, mir, kUnsignedByte, rlDest, rlSrc[0], false, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1219 | break; |
| 1220 | |
| 1221 | case OP_IPUT_WIDE: |
| 1222 | case OP_IPUT_WIDE_VOLATILE: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1223 | genIPut(cUnit, mir, kLong, rlSrc[0], rlSrc[1], true, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1224 | break; |
| 1225 | |
| 1226 | case OP_IPUT_OBJECT: |
| 1227 | case OP_IPUT_OBJECT_VOLATILE: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1228 | genIPut(cUnit, mir, kWord, rlSrc[0], rlSrc[1], false, true); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1229 | break; |
| 1230 | |
| 1231 | case OP_IPUT: |
| 1232 | case OP_IPUT_VOLATILE: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1233 | genIPut(cUnit, mir, kWord, rlSrc[0], rlSrc[1], false, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1234 | break; |
| 1235 | |
| 1236 | case OP_IPUT_BOOLEAN: |
| 1237 | case OP_IPUT_BYTE: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1238 | genIPut(cUnit, mir, kUnsignedByte, rlSrc[0], rlSrc[1], false, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1239 | break; |
| 1240 | |
| 1241 | case OP_IPUT_CHAR: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1242 | genIPut(cUnit, mir, kUnsignedHalf, rlSrc[0], rlSrc[1], false, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1243 | break; |
| 1244 | |
| 1245 | case OP_IPUT_SHORT: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1246 | genIPut(cUnit, mir, kSignedHalf, rlSrc[0], rlSrc[1], false, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1247 | break; |
| 1248 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1249 | case OP_SGET_OBJECT: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1250 | genSget(cUnit, mir, rlDest, false, true); |
| 1251 | break; |
| 1252 | case OP_SGET: |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1253 | case OP_SGET_BOOLEAN: |
| 1254 | case OP_SGET_BYTE: |
| 1255 | case OP_SGET_CHAR: |
| 1256 | case OP_SGET_SHORT: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1257 | genSget(cUnit, mir, rlDest, false, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1258 | break; |
| 1259 | |
| 1260 | case OP_SGET_WIDE: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1261 | genSget(cUnit, mir, rlDest, true, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1262 | break; |
| 1263 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1264 | case OP_SPUT_OBJECT: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1265 | genSput(cUnit, mir, rlSrc[0], false, true); |
| 1266 | break; |
| 1267 | |
| 1268 | case OP_SPUT: |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1269 | case OP_SPUT_BOOLEAN: |
| 1270 | case OP_SPUT_BYTE: |
| 1271 | case OP_SPUT_CHAR: |
| 1272 | case OP_SPUT_SHORT: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1273 | genSput(cUnit, mir, rlSrc[0], false, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1274 | break; |
| 1275 | |
| 1276 | case OP_SPUT_WIDE: |
Ian Rogers | 1bddec3 | 2012-02-04 12:27:34 -0800 | [diff] [blame] | 1277 | genSput(cUnit, mir, rlSrc[0], true, false); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1278 | break; |
| 1279 | |
| 1280 | case OP_INVOKE_STATIC_RANGE: |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 1281 | genInvoke(cUnit, mir, kStatic, true /*range*/); |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 1282 | break; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1283 | case OP_INVOKE_STATIC: |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 1284 | genInvoke(cUnit, mir, kStatic, false /*range*/); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1285 | break; |
| 1286 | |
| 1287 | case OP_INVOKE_DIRECT: |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 1288 | genInvoke(cUnit, mir, kDirect, false /*range*/); |
buzbee | 561227c | 2011-09-02 15:28:19 -0700 | [diff] [blame] | 1289 | break; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1290 | case OP_INVOKE_DIRECT_RANGE: |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 1291 | genInvoke(cUnit, mir, kDirect, true /*range*/); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1292 | break; |
| 1293 | |
| 1294 | case OP_INVOKE_VIRTUAL: |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 1295 | genInvoke(cUnit, mir, kVirtual, false /*range*/); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 1296 | break; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1297 | case OP_INVOKE_VIRTUAL_RANGE: |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 1298 | genInvoke(cUnit, mir, kVirtual, true /*range*/); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1299 | break; |
| 1300 | |
| 1301 | case OP_INVOKE_SUPER: |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 1302 | genInvoke(cUnit, mir, kSuper, false /*range*/); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 1303 | break; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1304 | case OP_INVOKE_SUPER_RANGE: |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 1305 | genInvoke(cUnit, mir, kSuper, true /*range*/); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1306 | break; |
| 1307 | |
| 1308 | case OP_INVOKE_INTERFACE: |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 1309 | genInvoke(cUnit, mir, kInterface, false /*range*/); |
Ian Rogers | a32a6fd | 2012-02-06 20:18:44 -0800 | [diff] [blame] | 1310 | break; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1311 | case OP_INVOKE_INTERFACE_RANGE: |
Ian Rogers | c8b306f | 2012-02-17 21:34:44 -0800 | [diff] [blame] | 1312 | genInvoke(cUnit, mir, kInterface, true /*range*/); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1313 | break; |
| 1314 | |
| 1315 | case OP_NEG_INT: |
| 1316 | case OP_NOT_INT: |
| 1317 | res = genArithOpInt(cUnit, mir, rlDest, rlSrc[0], rlSrc[0]); |
| 1318 | break; |
| 1319 | |
| 1320 | case OP_NEG_LONG: |
| 1321 | case OP_NOT_LONG: |
| 1322 | res = genArithOpLong(cUnit, mir, rlDest, rlSrc[0], rlSrc[0]); |
| 1323 | break; |
| 1324 | |
| 1325 | case OP_NEG_FLOAT: |
| 1326 | res = genArithOpFloat(cUnit, mir, rlDest, rlSrc[0], rlSrc[0]); |
| 1327 | break; |
| 1328 | |
| 1329 | case OP_NEG_DOUBLE: |
| 1330 | res = genArithOpDouble(cUnit, mir, rlDest, rlSrc[0], rlSrc[0]); |
| 1331 | break; |
| 1332 | |
| 1333 | case OP_INT_TO_LONG: |
| 1334 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1335 | if (rlSrc[0].location == kLocPhysReg) { |
| 1336 | genRegCopy(cUnit, rlResult.lowReg, rlSrc[0].lowReg); |
| 1337 | } else { |
| 1338 | loadValueDirect(cUnit, rlSrc[0], rlResult.lowReg); |
| 1339 | } |
| 1340 | opRegRegImm(cUnit, kOpAsr, rlResult.highReg, |
| 1341 | rlResult.lowReg, 31); |
| 1342 | storeValueWide(cUnit, rlDest, rlResult); |
| 1343 | break; |
| 1344 | |
| 1345 | case OP_LONG_TO_INT: |
| 1346 | rlSrc[0] = oatUpdateLocWide(cUnit, rlSrc[0]); |
| 1347 | rlSrc[0] = oatWideToNarrow(cUnit, rlSrc[0]); |
| 1348 | storeValue(cUnit, rlDest, rlSrc[0]); |
| 1349 | break; |
| 1350 | |
| 1351 | case OP_INT_TO_BYTE: |
| 1352 | rlSrc[0] = loadValue(cUnit, rlSrc[0], kCoreReg); |
| 1353 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1354 | opRegReg(cUnit, kOp2Byte, rlResult.lowReg, rlSrc[0].lowReg); |
| 1355 | storeValue(cUnit, rlDest, rlResult); |
| 1356 | break; |
| 1357 | |
| 1358 | case OP_INT_TO_SHORT: |
| 1359 | rlSrc[0] = loadValue(cUnit, rlSrc[0], kCoreReg); |
| 1360 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1361 | opRegReg(cUnit, kOp2Short, rlResult.lowReg, rlSrc[0].lowReg); |
| 1362 | storeValue(cUnit, rlDest, rlResult); |
| 1363 | break; |
| 1364 | |
| 1365 | case OP_INT_TO_CHAR: |
| 1366 | rlSrc[0] = loadValue(cUnit, rlSrc[0], kCoreReg); |
| 1367 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1368 | opRegReg(cUnit, kOp2Char, rlResult.lowReg, rlSrc[0].lowReg); |
| 1369 | storeValue(cUnit, rlDest, rlResult); |
| 1370 | break; |
| 1371 | |
| 1372 | case OP_INT_TO_FLOAT: |
| 1373 | case OP_INT_TO_DOUBLE: |
| 1374 | case OP_LONG_TO_FLOAT: |
| 1375 | case OP_LONG_TO_DOUBLE: |
| 1376 | case OP_FLOAT_TO_INT: |
| 1377 | case OP_FLOAT_TO_LONG: |
| 1378 | case OP_FLOAT_TO_DOUBLE: |
| 1379 | case OP_DOUBLE_TO_INT: |
| 1380 | case OP_DOUBLE_TO_LONG: |
| 1381 | case OP_DOUBLE_TO_FLOAT: |
| 1382 | genConversion(cUnit, mir); |
| 1383 | break; |
| 1384 | |
| 1385 | case OP_ADD_INT: |
| 1386 | case OP_SUB_INT: |
| 1387 | case OP_MUL_INT: |
| 1388 | case OP_DIV_INT: |
| 1389 | case OP_REM_INT: |
| 1390 | case OP_AND_INT: |
| 1391 | case OP_OR_INT: |
| 1392 | case OP_XOR_INT: |
| 1393 | case OP_SHL_INT: |
| 1394 | case OP_SHR_INT: |
| 1395 | case OP_USHR_INT: |
| 1396 | case OP_ADD_INT_2ADDR: |
| 1397 | case OP_SUB_INT_2ADDR: |
| 1398 | case OP_MUL_INT_2ADDR: |
| 1399 | case OP_DIV_INT_2ADDR: |
| 1400 | case OP_REM_INT_2ADDR: |
| 1401 | case OP_AND_INT_2ADDR: |
| 1402 | case OP_OR_INT_2ADDR: |
| 1403 | case OP_XOR_INT_2ADDR: |
| 1404 | case OP_SHL_INT_2ADDR: |
| 1405 | case OP_SHR_INT_2ADDR: |
| 1406 | case OP_USHR_INT_2ADDR: |
| 1407 | genArithOpInt(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 1408 | break; |
| 1409 | |
| 1410 | case OP_ADD_LONG: |
| 1411 | case OP_SUB_LONG: |
| 1412 | case OP_MUL_LONG: |
| 1413 | case OP_DIV_LONG: |
| 1414 | case OP_REM_LONG: |
| 1415 | case OP_AND_LONG: |
| 1416 | case OP_OR_LONG: |
| 1417 | case OP_XOR_LONG: |
| 1418 | case OP_ADD_LONG_2ADDR: |
| 1419 | case OP_SUB_LONG_2ADDR: |
| 1420 | case OP_MUL_LONG_2ADDR: |
| 1421 | case OP_DIV_LONG_2ADDR: |
| 1422 | case OP_REM_LONG_2ADDR: |
| 1423 | case OP_AND_LONG_2ADDR: |
| 1424 | case OP_OR_LONG_2ADDR: |
| 1425 | case OP_XOR_LONG_2ADDR: |
| 1426 | genArithOpLong(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 1427 | break; |
| 1428 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1429 | case OP_SHL_LONG: |
| 1430 | case OP_SHR_LONG: |
| 1431 | case OP_USHR_LONG: |
buzbee | e6d6196 | 2011-08-27 11:58:19 -0700 | [diff] [blame] | 1432 | case OP_SHL_LONG_2ADDR: |
| 1433 | case OP_SHR_LONG_2ADDR: |
| 1434 | case OP_USHR_LONG_2ADDR: |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1435 | genShiftOpLong(cUnit,mir, rlDest, rlSrc[0], rlSrc[1]); |
| 1436 | break; |
| 1437 | |
| 1438 | case OP_ADD_FLOAT: |
| 1439 | case OP_SUB_FLOAT: |
| 1440 | case OP_MUL_FLOAT: |
| 1441 | case OP_DIV_FLOAT: |
| 1442 | case OP_REM_FLOAT: |
| 1443 | case OP_ADD_FLOAT_2ADDR: |
| 1444 | case OP_SUB_FLOAT_2ADDR: |
| 1445 | case OP_MUL_FLOAT_2ADDR: |
| 1446 | case OP_DIV_FLOAT_2ADDR: |
| 1447 | case OP_REM_FLOAT_2ADDR: |
| 1448 | genArithOpFloat(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 1449 | break; |
| 1450 | |
| 1451 | case OP_ADD_DOUBLE: |
| 1452 | case OP_SUB_DOUBLE: |
| 1453 | case OP_MUL_DOUBLE: |
| 1454 | case OP_DIV_DOUBLE: |
| 1455 | case OP_REM_DOUBLE: |
| 1456 | case OP_ADD_DOUBLE_2ADDR: |
| 1457 | case OP_SUB_DOUBLE_2ADDR: |
| 1458 | case OP_MUL_DOUBLE_2ADDR: |
| 1459 | case OP_DIV_DOUBLE_2ADDR: |
| 1460 | case OP_REM_DOUBLE_2ADDR: |
| 1461 | genArithOpDouble(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 1462 | break; |
| 1463 | |
| 1464 | case OP_RSUB_INT: |
| 1465 | case OP_ADD_INT_LIT16: |
| 1466 | case OP_MUL_INT_LIT16: |
| 1467 | case OP_DIV_INT_LIT16: |
| 1468 | case OP_REM_INT_LIT16: |
| 1469 | case OP_AND_INT_LIT16: |
| 1470 | case OP_OR_INT_LIT16: |
| 1471 | case OP_XOR_INT_LIT16: |
| 1472 | case OP_ADD_INT_LIT8: |
| 1473 | case OP_RSUB_INT_LIT8: |
| 1474 | case OP_MUL_INT_LIT8: |
| 1475 | case OP_DIV_INT_LIT8: |
| 1476 | case OP_REM_INT_LIT8: |
| 1477 | case OP_AND_INT_LIT8: |
| 1478 | case OP_OR_INT_LIT8: |
| 1479 | case OP_XOR_INT_LIT8: |
| 1480 | case OP_SHL_INT_LIT8: |
| 1481 | case OP_SHR_INT_LIT8: |
| 1482 | case OP_USHR_INT_LIT8: |
| 1483 | genArithOpIntLit(cUnit, mir, rlDest, rlSrc[0], mir->dalvikInsn.vC); |
| 1484 | break; |
| 1485 | |
| 1486 | default: |
| 1487 | res = true; |
| 1488 | } |
| 1489 | return res; |
| 1490 | } |
| 1491 | |
Elliott Hughes | c1f143d | 2011-12-01 17:31:10 -0800 | [diff] [blame] | 1492 | STATIC const char* extendedMIROpNames[kMirOpLast - kMirOpFirst] = { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1493 | "kMirOpPhi", |
| 1494 | "kMirOpNullNRangeUpCheck", |
| 1495 | "kMirOpNullNRangeDownCheck", |
| 1496 | "kMirOpLowerBound", |
| 1497 | "kMirOpPunt", |
| 1498 | "kMirOpCheckInlinePrediction", |
| 1499 | }; |
| 1500 | |
| 1501 | /* Extended MIR instructions like PHI */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 1502 | STATIC void handleExtendedMethodMIR(CompilationUnit* cUnit, MIR* mir) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1503 | { |
| 1504 | int opOffset = mir->dalvikInsn.opcode - kMirOpFirst; |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 1505 | char* msg = NULL; |
| 1506 | if (cUnit->printMe) { |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 1507 | msg = (char*)oatNew(cUnit, strlen(extendedMIROpNames[opOffset]) + 1, |
| 1508 | false, kAllocDebugInfo); |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 1509 | strcpy(msg, extendedMIROpNames[opOffset]); |
| 1510 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1511 | ArmLIR* op = newLIR1(cUnit, kArmPseudoExtended, (int) msg); |
| 1512 | |
| 1513 | switch ((ExtendedMIROpcode)mir->dalvikInsn.opcode) { |
| 1514 | case kMirOpPhi: { |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 1515 | char* ssaString = NULL; |
| 1516 | if (cUnit->printMe) { |
| 1517 | ssaString = oatGetSSAString(cUnit, mir->ssaRep); |
| 1518 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1519 | op->flags.isNop = true; |
| 1520 | newLIR1(cUnit, kArmPseudoSSARep, (int) ssaString); |
| 1521 | break; |
| 1522 | } |
| 1523 | default: |
| 1524 | break; |
| 1525 | } |
| 1526 | } |
| 1527 | |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 1528 | /* |
| 1529 | * If there are any ins passed in registers that have not been promoted |
| 1530 | * to a callee-save register, flush them to the frame. Perform intial |
| 1531 | * assignment of promoted arguments. |
| 1532 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 1533 | STATIC void flushIns(CompilationUnit* cUnit) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1534 | { |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 1535 | if (cUnit->numIns == 0) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1536 | return; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 1537 | int firstArgReg = r1; |
| 1538 | int lastArgReg = r3; |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 1539 | int startVReg = cUnit->numDalvikRegisters - cUnit->numIns; |
buzbee | 8febc58 | 2011-10-25 12:39:20 -0700 | [diff] [blame] | 1540 | /* |
| 1541 | * Arguments passed in registers should be flushed |
| 1542 | * to their backing locations in the frame for now. |
| 1543 | * Also, we need to do initial assignment for promoted |
| 1544 | * arguments. NOTE: an older version of dx had an issue |
| 1545 | * in which it would reuse static method argument registers. |
| 1546 | * This could result in the same Dalvik virtual register |
| 1547 | * being promoted to both core and fp regs. In those |
| 1548 | * cases, copy argument to both. This will be uncommon |
| 1549 | * enough that it isn't worth attempting to optimize. |
| 1550 | */ |
Ian Rogers | a3760aa | 2011-11-14 14:32:37 -0800 | [diff] [blame] | 1551 | for (int i = 0; i < cUnit->numIns; i++) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 1552 | PromotionMap vMap = cUnit->promotionMap[startVReg + i]; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 1553 | if (i <= (lastArgReg - firstArgReg)) { |
buzbee | 8febc58 | 2011-10-25 12:39:20 -0700 | [diff] [blame] | 1554 | // If arriving in register |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 1555 | if (vMap.coreLocation == kLocPhysReg) { |
| 1556 | genRegCopy(cUnit, vMap.coreReg, firstArgReg + i); |
buzbee | 8febc58 | 2011-10-25 12:39:20 -0700 | [diff] [blame] | 1557 | } |
| 1558 | if (vMap.fpLocation == kLocPhysReg) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 1559 | genRegCopy(cUnit, vMap.fpReg, firstArgReg + i); |
| 1560 | } |
| 1561 | // Also put a copy in memory in case we're partially promoted |
| 1562 | storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i), |
| 1563 | firstArgReg + i, kWord); |
| 1564 | } else { |
buzbee | 8febc58 | 2011-10-25 12:39:20 -0700 | [diff] [blame] | 1565 | // If arriving in frame & promoted |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 1566 | if (vMap.coreLocation == kLocPhysReg) { |
| 1567 | loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i), |
| 1568 | vMap.coreReg); |
buzbee | 8febc58 | 2011-10-25 12:39:20 -0700 | [diff] [blame] | 1569 | } |
| 1570 | if (vMap.fpLocation == kLocPhysReg) { |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 1571 | loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i), |
| 1572 | vMap.fpReg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1573 | } |
| 1574 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1575 | } |
| 1576 | } |
| 1577 | |
| 1578 | /* Handle the content in each basic block */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 1579 | STATIC bool methodBlockCodeGen(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1580 | { |
| 1581 | MIR* mir; |
| 1582 | ArmLIR* labelList = (ArmLIR*) cUnit->blockLabelList; |
| 1583 | int blockId = bb->id; |
| 1584 | |
| 1585 | cUnit->curBlock = bb; |
| 1586 | labelList[blockId].operands[0] = bb->startOffset; |
| 1587 | |
| 1588 | /* Insert the block label */ |
| 1589 | labelList[blockId].opcode = kArmPseudoNormalBlockLabel; |
| 1590 | oatAppendLIR(cUnit, (LIR*) &labelList[blockId]); |
| 1591 | |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 1592 | /* Reset local optimization data on block boundaries */ |
| 1593 | oatResetRegPool(cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1594 | oatClobberAllRegs(cUnit); |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 1595 | oatResetDefTracking(cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1596 | |
| 1597 | ArmLIR* headLIR = NULL; |
| 1598 | |
buzbee | bbaf894 | 2011-10-02 13:08:29 -0700 | [diff] [blame] | 1599 | int spillCount = cUnit->numCoreSpills + cUnit->numFPSpills; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1600 | if (bb->blockType == kEntryBlock) { |
| 1601 | /* |
| 1602 | * On entry, r0, r1, r2 & r3 are live. Let the register allocation |
| 1603 | * mechanism know so it doesn't try to use any of them when |
| 1604 | * expanding the frame or flushing. This leaves the utility |
| 1605 | * code with a single temp: r12. This should be enough. |
| 1606 | */ |
| 1607 | oatLockTemp(cUnit, r0); |
| 1608 | oatLockTemp(cUnit, r1); |
| 1609 | oatLockTemp(cUnit, r2); |
| 1610 | oatLockTemp(cUnit, r3); |
buzbee | cefd187 | 2011-09-09 09:59:52 -0700 | [diff] [blame] | 1611 | |
| 1612 | /* |
| 1613 | * We can safely skip the stack overflow check if we're |
| 1614 | * a leaf *and* our frame size < fudge factor. |
| 1615 | */ |
| 1616 | bool skipOverflowCheck = ((cUnit->attrs & METHOD_IS_LEAF) && |
| 1617 | ((size_t)cUnit->frameSize < |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 1618 | Thread::kStackOverflowReservedBytes)); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1619 | newLIR0(cUnit, kArmPseudoMethodEntry); |
buzbee | cefd187 | 2011-09-09 09:59:52 -0700 | [diff] [blame] | 1620 | if (!skipOverflowCheck) { |
| 1621 | /* Load stack limit */ |
| 1622 | loadWordDisp(cUnit, rSELF, |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 1623 | Thread::StackEndOffset().Int32Value(), r12); |
buzbee | cefd187 | 2011-09-09 09:59:52 -0700 | [diff] [blame] | 1624 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1625 | /* Spill core callee saves */ |
| 1626 | newLIR1(cUnit, kThumb2Push, cUnit->coreSpillMask); |
| 1627 | /* Need to spill any FP regs? */ |
| 1628 | if (cUnit->numFPSpills) { |
buzbee | bbaf894 | 2011-10-02 13:08:29 -0700 | [diff] [blame] | 1629 | /* |
| 1630 | * NOTE: fp spills are a little different from core spills in that |
| 1631 | * they are pushed as a contiguous block. When promoting from |
| 1632 | * the fp set, we must allocate all singles from s16..highest-promoted |
| 1633 | */ |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1634 | newLIR1(cUnit, kThumb2VPushCS, cUnit->numFPSpills); |
| 1635 | } |
buzbee | cefd187 | 2011-09-09 09:59:52 -0700 | [diff] [blame] | 1636 | if (!skipOverflowCheck) { |
| 1637 | opRegRegImm(cUnit, kOpSub, rLR, rSP, |
buzbee | bbaf894 | 2011-10-02 13:08:29 -0700 | [diff] [blame] | 1638 | cUnit->frameSize - (spillCount * 4)); |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 1639 | genRegRegCheck(cUnit, kArmCondCc, rLR, r12, NULL, |
| 1640 | kArmThrowStackOverflow); |
buzbee | cefd187 | 2011-09-09 09:59:52 -0700 | [diff] [blame] | 1641 | genRegCopy(cUnit, rSP, rLR); // Establish stack |
| 1642 | } else { |
| 1643 | opRegImm(cUnit, kOpSub, rSP, |
buzbee | bbaf894 | 2011-10-02 13:08:29 -0700 | [diff] [blame] | 1644 | cUnit->frameSize - (spillCount * 4)); |
buzbee | cefd187 | 2011-09-09 09:59:52 -0700 | [diff] [blame] | 1645 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1646 | storeBaseDisp(cUnit, rSP, 0, r0, kWord); |
| 1647 | flushIns(cUnit); |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 1648 | |
| 1649 | if (cUnit->genDebugger) { |
| 1650 | // Refresh update debugger callout |
| 1651 | loadWordDisp(cUnit, rSELF, |
| 1652 | OFFSETOF_MEMBER(Thread, pUpdateDebuggerFromCode), rSUSPEND); |
| 1653 | genDebuggerUpdate(cUnit, DEBUGGER_METHOD_ENTRY); |
| 1654 | } |
| 1655 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1656 | oatFreeTemp(cUnit, r0); |
| 1657 | oatFreeTemp(cUnit, r1); |
| 1658 | oatFreeTemp(cUnit, r2); |
| 1659 | oatFreeTemp(cUnit, r3); |
| 1660 | } else if (bb->blockType == kExitBlock) { |
buzbee | 80c4d57 | 2012-02-24 13:35:44 -0800 | [diff] [blame] | 1661 | /* |
| 1662 | * In the exit path, r0/r1 are live - make sure they aren't |
| 1663 | * allocated by the register utilities as temps. |
| 1664 | */ |
| 1665 | oatLockTemp(cUnit, r0); |
| 1666 | oatLockTemp(cUnit, r1); |
| 1667 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1668 | newLIR0(cUnit, kArmPseudoMethodExit); |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 1669 | /* If we're compiling for the debugger, generate an update callout */ |
| 1670 | if (cUnit->genDebugger) { |
| 1671 | genDebuggerUpdate(cUnit, DEBUGGER_METHOD_EXIT); |
| 1672 | } |
buzbee | bbaf894 | 2011-10-02 13:08:29 -0700 | [diff] [blame] | 1673 | opRegImm(cUnit, kOpAdd, rSP, cUnit->frameSize - (spillCount * 4)); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1674 | /* Need to restore any FP callee saves? */ |
| 1675 | if (cUnit->numFPSpills) { |
| 1676 | newLIR1(cUnit, kThumb2VPopCS, cUnit->numFPSpills); |
| 1677 | } |
| 1678 | if (cUnit->coreSpillMask & (1 << rLR)) { |
| 1679 | /* Unspill rLR to rPC */ |
| 1680 | cUnit->coreSpillMask &= ~(1 << rLR); |
| 1681 | cUnit->coreSpillMask |= (1 << rPC); |
| 1682 | } |
| 1683 | newLIR1(cUnit, kThumb2Pop, cUnit->coreSpillMask); |
| 1684 | if (!(cUnit->coreSpillMask & (1 << rPC))) { |
| 1685 | /* We didn't pop to rPC, so must do a bv rLR */ |
| 1686 | newLIR1(cUnit, kThumbBx, rLR); |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | for (mir = bb->firstMIRInsn; mir; mir = mir->next) { |
| 1691 | |
| 1692 | oatResetRegPool(cUnit); |
buzbee | c0ecd65 | 2011-09-25 18:11:54 -0700 | [diff] [blame] | 1693 | if (cUnit->disableOpt & (1 << kTrackLiveTemps)) { |
| 1694 | oatClobberAllRegs(cUnit); |
| 1695 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1696 | |
| 1697 | if (cUnit->disableOpt & (1 << kSuppressLoads)) { |
| 1698 | oatResetDefTracking(cUnit); |
| 1699 | } |
| 1700 | |
| 1701 | if ((int)mir->dalvikInsn.opcode >= (int)kMirOpFirst) { |
| 1702 | handleExtendedMethodMIR(cUnit, mir); |
| 1703 | continue; |
| 1704 | } |
| 1705 | |
| 1706 | cUnit->currentDalvikOffset = mir->offset; |
| 1707 | |
| 1708 | Opcode dalvikOpcode = mir->dalvikInsn.opcode; |
| 1709 | InstructionFormat dalvikFormat = |
| 1710 | dexGetFormatFromOpcode(dalvikOpcode); |
| 1711 | |
| 1712 | ArmLIR* boundaryLIR; |
| 1713 | |
| 1714 | /* Mark the beginning of a Dalvik instruction for line tracking */ |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 1715 | char* instStr = cUnit->printMe ? |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 1716 | oatGetDalvikDisassembly(cUnit, &mir->dalvikInsn, "") : NULL; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1717 | boundaryLIR = newLIR1(cUnit, kArmPseudoDalvikByteCodeBoundary, |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 1718 | (intptr_t) instStr); |
buzbee | 85d8c1e | 2012-01-27 15:52:35 -0800 | [diff] [blame] | 1719 | cUnit->boundaryMap.insert(std::make_pair(mir->offset, |
| 1720 | (LIR*)boundaryLIR)); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1721 | /* Remember the first LIR for this block */ |
| 1722 | if (headLIR == NULL) { |
| 1723 | headLIR = boundaryLIR; |
| 1724 | /* Set the first boundaryLIR as a scheduling barrier */ |
| 1725 | headLIR->defMask = ENCODE_ALL; |
| 1726 | } |
| 1727 | |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 1728 | /* If we're compiling for the debugger, generate an update callout */ |
| 1729 | if (cUnit->genDebugger) { |
| 1730 | genDebuggerUpdate(cUnit, mir->offset); |
| 1731 | } |
| 1732 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1733 | /* Don't generate the SSA annotation unless verbose mode is on */ |
| 1734 | if (cUnit->printMe && mir->ssaRep) { |
Elliott Hughes | c1f143d | 2011-12-01 17:31:10 -0800 | [diff] [blame] | 1735 | char* ssaString = oatGetSSAString(cUnit, mir->ssaRep); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1736 | newLIR1(cUnit, kArmPseudoSSARep, (int) ssaString); |
| 1737 | } |
| 1738 | |
| 1739 | bool notHandled = compileDalvikInstruction(cUnit, mir, bb, labelList); |
| 1740 | |
| 1741 | if (notHandled) { |
| 1742 | char buf[100]; |
| 1743 | snprintf(buf, 100, "%#06x: Opcode %#x (%s) / Fmt %d not handled", |
| 1744 | mir->offset, |
| 1745 | dalvikOpcode, dexGetOpcodeName(dalvikOpcode), |
| 1746 | dalvikFormat); |
| 1747 | LOG(FATAL) << buf; |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | if (headLIR) { |
| 1752 | /* |
| 1753 | * Eliminate redundant loads/stores and delay stores into later |
| 1754 | * slots |
| 1755 | */ |
| 1756 | oatApplyLocalOptimizations(cUnit, (LIR*) headLIR, |
| 1757 | cUnit->lastLIRInsn); |
| 1758 | |
| 1759 | /* |
| 1760 | * Generate an unconditional branch to the fallthrough block. |
| 1761 | */ |
| 1762 | if (bb->fallThrough) { |
| 1763 | genUnconditionalBranch(cUnit, |
| 1764 | &labelList[bb->fallThrough->id]); |
| 1765 | } |
| 1766 | } |
| 1767 | return false; |
| 1768 | } |
| 1769 | |
| 1770 | /* |
| 1771 | * Nop any unconditional branches that go to the next instruction. |
| 1772 | * Note: new redundant branches may be inserted later, and we'll |
| 1773 | * use a check in final instruction assembly to nop those out. |
| 1774 | */ |
| 1775 | void removeRedundantBranches(CompilationUnit* cUnit) |
| 1776 | { |
| 1777 | ArmLIR* thisLIR; |
| 1778 | |
| 1779 | for (thisLIR = (ArmLIR*) cUnit->firstLIRInsn; |
| 1780 | thisLIR != (ArmLIR*) cUnit->lastLIRInsn; |
| 1781 | thisLIR = NEXT_LIR(thisLIR)) { |
| 1782 | |
| 1783 | /* Branch to the next instruction */ |
| 1784 | if ((thisLIR->opcode == kThumbBUncond) || |
| 1785 | (thisLIR->opcode == kThumb2BUncond)) { |
| 1786 | ArmLIR* nextLIR = thisLIR; |
| 1787 | |
| 1788 | while (true) { |
| 1789 | nextLIR = NEXT_LIR(nextLIR); |
| 1790 | |
| 1791 | /* |
| 1792 | * Is the branch target the next instruction? |
| 1793 | */ |
| 1794 | if (nextLIR == (ArmLIR*) thisLIR->generic.target) { |
| 1795 | thisLIR->flags.isNop = true; |
| 1796 | break; |
| 1797 | } |
| 1798 | |
| 1799 | /* |
| 1800 | * Found real useful stuff between the branch and the target. |
| 1801 | * Need to explicitly check the lastLIRInsn here because it |
| 1802 | * might be the last real instruction. |
| 1803 | */ |
| 1804 | if (!isPseudoOpcode(nextLIR->opcode) || |
| 1805 | (nextLIR = (ArmLIR*) cUnit->lastLIRInsn)) |
| 1806 | break; |
| 1807 | } |
| 1808 | } |
| 1809 | } |
| 1810 | } |
| 1811 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 1812 | STATIC void handleSuspendLaunchpads(CompilationUnit *cUnit) |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 1813 | { |
| 1814 | ArmLIR** suspendLabel = |
| 1815 | (ArmLIR **) cUnit->suspendLaunchpads.elemList; |
| 1816 | int numElems = cUnit->suspendLaunchpads.numUsed; |
| 1817 | |
| 1818 | for (int i = 0; i < numElems; i++) { |
| 1819 | /* TUNING: move suspend count load into helper */ |
| 1820 | ArmLIR* lab = suspendLabel[i]; |
| 1821 | ArmLIR* resumeLab = (ArmLIR*)lab->operands[0]; |
| 1822 | cUnit->currentDalvikOffset = lab->operands[1]; |
| 1823 | oatAppendLIR(cUnit, (LIR *)lab); |
| 1824 | loadWordDisp(cUnit, rSELF, |
| 1825 | OFFSETOF_MEMBER(Thread, pTestSuspendFromCode), rLR); |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 1826 | if (!cUnit->genDebugger) { |
| 1827 | // use rSUSPEND for suspend count |
| 1828 | loadWordDisp(cUnit, rSELF, |
| 1829 | Thread::SuspendCountOffset().Int32Value(), rSUSPEND); |
| 1830 | } |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 1831 | opReg(cUnit, kOpBlx, rLR); |
buzbee | 44b412b | 2012-02-04 08:50:53 -0800 | [diff] [blame] | 1832 | if ( cUnit->genDebugger) { |
| 1833 | // use rSUSPEND for update debugger |
| 1834 | loadWordDisp(cUnit, rSELF, |
| 1835 | OFFSETOF_MEMBER(Thread, pUpdateDebuggerFromCode), rSUSPEND); |
| 1836 | } |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 1837 | genUnconditionalBranch(cUnit, resumeLab); |
| 1838 | } |
| 1839 | } |
| 1840 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 1841 | STATIC void handleThrowLaunchpads(CompilationUnit *cUnit) |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 1842 | { |
| 1843 | ArmLIR** throwLabel = |
| 1844 | (ArmLIR **) cUnit->throwLaunchpads.elemList; |
| 1845 | int numElems = cUnit->throwLaunchpads.numUsed; |
| 1846 | int i; |
| 1847 | |
| 1848 | for (i = 0; i < numElems; i++) { |
| 1849 | ArmLIR* lab = throwLabel[i]; |
| 1850 | cUnit->currentDalvikOffset = lab->operands[1]; |
| 1851 | oatAppendLIR(cUnit, (LIR *)lab); |
| 1852 | int funcOffset = 0; |
| 1853 | int v1 = lab->operands[2]; |
| 1854 | int v2 = lab->operands[3]; |
| 1855 | switch(lab->operands[0]) { |
| 1856 | case kArmThrowNullPointer: |
| 1857 | funcOffset = OFFSETOF_MEMBER(Thread, pThrowNullPointerFromCode); |
| 1858 | break; |
| 1859 | case kArmThrowArrayBounds: |
| 1860 | if (v2 != r0) { |
| 1861 | genRegCopy(cUnit, r0, v1); |
| 1862 | genRegCopy(cUnit, r1, v2); |
| 1863 | } else { |
| 1864 | if (v1 == r1) { |
| 1865 | genRegCopy(cUnit, r12, v1); |
| 1866 | genRegCopy(cUnit, r1, v2); |
| 1867 | genRegCopy(cUnit, r0, r12); |
| 1868 | } else { |
| 1869 | genRegCopy(cUnit, r1, v2); |
| 1870 | genRegCopy(cUnit, r0, v1); |
| 1871 | } |
| 1872 | } |
| 1873 | funcOffset = OFFSETOF_MEMBER(Thread, pThrowArrayBoundsFromCode); |
| 1874 | break; |
| 1875 | case kArmThrowDivZero: |
| 1876 | funcOffset = OFFSETOF_MEMBER(Thread, pThrowDivZeroFromCode); |
| 1877 | break; |
| 1878 | case kArmThrowVerificationError: |
| 1879 | loadConstant(cUnit, r0, v1); |
| 1880 | loadConstant(cUnit, r1, v2); |
| 1881 | funcOffset = |
| 1882 | OFFSETOF_MEMBER(Thread, pThrowVerificationErrorFromCode); |
| 1883 | break; |
| 1884 | case kArmThrowNegArraySize: |
| 1885 | genRegCopy(cUnit, r0, v1); |
| 1886 | funcOffset = |
| 1887 | OFFSETOF_MEMBER(Thread, pThrowNegArraySizeFromCode); |
| 1888 | break; |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 1889 | case kArmThrowNoSuchMethod: |
buzbee | 13ac45a | 2012-01-12 12:30:16 -0800 | [diff] [blame] | 1890 | genRegCopy(cUnit, r0, v1); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 1891 | funcOffset = |
| 1892 | OFFSETOF_MEMBER(Thread, pThrowNoSuchMethodFromCode); |
| 1893 | break; |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 1894 | case kArmThrowStackOverflow: |
| 1895 | funcOffset = |
Ian Rogers | 932746a | 2011-09-22 18:57:50 -0700 | [diff] [blame] | 1896 | OFFSETOF_MEMBER(Thread, pThrowStackOverflowFromCode); |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 1897 | // Restore stack alignment |
buzbee | bbaf894 | 2011-10-02 13:08:29 -0700 | [diff] [blame] | 1898 | opRegImm(cUnit, kOpAdd, rSP, |
| 1899 | (cUnit->numCoreSpills + cUnit->numFPSpills) * 4); |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 1900 | break; |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 1901 | default: |
| 1902 | LOG(FATAL) << "Unexpected throw kind: " << lab->operands[0]; |
| 1903 | } |
| 1904 | loadWordDisp(cUnit, rSELF, funcOffset, rLR); |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 1905 | callRuntimeHelper(cUnit, rLR); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 1906 | } |
| 1907 | } |
| 1908 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1909 | void oatMethodMIR2LIR(CompilationUnit* cUnit) |
| 1910 | { |
| 1911 | /* Used to hold the labels of each block */ |
| 1912 | cUnit->blockLabelList = |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 1913 | (void *) oatNew(cUnit, sizeof(ArmLIR) * cUnit->numBlocks, true, |
| 1914 | kAllocLIR); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1915 | |
| 1916 | oatDataFlowAnalysisDispatcher(cUnit, methodBlockCodeGen, |
| 1917 | kPreOrderDFSTraversal, false /* Iterative */); |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 1918 | handleSuspendLaunchpads(cUnit); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 1919 | |
| 1920 | handleThrowLaunchpads(cUnit); |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 1921 | |
| 1922 | removeRedundantBranches(cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | /* Common initialization routine for an architecture family */ |
| 1926 | bool oatArchInit() |
| 1927 | { |
| 1928 | int i; |
| 1929 | |
| 1930 | for (i = 0; i < kArmLast; i++) { |
| 1931 | if (EncodingMap[i].opcode != i) { |
| 1932 | LOG(FATAL) << "Encoding order for " << EncodingMap[i].name << |
| 1933 | " is wrong: expecting " << i << ", seeing " << |
| 1934 | (int)EncodingMap[i].opcode; |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | return oatArchVariantInit(); |
| 1939 | } |
| 1940 | |
| 1941 | /* Needed by the Assembler */ |
| 1942 | void oatSetupResourceMasks(ArmLIR* lir) |
| 1943 | { |
| 1944 | setupResourceMasks(lir); |
| 1945 | } |
| 1946 | |
| 1947 | /* Needed by the ld/st optmizatons */ |
| 1948 | ArmLIR* oatRegCopyNoInsert(CompilationUnit* cUnit, int rDest, int rSrc) |
| 1949 | { |
| 1950 | return genRegCopyNoInsert(cUnit, rDest, rSrc); |
| 1951 | } |
| 1952 | |
| 1953 | /* Needed by the register allocator */ |
| 1954 | ArmLIR* oatRegCopy(CompilationUnit* cUnit, int rDest, int rSrc) |
| 1955 | { |
| 1956 | return genRegCopy(cUnit, rDest, rSrc); |
| 1957 | } |
| 1958 | |
| 1959 | /* Needed by the register allocator */ |
| 1960 | void oatRegCopyWide(CompilationUnit* cUnit, int destLo, int destHi, |
| 1961 | int srcLo, int srcHi) |
| 1962 | { |
| 1963 | genRegCopyWide(cUnit, destLo, destHi, srcLo, srcHi); |
| 1964 | } |
| 1965 | |
| 1966 | void oatFlushRegImpl(CompilationUnit* cUnit, int rBase, |
| 1967 | int displacement, int rSrc, OpSize size) |
| 1968 | { |
| 1969 | storeBaseDisp(cUnit, rBase, displacement, rSrc, size); |
| 1970 | } |
| 1971 | |
| 1972 | void oatFlushRegWideImpl(CompilationUnit* cUnit, int rBase, |
| 1973 | int displacement, int rSrcLo, int rSrcHi) |
| 1974 | { |
| 1975 | storeBaseDispWide(cUnit, rBase, displacement, rSrcLo, rSrcHi); |
| 1976 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 1977 | |
| 1978 | } // namespace art |