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