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