buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | namespace art { |
| 18 | |
| 19 | /* |
| 20 | * This source files contains "gen" codegen routines that should |
| 21 | * be applicable to most targets. Only mid-level support utilities |
| 22 | * and "op" calls may be used here. |
| 23 | */ |
| 24 | |
| 25 | #if defined(TARGET_ARM) |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 26 | LIR* opIT(CompilationUnit* cUnit, ArmConditionCode cond, const char* guide); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 27 | #endif |
| 28 | |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 29 | void callRuntimeHelperImm(CompilationUnit* cUnit, int helperOffset, int arg0) { |
| 30 | #if !defined(TARGET_X86) |
| 31 | int rTgt = loadHelper(cUnit, helperOffset); |
| 32 | #endif |
| 33 | loadConstant(cUnit, rARG0, arg0); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 34 | oatClobberCalleeSave(cUnit); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 35 | #if !defined(TARGET_X86) |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 36 | opReg(cUnit, kOpBlx, rTgt); |
| 37 | oatFreeTemp(cUnit, rTgt); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 38 | #else |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 39 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 40 | #endif |
| 41 | } |
| 42 | |
| 43 | void callRuntimeHelperRegLocation(CompilationUnit* cUnit, int helperOffset, |
| 44 | RegLocation arg0) { |
| 45 | #if !defined(TARGET_X86) |
| 46 | int rTgt = loadHelper(cUnit, helperOffset); |
| 47 | #endif |
| 48 | if (arg0.wide == 0) { |
| 49 | loadValueDirectFixed(cUnit, arg0, rARG0); |
| 50 | } else { |
| 51 | loadValueDirectWideFixed(cUnit, arg0, rARG0, rARG1); |
| 52 | } |
| 53 | oatClobberCalleeSave(cUnit); |
| 54 | #if !defined(TARGET_X86) |
| 55 | opReg(cUnit, kOpBlx, rTgt); |
| 56 | oatFreeTemp(cUnit, rTgt); |
| 57 | #else |
| 58 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 59 | #endif |
| 60 | } |
| 61 | |
| 62 | void callRuntimeHelperImmImm(CompilationUnit* cUnit, int helperOffset, |
| 63 | int arg0, int arg1) { |
| 64 | #if !defined(TARGET_X86) |
| 65 | int rTgt = loadHelper(cUnit, helperOffset); |
| 66 | #endif |
| 67 | loadConstant(cUnit, rARG0, arg0); |
| 68 | loadConstant(cUnit, rARG1, arg1); |
| 69 | oatClobberCalleeSave(cUnit); |
| 70 | #if !defined(TARGET_X86) |
| 71 | opReg(cUnit, kOpBlx, rTgt); |
| 72 | oatFreeTemp(cUnit, rTgt); |
| 73 | #else |
| 74 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 75 | #endif |
| 76 | } |
| 77 | |
| 78 | void callRuntimeHelperImmRegLocation(CompilationUnit* cUnit, int helperOffset, |
| 79 | int arg0, RegLocation arg1) { |
| 80 | #if !defined(TARGET_X86) |
| 81 | int rTgt = loadHelper(cUnit, helperOffset); |
| 82 | #endif |
| 83 | if (arg1.wide == 0) { |
| 84 | loadValueDirectFixed(cUnit, arg1, rARG1); |
| 85 | } else { |
| 86 | loadValueDirectWideFixed(cUnit, arg1, rARG1, rARG2); |
| 87 | } |
| 88 | loadConstant(cUnit, rARG0, arg0); |
| 89 | oatClobberCalleeSave(cUnit); |
| 90 | #if !defined(TARGET_X86) |
| 91 | opReg(cUnit, kOpBlx, rTgt); |
| 92 | oatFreeTemp(cUnit, rTgt); |
| 93 | #else |
| 94 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 95 | #endif |
| 96 | } |
| 97 | |
| 98 | void callRuntimeHelperRegLocationImm(CompilationUnit* cUnit, int helperOffset, |
| 99 | RegLocation arg0, int arg1) { |
| 100 | #if !defined(TARGET_X86) |
| 101 | int rTgt = loadHelper(cUnit, helperOffset); |
| 102 | #endif |
| 103 | loadValueDirectFixed(cUnit, arg0, rARG0); |
| 104 | loadConstant(cUnit, rARG1, arg1); |
| 105 | oatClobberCalleeSave(cUnit); |
| 106 | #if !defined(TARGET_X86) |
| 107 | opReg(cUnit, kOpBlx, rTgt); |
| 108 | oatFreeTemp(cUnit, rTgt); |
| 109 | #else |
| 110 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 111 | #endif |
| 112 | } |
| 113 | |
| 114 | void callRuntimeHelperImmReg(CompilationUnit* cUnit, int helperOffset, |
| 115 | int arg0, int arg1) { |
| 116 | #if !defined(TARGET_X86) |
| 117 | int rTgt = loadHelper(cUnit, helperOffset); |
| 118 | #endif |
| 119 | opRegCopy(cUnit, rARG1, arg1); |
| 120 | loadConstant(cUnit, rARG0, arg0); |
| 121 | oatClobberCalleeSave(cUnit); |
| 122 | #if !defined(TARGET_X86) |
| 123 | opReg(cUnit, kOpBlx, rTgt); |
| 124 | oatFreeTemp(cUnit, rTgt); |
| 125 | #else |
| 126 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 127 | #endif |
| 128 | } |
| 129 | |
| 130 | void callRuntimeHelperRegImm(CompilationUnit* cUnit, int helperOffset, |
| 131 | int arg0, int arg1) { |
| 132 | #if !defined(TARGET_X86) |
| 133 | int rTgt = loadHelper(cUnit, helperOffset); |
| 134 | #endif |
| 135 | opRegCopy(cUnit, rARG0, arg0); |
| 136 | loadConstant(cUnit, rARG1, arg1); |
| 137 | oatClobberCalleeSave(cUnit); |
| 138 | #if !defined(TARGET_X86) |
| 139 | opReg(cUnit, kOpBlx, rTgt); |
| 140 | oatFreeTemp(cUnit, rTgt); |
| 141 | #else |
| 142 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 143 | #endif |
| 144 | } |
| 145 | |
| 146 | void callRuntimeHelperImmMethod(CompilationUnit* cUnit, int helperOffset, |
| 147 | int arg0) { |
| 148 | #if !defined(TARGET_X86) |
| 149 | int rTgt = loadHelper(cUnit, helperOffset); |
| 150 | #endif |
| 151 | loadCurrMethodDirect(cUnit, rARG1); |
| 152 | loadConstant(cUnit, rARG0, arg0); |
| 153 | oatClobberCalleeSave(cUnit); |
| 154 | #if !defined(TARGET_X86) |
| 155 | opReg(cUnit, kOpBlx, rTgt); |
| 156 | oatFreeTemp(cUnit, rTgt); |
| 157 | #else |
| 158 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 159 | #endif |
| 160 | } |
| 161 | |
| 162 | void callRuntimeHelperRegLocationRegLocation(CompilationUnit* cUnit, |
| 163 | int helperOffset, |
| 164 | RegLocation arg0, |
| 165 | RegLocation arg1) { |
| 166 | #if !defined(TARGET_X86) |
| 167 | int rTgt = loadHelper(cUnit, helperOffset); |
| 168 | #endif |
| 169 | if (arg0.wide == 0) { |
| 170 | loadValueDirectFixed(cUnit, arg0, rARG0); |
| 171 | if (arg1.wide == 0) { |
| 172 | loadValueDirectFixed(cUnit, arg1, rARG1); |
| 173 | } else { |
| 174 | loadValueDirectWideFixed(cUnit, arg1, rARG1, rARG2); |
| 175 | } |
| 176 | } else { |
| 177 | loadValueDirectWideFixed(cUnit, arg0, rARG0, rARG1); |
| 178 | if (arg1.wide == 0) { |
| 179 | loadValueDirectFixed(cUnit, arg1, rARG2); |
| 180 | } else { |
| 181 | #if defined(TARGET_X86) |
| 182 | UNIMPLEMENTED(FATAL); |
| 183 | #else |
| 184 | loadValueDirectWideFixed(cUnit, arg1, rARG2, rARG3); |
| 185 | #endif |
| 186 | } |
| 187 | } |
| 188 | oatClobberCalleeSave(cUnit); |
| 189 | #if !defined(TARGET_X86) |
| 190 | opReg(cUnit, kOpBlx, rTgt); |
| 191 | oatFreeTemp(cUnit, rTgt); |
| 192 | #else |
| 193 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 194 | #endif |
| 195 | } |
| 196 | |
| 197 | void callRuntimeHelperRegReg(CompilationUnit* cUnit, int helperOffset, |
| 198 | int arg0, int arg1) { |
| 199 | #if !defined(TARGET_X86) |
| 200 | int rTgt = loadHelper(cUnit, helperOffset); |
| 201 | #endif |
| 202 | DCHECK_NE((int)rARG0, arg1); // check copy into arg0 won't clobber arg1 |
| 203 | opRegCopy(cUnit, rARG0, arg0); |
| 204 | opRegCopy(cUnit, rARG1, arg1); |
| 205 | oatClobberCalleeSave(cUnit); |
| 206 | #if !defined(TARGET_X86) |
| 207 | opReg(cUnit, kOpBlx, rTgt); |
| 208 | oatFreeTemp(cUnit, rTgt); |
| 209 | #else |
| 210 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 211 | #endif |
| 212 | } |
| 213 | |
| 214 | void callRuntimeHelperRegRegImm(CompilationUnit* cUnit, int helperOffset, |
| 215 | int arg0, int arg1, int arg2) { |
| 216 | #if !defined(TARGET_X86) |
| 217 | int rTgt = loadHelper(cUnit, helperOffset); |
| 218 | #endif |
| 219 | DCHECK_NE((int)rARG0, arg1); // check copy into arg0 won't clobber arg1 |
| 220 | opRegCopy(cUnit, rARG0, arg0); |
| 221 | opRegCopy(cUnit, rARG1, arg1); |
| 222 | loadConstant(cUnit, rARG2, arg2); |
| 223 | oatClobberCalleeSave(cUnit); |
| 224 | #if !defined(TARGET_X86) |
| 225 | opReg(cUnit, kOpBlx, rTgt); |
| 226 | oatFreeTemp(cUnit, rTgt); |
| 227 | #else |
| 228 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 229 | #endif |
| 230 | } |
| 231 | |
| 232 | void callRuntimeHelperImmMethodRegLocation(CompilationUnit* cUnit, int helperOffset, |
| 233 | int arg0, RegLocation arg2) { |
| 234 | #if !defined(TARGET_X86) |
| 235 | int rTgt = loadHelper(cUnit, helperOffset); |
| 236 | #endif |
| 237 | loadValueDirectFixed(cUnit, arg2, rARG2); |
| 238 | loadCurrMethodDirect(cUnit, rARG1); |
| 239 | loadConstant(cUnit, rARG0, arg0); |
| 240 | oatClobberCalleeSave(cUnit); |
| 241 | #if !defined(TARGET_X86) |
| 242 | opReg(cUnit, kOpBlx, rTgt); |
| 243 | oatFreeTemp(cUnit, rTgt); |
| 244 | #else |
| 245 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 246 | #endif |
| 247 | } |
| 248 | |
| 249 | void callRuntimeHelperImmMethodImm(CompilationUnit* cUnit, int helperOffset, |
| 250 | int arg0, int arg2) { |
| 251 | #if !defined(TARGET_X86) |
| 252 | int rTgt = loadHelper(cUnit, helperOffset); |
| 253 | #endif |
| 254 | loadCurrMethodDirect(cUnit, rARG1); |
| 255 | loadConstant(cUnit, rARG2, arg2); |
| 256 | loadConstant(cUnit, rARG0, arg0); |
| 257 | oatClobberCalleeSave(cUnit); |
| 258 | #if !defined(TARGET_X86) |
| 259 | opReg(cUnit, kOpBlx, rTgt); |
| 260 | oatFreeTemp(cUnit, rTgt); |
| 261 | #else |
| 262 | opThreadMem(cUnit, kOpBlx, helperOffset); |
| 263 | #endif |
| 264 | } |
| 265 | |
| 266 | void callRuntimeHelperImmRegLocationRegLocation(CompilationUnit* cUnit, |
| 267 | int helperOffset, |
| 268 | int arg0, RegLocation arg1, |
| 269 | RegLocation arg2) { |
| 270 | #if !defined(TARGET_X86) |
| 271 | int rTgt = loadHelper(cUnit, helperOffset); |
| 272 | #endif |
| 273 | loadValueDirectFixed(cUnit, arg1, rARG1); |
| 274 | if (arg2.wide == 0) { |
| 275 | loadValueDirectFixed(cUnit, arg2, rARG2); |
| 276 | } else { |
| 277 | #if defined(TARGET_X86) |
| 278 | UNIMPLEMENTED(FATAL); |
| 279 | #else |
| 280 | loadValueDirectWideFixed(cUnit, arg2, rARG2, rARG3); |
| 281 | #endif |
| 282 | } |
| 283 | loadConstant(cUnit, rARG0, arg0); |
| 284 | oatClobberCalleeSave(cUnit); |
| 285 | #if !defined(TARGET_X86) |
| 286 | opReg(cUnit, kOpBlx, rTgt); |
| 287 | oatFreeTemp(cUnit, rTgt); |
| 288 | #else |
| 289 | opThreadMem(cUnit, kOpBlx, helperOffset); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 290 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /* |
| 294 | * Generate an kPseudoBarrier marker to indicate the boundary of special |
| 295 | * blocks. |
| 296 | */ |
| 297 | void genBarrier(CompilationUnit* cUnit) |
| 298 | { |
| 299 | LIR* barrier = newLIR0(cUnit, kPseudoBarrier); |
| 300 | /* Mark all resources as being clobbered */ |
| 301 | barrier->defMask = -1; |
| 302 | } |
| 303 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 304 | |
| 305 | /* Generate unconditional branch instructions */ |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 306 | LIR* opUnconditionalBranch(CompilationUnit* cUnit, LIR* target) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 307 | { |
Ian Rogers | 680b1bd | 2012-03-07 20:18:49 -0800 | [diff] [blame] | 308 | LIR* branch = opBranchUnconditional(cUnit, kOpUncondBr); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 309 | branch->target = (LIR*) target; |
| 310 | return branch; |
| 311 | } |
| 312 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 313 | // FIXME: need to do some work to split out targets with |
| 314 | // condition codes and those without |
| 315 | #if defined(TARGET_ARM) || defined(TARGET_X86) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 316 | LIR* genCheck(CompilationUnit* cUnit, ConditionCode cCode, MIR* mir, |
| 317 | ThrowKind kind) |
| 318 | { |
buzbee | a2ebdd7 | 2012-03-04 14:57:06 -0800 | [diff] [blame] | 319 | LIR* tgt = rawLIR(cUnit, 0, kPseudoThrowTarget, kind, |
| 320 | mir ? mir->offset : 0); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 321 | LIR* branch = opCondBranch(cUnit, cCode, tgt); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 322 | // Remember branch target - will process later |
| 323 | oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, (intptr_t)tgt); |
| 324 | return branch; |
| 325 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 326 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 327 | |
| 328 | LIR* genImmedCheck(CompilationUnit* cUnit, ConditionCode cCode, |
| 329 | int reg, int immVal, MIR* mir, ThrowKind kind) |
| 330 | { |
buzbee | a2ebdd7 | 2012-03-04 14:57:06 -0800 | [diff] [blame] | 331 | LIR* tgt = rawLIR(cUnit, 0, kPseudoThrowTarget, kind, mir->offset); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 332 | LIR* branch; |
| 333 | if (cCode == kCondAl) { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 334 | branch = opUnconditionalBranch(cUnit, tgt); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 335 | } else { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 336 | branch = opCmpImmBranch(cUnit, cCode, reg, immVal, tgt); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 337 | } |
| 338 | // Remember branch target - will process later |
| 339 | oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, (intptr_t)tgt); |
| 340 | return branch; |
| 341 | } |
| 342 | |
| 343 | /* Perform null-check on a register. */ |
| 344 | LIR* genNullCheck(CompilationUnit* cUnit, int sReg, int mReg, MIR* mir) |
| 345 | { |
| 346 | if (!(cUnit->disableOpt & (1 << kNullCheckElimination)) && |
| 347 | mir->optimizationFlags & MIR_IGNORE_NULL_CHECK) { |
| 348 | return NULL; |
| 349 | } |
| 350 | return genImmedCheck(cUnit, kCondEq, mReg, 0, mir, kThrowNullPointer); |
| 351 | } |
| 352 | |
| 353 | /* Perform check on two registers */ |
| 354 | LIR* genRegRegCheck(CompilationUnit* cUnit, ConditionCode cCode, |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 355 | int reg1, int reg2, MIR* mir, ThrowKind kind) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 356 | { |
buzbee | a2ebdd7 | 2012-03-04 14:57:06 -0800 | [diff] [blame] | 357 | LIR* tgt = rawLIR(cUnit, 0, kPseudoThrowTarget, kind, |
| 358 | mir ? mir->offset : 0, reg1, reg2); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 359 | #if defined(TARGET_MIPS) |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 360 | LIR* branch = opCmpBranch(cUnit, cCode, reg1, reg2, tgt); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 361 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 362 | opRegReg(cUnit, kOpCmp, reg1, reg2); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 363 | LIR* branch = opCondBranch(cUnit, cCode, tgt); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 364 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 365 | // Remember branch target - will process later |
| 366 | oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, (intptr_t)tgt); |
| 367 | return branch; |
| 368 | } |
| 369 | |
| 370 | void genCompareAndBranch(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir, |
| 371 | RegLocation rlSrc1, RegLocation rlSrc2, LIR* labelList) |
| 372 | { |
| 373 | ConditionCode cond; |
| 374 | rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg); |
| 375 | rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 376 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 377 | switch(opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 378 | case Instruction::IF_EQ: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 379 | cond = kCondEq; |
| 380 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 381 | case Instruction::IF_NE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 382 | cond = kCondNe; |
| 383 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 384 | case Instruction::IF_LT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 385 | cond = kCondLt; |
| 386 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 387 | case Instruction::IF_GE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 388 | cond = kCondGe; |
| 389 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 390 | case Instruction::IF_GT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 391 | cond = kCondGt; |
| 392 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 393 | case Instruction::IF_LE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 394 | cond = kCondLe; |
| 395 | break; |
| 396 | default: |
| 397 | cond = (ConditionCode)0; |
| 398 | LOG(FATAL) << "Unexpected opcode " << (int)opcode; |
| 399 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 400 | #if defined(TARGET_MIPS) |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 401 | opCmpBranch(cUnit, cond, rlSrc1.lowReg, rlSrc2.lowReg, |
| 402 | &labelList[bb->taken->id]); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 403 | #else |
| 404 | opRegReg(cUnit, kOpCmp, rlSrc1.lowReg, rlSrc2.lowReg); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 405 | opCondBranch(cUnit, cond, &labelList[bb->taken->id]); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 406 | #endif |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 407 | opUnconditionalBranch(cUnit, &labelList[bb->fallThrough->id]); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void genCompareZeroAndBranch(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir, |
| 411 | RegLocation rlSrc, LIR* labelList) |
| 412 | { |
| 413 | ConditionCode cond; |
| 414 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 415 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 416 | switch(opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 417 | case Instruction::IF_EQZ: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 418 | cond = kCondEq; |
| 419 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 420 | case Instruction::IF_NEZ: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 421 | cond = kCondNe; |
| 422 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 423 | case Instruction::IF_LTZ: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 424 | cond = kCondLt; |
| 425 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 426 | case Instruction::IF_GEZ: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 427 | cond = kCondGe; |
| 428 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 429 | case Instruction::IF_GTZ: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 430 | cond = kCondGt; |
| 431 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 432 | case Instruction::IF_LEZ: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 433 | cond = kCondLe; |
| 434 | break; |
| 435 | default: |
| 436 | cond = (ConditionCode)0; |
| 437 | LOG(FATAL) << "Unexpected opcode " << (int)opcode; |
| 438 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 439 | #if defined(TARGET_MIPS) |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 440 | opCmpImmBranch(cUnit, cond, rlSrc.lowReg, 0, &labelList[bb->taken->id]); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 441 | #else |
| 442 | opRegImm(cUnit, kOpCmp, rlSrc.lowReg, 0); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 443 | opCondBranch(cUnit, cond, &labelList[bb->taken->id]); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 444 | #endif |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 445 | opUnconditionalBranch(cUnit, &labelList[bb->fallThrough->id]); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | void genIntToLong(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 449 | RegLocation rlSrc) |
| 450 | { |
| 451 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 452 | if (rlSrc.location == kLocPhysReg) { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 453 | opRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 454 | } else { |
| 455 | loadValueDirect(cUnit, rlSrc, rlResult.lowReg); |
| 456 | } |
| 457 | opRegRegImm(cUnit, kOpAsr, rlResult.highReg, |
| 458 | rlResult.lowReg, 31); |
| 459 | storeValueWide(cUnit, rlDest, rlResult); |
| 460 | } |
| 461 | |
| 462 | void genIntNarrowing(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 463 | RegLocation rlSrc) |
| 464 | { |
| 465 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 466 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 467 | OpKind op = kOpInvalid; |
| 468 | switch(mir->dalvikInsn.opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 469 | case Instruction::INT_TO_BYTE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 470 | op = kOp2Byte; |
| 471 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 472 | case Instruction::INT_TO_SHORT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 473 | op = kOp2Short; |
| 474 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 475 | case Instruction::INT_TO_CHAR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 476 | op = kOp2Char; |
| 477 | break; |
| 478 | default: |
| 479 | LOG(ERROR) << "Bad int conversion type"; |
| 480 | } |
| 481 | opRegReg(cUnit, op, rlResult.lowReg, rlSrc.lowReg); |
| 482 | storeValue(cUnit, rlDest, rlResult); |
| 483 | } |
| 484 | |
| 485 | /* |
| 486 | * Let helper function take care of everything. Will call |
| 487 | * Array::AllocFromCode(type_idx, method, count); |
| 488 | * Note: AllocFromCode will handle checks for errNegativeArraySize. |
| 489 | */ |
| 490 | void genNewArray(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 491 | RegLocation rlSrc) |
| 492 | { |
| 493 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
| 494 | uint32_t type_idx = mir->dalvikInsn.vC; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 495 | int funcOffset; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 496 | if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
| 497 | cUnit->dex_cache, |
| 498 | *cUnit->dex_file, |
| 499 | type_idx)) { |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 500 | funcOffset = OFFSETOF_MEMBER(Thread, pAllocArrayFromCode); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 501 | } else { |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 502 | funcOffset= OFFSETOF_MEMBER(Thread, pAllocArrayFromCodeWithAccessCheck); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 503 | } |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 504 | callRuntimeHelperImmMethodRegLocation(cUnit, funcOffset, type_idx, rlSrc); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 505 | RegLocation rlResult = oatGetReturn(cUnit, false); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 506 | storeValue(cUnit, rlDest, rlResult); |
| 507 | } |
| 508 | |
| 509 | /* |
| 510 | * Similar to genNewArray, but with post-allocation initialization. |
| 511 | * Verifier guarantees we're dealing with an array class. Current |
| 512 | * code throws runtime exception "bad Filled array req" for 'D' and 'J'. |
| 513 | * Current code also throws internal unimp if not 'L', '[' or 'I'. |
| 514 | */ |
| 515 | void genFilledNewArray(CompilationUnit* cUnit, MIR* mir, bool isRange) |
| 516 | { |
| 517 | DecodedInstruction* dInsn = &mir->dalvikInsn; |
| 518 | int elems = dInsn->vA; |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 519 | int typeIdx = dInsn->vB; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 520 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 521 | int funcOffset; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 522 | if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
| 523 | cUnit->dex_cache, |
| 524 | *cUnit->dex_file, |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 525 | typeIdx)) { |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 526 | funcOffset = OFFSETOF_MEMBER(Thread, pCheckAndAllocArrayFromCode); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 527 | } else { |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 528 | funcOffset = OFFSETOF_MEMBER(Thread, |
| 529 | pCheckAndAllocArrayFromCodeWithAccessCheck); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 530 | } |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 531 | callRuntimeHelperImmMethodImm(cUnit, funcOffset, typeIdx, elems); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 532 | oatFreeTemp(cUnit, rARG2); |
| 533 | oatFreeTemp(cUnit, rARG1); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 534 | /* |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 535 | * NOTE: the implicit target for Instruction::FILLED_NEW_ARRAY is the |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 536 | * return region. Because AllocFromCode placed the new array |
| 537 | * in rRET0, we'll just lock it into place. When debugger support is |
| 538 | * added, it may be necessary to additionally copy all return |
| 539 | * values to a home location in thread-local storage |
| 540 | */ |
| 541 | oatLockTemp(cUnit, rRET0); |
| 542 | |
| 543 | // TODO: use the correct component size, currently all supported types |
| 544 | // share array alignment with ints (see comment at head of function) |
| 545 | size_t component_size = sizeof(int32_t); |
| 546 | |
| 547 | // Having a range of 0 is legal |
| 548 | if (isRange && (dInsn->vA > 0)) { |
| 549 | /* |
| 550 | * Bit of ugliness here. We're going generate a mem copy loop |
| 551 | * on the register range, but it is possible that some regs |
| 552 | * in the range have been promoted. This is unlikely, but |
| 553 | * before generating the copy, we'll just force a flush |
| 554 | * of any regs in the source range that have been promoted to |
| 555 | * home location. |
| 556 | */ |
| 557 | for (unsigned int i = 0; i < dInsn->vA; i++) { |
| 558 | RegLocation loc = oatUpdateLoc(cUnit, |
| 559 | oatGetSrc(cUnit, mir, i)); |
| 560 | if (loc.location == kLocPhysReg) { |
| 561 | storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow), |
| 562 | loc.lowReg, kWord); |
| 563 | } |
| 564 | } |
| 565 | /* |
| 566 | * TUNING note: generated code here could be much improved, but |
| 567 | * this is an uncommon operation and isn't especially performance |
| 568 | * critical. |
| 569 | */ |
| 570 | int rSrc = oatAllocTemp(cUnit); |
| 571 | int rDst = oatAllocTemp(cUnit); |
| 572 | int rIdx = oatAllocTemp(cUnit); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 573 | #if defined(TARGET_ARM) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 574 | int rVal = rLR; // Using a lot of temps, rLR is known free here |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 575 | #else |
| 576 | int rVal = oatAllocTemp(cUnit); |
| 577 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 578 | // Set up source pointer |
| 579 | RegLocation rlFirst = oatGetSrc(cUnit, mir, 0); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 580 | #if defined(TARGET_X86) |
| 581 | UNIMPLEMENTED(FATAL); |
| 582 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 583 | opRegRegImm(cUnit, kOpAdd, rSrc, rSP, |
| 584 | oatSRegOffset(cUnit, rlFirst.sRegLow)); |
| 585 | // Set up the target pointer |
| 586 | opRegRegImm(cUnit, kOpAdd, rDst, rRET0, |
| 587 | Array::DataOffset(component_size).Int32Value()); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 588 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 589 | // Set up the loop counter (known to be > 0) |
| 590 | loadConstant(cUnit, rIdx, dInsn->vA - 1); |
| 591 | // Generate the copy loop. Going backwards for convenience |
| 592 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 593 | // Copy next element |
| 594 | loadBaseIndexed(cUnit, rSrc, rIdx, rVal, 2, kWord); |
| 595 | storeBaseIndexed(cUnit, rDst, rIdx, rVal, 2, kWord); |
| 596 | #if defined(TARGET_ARM) |
| 597 | // Combine sub & test using sub setflags encoding here |
| 598 | newLIR3(cUnit, kThumb2SubsRRI12, rIdx, rIdx, 1); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 599 | opCondBranch(cUnit, kCondGe, target); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 600 | #else |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 601 | oatFreeTemp(cUnit, rVal); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 602 | opRegImm(cUnit, kOpSub, rIdx, 1); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 603 | opCmpImmBranch(cUnit, kCondGe, rIdx, 0, target); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 604 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 605 | } else if (!isRange) { |
| 606 | // TUNING: interleave |
| 607 | for (unsigned int i = 0; i < dInsn->vA; i++) { |
| 608 | RegLocation rlArg = loadValue(cUnit, |
| 609 | oatGetSrc(cUnit, mir, i), kCoreReg); |
| 610 | storeBaseDisp(cUnit, rRET0, |
| 611 | Array::DataOffset(component_size).Int32Value() + |
| 612 | i * 4, rlArg.lowReg, kWord); |
| 613 | // If the loadValue caused a temp to be allocated, free it |
| 614 | if (oatIsTemp(cUnit, rlArg.lowReg)) { |
| 615 | oatFreeTemp(cUnit, rlArg.lowReg); |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | void genSput(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc, |
| 622 | bool isLongOrDouble, bool isObject) |
| 623 | { |
| 624 | int fieldOffset; |
| 625 | int ssbIndex; |
| 626 | bool isVolatile; |
| 627 | bool isReferrersClass; |
| 628 | uint32_t fieldIdx = mir->dalvikInsn.vB; |
| 629 | |
| 630 | OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker, |
| 631 | *cUnit->dex_file, *cUnit->dex_cache, |
| 632 | cUnit->code_item, cUnit->method_idx, |
| 633 | cUnit->access_flags); |
| 634 | |
| 635 | bool fastPath = |
| 636 | cUnit->compiler->ComputeStaticFieldInfo(fieldIdx, &mUnit, |
| 637 | fieldOffset, ssbIndex, |
| 638 | isReferrersClass, isVolatile, true); |
| 639 | if (fastPath && !SLOW_FIELD_PATH) { |
| 640 | DCHECK_GE(fieldOffset, 0); |
| 641 | int rBase; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 642 | if (isReferrersClass) { |
| 643 | // Fast path, static storage base is this method's class |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 644 | RegLocation rlMethod = loadCurrMethod(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 645 | rBase = oatAllocTemp(cUnit); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 646 | loadWordDisp(cUnit, rlMethod.lowReg, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 647 | Method::DeclaringClassOffset().Int32Value(), rBase); |
| 648 | } else { |
| 649 | // Medium path, static storage base in a different class which |
| 650 | // requires checks that the other class is initialized. |
| 651 | DCHECK_GE(ssbIndex, 0); |
| 652 | // May do runtime call so everything to home locations. |
| 653 | oatFlushAllRegs(cUnit); |
| 654 | // Using fixed register to sync with possible call to runtime |
| 655 | // support. |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 656 | int rMethod = rARG1; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 657 | oatLockTemp(cUnit, rMethod); |
| 658 | loadCurrMethodDirect(cUnit, rMethod); |
| 659 | rBase = rARG0; |
| 660 | oatLockTemp(cUnit, rBase); |
| 661 | loadWordDisp(cUnit, rMethod, |
| 662 | Method::DexCacheInitializedStaticStorageOffset().Int32Value(), |
| 663 | rBase); |
| 664 | loadWordDisp(cUnit, rBase, |
| 665 | Array::DataOffset(sizeof(Object*)).Int32Value() + sizeof(int32_t*) * |
| 666 | ssbIndex, rBase); |
| 667 | // rBase now points at appropriate static storage base (Class*) |
| 668 | // or NULL if not initialized. Check for NULL and call helper if NULL. |
| 669 | // TUNING: fast path should fall through |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 670 | LIR* branchOver = opCmpImmBranch(cUnit, kCondNe, rBase, 0, NULL); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 671 | loadConstant(cUnit, rARG0, ssbIndex); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 672 | callRuntimeHelperImm(cUnit, |
| 673 | OFFSETOF_MEMBER(Thread, pInitializeStaticStorage), |
| 674 | ssbIndex); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 675 | #if defined(TARGET_MIPS) |
| 676 | // For Arm, rRET0 = rARG0 = rBASE, for Mips, we need to copy |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 677 | opRegCopy(cUnit, rBase, rRET0); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 678 | #endif |
| 679 | LIR* skipTarget = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 680 | branchOver->target = (LIR*)skipTarget; |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 681 | oatFreeTemp(cUnit, rMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 682 | } |
| 683 | // rBase now holds static storage base |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 684 | if (isLongOrDouble) { |
| 685 | rlSrc = oatGetSrcWide(cUnit, mir, 0, 1); |
| 686 | rlSrc = loadValueWide(cUnit, rlSrc, kAnyReg); |
| 687 | } else { |
| 688 | rlSrc = oatGetSrc(cUnit, mir, 0); |
| 689 | rlSrc = loadValue(cUnit, rlSrc, kAnyReg); |
| 690 | } |
| 691 | //FIXME: need to generalize the barrier call |
| 692 | if (isVolatile) { |
| 693 | oatGenMemBarrier(cUnit, kST); |
| 694 | } |
| 695 | if (isLongOrDouble) { |
| 696 | storeBaseDispWide(cUnit, rBase, fieldOffset, rlSrc.lowReg, |
| 697 | rlSrc.highReg); |
| 698 | } else { |
| 699 | storeWordDisp(cUnit, rBase, fieldOffset, rlSrc.lowReg); |
| 700 | } |
| 701 | if (isVolatile) { |
| 702 | oatGenMemBarrier(cUnit, kSY); |
| 703 | } |
| 704 | if (isObject) { |
| 705 | markGCCard(cUnit, rlSrc.lowReg, rBase); |
| 706 | } |
| 707 | oatFreeTemp(cUnit, rBase); |
| 708 | } else { |
| 709 | oatFlushAllRegs(cUnit); // Everything to home locations |
| 710 | int setterOffset = isLongOrDouble ? OFFSETOF_MEMBER(Thread, pSet64Static) : |
| 711 | (isObject ? OFFSETOF_MEMBER(Thread, pSetObjStatic) |
| 712 | : OFFSETOF_MEMBER(Thread, pSet32Static)); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 713 | callRuntimeHelperImmRegLocation(cUnit, setterOffset, fieldIdx, rlSrc); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | |
| 717 | void genSget(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 718 | bool isLongOrDouble, bool isObject) |
| 719 | { |
| 720 | int fieldOffset; |
| 721 | int ssbIndex; |
| 722 | bool isVolatile; |
| 723 | bool isReferrersClass; |
| 724 | uint32_t fieldIdx = mir->dalvikInsn.vB; |
| 725 | |
| 726 | OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker, |
| 727 | *cUnit->dex_file, *cUnit->dex_cache, |
| 728 | cUnit->code_item, cUnit->method_idx, |
| 729 | cUnit->access_flags); |
| 730 | |
| 731 | bool fastPath = |
| 732 | cUnit->compiler->ComputeStaticFieldInfo(fieldIdx, &mUnit, |
| 733 | fieldOffset, ssbIndex, |
| 734 | isReferrersClass, isVolatile, |
| 735 | false); |
| 736 | if (fastPath && !SLOW_FIELD_PATH) { |
| 737 | DCHECK_GE(fieldOffset, 0); |
| 738 | int rBase; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 739 | if (isReferrersClass) { |
| 740 | // Fast path, static storage base is this method's class |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 741 | RegLocation rlMethod = loadCurrMethod(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 742 | rBase = oatAllocTemp(cUnit); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 743 | loadWordDisp(cUnit, rlMethod.lowReg, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 744 | Method::DeclaringClassOffset().Int32Value(), rBase); |
| 745 | } else { |
| 746 | // Medium path, static storage base in a different class which |
| 747 | // requires checks that the other class is initialized |
| 748 | DCHECK_GE(ssbIndex, 0); |
| 749 | // May do runtime call so everything to home locations. |
| 750 | oatFlushAllRegs(cUnit); |
| 751 | // Using fixed register to sync with possible call to runtime |
| 752 | // support |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 753 | int rMethod = rARG1; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 754 | oatLockTemp(cUnit, rMethod); |
| 755 | loadCurrMethodDirect(cUnit, rMethod); |
| 756 | rBase = rARG0; |
| 757 | oatLockTemp(cUnit, rBase); |
| 758 | loadWordDisp(cUnit, rMethod, |
| 759 | Method::DexCacheInitializedStaticStorageOffset().Int32Value(), |
| 760 | rBase); |
| 761 | loadWordDisp(cUnit, rBase, |
| 762 | Array::DataOffset(sizeof(Object*)).Int32Value() + |
| 763 | sizeof(int32_t*) * ssbIndex, |
| 764 | rBase); |
| 765 | // rBase now points at appropriate static storage base (Class*) |
| 766 | // or NULL if not initialized. Check for NULL and call helper if NULL. |
| 767 | // TUNING: fast path should fall through |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 768 | LIR* branchOver = opCmpImmBranch(cUnit, kCondNe, rBase, 0, NULL); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 769 | callRuntimeHelperImm(cUnit, |
| 770 | OFFSETOF_MEMBER(Thread, pInitializeStaticStorage), |
| 771 | ssbIndex); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 772 | #if defined(TARGET_MIPS) |
| 773 | // For Arm, rRET0 = rARG0 = rBASE, for Mips, we need to copy |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 774 | opRegCopy(cUnit, rBase, rRET0); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 775 | #endif |
| 776 | LIR* skipTarget = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 777 | branchOver->target = (LIR*)skipTarget; |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 778 | oatFreeTemp(cUnit, rMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 779 | } |
| 780 | // rBase now holds static storage base |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 781 | rlDest = isLongOrDouble ? oatGetDestWide(cUnit, mir, 0, 1) |
| 782 | : oatGetDest(cUnit, mir, 0); |
| 783 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 784 | if (isVolatile) { |
| 785 | oatGenMemBarrier(cUnit, kSY); |
| 786 | } |
| 787 | if (isLongOrDouble) { |
| 788 | loadBaseDispWide(cUnit, NULL, rBase, fieldOffset, rlResult.lowReg, |
| 789 | rlResult.highReg, INVALID_SREG); |
| 790 | } else { |
| 791 | loadWordDisp(cUnit, rBase, fieldOffset, rlResult.lowReg); |
| 792 | } |
| 793 | oatFreeTemp(cUnit, rBase); |
| 794 | if (isLongOrDouble) { |
| 795 | storeValueWide(cUnit, rlDest, rlResult); |
| 796 | } else { |
| 797 | storeValue(cUnit, rlDest, rlResult); |
| 798 | } |
| 799 | } else { |
| 800 | oatFlushAllRegs(cUnit); // Everything to home locations |
| 801 | int getterOffset = isLongOrDouble ? OFFSETOF_MEMBER(Thread, pGet64Static) : |
| 802 | (isObject ? OFFSETOF_MEMBER(Thread, pGetObjStatic) |
| 803 | : OFFSETOF_MEMBER(Thread, pGet32Static)); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 804 | callRuntimeHelperImm(cUnit, getterOffset, fieldIdx); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 805 | if (isLongOrDouble) { |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 806 | RegLocation rlResult = oatGetReturnWide(cUnit, rlDest.fp); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 807 | storeValueWide(cUnit, rlDest, rlResult); |
| 808 | } else { |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 809 | RegLocation rlResult = oatGetReturn(cUnit, rlDest.fp); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 810 | storeValue(cUnit, rlDest, rlResult); |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | |
| 816 | // Debugging routine - if null target, branch to DebugMe |
| 817 | void genShowTarget(CompilationUnit* cUnit) |
| 818 | { |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 819 | #if defined(TARGET_X86) |
| 820 | UNIMPLEMENTED(WARNING) << "genShowTarget"; |
| 821 | #else |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 822 | LIR* branchOver = opCmpImmBranch(cUnit, kCondNe, rINVOKE_TGT, 0, NULL); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 823 | loadWordDisp(cUnit, rSELF, |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 824 | OFFSETOF_MEMBER(Thread, pDebugMe), rINVOKE_TGT); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 825 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 826 | branchOver->target = (LIR*)target; |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 827 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | void genThrowVerificationError(CompilationUnit* cUnit, MIR* mir) |
| 831 | { |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 832 | callRuntimeHelperImmImm(cUnit, OFFSETOF_MEMBER(Thread, |
| 833 | pThrowVerificationErrorFromCode), |
| 834 | mir->dalvikInsn.vA, mir->dalvikInsn.vB); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | void handleSuspendLaunchpads(CompilationUnit *cUnit) |
| 838 | { |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 839 | LIR** suspendLabel = (LIR **)cUnit->suspendLaunchpads.elemList; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 840 | int numElems = cUnit->suspendLaunchpads.numUsed; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 841 | for (int i = 0; i < numElems; i++) { |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 842 | oatResetRegPool(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 843 | LIR* lab = suspendLabel[i]; |
| 844 | LIR* resumeLab = (LIR*)lab->operands[0]; |
| 845 | cUnit->currentDalvikOffset = lab->operands[1]; |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 846 | oatAppendLIR(cUnit, lab); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 847 | #if defined(TARGET_X86) |
| 848 | opThreadMem(cUnit, kOpBlx, |
| 849 | OFFSETOF_MEMBER(Thread, pTestSuspendFromCode)); |
| 850 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 851 | int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, |
| 852 | pTestSuspendFromCode)); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 853 | opReg(cUnit, kOpBlx, rTgt); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 854 | #endif |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 855 | opUnconditionalBranch(cUnit, resumeLab); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | |
| 859 | void handleThrowLaunchpads(CompilationUnit *cUnit) |
| 860 | { |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 861 | LIR** throwLabel = (LIR **)cUnit->throwLaunchpads.elemList; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 862 | int numElems = cUnit->throwLaunchpads.numUsed; |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 863 | for (int i = 0; i < numElems; i++) { |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 864 | oatResetRegPool(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 865 | LIR* lab = throwLabel[i]; |
| 866 | cUnit->currentDalvikOffset = lab->operands[1]; |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 867 | oatAppendLIR(cUnit, lab); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 868 | int funcOffset = 0; |
| 869 | int v1 = lab->operands[2]; |
| 870 | int v2 = lab->operands[3]; |
| 871 | switch(lab->operands[0]) { |
| 872 | case kThrowNullPointer: |
| 873 | funcOffset = OFFSETOF_MEMBER(Thread, pThrowNullPointerFromCode); |
| 874 | break; |
| 875 | case kThrowArrayBounds: |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 876 | if (v2 != rARG0) { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 877 | opRegCopy(cUnit, rARG0, v1); |
| 878 | opRegCopy(cUnit, rARG1, v2); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 879 | } else { |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 880 | if (v1 == rARG1) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 881 | #if defined(TARGET_ARM) |
| 882 | int rTmp = r12; |
| 883 | #else |
| 884 | int rTmp = oatAllocTemp(cUnit); |
| 885 | #endif |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 886 | opRegCopy(cUnit, rTmp, v1); |
| 887 | opRegCopy(cUnit, rARG1, v2); |
| 888 | opRegCopy(cUnit, rARG0, rTmp); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 889 | } else { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 890 | opRegCopy(cUnit, rARG1, v2); |
| 891 | opRegCopy(cUnit, rARG0, v1); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | funcOffset = OFFSETOF_MEMBER(Thread, pThrowArrayBoundsFromCode); |
| 895 | break; |
| 896 | case kThrowDivZero: |
| 897 | funcOffset = OFFSETOF_MEMBER(Thread, pThrowDivZeroFromCode); |
| 898 | break; |
| 899 | case kThrowVerificationError: |
| 900 | loadConstant(cUnit, rARG0, v1); |
| 901 | loadConstant(cUnit, rARG1, v2); |
| 902 | funcOffset = |
| 903 | OFFSETOF_MEMBER(Thread, pThrowVerificationErrorFromCode); |
| 904 | break; |
| 905 | case kThrowNegArraySize: |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 906 | opRegCopy(cUnit, rARG0, v1); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 907 | funcOffset = |
| 908 | OFFSETOF_MEMBER(Thread, pThrowNegArraySizeFromCode); |
| 909 | break; |
| 910 | case kThrowNoSuchMethod: |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 911 | opRegCopy(cUnit, rARG0, v1); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 912 | funcOffset = |
| 913 | OFFSETOF_MEMBER(Thread, pThrowNoSuchMethodFromCode); |
| 914 | break; |
| 915 | case kThrowStackOverflow: |
| 916 | funcOffset = |
| 917 | OFFSETOF_MEMBER(Thread, pThrowStackOverflowFromCode); |
| 918 | // Restore stack alignment |
| 919 | opRegImm(cUnit, kOpAdd, rSP, |
| 920 | (cUnit->numCoreSpills + cUnit->numFPSpills) * 4); |
| 921 | break; |
| 922 | default: |
| 923 | LOG(FATAL) << "Unexpected throw kind: " << lab->operands[0]; |
| 924 | } |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 925 | oatClobberCalleeSave(cUnit); |
| 926 | #if !defined(TARGET_X86) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 927 | int rTgt = loadHelper(cUnit, funcOffset); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 928 | opReg(cUnit, kOpBlx, rTgt); |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 929 | oatFreeTemp(cUnit, rTgt); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 930 | #else |
| 931 | opThreadMem(cUnit, kOpBlx, funcOffset); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 932 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | |
| 936 | /* Needed by the Assembler */ |
| 937 | void oatSetupResourceMasks(LIR* lir) |
| 938 | { |
| 939 | setupResourceMasks(lir); |
| 940 | } |
| 941 | |
| 942 | void genIGet(CompilationUnit* cUnit, MIR* mir, OpSize size, |
| 943 | RegLocation rlDest, RegLocation rlObj, |
| 944 | bool isLongOrDouble, bool isObject) |
| 945 | { |
| 946 | int fieldOffset; |
| 947 | bool isVolatile; |
| 948 | uint32_t fieldIdx = mir->dalvikInsn.vC; |
| 949 | |
| 950 | OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker, |
| 951 | *cUnit->dex_file, *cUnit->dex_cache, |
| 952 | cUnit->code_item, cUnit->method_idx, |
| 953 | cUnit->access_flags); |
| 954 | |
| 955 | bool fastPath = cUnit->compiler->ComputeInstanceFieldInfo(fieldIdx, &mUnit, |
| 956 | fieldOffset, isVolatile, false); |
| 957 | |
| 958 | if (fastPath && !SLOW_FIELD_PATH) { |
| 959 | RegLocation rlResult; |
| 960 | RegisterClass regClass = oatRegClassBySize(size); |
| 961 | DCHECK_GE(fieldOffset, 0); |
| 962 | rlObj = loadValue(cUnit, rlObj, kCoreReg); |
| 963 | if (isLongOrDouble) { |
| 964 | DCHECK(rlDest.wide); |
| 965 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir);/* null? */ |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 966 | #if defined(TARGET_X86) |
| 967 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
| 968 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir);/* null? */ |
| 969 | loadBaseDispWide(cUnit, mir, rlObj.lowReg, fieldOffset, rlResult.lowReg, |
| 970 | rlResult.highReg, rlObj.sRegLow); |
| 971 | if (isVolatile) { |
| 972 | oatGenMemBarrier(cUnit, kSY); |
| 973 | } |
| 974 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 975 | int regPtr = oatAllocTemp(cUnit); |
| 976 | opRegRegImm(cUnit, kOpAdd, regPtr, rlObj.lowReg, fieldOffset); |
| 977 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
| 978 | loadPair(cUnit, regPtr, rlResult.lowReg, rlResult.highReg); |
| 979 | if (isVolatile) { |
| 980 | oatGenMemBarrier(cUnit, kSY); |
| 981 | } |
| 982 | oatFreeTemp(cUnit, regPtr); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 983 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 984 | storeValueWide(cUnit, rlDest, rlResult); |
| 985 | } else { |
| 986 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
| 987 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir);/* null? */ |
| 988 | loadBaseDisp(cUnit, mir, rlObj.lowReg, fieldOffset, rlResult.lowReg, |
| 989 | kWord, rlObj.sRegLow); |
| 990 | if (isVolatile) { |
| 991 | oatGenMemBarrier(cUnit, kSY); |
| 992 | } |
| 993 | storeValue(cUnit, rlDest, rlResult); |
| 994 | } |
| 995 | } else { |
| 996 | int getterOffset = isLongOrDouble ? OFFSETOF_MEMBER(Thread, pGet64Instance) : |
| 997 | (isObject ? OFFSETOF_MEMBER(Thread, pGetObjInstance) |
| 998 | : OFFSETOF_MEMBER(Thread, pGet32Instance)); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 999 | callRuntimeHelperImmRegLocation(cUnit, getterOffset, fieldIdx, rlObj); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1000 | if (isLongOrDouble) { |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 1001 | RegLocation rlResult = oatGetReturnWide(cUnit, rlDest.fp); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1002 | storeValueWide(cUnit, rlDest, rlResult); |
| 1003 | } else { |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 1004 | RegLocation rlResult = oatGetReturn(cUnit, rlDest.fp); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1005 | storeValue(cUnit, rlDest, rlResult); |
| 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | void genIPut(CompilationUnit* cUnit, MIR* mir, OpSize size, RegLocation rlSrc, |
| 1011 | RegLocation rlObj, bool isLongOrDouble, bool isObject) |
| 1012 | { |
| 1013 | int fieldOffset; |
| 1014 | bool isVolatile; |
| 1015 | uint32_t fieldIdx = mir->dalvikInsn.vC; |
| 1016 | |
| 1017 | OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker, |
| 1018 | *cUnit->dex_file, *cUnit->dex_cache, |
| 1019 | cUnit->code_item, cUnit->method_idx, |
| 1020 | cUnit->access_flags); |
| 1021 | |
| 1022 | bool fastPath = cUnit->compiler->ComputeInstanceFieldInfo(fieldIdx, &mUnit, |
| 1023 | fieldOffset, isVolatile, true); |
| 1024 | if (fastPath && !SLOW_FIELD_PATH) { |
| 1025 | RegisterClass regClass = oatRegClassBySize(size); |
| 1026 | DCHECK_GE(fieldOffset, 0); |
| 1027 | rlObj = loadValue(cUnit, rlObj, kCoreReg); |
| 1028 | if (isLongOrDouble) { |
| 1029 | int regPtr; |
| 1030 | rlSrc = loadValueWide(cUnit, rlSrc, kAnyReg); |
| 1031 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir);/* null? */ |
| 1032 | regPtr = oatAllocTemp(cUnit); |
| 1033 | opRegRegImm(cUnit, kOpAdd, regPtr, rlObj.lowReg, fieldOffset); |
| 1034 | if (isVolatile) { |
| 1035 | oatGenMemBarrier(cUnit, kST); |
| 1036 | } |
| 1037 | storePair(cUnit, regPtr, rlSrc.lowReg, rlSrc.highReg); |
| 1038 | if (isVolatile) { |
| 1039 | oatGenMemBarrier(cUnit, kSY); |
| 1040 | } |
| 1041 | oatFreeTemp(cUnit, regPtr); |
| 1042 | } else { |
| 1043 | rlSrc = loadValue(cUnit, rlSrc, regClass); |
| 1044 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir);/* null? */ |
| 1045 | if (isVolatile) { |
| 1046 | oatGenMemBarrier(cUnit, kST); |
| 1047 | } |
| 1048 | storeBaseDisp(cUnit, rlObj.lowReg, fieldOffset, rlSrc.lowReg, kWord); |
| 1049 | if (isVolatile) { |
| 1050 | oatGenMemBarrier(cUnit, kSY); |
| 1051 | } |
buzbee | a7c1268 | 2012-03-19 13:13:53 -0700 | [diff] [blame^] | 1052 | if (isObject) { |
| 1053 | markGCCard(cUnit, rlSrc.lowReg, rlObj.lowReg); |
| 1054 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1055 | } |
| 1056 | } else { |
| 1057 | int setterOffset = isLongOrDouble ? OFFSETOF_MEMBER(Thread, pSet64Instance) : |
| 1058 | (isObject ? OFFSETOF_MEMBER(Thread, pSetObjInstance) |
| 1059 | : OFFSETOF_MEMBER(Thread, pSet32Instance)); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1060 | callRuntimeHelperImmRegLocationRegLocation(cUnit, setterOffset, |
| 1061 | fieldIdx, rlObj, rlSrc); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | void genConstClass(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 1066 | RegLocation rlSrc) |
| 1067 | { |
| 1068 | uint32_t type_idx = mir->dalvikInsn.vB; |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 1069 | RegLocation rlMethod = loadCurrMethod(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1070 | int resReg = oatAllocTemp(cUnit); |
| 1071 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1072 | if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
| 1073 | cUnit->dex_cache, |
| 1074 | *cUnit->dex_file, |
| 1075 | type_idx)) { |
| 1076 | // Call out to helper which resolves type and verifies access. |
| 1077 | // Resolved type returned in rRET0. |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1078 | callRuntimeHelperImmReg(cUnit, |
| 1079 | OFFSETOF_MEMBER(Thread, |
| 1080 | pInitializeTypeAndVerifyAccessFromCode), |
| 1081 | type_idx, rlMethod.lowReg); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 1082 | RegLocation rlResult = oatGetReturn(cUnit, false); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1083 | storeValue(cUnit, rlDest, rlResult); |
| 1084 | } else { |
| 1085 | // We're don't need access checks, load type from dex cache |
| 1086 | int32_t dex_cache_offset = |
| 1087 | Method::DexCacheResolvedTypesOffset().Int32Value(); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 1088 | loadWordDisp(cUnit, rlMethod.lowReg, dex_cache_offset, resReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1089 | int32_t offset_of_type = |
| 1090 | Array::DataOffset(sizeof(Class*)).Int32Value() + (sizeof(Class*) |
| 1091 | * type_idx); |
| 1092 | loadWordDisp(cUnit, resReg, offset_of_type, rlResult.lowReg); |
| 1093 | if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(cUnit->dex_cache, |
| 1094 | type_idx) || SLOW_TYPE_PATH) { |
| 1095 | // Slow path, at runtime test if type is null and if so initialize |
| 1096 | oatFlushAllRegs(cUnit); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1097 | LIR* branch1 = opCmpImmBranch(cUnit, kCondEq, rlResult.lowReg, 0, |
| 1098 | NULL); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1099 | // Resolved, store and hop over following code |
| 1100 | storeValue(cUnit, rlDest, rlResult); |
buzbee | 3d66194 | 2012-03-14 17:37:27 -0700 | [diff] [blame] | 1101 | /* |
| 1102 | * Because we have stores of the target value on two paths, |
| 1103 | * clobber temp tracking for the destination using the ssa name |
| 1104 | */ |
| 1105 | oatClobberSReg(cUnit, rlDest.sRegLow); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1106 | LIR* branch2 = opUnconditionalBranch(cUnit,0); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1107 | // TUNING: move slow path to end & remove unconditional branch |
| 1108 | LIR* target1 = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 1109 | // Call out to helper, which will return resolved type in rARG0 |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1110 | callRuntimeHelperImmReg(cUnit, OFFSETOF_MEMBER(Thread, |
| 1111 | pInitializeTypeFromCode), |
| 1112 | type_idx, rlMethod.lowReg); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 1113 | RegLocation rlResult = oatGetReturn(cUnit, false); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1114 | storeValue(cUnit, rlDest, rlResult); |
buzbee | 3d66194 | 2012-03-14 17:37:27 -0700 | [diff] [blame] | 1115 | /* |
| 1116 | * Because we have stores of the target value on two paths, |
| 1117 | * clobber temp tracking for the destination using the ssa name |
| 1118 | */ |
| 1119 | oatClobberSReg(cUnit, rlDest.sRegLow); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1120 | // Rejoin code paths |
| 1121 | LIR* target2 = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1122 | branch1->target = (LIR*)target1; |
| 1123 | branch2->target = (LIR*)target2; |
| 1124 | } else { |
| 1125 | // Fast path, we're done - just store result |
| 1126 | storeValue(cUnit, rlDest, rlResult); |
| 1127 | } |
| 1128 | } |
| 1129 | } |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1130 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1131 | void genConstString(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 1132 | RegLocation rlSrc) |
| 1133 | { |
| 1134 | /* NOTE: Most strings should be available at compile time */ |
| 1135 | uint32_t string_idx = mir->dalvikInsn.vB; |
| 1136 | int32_t offset_of_string = Array::DataOffset(sizeof(String*)).Int32Value() + |
| 1137 | (sizeof(String*) * string_idx); |
| 1138 | if (!cUnit->compiler->CanAssumeStringIsPresentInDexCache( |
| 1139 | cUnit->dex_cache, string_idx) || SLOW_STRING_PATH) { |
| 1140 | // slow path, resolve string if not in dex cache |
| 1141 | oatFlushAllRegs(cUnit); |
| 1142 | oatLockCallTemps(cUnit); // Using explicit registers |
| 1143 | loadCurrMethodDirect(cUnit, rARG2); |
| 1144 | loadWordDisp(cUnit, rARG2, |
| 1145 | Method::DexCacheStringsOffset().Int32Value(), rARG0); |
| 1146 | // Might call out to helper, which will return resolved string in rRET0 |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1147 | #if !defined(TARGET_X86) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1148 | int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, |
| 1149 | pResolveStringFromCode)); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1150 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1151 | loadWordDisp(cUnit, rRET0, offset_of_string, rARG0); |
| 1152 | loadConstant(cUnit, rARG1, string_idx); |
| 1153 | #if defined(TARGET_ARM) |
| 1154 | opRegImm(cUnit, kOpCmp, rRET0, 0); // Is resolved? |
| 1155 | genBarrier(cUnit); |
| 1156 | // For testing, always force through helper |
| 1157 | if (!EXERCISE_SLOWEST_STRING_PATH) { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1158 | opIT(cUnit, kArmCondEq, "T"); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1159 | } |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1160 | opRegCopy(cUnit, rARG0, rARG2); // .eq |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1161 | opReg(cUnit, kOpBlx, rTgt); // .eq, helper(Method*, string_idx) |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1162 | oatFreeTemp(cUnit, rTgt); |
| 1163 | #elif defined(TARGET_MIPS) |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1164 | LIR* branch = opCmpImmBranch(cUnit, kCondNe, rRET0, 0, NULL); |
| 1165 | opRegCopy(cUnit, rARG0, rARG2); // .eq |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1166 | opReg(cUnit, kOpBlx, rTgt); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1167 | oatFreeTemp(cUnit, rTgt); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1168 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1169 | branch->target = target; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1170 | #else |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1171 | callRuntimeHelperRegReg(cUnit, OFFSETOF_MEMBER(Thread, |
| 1172 | pResolveStringFromCode), |
| 1173 | rARG2, rARG1); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1174 | #endif |
| 1175 | genBarrier(cUnit); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 1176 | storeValue(cUnit, rlDest, oatGetReturn(cUnit, false)); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1177 | } else { |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 1178 | RegLocation rlMethod = loadCurrMethod(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1179 | int resReg = oatAllocTemp(cUnit); |
| 1180 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 1181 | loadWordDisp(cUnit, rlMethod.lowReg, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1182 | Method::DexCacheStringsOffset().Int32Value(), resReg); |
| 1183 | loadWordDisp(cUnit, resReg, offset_of_string, rlResult.lowReg); |
| 1184 | storeValue(cUnit, rlDest, rlResult); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | /* |
| 1189 | * Let helper function take care of everything. Will |
| 1190 | * call Class::NewInstanceFromCode(type_idx, method); |
| 1191 | */ |
| 1192 | void genNewInstance(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest) |
| 1193 | { |
| 1194 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
| 1195 | uint32_t type_idx = mir->dalvikInsn.vB; |
| 1196 | // alloc will always check for resolution, do we also need to verify |
| 1197 | // access because the verifier was unable to? |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1198 | int funcOffset; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1199 | if (cUnit->compiler->CanAccessInstantiableTypeWithoutChecks( |
| 1200 | cUnit->method_idx, cUnit->dex_cache, *cUnit->dex_file, type_idx)) { |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1201 | funcOffset = OFFSETOF_MEMBER(Thread, pAllocObjectFromCode); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1202 | } else { |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1203 | funcOffset = |
| 1204 | OFFSETOF_MEMBER(Thread, pAllocObjectFromCodeWithAccessCheck); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1205 | } |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1206 | callRuntimeHelperImmMethod(cUnit, funcOffset, type_idx); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 1207 | RegLocation rlResult = oatGetReturn(cUnit, false); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1208 | storeValue(cUnit, rlDest, rlResult); |
| 1209 | } |
| 1210 | |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1211 | void genThrow(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc) |
| 1212 | { |
| 1213 | oatFlushAllRegs(cUnit); |
| 1214 | callRuntimeHelperRegLocation(cUnit, OFFSETOF_MEMBER(Thread, pDeliverException), rlSrc); |
| 1215 | } |
| 1216 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1217 | void genInstanceof(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 1218 | RegLocation rlSrc) |
| 1219 | { |
| 1220 | oatFlushAllRegs(cUnit); |
| 1221 | // May generate a call - use explicit registers |
| 1222 | oatLockCallTemps(cUnit); |
| 1223 | uint32_t type_idx = mir->dalvikInsn.vC; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 1224 | loadCurrMethodDirect(cUnit, rARG1); // rARG1 <= current Method* |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1225 | int classReg = rARG2; // rARG2 will hold the Class* |
| 1226 | if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
| 1227 | cUnit->dex_cache, |
| 1228 | *cUnit->dex_file, |
| 1229 | type_idx)) { |
| 1230 | // Check we have access to type_idx and if not throw IllegalAccessError, |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 1231 | // returns Class* in rARG0 |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1232 | callRuntimeHelperImm(cUnit, |
| 1233 | OFFSETOF_MEMBER(Thread, pInitializeTypeAndVerifyAccessFromCode), |
| 1234 | type_idx); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1235 | opRegCopy(cUnit, classReg, rRET0); // Align usage with fast path |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 1236 | loadValueDirectFixed(cUnit, rlSrc, rARG0); // rARG0 <= ref |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1237 | } else { |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 1238 | // Load dex cache entry into classReg (rARG2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1239 | loadValueDirectFixed(cUnit, rlSrc, rARG0); // rARG0 <= ref |
| 1240 | loadWordDisp(cUnit, rARG1, |
| 1241 | Method::DexCacheResolvedTypesOffset().Int32Value(), |
| 1242 | classReg); |
| 1243 | int32_t offset_of_type = |
| 1244 | Array::DataOffset(sizeof(Class*)).Int32Value() + (sizeof(Class*) |
| 1245 | * type_idx); |
| 1246 | loadWordDisp(cUnit, classReg, offset_of_type, classReg); |
| 1247 | if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache( |
| 1248 | cUnit->dex_cache, type_idx)) { |
| 1249 | // Need to test presence of type in dex cache at runtime |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1250 | LIR* hopBranch = opCmpImmBranch(cUnit, kCondNe, classReg, 0, NULL); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1251 | // Not resolved |
| 1252 | // Call out to helper, which will return resolved type in rRET0 |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1253 | callRuntimeHelperImm(cUnit, OFFSETOF_MEMBER(Thread, |
| 1254 | pInitializeTypeFromCode), |
| 1255 | type_idx); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1256 | opRegCopy(cUnit, rARG2, rRET0); // Align usage with fast path |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1257 | loadValueDirectFixed(cUnit, rlSrc, rARG0); /* reload Ref */ |
| 1258 | // Rejoin code paths |
| 1259 | LIR* hopTarget = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1260 | hopBranch->target = (LIR*)hopTarget; |
| 1261 | } |
| 1262 | } |
| 1263 | /* rARG0 is ref, rARG2 is class. If ref==null, use directly as bool result */ |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1264 | LIR* branch1 = opCmpImmBranch(cUnit, kCondEq, rARG0, 0, NULL); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1265 | /* load object->clazz */ |
| 1266 | DCHECK_EQ(Object::ClassOffset().Int32Value(), 0); |
| 1267 | loadWordDisp(cUnit, rARG0, Object::ClassOffset().Int32Value(), rARG1); |
| 1268 | /* rARG0 is ref, rARG1 is ref->clazz, rARG2 is class */ |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 1269 | #if defined(TARGET_ARM) |
| 1270 | /* Uses conditional nullification */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1271 | int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, |
| 1272 | pInstanceofNonTrivialFromCode)); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1273 | opRegReg(cUnit, kOpCmp, rARG1, rARG2); // Same? |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1274 | opIT(cUnit, kArmCondEq, "EE"); // if-convert the test |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1275 | loadConstant(cUnit, rARG0, 1); // .eq case - load true |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1276 | opRegCopy(cUnit, rARG0, rARG2); // .ne case - arg0 <= class |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1277 | opReg(cUnit, kOpBlx, rTgt); // .ne case: helper(class, ref->class) |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1278 | oatFreeTemp(cUnit, rTgt); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1279 | #else |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 1280 | /* Uses branchovers */ |
| 1281 | loadConstant(cUnit, rARG0, 1); // assume true |
| 1282 | LIR* branchover = opCmpBranch(cUnit, kCondEq, rARG1, rARG2, NULL); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1283 | #if !defined(TARGET_X86) |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 1284 | int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, |
| 1285 | pInstanceofNonTrivialFromCode)); |
| 1286 | opRegCopy(cUnit, rARG0, rARG2); // .ne case - arg0 <= class |
| 1287 | opReg(cUnit, kOpBlx, rTgt); // .ne case: helper(class, ref->class) |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1288 | oatFreeTemp(cUnit, rTgt); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1289 | #else |
| 1290 | opRegCopy(cUnit, rARG0, rARG2); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1291 | opThreadMem(cUnit, kOpBlx, |
| 1292 | OFFSETOF_MEMBER(Thread, pInstanceofNonTrivialFromCode)); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1293 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1294 | #endif |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 1295 | oatClobberCalleeSave(cUnit); |
| 1296 | /* branch targets here */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1297 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 1298 | RegLocation rlResult = oatGetReturn(cUnit, false); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1299 | storeValue(cUnit, rlDest, rlResult); |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 1300 | branch1->target = target; |
| 1301 | #if !defined(TARGET_ARM) |
| 1302 | branchover->target = target; |
| 1303 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | void genCheckCast(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc) |
| 1307 | { |
| 1308 | oatFlushAllRegs(cUnit); |
| 1309 | // May generate a call - use explicit registers |
| 1310 | oatLockCallTemps(cUnit); |
| 1311 | uint32_t type_idx = mir->dalvikInsn.vB; |
| 1312 | loadCurrMethodDirect(cUnit, rARG1); // rARG1 <= current Method* |
| 1313 | int classReg = rARG2; // rARG2 will hold the Class* |
| 1314 | if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
| 1315 | cUnit->dex_cache, |
| 1316 | *cUnit->dex_file, |
| 1317 | type_idx)) { |
| 1318 | // Check we have access to type_idx and if not throw IllegalAccessError, |
| 1319 | // returns Class* in rRET0 |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1320 | // InitializeTypeAndVerifyAccess(idx, method) |
| 1321 | callRuntimeHelperImmReg(cUnit, |
| 1322 | OFFSETOF_MEMBER(Thread, |
| 1323 | pInitializeTypeAndVerifyAccessFromCode), |
| 1324 | type_idx, rARG1); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1325 | opRegCopy(cUnit, classReg, rRET0); // Align usage with fast path |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1326 | } else { |
| 1327 | // Load dex cache entry into classReg (rARG2) |
| 1328 | loadWordDisp(cUnit, rARG1, |
| 1329 | Method::DexCacheResolvedTypesOffset().Int32Value(), |
| 1330 | classReg); |
| 1331 | int32_t offset_of_type = |
| 1332 | Array::DataOffset(sizeof(Class*)).Int32Value() + |
| 1333 | (sizeof(Class*) * type_idx); |
| 1334 | loadWordDisp(cUnit, classReg, offset_of_type, classReg); |
| 1335 | if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache( |
| 1336 | cUnit->dex_cache, type_idx)) { |
| 1337 | // Need to test presence of type in dex cache at runtime |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1338 | LIR* hopBranch = opCmpImmBranch(cUnit, kCondNe, classReg, 0, NULL); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1339 | // Not resolved |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 1340 | // Call out to helper, which will return resolved type in rARG0 |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1341 | // InitializeTypeFromCode(idx, method) |
| 1342 | callRuntimeHelperImmReg(cUnit, |
| 1343 | OFFSETOF_MEMBER(Thread, pInitializeTypeFromCode), |
| 1344 | type_idx, rARG1); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1345 | opRegCopy(cUnit, classReg, rARG0); // Align usage with fast path |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1346 | // Rejoin code paths |
| 1347 | LIR* hopTarget = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1348 | hopBranch->target = (LIR*)hopTarget; |
| 1349 | } |
| 1350 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 1351 | // At this point, classReg (rARG2) has class |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1352 | loadValueDirectFixed(cUnit, rlSrc, rARG0); // rARG0 <= ref |
| 1353 | /* Null is OK - continue */ |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1354 | LIR* branch1 = opCmpImmBranch(cUnit, kCondEq, rARG0, 0, NULL); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1355 | /* load object->clazz */ |
| 1356 | DCHECK_EQ(Object::ClassOffset().Int32Value(), 0); |
| 1357 | loadWordDisp(cUnit, rARG0, Object::ClassOffset().Int32Value(), rARG1); |
| 1358 | /* rARG1 now contains object->clazz */ |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1359 | #if defined(TARGET_MIPS) || defined(TARGET_X86) |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1360 | LIR* branch2 = opCmpBranch(cUnit, kCondEq, rARG1, classReg, NULL); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1361 | callRuntimeHelperRegReg(cUnit, OFFSETOF_MEMBER(Thread, |
| 1362 | pCheckCastFromCode), |
| 1363 | rARG1, rARG2); |
| 1364 | #else // defined(TARGET_ARM) |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1365 | int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, |
| 1366 | pCheckCastFromCode)); |
| 1367 | opRegReg(cUnit, kOpCmp, rARG1, classReg); |
| 1368 | LIR* branch2 = opCondBranch(cUnit, kCondEq, NULL); /* If eq, trivial yes */ |
| 1369 | opRegCopy(cUnit, rARG0, rARG1); |
| 1370 | opRegCopy(cUnit, rARG1, rARG2); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1371 | oatClobberCalleeSave(cUnit); |
| 1372 | opReg(cUnit, kOpBlx, rTgt); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1373 | oatFreeTemp(cUnit, rTgt); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1374 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1375 | /* branch target here */ |
| 1376 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1377 | branch1->target = (LIR*)target; |
| 1378 | branch2->target = (LIR*)target; |
| 1379 | } |
| 1380 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1381 | /* |
| 1382 | * Generate array store |
| 1383 | * |
| 1384 | */ |
| 1385 | void genArrayObjPut(CompilationUnit* cUnit, MIR* mir, RegLocation rlArray, |
| 1386 | RegLocation rlIndex, RegLocation rlSrc, int scale) |
| 1387 | { |
| 1388 | RegisterClass regClass = oatRegClassBySize(kWord); |
| 1389 | int lenOffset = Array::LengthOffset().Int32Value(); |
| 1390 | int dataOffset = Array::DataOffset(sizeof(Object*)).Int32Value(); |
| 1391 | |
| 1392 | oatFlushAllRegs(cUnit); |
| 1393 | /* Make sure it's a legal object Put. Use direct regs at first */ |
| 1394 | loadValueDirectFixed(cUnit, rlArray, rARG1); |
| 1395 | loadValueDirectFixed(cUnit, rlSrc, rARG0); |
| 1396 | |
| 1397 | /* null array object? */ |
| 1398 | genNullCheck(cUnit, rlArray.sRegLow, rARG1, mir); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1399 | /* Get the array's clazz */ |
| 1400 | loadWordDisp(cUnit, rARG1, Object::ClassOffset().Int32Value(), rARG1); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1401 | callRuntimeHelperRegReg(cUnit, OFFSETOF_MEMBER(Thread, |
| 1402 | pCanPutArrayElementFromCode), |
| 1403 | rARG0, rARG1); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1404 | oatFreeTemp(cUnit, rARG0); |
| 1405 | oatFreeTemp(cUnit, rARG1); |
| 1406 | |
| 1407 | // Now, redo loadValues in case they didn't survive the call |
| 1408 | |
| 1409 | int regPtr; |
| 1410 | rlArray = loadValue(cUnit, rlArray, kCoreReg); |
| 1411 | rlIndex = loadValue(cUnit, rlIndex, kCoreReg); |
| 1412 | |
| 1413 | if (oatIsTemp(cUnit, rlArray.lowReg)) { |
| 1414 | oatClobber(cUnit, rlArray.lowReg); |
| 1415 | regPtr = rlArray.lowReg; |
| 1416 | } else { |
| 1417 | regPtr = oatAllocTemp(cUnit); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1418 | opRegCopy(cUnit, regPtr, rlArray.lowReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1419 | } |
| 1420 | |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 1421 | bool needsRangeCheck = (!(mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK)); |
| 1422 | int regLen = INVALID_REG; |
| 1423 | if (needsRangeCheck) { |
| 1424 | regLen = oatAllocTemp(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1425 | //NOTE: max live temps(4) here. |
| 1426 | /* Get len */ |
| 1427 | loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen); |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 1428 | } |
| 1429 | /* regPtr -> array data */ |
| 1430 | opRegImm(cUnit, kOpAdd, regPtr, dataOffset); |
| 1431 | /* at this point, regPtr points to array, 2 live temps */ |
| 1432 | rlSrc = loadValue(cUnit, rlSrc, regClass); |
| 1433 | if (needsRangeCheck) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1434 | genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, mir, |
| 1435 | kThrowArrayBounds); |
| 1436 | oatFreeTemp(cUnit, regLen); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1437 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1438 | storeBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlSrc.lowReg, |
| 1439 | scale, kWord); |
buzbee | a7c1268 | 2012-03-19 13:13:53 -0700 | [diff] [blame^] | 1440 | markGCCard(cUnit, rlSrc.lowReg, rlArray.lowReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | /* |
| 1444 | * Generate array load |
| 1445 | */ |
| 1446 | void genArrayGet(CompilationUnit* cUnit, MIR* mir, OpSize size, |
| 1447 | RegLocation rlArray, RegLocation rlIndex, |
| 1448 | RegLocation rlDest, int scale) |
| 1449 | { |
| 1450 | RegisterClass regClass = oatRegClassBySize(size); |
| 1451 | int lenOffset = Array::LengthOffset().Int32Value(); |
| 1452 | int dataOffset; |
| 1453 | RegLocation rlResult; |
| 1454 | rlArray = loadValue(cUnit, rlArray, kCoreReg); |
| 1455 | rlIndex = loadValue(cUnit, rlIndex, kCoreReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1456 | |
| 1457 | if (size == kLong || size == kDouble) { |
| 1458 | dataOffset = Array::DataOffset(sizeof(int64_t)).Int32Value(); |
| 1459 | } else { |
| 1460 | dataOffset = Array::DataOffset(sizeof(int32_t)).Int32Value(); |
| 1461 | } |
| 1462 | |
| 1463 | /* null object? */ |
| 1464 | genNullCheck(cUnit, rlArray.sRegLow, rlArray.lowReg, mir); |
| 1465 | |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 1466 | #if defined(TARGET_X86) |
| 1467 | if (!(mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK)) { |
| 1468 | /* if (rlIndex >= [rlArray + lenOffset]) goto kThrowArrayBounds */ |
| 1469 | genRegMemCheck(cUnit, kCondUge, rlIndex.lowReg, rlArray.lowReg, |
| 1470 | lenOffset, mir, kThrowArrayBounds); |
| 1471 | } |
| 1472 | if ((size == kLong) || (size == kDouble)) { |
| 1473 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
| 1474 | loadBaseIndexedDisp(cUnit, NULL, rlArray.lowReg, rlIndex.lowReg, scale, dataOffset, |
| 1475 | rlResult.lowReg, rlResult.highReg, size, INVALID_SREG); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1476 | |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 1477 | storeValueWide(cUnit, rlDest, rlResult); |
| 1478 | } else { |
| 1479 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
| 1480 | |
| 1481 | loadBaseIndexedDisp(cUnit, NULL, rlArray.lowReg, rlIndex.lowReg, scale, dataOffset, |
| 1482 | rlResult.lowReg, INVALID_REG, size, INVALID_SREG); |
| 1483 | |
| 1484 | storeValue(cUnit, rlDest, rlResult); |
| 1485 | } |
| 1486 | #else |
| 1487 | int regPtr = oatAllocTemp(cUnit); |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 1488 | bool needsRangeCheck = (!(mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK)); |
| 1489 | int regLen = INVALID_REG; |
| 1490 | if (needsRangeCheck) { |
| 1491 | regLen = oatAllocTemp(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1492 | /* Get len */ |
| 1493 | loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1494 | } |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 1495 | /* regPtr -> array data */ |
| 1496 | opRegRegImm(cUnit, kOpAdd, regPtr, rlArray.lowReg, dataOffset); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1497 | oatFreeTemp(cUnit, rlArray.lowReg); |
| 1498 | if ((size == kLong) || (size == kDouble)) { |
| 1499 | if (scale) { |
| 1500 | int rNewIndex = oatAllocTemp(cUnit); |
| 1501 | opRegRegImm(cUnit, kOpLsl, rNewIndex, rlIndex.lowReg, scale); |
| 1502 | opRegReg(cUnit, kOpAdd, regPtr, rNewIndex); |
| 1503 | oatFreeTemp(cUnit, rNewIndex); |
| 1504 | } else { |
| 1505 | opRegReg(cUnit, kOpAdd, regPtr, rlIndex.lowReg); |
| 1506 | } |
| 1507 | oatFreeTemp(cUnit, rlIndex.lowReg); |
| 1508 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
| 1509 | |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 1510 | if (needsRangeCheck) { |
| 1511 | // TODO: change kCondCS to a more meaningful name, is the sense of |
| 1512 | // carry-set/clear flipped? |
| 1513 | genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, mir, |
| 1514 | kThrowArrayBounds); |
| 1515 | oatFreeTemp(cUnit, regLen); |
| 1516 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1517 | loadPair(cUnit, regPtr, rlResult.lowReg, rlResult.highReg); |
| 1518 | |
| 1519 | oatFreeTemp(cUnit, regPtr); |
| 1520 | storeValueWide(cUnit, rlDest, rlResult); |
| 1521 | } else { |
| 1522 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
| 1523 | |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 1524 | if (needsRangeCheck) { |
| 1525 | // TODO: change kCondCS to a more meaningful name, is the sense of |
| 1526 | // carry-set/clear flipped? |
| 1527 | genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, mir, |
| 1528 | kThrowArrayBounds); |
| 1529 | oatFreeTemp(cUnit, regLen); |
| 1530 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1531 | loadBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlResult.lowReg, |
| 1532 | scale, size); |
| 1533 | |
| 1534 | oatFreeTemp(cUnit, regPtr); |
| 1535 | storeValue(cUnit, rlDest, rlResult); |
| 1536 | } |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 1537 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | /* |
| 1541 | * Generate array store |
| 1542 | * |
| 1543 | */ |
| 1544 | void genArrayPut(CompilationUnit* cUnit, MIR* mir, OpSize size, |
| 1545 | RegLocation rlArray, RegLocation rlIndex, |
| 1546 | RegLocation rlSrc, int scale) |
| 1547 | { |
| 1548 | RegisterClass regClass = oatRegClassBySize(size); |
| 1549 | int lenOffset = Array::LengthOffset().Int32Value(); |
| 1550 | int dataOffset; |
| 1551 | |
| 1552 | if (size == kLong || size == kDouble) { |
| 1553 | dataOffset = Array::DataOffset(sizeof(int64_t)).Int32Value(); |
| 1554 | } else { |
| 1555 | dataOffset = Array::DataOffset(sizeof(int32_t)).Int32Value(); |
| 1556 | } |
| 1557 | |
| 1558 | int regPtr; |
| 1559 | rlArray = loadValue(cUnit, rlArray, kCoreReg); |
| 1560 | rlIndex = loadValue(cUnit, rlIndex, kCoreReg); |
| 1561 | |
| 1562 | if (oatIsTemp(cUnit, rlArray.lowReg)) { |
| 1563 | oatClobber(cUnit, rlArray.lowReg); |
| 1564 | regPtr = rlArray.lowReg; |
| 1565 | } else { |
| 1566 | regPtr = oatAllocTemp(cUnit); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1567 | opRegCopy(cUnit, regPtr, rlArray.lowReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | /* null object? */ |
| 1571 | genNullCheck(cUnit, rlArray.sRegLow, rlArray.lowReg, mir); |
| 1572 | |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 1573 | bool needsRangeCheck = (!(mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK)); |
| 1574 | int regLen = INVALID_REG; |
| 1575 | if (needsRangeCheck) { |
| 1576 | regLen = oatAllocTemp(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1577 | //NOTE: max live temps(4) here. |
| 1578 | /* Get len */ |
| 1579 | loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1580 | } |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 1581 | /* regPtr -> array data */ |
| 1582 | opRegImm(cUnit, kOpAdd, regPtr, dataOffset); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1583 | /* at this point, regPtr points to array, 2 live temps */ |
| 1584 | if ((size == kLong) || (size == kDouble)) { |
| 1585 | //TUNING: specific wide routine that can handle fp regs |
| 1586 | if (scale) { |
| 1587 | int rNewIndex = oatAllocTemp(cUnit); |
| 1588 | opRegRegImm(cUnit, kOpLsl, rNewIndex, rlIndex.lowReg, scale); |
| 1589 | opRegReg(cUnit, kOpAdd, regPtr, rNewIndex); |
| 1590 | oatFreeTemp(cUnit, rNewIndex); |
| 1591 | } else { |
| 1592 | opRegReg(cUnit, kOpAdd, regPtr, rlIndex.lowReg); |
| 1593 | } |
| 1594 | rlSrc = loadValueWide(cUnit, rlSrc, regClass); |
| 1595 | |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 1596 | if (needsRangeCheck) { |
| 1597 | genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, mir, |
| 1598 | kThrowArrayBounds); |
| 1599 | oatFreeTemp(cUnit, regLen); |
| 1600 | } |
| 1601 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1602 | storePair(cUnit, regPtr, rlSrc.lowReg, rlSrc.highReg); |
| 1603 | |
| 1604 | oatFreeTemp(cUnit, regPtr); |
| 1605 | } else { |
| 1606 | rlSrc = loadValue(cUnit, rlSrc, regClass); |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 1607 | if (needsRangeCheck) { |
| 1608 | genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, mir, |
| 1609 | kThrowArrayBounds); |
| 1610 | oatFreeTemp(cUnit, regLen); |
| 1611 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1612 | storeBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlSrc.lowReg, |
| 1613 | scale, size); |
| 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | void genLong3Addr(CompilationUnit* cUnit, MIR* mir, OpKind firstOp, |
| 1618 | OpKind secondOp, RegLocation rlDest, |
| 1619 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 1620 | { |
| 1621 | RegLocation rlResult; |
| 1622 | #if defined(TARGET_ARM) |
| 1623 | /* |
| 1624 | * NOTE: This is the one place in the code in which we might have |
| 1625 | * as many as six live temporary registers. There are 5 in the normal |
| 1626 | * set for Arm. Until we have spill capabilities, temporarily add |
| 1627 | * lr to the temp set. It is safe to do this locally, but note that |
| 1628 | * lr is used explicitly elsewhere in the code generator and cannot |
| 1629 | * normally be used as a general temp register. |
| 1630 | */ |
| 1631 | oatMarkTemp(cUnit, rLR); // Add lr to the temp pool |
| 1632 | oatFreeTemp(cUnit, rLR); // and make it available |
| 1633 | #endif |
| 1634 | rlSrc1 = loadValueWide(cUnit, rlSrc1, kCoreReg); |
| 1635 | rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg); |
| 1636 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1637 | // The longs may overlap - use intermediate temp if so |
| 1638 | if (rlResult.lowReg == rlSrc1.highReg) { |
| 1639 | int tReg = oatAllocTemp(cUnit); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 1640 | opRegCopy(cUnit, tReg, rlSrc1.highReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1641 | opRegRegReg(cUnit, firstOp, rlResult.lowReg, rlSrc1.lowReg, |
| 1642 | rlSrc2.lowReg); |
| 1643 | opRegRegReg(cUnit, secondOp, rlResult.highReg, tReg, |
| 1644 | rlSrc2.highReg); |
| 1645 | oatFreeTemp(cUnit, tReg); |
| 1646 | } else { |
| 1647 | opRegRegReg(cUnit, firstOp, rlResult.lowReg, rlSrc1.lowReg, |
| 1648 | rlSrc2.lowReg); |
| 1649 | opRegRegReg(cUnit, secondOp, rlResult.highReg, rlSrc1.highReg, |
| 1650 | rlSrc2.highReg); |
| 1651 | } |
| 1652 | /* |
| 1653 | * NOTE: If rlDest refers to a frame variable in a large frame, the |
| 1654 | * following storeValueWide might need to allocate a temp register. |
| 1655 | * To further work around the lack of a spill capability, explicitly |
| 1656 | * free any temps from rlSrc1 & rlSrc2 that aren't still live in rlResult. |
| 1657 | * Remove when spill is functional. |
| 1658 | */ |
| 1659 | freeRegLocTemps(cUnit, rlResult, rlSrc1); |
| 1660 | freeRegLocTemps(cUnit, rlResult, rlSrc2); |
| 1661 | storeValueWide(cUnit, rlDest, rlResult); |
| 1662 | #if defined(TARGET_ARM) |
| 1663 | oatClobber(cUnit, rLR); |
| 1664 | oatUnmarkTemp(cUnit, rLR); // Remove lr from the temp pool |
| 1665 | #endif |
| 1666 | } |
| 1667 | |
| 1668 | |
| 1669 | bool genShiftOpLong(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 1670 | RegLocation rlSrc1, RegLocation rlShift) |
| 1671 | { |
| 1672 | int funcOffset; |
| 1673 | |
| 1674 | switch( mir->dalvikInsn.opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1675 | case Instruction::SHL_LONG: |
| 1676 | case Instruction::SHL_LONG_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1677 | funcOffset = OFFSETOF_MEMBER(Thread, pShlLong); |
| 1678 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1679 | case Instruction::SHR_LONG: |
| 1680 | case Instruction::SHR_LONG_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1681 | funcOffset = OFFSETOF_MEMBER(Thread, pShrLong); |
| 1682 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1683 | case Instruction::USHR_LONG: |
| 1684 | case Instruction::USHR_LONG_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1685 | funcOffset = OFFSETOF_MEMBER(Thread, pUshrLong); |
| 1686 | break; |
| 1687 | default: |
| 1688 | LOG(FATAL) << "Unexpected case"; |
| 1689 | return true; |
| 1690 | } |
| 1691 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1692 | callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset, rlSrc1, rlShift); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 1693 | RegLocation rlResult = oatGetReturnWide(cUnit, false); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1694 | storeValueWide(cUnit, rlDest, rlResult); |
| 1695 | return false; |
| 1696 | } |
| 1697 | |
| 1698 | |
| 1699 | bool genArithOpInt(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 1700 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 1701 | { |
| 1702 | OpKind op = kOpBkpt; |
| 1703 | bool callOut = false; |
| 1704 | bool checkZero = false; |
| 1705 | bool unary = false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1706 | RegLocation rlResult; |
| 1707 | bool shiftOp = false; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 1708 | int funcOffset; |
| 1709 | int retReg = rRET0; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1710 | switch (mir->dalvikInsn.opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1711 | case Instruction::NEG_INT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1712 | op = kOpNeg; |
| 1713 | unary = true; |
| 1714 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1715 | case Instruction::NOT_INT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1716 | op = kOpMvn; |
| 1717 | unary = true; |
| 1718 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1719 | case Instruction::ADD_INT: |
| 1720 | case Instruction::ADD_INT_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1721 | op = kOpAdd; |
| 1722 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1723 | case Instruction::SUB_INT: |
| 1724 | case Instruction::SUB_INT_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1725 | op = kOpSub; |
| 1726 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1727 | case Instruction::MUL_INT: |
| 1728 | case Instruction::MUL_INT_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1729 | op = kOpMul; |
| 1730 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1731 | case Instruction::DIV_INT: |
| 1732 | case Instruction::DIV_INT_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1733 | checkZero = true; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 1734 | op = kOpDiv; |
| 1735 | callOut = true; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1736 | funcOffset = OFFSETOF_MEMBER(Thread, pIdiv); |
| 1737 | retReg = rRET0; |
| 1738 | break; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 1739 | /* NOTE: returns in rARG1 */ |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1740 | case Instruction::REM_INT: |
| 1741 | case Instruction::REM_INT_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1742 | checkZero = true; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 1743 | op = kOpRem; |
| 1744 | callOut = true; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1745 | funcOffset = OFFSETOF_MEMBER(Thread, pIdivmod); |
| 1746 | retReg = rRET1; |
| 1747 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1748 | case Instruction::AND_INT: |
| 1749 | case Instruction::AND_INT_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1750 | op = kOpAnd; |
| 1751 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1752 | case Instruction::OR_INT: |
| 1753 | case Instruction::OR_INT_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1754 | op = kOpOr; |
| 1755 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1756 | case Instruction::XOR_INT: |
| 1757 | case Instruction::XOR_INT_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1758 | op = kOpXor; |
| 1759 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1760 | case Instruction::SHL_INT: |
| 1761 | case Instruction::SHL_INT_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1762 | shiftOp = true; |
| 1763 | op = kOpLsl; |
| 1764 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1765 | case Instruction::SHR_INT: |
| 1766 | case Instruction::SHR_INT_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1767 | shiftOp = true; |
| 1768 | op = kOpAsr; |
| 1769 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1770 | case Instruction::USHR_INT: |
| 1771 | case Instruction::USHR_INT_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1772 | shiftOp = true; |
| 1773 | op = kOpLsr; |
| 1774 | break; |
| 1775 | default: |
| 1776 | LOG(FATAL) << "Invalid word arith op: " << |
| 1777 | (int)mir->dalvikInsn.opcode; |
| 1778 | } |
| 1779 | if (!callOut) { |
| 1780 | rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg); |
| 1781 | if (unary) { |
| 1782 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1783 | opRegReg(cUnit, op, rlResult.lowReg, |
| 1784 | rlSrc1.lowReg); |
| 1785 | } else { |
| 1786 | rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 1787 | #if defined(TARGET_X86) |
| 1788 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1789 | opRegRegReg(cUnit, op, rlResult.lowReg, |
| 1790 | rlSrc1.lowReg, rlSrc2.lowReg); |
| 1791 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1792 | if (shiftOp) { |
| 1793 | int tReg = oatAllocTemp(cUnit); |
| 1794 | opRegRegImm(cUnit, kOpAnd, tReg, rlSrc2.lowReg, 31); |
| 1795 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1796 | opRegRegReg(cUnit, op, rlResult.lowReg, |
| 1797 | rlSrc1.lowReg, tReg); |
| 1798 | oatFreeTemp(cUnit, tReg); |
| 1799 | } else { |
| 1800 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1801 | opRegRegReg(cUnit, op, rlResult.lowReg, |
| 1802 | rlSrc1.lowReg, rlSrc2.lowReg); |
| 1803 | } |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 1804 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1805 | } |
| 1806 | storeValue(cUnit, rlDest, rlResult); |
| 1807 | } else { |
| 1808 | RegLocation rlResult; |
| 1809 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
| 1810 | loadValueDirectFixed(cUnit, rlSrc2, rRET1); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1811 | #if !defined(TARGET_X86) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1812 | int rTgt = loadHelper(cUnit, funcOffset); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1813 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1814 | loadValueDirectFixed(cUnit, rlSrc1, rARG0); |
| 1815 | if (checkZero) { |
| 1816 | genImmedCheck(cUnit, kCondEq, rARG1, 0, mir, kThrowDivZero); |
| 1817 | } |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1818 | #if !defined(TARGET_X86) |
| 1819 | opReg(cUnit, kOpBlx, rTgt); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1820 | oatFreeTemp(cUnit, rTgt); |
| 1821 | #else |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1822 | opThreadMem(cUnit, kOpBlx, funcOffset); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 1823 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1824 | if (retReg == rRET0) |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 1825 | rlResult = oatGetReturn(cUnit, false); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1826 | else |
| 1827 | rlResult = oatGetReturnAlt(cUnit); |
| 1828 | storeValue(cUnit, rlDest, rlResult); |
| 1829 | } |
| 1830 | return false; |
| 1831 | } |
| 1832 | |
| 1833 | /* |
| 1834 | * The following are the first-level codegen routines that analyze the format |
| 1835 | * of each bytecode then either dispatch special purpose codegen routines |
| 1836 | * or produce corresponding Thumb instructions directly. |
| 1837 | */ |
| 1838 | |
| 1839 | bool isPowerOfTwo(int x) |
| 1840 | { |
| 1841 | return (x & (x - 1)) == 0; |
| 1842 | } |
| 1843 | |
| 1844 | // Returns true if no more than two bits are set in 'x'. |
| 1845 | bool isPopCountLE2(unsigned int x) |
| 1846 | { |
| 1847 | x &= x - 1; |
| 1848 | return (x & (x - 1)) == 0; |
| 1849 | } |
| 1850 | |
| 1851 | // Returns the index of the lowest set bit in 'x'. |
| 1852 | int lowestSetBit(unsigned int x) { |
| 1853 | int bit_posn = 0; |
| 1854 | while ((x & 0xf) == 0) { |
| 1855 | bit_posn += 4; |
| 1856 | x >>= 4; |
| 1857 | } |
| 1858 | while ((x & 1) == 0) { |
| 1859 | bit_posn++; |
| 1860 | x >>= 1; |
| 1861 | } |
| 1862 | return bit_posn; |
| 1863 | } |
| 1864 | |
| 1865 | // Returns true if it added instructions to 'cUnit' to divide 'rlSrc' by 'lit' |
| 1866 | // and store the result in 'rlDest'. |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1867 | bool handleEasyDivide(CompilationUnit* cUnit, Instruction::Code dalvikOpcode, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1868 | RegLocation rlSrc, RegLocation rlDest, int lit) |
| 1869 | { |
| 1870 | if (lit < 2 || !isPowerOfTwo(lit)) { |
| 1871 | return false; |
| 1872 | } |
| 1873 | int k = lowestSetBit(lit); |
| 1874 | if (k >= 30) { |
| 1875 | // Avoid special cases. |
| 1876 | return false; |
| 1877 | } |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1878 | bool div = (dalvikOpcode == Instruction::DIV_INT_LIT8 || |
| 1879 | dalvikOpcode == Instruction::DIV_INT_LIT16); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1880 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 1881 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1882 | if (div) { |
| 1883 | int tReg = oatAllocTemp(cUnit); |
| 1884 | if (lit == 2) { |
| 1885 | // Division by 2 is by far the most common division by constant. |
| 1886 | opRegRegImm(cUnit, kOpLsr, tReg, rlSrc.lowReg, 32 - k); |
| 1887 | opRegRegReg(cUnit, kOpAdd, tReg, tReg, rlSrc.lowReg); |
| 1888 | opRegRegImm(cUnit, kOpAsr, rlResult.lowReg, tReg, k); |
| 1889 | } else { |
| 1890 | opRegRegImm(cUnit, kOpAsr, tReg, rlSrc.lowReg, 31); |
| 1891 | opRegRegImm(cUnit, kOpLsr, tReg, tReg, 32 - k); |
| 1892 | opRegRegReg(cUnit, kOpAdd, tReg, tReg, rlSrc.lowReg); |
| 1893 | opRegRegImm(cUnit, kOpAsr, rlResult.lowReg, tReg, k); |
| 1894 | } |
| 1895 | } else { |
| 1896 | int cReg = oatAllocTemp(cUnit); |
| 1897 | loadConstant(cUnit, cReg, lit - 1); |
| 1898 | int tReg1 = oatAllocTemp(cUnit); |
| 1899 | int tReg2 = oatAllocTemp(cUnit); |
| 1900 | if (lit == 2) { |
| 1901 | opRegRegImm(cUnit, kOpLsr, tReg1, rlSrc.lowReg, 32 - k); |
| 1902 | opRegRegReg(cUnit, kOpAdd, tReg2, tReg1, rlSrc.lowReg); |
| 1903 | opRegRegReg(cUnit, kOpAnd, tReg2, tReg2, cReg); |
| 1904 | opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg2, tReg1); |
| 1905 | } else { |
| 1906 | opRegRegImm(cUnit, kOpAsr, tReg1, rlSrc.lowReg, 31); |
| 1907 | opRegRegImm(cUnit, kOpLsr, tReg1, tReg1, 32 - k); |
| 1908 | opRegRegReg(cUnit, kOpAdd, tReg2, tReg1, rlSrc.lowReg); |
| 1909 | opRegRegReg(cUnit, kOpAnd, tReg2, tReg2, cReg); |
| 1910 | opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg2, tReg1); |
| 1911 | } |
| 1912 | } |
| 1913 | storeValue(cUnit, rlDest, rlResult); |
| 1914 | return true; |
| 1915 | } |
| 1916 | |
| 1917 | void genMultiplyByTwoBitMultiplier(CompilationUnit* cUnit, RegLocation rlSrc, |
| 1918 | RegLocation rlResult, int lit, |
| 1919 | int firstBit, int secondBit) |
| 1920 | { |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 1921 | #if defined(TARGET_ARM) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1922 | opRegRegRegShift(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, rlSrc.lowReg, |
| 1923 | encodeShift(kArmLsl, secondBit - firstBit)); |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 1924 | #else |
| 1925 | int tReg = oatAllocTemp(cUnit); |
| 1926 | opRegRegImm(cUnit, kOpLsl, tReg, rlSrc.lowReg, secondBit - firstBit); |
| 1927 | opRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, tReg); |
| 1928 | oatFreeTemp(cUnit, tReg); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 1929 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1930 | if (firstBit != 0) { |
| 1931 | opRegRegImm(cUnit, kOpLsl, rlResult.lowReg, rlResult.lowReg, firstBit); |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | // Returns true if it added instructions to 'cUnit' to multiply 'rlSrc' by 'lit' |
| 1936 | // and store the result in 'rlDest'. |
| 1937 | bool handleEasyMultiply(CompilationUnit* cUnit, RegLocation rlSrc, |
| 1938 | RegLocation rlDest, int lit) |
| 1939 | { |
| 1940 | // Can we simplify this multiplication? |
| 1941 | bool powerOfTwo = false; |
| 1942 | bool popCountLE2 = false; |
| 1943 | bool powerOfTwoMinusOne = false; |
| 1944 | if (lit < 2) { |
| 1945 | // Avoid special cases. |
| 1946 | return false; |
| 1947 | } else if (isPowerOfTwo(lit)) { |
| 1948 | powerOfTwo = true; |
| 1949 | } else if (isPopCountLE2(lit)) { |
| 1950 | popCountLE2 = true; |
| 1951 | } else if (isPowerOfTwo(lit + 1)) { |
| 1952 | powerOfTwoMinusOne = true; |
| 1953 | } else { |
| 1954 | return false; |
| 1955 | } |
| 1956 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 1957 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1958 | if (powerOfTwo) { |
| 1959 | // Shift. |
| 1960 | opRegRegImm(cUnit, kOpLsl, rlResult.lowReg, rlSrc.lowReg, |
| 1961 | lowestSetBit(lit)); |
| 1962 | } else if (popCountLE2) { |
| 1963 | // Shift and add and shift. |
| 1964 | int firstBit = lowestSetBit(lit); |
| 1965 | int secondBit = lowestSetBit(lit ^ (1 << firstBit)); |
| 1966 | genMultiplyByTwoBitMultiplier(cUnit, rlSrc, rlResult, lit, |
| 1967 | firstBit, secondBit); |
| 1968 | } else { |
| 1969 | // Reverse subtract: (src << (shift + 1)) - src. |
| 1970 | DCHECK(powerOfTwoMinusOne); |
| 1971 | // TUNING: rsb dst, src, src lsl#lowestSetBit(lit + 1) |
| 1972 | int tReg = oatAllocTemp(cUnit); |
| 1973 | opRegRegImm(cUnit, kOpLsl, tReg, rlSrc.lowReg, lowestSetBit(lit + 1)); |
| 1974 | opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg, rlSrc.lowReg); |
| 1975 | } |
| 1976 | storeValue(cUnit, rlDest, rlResult); |
| 1977 | return true; |
| 1978 | } |
| 1979 | |
| 1980 | bool genArithOpIntLit(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 1981 | RegLocation rlSrc, int lit) |
| 1982 | { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1983 | Instruction::Code dalvikOpcode = mir->dalvikInsn.opcode; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1984 | RegLocation rlResult; |
| 1985 | OpKind op = (OpKind)0; /* Make gcc happy */ |
| 1986 | int shiftOp = false; |
| 1987 | bool isDiv = false; |
| 1988 | int funcOffset; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1989 | |
| 1990 | switch (dalvikOpcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1991 | case Instruction::RSUB_INT_LIT8: |
| 1992 | case Instruction::RSUB_INT: { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1993 | int tReg; |
| 1994 | //TUNING: add support for use of Arm rsub op |
| 1995 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 1996 | tReg = oatAllocTemp(cUnit); |
| 1997 | loadConstant(cUnit, tReg, lit); |
| 1998 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1999 | opRegRegReg(cUnit, kOpSub, rlResult.lowReg, |
| 2000 | tReg, rlSrc.lowReg); |
| 2001 | storeValue(cUnit, rlDest, rlResult); |
| 2002 | return false; |
| 2003 | break; |
| 2004 | } |
| 2005 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2006 | case Instruction::ADD_INT_LIT8: |
| 2007 | case Instruction::ADD_INT_LIT16: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2008 | op = kOpAdd; |
| 2009 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2010 | case Instruction::MUL_INT_LIT8: |
| 2011 | case Instruction::MUL_INT_LIT16: { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2012 | if (handleEasyMultiply(cUnit, rlSrc, rlDest, lit)) { |
| 2013 | return false; |
| 2014 | } |
| 2015 | op = kOpMul; |
| 2016 | break; |
| 2017 | } |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2018 | case Instruction::AND_INT_LIT8: |
| 2019 | case Instruction::AND_INT_LIT16: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2020 | op = kOpAnd; |
| 2021 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2022 | case Instruction::OR_INT_LIT8: |
| 2023 | case Instruction::OR_INT_LIT16: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2024 | op = kOpOr; |
| 2025 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2026 | case Instruction::XOR_INT_LIT8: |
| 2027 | case Instruction::XOR_INT_LIT16: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2028 | op = kOpXor; |
| 2029 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2030 | case Instruction::SHL_INT_LIT8: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2031 | lit &= 31; |
| 2032 | shiftOp = true; |
| 2033 | op = kOpLsl; |
| 2034 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2035 | case Instruction::SHR_INT_LIT8: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2036 | lit &= 31; |
| 2037 | shiftOp = true; |
| 2038 | op = kOpAsr; |
| 2039 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2040 | case Instruction::USHR_INT_LIT8: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2041 | lit &= 31; |
| 2042 | shiftOp = true; |
| 2043 | op = kOpLsr; |
| 2044 | break; |
| 2045 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2046 | case Instruction::DIV_INT_LIT8: |
| 2047 | case Instruction::DIV_INT_LIT16: |
| 2048 | case Instruction::REM_INT_LIT8: |
| 2049 | case Instruction::REM_INT_LIT16: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2050 | if (lit == 0) { |
| 2051 | genImmedCheck(cUnit, kCondAl, 0, 0, mir, kThrowDivZero); |
| 2052 | return false; |
| 2053 | } |
| 2054 | if (handleEasyDivide(cUnit, dalvikOpcode, rlSrc, rlDest, lit)) { |
| 2055 | return false; |
| 2056 | } |
| 2057 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
| 2058 | loadValueDirectFixed(cUnit, rlSrc, rARG0); |
| 2059 | oatClobber(cUnit, rARG0); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2060 | if ((dalvikOpcode == Instruction::DIV_INT_LIT8) || |
| 2061 | (dalvikOpcode == Instruction::DIV_INT_LIT16)) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2062 | funcOffset = OFFSETOF_MEMBER(Thread, pIdiv); |
| 2063 | isDiv = true; |
| 2064 | } else { |
| 2065 | funcOffset = OFFSETOF_MEMBER(Thread, pIdivmod); |
| 2066 | isDiv = false; |
| 2067 | } |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 2068 | callRuntimeHelperRegImm(cUnit, funcOffset, rARG0, lit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2069 | if (isDiv) |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 2070 | rlResult = oatGetReturn(cUnit, false); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2071 | else |
| 2072 | rlResult = oatGetReturnAlt(cUnit); |
| 2073 | storeValue(cUnit, rlDest, rlResult); |
| 2074 | return false; |
| 2075 | break; |
| 2076 | default: |
| 2077 | return true; |
| 2078 | } |
| 2079 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 2080 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 2081 | // Avoid shifts by literal 0 - no support in Thumb. Change to copy |
| 2082 | if (shiftOp && (lit == 0)) { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 2083 | opRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2084 | } else { |
| 2085 | opRegRegImm(cUnit, op, rlResult.lowReg, rlSrc.lowReg, lit); |
| 2086 | } |
| 2087 | storeValue(cUnit, rlDest, rlResult); |
| 2088 | return false; |
| 2089 | } |
| 2090 | |
| 2091 | bool genArithOpLong(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 2092 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 2093 | { |
| 2094 | RegLocation rlResult; |
| 2095 | OpKind firstOp = kOpBkpt; |
| 2096 | OpKind secondOp = kOpBkpt; |
| 2097 | bool callOut = false; |
| 2098 | bool checkZero = false; |
| 2099 | int funcOffset; |
| 2100 | int retReg = rRET0; |
| 2101 | |
| 2102 | switch (mir->dalvikInsn.opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2103 | case Instruction::NOT_LONG: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2104 | rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg); |
| 2105 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 2106 | // Check for destructive overlap |
| 2107 | if (rlResult.lowReg == rlSrc2.highReg) { |
| 2108 | int tReg = oatAllocTemp(cUnit); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 2109 | opRegCopy(cUnit, tReg, rlSrc2.highReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2110 | opRegReg(cUnit, kOpMvn, rlResult.lowReg, rlSrc2.lowReg); |
| 2111 | opRegReg(cUnit, kOpMvn, rlResult.highReg, tReg); |
| 2112 | oatFreeTemp(cUnit, tReg); |
| 2113 | } else { |
| 2114 | opRegReg(cUnit, kOpMvn, rlResult.lowReg, rlSrc2.lowReg); |
| 2115 | opRegReg(cUnit, kOpMvn, rlResult.highReg, rlSrc2.highReg); |
| 2116 | } |
| 2117 | storeValueWide(cUnit, rlDest, rlResult); |
| 2118 | return false; |
| 2119 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2120 | case Instruction::ADD_LONG: |
| 2121 | case Instruction::ADD_LONG_2ADDR: |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 2122 | #if defined(TARGET_MIPS) |
| 2123 | return genAddLong(cUnit, mir, rlDest, rlSrc1, rlSrc2); |
| 2124 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2125 | firstOp = kOpAdd; |
| 2126 | secondOp = kOpAdc; |
| 2127 | break; |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 2128 | #endif |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2129 | case Instruction::SUB_LONG: |
| 2130 | case Instruction::SUB_LONG_2ADDR: |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 2131 | #if defined(TARGET_MIPS) |
| 2132 | return genSubLong(cUnit, mir, rlDest, rlSrc1, rlSrc2); |
| 2133 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2134 | firstOp = kOpSub; |
| 2135 | secondOp = kOpSbc; |
| 2136 | break; |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 2137 | #endif |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2138 | case Instruction::MUL_LONG: |
| 2139 | case Instruction::MUL_LONG_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2140 | callOut = true; |
| 2141 | retReg = rRET0; |
| 2142 | funcOffset = OFFSETOF_MEMBER(Thread, pLmul); |
| 2143 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2144 | case Instruction::DIV_LONG: |
| 2145 | case Instruction::DIV_LONG_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2146 | callOut = true; |
| 2147 | checkZero = true; |
| 2148 | retReg = rRET0; |
| 2149 | funcOffset = OFFSETOF_MEMBER(Thread, pLdivmod); |
| 2150 | break; |
| 2151 | /* NOTE - result is in rARG2/rARG3 instead of rRET0/rRET1 */ |
| 2152 | // FIXME: is true, or could be made true, or other targets? |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2153 | case Instruction::REM_LONG: |
| 2154 | case Instruction::REM_LONG_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2155 | callOut = true; |
| 2156 | checkZero = true; |
| 2157 | funcOffset = OFFSETOF_MEMBER(Thread, pLdivmod); |
| 2158 | retReg = rARG2; |
| 2159 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2160 | case Instruction::AND_LONG_2ADDR: |
| 2161 | case Instruction::AND_LONG: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2162 | firstOp = kOpAnd; |
| 2163 | secondOp = kOpAnd; |
| 2164 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2165 | case Instruction::OR_LONG: |
| 2166 | case Instruction::OR_LONG_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2167 | firstOp = kOpOr; |
| 2168 | secondOp = kOpOr; |
| 2169 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2170 | case Instruction::XOR_LONG: |
| 2171 | case Instruction::XOR_LONG_2ADDR: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2172 | firstOp = kOpXor; |
| 2173 | secondOp = kOpXor; |
| 2174 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2175 | case Instruction::NEG_LONG: { |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 2176 | return genNegLong(cUnit, mir, rlDest, rlSrc2); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2177 | } |
| 2178 | default: |
| 2179 | LOG(FATAL) << "Invalid long arith op"; |
| 2180 | } |
| 2181 | if (!callOut) { |
| 2182 | genLong3Addr(cUnit, mir, firstOp, secondOp, rlDest, rlSrc1, rlSrc2); |
| 2183 | } else { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2184 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
| 2185 | if (checkZero) { |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 2186 | #if defined(TARGET_X86) |
| 2187 | UNIMPLEMENTED(FATAL); |
| 2188 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2189 | loadValueDirectWideFixed(cUnit, rlSrc2, rARG2, rARG3); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 2190 | int rTgt = loadHelper(cUnit, funcOffset); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 2191 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2192 | loadValueDirectWideFixed(cUnit, rlSrc1, rARG0, rARG1); |
| 2193 | int tReg = oatAllocTemp(cUnit); |
| 2194 | #if defined(TARGET_ARM) |
| 2195 | newLIR4(cUnit, kThumb2OrrRRRs, tReg, rARG2, rARG3, 0); |
| 2196 | oatFreeTemp(cUnit, tReg); |
| 2197 | genCheck(cUnit, kCondEq, mir, kThrowDivZero); |
| 2198 | #else |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 2199 | #if defined(TARGET_X86) |
| 2200 | UNIMPLEMENTED(FATAL); |
| 2201 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2202 | opRegRegReg(cUnit, kOpOr, tReg, rARG2, rARG3); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 2203 | #endif |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 2204 | genImmedCheck(cUnit, kCondEq, tReg, 0, mir, kThrowDivZero); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2205 | oatFreeTemp(cUnit, tReg); |
| 2206 | #endif |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 2207 | #if !defined(TARGET_X86) |
| 2208 | opReg(cUnit, kOpBlx, rTgt); |
| 2209 | oatFreeTemp(cUnit, rTgt); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 2210 | #endif |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 2211 | } else { |
| 2212 | callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset, |
| 2213 | rlSrc1, rlSrc2); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2214 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2215 | // Adjust return regs in to handle case of rem returning rARG2/rARG3 |
| 2216 | if (retReg == rRET0) |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 2217 | rlResult = oatGetReturnWide(cUnit, false); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2218 | else |
| 2219 | rlResult = oatGetReturnWideAlt(cUnit); |
| 2220 | storeValueWide(cUnit, rlDest, rlResult); |
| 2221 | } |
| 2222 | return false; |
| 2223 | } |
| 2224 | |
| 2225 | bool genConversionCall(CompilationUnit* cUnit, MIR* mir, int funcOffset, |
| 2226 | int srcSize, int tgtSize) |
| 2227 | { |
| 2228 | /* |
| 2229 | * Don't optimize the register usage since it calls out to support |
| 2230 | * functions |
| 2231 | */ |
| 2232 | RegLocation rlSrc; |
| 2233 | RegLocation rlDest; |
| 2234 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2235 | if (srcSize == 1) { |
| 2236 | rlSrc = oatGetSrc(cUnit, mir, 0); |
| 2237 | loadValueDirectFixed(cUnit, rlSrc, rARG0); |
| 2238 | } else { |
| 2239 | rlSrc = oatGetSrcWide(cUnit, mir, 0, 1); |
| 2240 | loadValueDirectWideFixed(cUnit, rlSrc, rARG0, rARG1); |
| 2241 | } |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 2242 | callRuntimeHelperRegLocation(cUnit, funcOffset, rlSrc); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2243 | if (tgtSize == 1) { |
| 2244 | RegLocation rlResult; |
| 2245 | rlDest = oatGetDest(cUnit, mir, 0); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 2246 | rlResult = oatGetReturn(cUnit, rlDest.fp); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2247 | storeValue(cUnit, rlDest, rlResult); |
| 2248 | } else { |
| 2249 | RegLocation rlResult; |
| 2250 | rlDest = oatGetDestWide(cUnit, mir, 0, 1); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 2251 | rlResult = oatGetReturnWide(cUnit, rlDest.fp); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2252 | storeValueWide(cUnit, rlDest, rlResult); |
| 2253 | } |
| 2254 | return false; |
| 2255 | } |
| 2256 | |
| 2257 | void genNegFloat(CompilationUnit* cUnit, RegLocation rlDest, RegLocation rlSrc); |
| 2258 | bool genArithOpFloatPortable(CompilationUnit* cUnit, MIR* mir, |
| 2259 | RegLocation rlDest, RegLocation rlSrc1, |
| 2260 | RegLocation rlSrc2) |
| 2261 | { |
| 2262 | RegLocation rlResult; |
| 2263 | int funcOffset; |
| 2264 | |
| 2265 | switch (mir->dalvikInsn.opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2266 | case Instruction::ADD_FLOAT_2ADDR: |
| 2267 | case Instruction::ADD_FLOAT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2268 | funcOffset = OFFSETOF_MEMBER(Thread, pFadd); |
| 2269 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2270 | case Instruction::SUB_FLOAT_2ADDR: |
| 2271 | case Instruction::SUB_FLOAT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2272 | funcOffset = OFFSETOF_MEMBER(Thread, pFsub); |
| 2273 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2274 | case Instruction::DIV_FLOAT_2ADDR: |
| 2275 | case Instruction::DIV_FLOAT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2276 | funcOffset = OFFSETOF_MEMBER(Thread, pFdiv); |
| 2277 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2278 | case Instruction::MUL_FLOAT_2ADDR: |
| 2279 | case Instruction::MUL_FLOAT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2280 | funcOffset = OFFSETOF_MEMBER(Thread, pFmul); |
| 2281 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2282 | case Instruction::REM_FLOAT_2ADDR: |
| 2283 | case Instruction::REM_FLOAT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2284 | funcOffset = OFFSETOF_MEMBER(Thread, pFmodf); |
| 2285 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2286 | case Instruction::NEG_FLOAT: { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2287 | genNegFloat(cUnit, rlDest, rlSrc1); |
| 2288 | return false; |
| 2289 | } |
| 2290 | default: |
| 2291 | return true; |
| 2292 | } |
| 2293 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 2294 | callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset, rlSrc1, rlSrc2); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 2295 | rlResult = oatGetReturn(cUnit, true); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2296 | storeValue(cUnit, rlDest, rlResult); |
| 2297 | return false; |
| 2298 | } |
| 2299 | |
| 2300 | void genNegDouble(CompilationUnit* cUnit, RegLocation rlDst, RegLocation rlSrc); |
| 2301 | bool genArithOpDoublePortable(CompilationUnit* cUnit, MIR* mir, |
| 2302 | RegLocation rlDest, RegLocation rlSrc1, |
| 2303 | RegLocation rlSrc2) |
| 2304 | { |
| 2305 | RegLocation rlResult; |
| 2306 | int funcOffset; |
| 2307 | |
| 2308 | switch (mir->dalvikInsn.opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2309 | case Instruction::ADD_DOUBLE_2ADDR: |
| 2310 | case Instruction::ADD_DOUBLE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2311 | funcOffset = OFFSETOF_MEMBER(Thread, pDadd); |
| 2312 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2313 | case Instruction::SUB_DOUBLE_2ADDR: |
| 2314 | case Instruction::SUB_DOUBLE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2315 | funcOffset = OFFSETOF_MEMBER(Thread, pDsub); |
| 2316 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2317 | case Instruction::DIV_DOUBLE_2ADDR: |
| 2318 | case Instruction::DIV_DOUBLE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2319 | funcOffset = OFFSETOF_MEMBER(Thread, pDdiv); |
| 2320 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2321 | case Instruction::MUL_DOUBLE_2ADDR: |
| 2322 | case Instruction::MUL_DOUBLE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2323 | funcOffset = OFFSETOF_MEMBER(Thread, pDmul); |
| 2324 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2325 | case Instruction::REM_DOUBLE_2ADDR: |
| 2326 | case Instruction::REM_DOUBLE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2327 | funcOffset = OFFSETOF_MEMBER(Thread, pFmod); |
| 2328 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2329 | case Instruction::NEG_DOUBLE: { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2330 | genNegDouble(cUnit, rlDest, rlSrc1); |
| 2331 | return false; |
| 2332 | } |
| 2333 | default: |
| 2334 | return true; |
| 2335 | } |
| 2336 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 2337 | callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset, rlSrc1, rlSrc2); |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 2338 | rlResult = oatGetReturnWide(cUnit, true); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2339 | storeValueWide(cUnit, rlDest, rlResult); |
| 2340 | return false; |
| 2341 | } |
| 2342 | |
| 2343 | bool genConversionPortable(CompilationUnit* cUnit, MIR* mir) |
| 2344 | { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2345 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2346 | |
| 2347 | switch (opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2348 | case Instruction::INT_TO_FLOAT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2349 | return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pI2f), |
| 2350 | 1, 1); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2351 | case Instruction::FLOAT_TO_INT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2352 | return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pF2iz), |
| 2353 | 1, 1); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2354 | case Instruction::DOUBLE_TO_FLOAT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2355 | return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pD2f), |
| 2356 | 2, 1); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2357 | case Instruction::FLOAT_TO_DOUBLE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2358 | return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pF2d), |
| 2359 | 1, 2); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2360 | case Instruction::INT_TO_DOUBLE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2361 | return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pI2d), |
| 2362 | 1, 2); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2363 | case Instruction::DOUBLE_TO_INT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2364 | return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pD2iz), |
| 2365 | 2, 1); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2366 | case Instruction::FLOAT_TO_LONG: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2367 | return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, |
| 2368 | pF2l), 1, 2); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2369 | case Instruction::LONG_TO_FLOAT: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2370 | return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pL2f), |
| 2371 | 2, 1); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2372 | case Instruction::DOUBLE_TO_LONG: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2373 | return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, |
| 2374 | pD2l), 2, 2); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2375 | case Instruction::LONG_TO_DOUBLE: |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2376 | return genConversionCall(cUnit, mir, OFFSETOF_MEMBER(Thread, pL2d), |
| 2377 | 2, 2); |
| 2378 | default: |
| 2379 | return true; |
| 2380 | } |
| 2381 | return false; |
| 2382 | } |
| 2383 | |
| 2384 | /* |
| 2385 | * Generate callout to updateDebugger. Note that we're overloading |
| 2386 | * the use of rSUSPEND here. When the debugger is active, this |
| 2387 | * register holds the address of the update function. So, if it's |
| 2388 | * non-null, we call out to it. |
| 2389 | * |
| 2390 | * Note also that rRET0 and rRET1 must be preserved across this |
| 2391 | * code. This must be handled by the stub. |
| 2392 | */ |
| 2393 | void genDebuggerUpdate(CompilationUnit* cUnit, int32_t offset) |
| 2394 | { |
| 2395 | // Following DCHECK verifies that dPC is in range of single load immediate |
| 2396 | DCHECK((offset == DEBUGGER_METHOD_ENTRY) || |
| 2397 | (offset == DEBUGGER_METHOD_EXIT) || ((offset & 0xffff) == offset)); |
| 2398 | oatClobberCalleeSave(cUnit); |
| 2399 | #if defined(TARGET_ARM) |
| 2400 | opRegImm(cUnit, kOpCmp, rSUSPEND, 0); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 2401 | opIT(cUnit, kArmCondNe, "T"); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2402 | loadConstant(cUnit, rARG2, offset); // arg2 <- Entry code |
| 2403 | opReg(cUnit, kOpBlx, rSUSPEND); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 2404 | #elif defined(TARGET_X86) |
| 2405 | UNIMPLEMENTED(FATAL); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2406 | #else |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 2407 | LIR* branch = opCmpImmBranch(cUnit, kCondEq, rSUSPEND, 0, NULL); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2408 | loadConstant(cUnit, rARG2, offset); |
| 2409 | opReg(cUnit, kOpBlx, rSUSPEND); |
| 2410 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2411 | branch->target = (LIR*)target; |
| 2412 | #endif |
| 2413 | oatFreeTemp(cUnit, rARG2); |
| 2414 | } |
| 2415 | |
| 2416 | /* Check if we need to check for pending suspend request */ |
| 2417 | void genSuspendTest(CompilationUnit* cUnit, MIR* mir) |
| 2418 | { |
| 2419 | if (NO_SUSPEND || (mir->optimizationFlags & MIR_IGNORE_SUSPEND_CHECK)) { |
| 2420 | return; |
| 2421 | } |
| 2422 | oatFlushAllRegs(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2423 | if (cUnit->genDebugger) { |
| 2424 | // If generating code for the debugger, always check for suspension |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 2425 | #if defined(TARGET_X86) |
| 2426 | UNIMPLEMENTED(FATAL); |
| 2427 | #else |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 2428 | int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, |
| 2429 | pTestSuspendFromCode)); |
| 2430 | opReg(cUnit, kOpBlx, rTgt); |
| 2431 | // Refresh rSUSPEND |
| 2432 | loadWordDisp(cUnit, rSELF, |
| 2433 | OFFSETOF_MEMBER(Thread, pUpdateDebuggerFromCode), |
| 2434 | rSUSPEND); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 2435 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2436 | } else { |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 2437 | LIR* branch = NULL; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2438 | #if defined(TARGET_ARM) |
| 2439 | // In non-debug case, only check periodically |
| 2440 | newLIR2(cUnit, kThumbSubRI8, rSUSPEND, 1); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 2441 | branch = opCondBranch(cUnit, kCondEq, NULL); |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 2442 | #elif defined(TARGET_X86) |
| 2443 | newLIR2(cUnit, kX86Cmp32TI, Thread::SuspendCountOffset().Int32Value(), 0); |
| 2444 | branch = opCondBranch(cUnit, kCondNe, NULL); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2445 | #else |
| 2446 | opRegImm(cUnit, kOpSub, rSUSPEND, 1); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 2447 | branch = opCmpImmBranch(cUnit, kCondEq, rSUSPEND, 0, NULL); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2448 | #endif |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 2449 | LIR* retLab = newLIR0(cUnit, kPseudoTargetLabel); |
| 2450 | LIR* target = rawLIR(cUnit, cUnit->currentDalvikOffset, |
| 2451 | kPseudoSuspendTarget, (intptr_t)retLab, mir->offset); |
| 2452 | branch->target = (LIR*)target; |
| 2453 | oatInsertGrowableList(cUnit, &cUnit->suspendLaunchpads, (intptr_t)target); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2454 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | } // namespace art |