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