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