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