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