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