Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [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 | */ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 16 | #include "dex/compiler_ir.h" |
| 17 | #include "dex/compiler_internals.h" |
Brian Carlstrom | 60d7a65 | 2014-03-13 18:10:08 -0700 | [diff] [blame] | 18 | #include "dex/quick/arm/arm_lir.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 19 | #include "dex/quick/mir_to_lir-inl.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 20 | #include "entrypoints/quick/quick_entrypoints.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 21 | #include "mirror/array.h" |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 22 | #include "mirror/object-inl.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 23 | #include "verifier/method_verifier.h" |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 24 | #include <functional> |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | /* |
| 29 | * This source files contains "gen" codegen routines that should |
| 30 | * be applicable to most targets. Only mid-level support utilities |
| 31 | * and "op" calls may be used here. |
| 32 | */ |
| 33 | |
| 34 | /* |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 35 | * Generate a kPseudoBarrier marker to indicate the boundary of special |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 36 | * blocks. |
| 37 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 38 | void Mir2Lir::GenBarrier() { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 39 | LIR* barrier = NewLIR0(kPseudoBarrier); |
| 40 | /* Mark all resources as being clobbered */ |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 41 | DCHECK(!barrier->flags.use_def_invalid); |
| 42 | barrier->u.m.def_mask = ENCODE_ALL; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 45 | void Mir2Lir::GenDivZeroException() { |
| 46 | LIR* branch = OpUnconditionalBranch(nullptr); |
| 47 | AddDivZeroCheckSlowPath(branch); |
| 48 | } |
| 49 | |
| 50 | void Mir2Lir::GenDivZeroCheck(ConditionCode c_code) { |
Mingyao Yang | 4289456 | 2014-04-07 12:42:16 -0700 | [diff] [blame] | 51 | LIR* branch = OpCondBranch(c_code, nullptr); |
| 52 | AddDivZeroCheckSlowPath(branch); |
| 53 | } |
| 54 | |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 55 | void Mir2Lir::GenDivZeroCheck(RegStorage reg) { |
| 56 | LIR* branch = OpCmpImmBranch(kCondEq, reg, 0, nullptr); |
Mingyao Yang | 4289456 | 2014-04-07 12:42:16 -0700 | [diff] [blame] | 57 | AddDivZeroCheckSlowPath(branch); |
| 58 | } |
| 59 | |
| 60 | void Mir2Lir::AddDivZeroCheckSlowPath(LIR* branch) { |
| 61 | class DivZeroCheckSlowPath : public Mir2Lir::LIRSlowPath { |
| 62 | public: |
| 63 | DivZeroCheckSlowPath(Mir2Lir* m2l, LIR* branch) |
| 64 | : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch) { |
| 65 | } |
| 66 | |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 67 | void Compile() OVERRIDE { |
Mingyao Yang | 4289456 | 2014-04-07 12:42:16 -0700 | [diff] [blame] | 68 | m2l_->ResetRegPool(); |
| 69 | m2l_->ResetDefTracking(); |
| 70 | GenerateTargetLabel(); |
| 71 | m2l_->CallRuntimeHelper(QUICK_ENTRYPOINT_OFFSET(4, pThrowDivZero), true); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | AddSlowPath(new (arena_) DivZeroCheckSlowPath(this, branch)); |
| 76 | } |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 77 | |
Mingyao Yang | 80365d9 | 2014-04-18 12:10:58 -0700 | [diff] [blame] | 78 | void Mir2Lir::GenArrayBoundsCheck(RegStorage index, RegStorage length) { |
| 79 | class ArrayBoundsCheckSlowPath : public Mir2Lir::LIRSlowPath { |
| 80 | public: |
| 81 | ArrayBoundsCheckSlowPath(Mir2Lir* m2l, LIR* branch, RegStorage index, RegStorage length) |
| 82 | : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch), |
| 83 | index_(index), length_(length) { |
| 84 | } |
| 85 | |
| 86 | void Compile() OVERRIDE { |
| 87 | m2l_->ResetRegPool(); |
| 88 | m2l_->ResetDefTracking(); |
| 89 | GenerateTargetLabel(); |
| 90 | m2l_->CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(4, pThrowArrayBounds), |
| 91 | index_, length_, true); |
| 92 | } |
| 93 | |
| 94 | private: |
| 95 | const RegStorage index_; |
| 96 | const RegStorage length_; |
| 97 | }; |
| 98 | |
| 99 | LIR* branch = OpCmpBranch(kCondUge, index, length, nullptr); |
| 100 | AddSlowPath(new (arena_) ArrayBoundsCheckSlowPath(this, branch, index, length)); |
| 101 | } |
| 102 | |
| 103 | void Mir2Lir::GenArrayBoundsCheck(int index, RegStorage length) { |
| 104 | class ArrayBoundsCheckSlowPath : public Mir2Lir::LIRSlowPath { |
| 105 | public: |
| 106 | ArrayBoundsCheckSlowPath(Mir2Lir* m2l, LIR* branch, int index, RegStorage length) |
| 107 | : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch), |
| 108 | index_(index), length_(length) { |
| 109 | } |
| 110 | |
| 111 | void Compile() OVERRIDE { |
| 112 | m2l_->ResetRegPool(); |
| 113 | m2l_->ResetDefTracking(); |
| 114 | GenerateTargetLabel(); |
| 115 | |
| 116 | m2l_->OpRegCopy(m2l_->TargetReg(kArg1), length_); |
| 117 | m2l_->LoadConstant(m2l_->TargetReg(kArg0), index_); |
| 118 | m2l_->CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(4, pThrowArrayBounds), |
| 119 | m2l_->TargetReg(kArg0), m2l_->TargetReg(kArg1), true); |
| 120 | } |
| 121 | |
| 122 | private: |
| 123 | const int32_t index_; |
| 124 | const RegStorage length_; |
| 125 | }; |
| 126 | |
| 127 | LIR* branch = OpCmpImmBranch(kCondLs, length, index, nullptr); |
| 128 | AddSlowPath(new (arena_) ArrayBoundsCheckSlowPath(this, branch, index, length)); |
| 129 | } |
| 130 | |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 131 | LIR* Mir2Lir::GenNullCheck(RegStorage reg) { |
| 132 | class NullCheckSlowPath : public Mir2Lir::LIRSlowPath { |
| 133 | public: |
| 134 | NullCheckSlowPath(Mir2Lir* m2l, LIR* branch) |
| 135 | : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch) { |
| 136 | } |
| 137 | |
| 138 | void Compile() OVERRIDE { |
| 139 | m2l_->ResetRegPool(); |
| 140 | m2l_->ResetDefTracking(); |
| 141 | GenerateTargetLabel(); |
| 142 | m2l_->CallRuntimeHelper(QUICK_ENTRYPOINT_OFFSET(4, pThrowNullPointer), true); |
| 143 | } |
| 144 | }; |
| 145 | |
| 146 | LIR* branch = OpCmpImmBranch(kCondEq, reg, 0, nullptr); |
| 147 | AddSlowPath(new (arena_) NullCheckSlowPath(this, branch)); |
| 148 | return branch; |
| 149 | } |
| 150 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 151 | /* Perform null-check on a register. */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 152 | LIR* Mir2Lir::GenNullCheck(RegStorage m_reg, int opt_flags) { |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 153 | if (Runtime::Current()->ExplicitNullChecks()) { |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 154 | return GenExplicitNullCheck(m_reg, opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 155 | } |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 156 | return nullptr; |
| 157 | } |
| 158 | |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 159 | /* Perform an explicit null-check on a register. */ |
| 160 | LIR* Mir2Lir::GenExplicitNullCheck(RegStorage m_reg, int opt_flags) { |
| 161 | if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) { |
| 162 | return NULL; |
| 163 | } |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 164 | return GenNullCheck(m_reg); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 167 | void Mir2Lir::MarkPossibleNullPointerException(int opt_flags) { |
| 168 | if (!Runtime::Current()->ExplicitNullChecks()) { |
| 169 | if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) { |
| 170 | return; |
| 171 | } |
| 172 | MarkSafepointPC(last_lir_insn_); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | void Mir2Lir::MarkPossibleStackOverflowException() { |
| 177 | if (!Runtime::Current()->ExplicitStackOverflowChecks()) { |
| 178 | MarkSafepointPC(last_lir_insn_); |
| 179 | } |
| 180 | } |
| 181 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 182 | void Mir2Lir::ForceImplicitNullCheck(RegStorage reg, int opt_flags) { |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 183 | if (!Runtime::Current()->ExplicitNullChecks()) { |
| 184 | if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) { |
| 185 | return; |
| 186 | } |
| 187 | // Force an implicit null check by performing a memory operation (load) from the given |
| 188 | // register with offset 0. This will cause a signal if the register contains 0 (null). |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 189 | RegStorage tmp = AllocTemp(); |
| 190 | // TODO: for Mips, would be best to use rZERO as the bogus register target. |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 191 | LIR* load = Load32Disp(reg, 0, tmp); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 192 | FreeTemp(tmp); |
| 193 | MarkSafepointPC(load); |
| 194 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 197 | void Mir2Lir::GenCompareAndBranch(Instruction::Code opcode, RegLocation rl_src1, |
| 198 | RegLocation rl_src2, LIR* taken, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 199 | LIR* fall_through) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 200 | ConditionCode cond; |
| 201 | switch (opcode) { |
| 202 | case Instruction::IF_EQ: |
| 203 | cond = kCondEq; |
| 204 | break; |
| 205 | case Instruction::IF_NE: |
| 206 | cond = kCondNe; |
| 207 | break; |
| 208 | case Instruction::IF_LT: |
| 209 | cond = kCondLt; |
| 210 | break; |
| 211 | case Instruction::IF_GE: |
| 212 | cond = kCondGe; |
| 213 | break; |
| 214 | case Instruction::IF_GT: |
| 215 | cond = kCondGt; |
| 216 | break; |
| 217 | case Instruction::IF_LE: |
| 218 | cond = kCondLe; |
| 219 | break; |
| 220 | default: |
| 221 | cond = static_cast<ConditionCode>(0); |
| 222 | LOG(FATAL) << "Unexpected opcode " << opcode; |
| 223 | } |
| 224 | |
| 225 | // Normalize such that if either operand is constant, src2 will be constant |
| 226 | if (rl_src1.is_const) { |
| 227 | RegLocation rl_temp = rl_src1; |
| 228 | rl_src1 = rl_src2; |
| 229 | rl_src2 = rl_temp; |
| 230 | cond = FlipComparisonOrder(cond); |
| 231 | } |
| 232 | |
| 233 | rl_src1 = LoadValue(rl_src1, kCoreReg); |
| 234 | // Is this really an immediate comparison? |
| 235 | if (rl_src2.is_const) { |
| 236 | // If it's already live in a register or not easily materialized, just keep going |
| 237 | RegLocation rl_temp = UpdateLoc(rl_src2); |
| 238 | if ((rl_temp.location == kLocDalvikFrame) && |
| 239 | InexpensiveConstantInt(mir_graph_->ConstantValue(rl_src2))) { |
| 240 | // OK - convert this to a compare immediate and branch |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 241 | OpCmpImmBranch(cond, rl_src1.reg, mir_graph_->ConstantValue(rl_src2), taken); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 242 | return; |
| 243 | } |
| 244 | } |
| 245 | rl_src2 = LoadValue(rl_src2, kCoreReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 246 | OpCmpBranch(cond, rl_src1.reg, rl_src2.reg, taken); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | void Mir2Lir::GenCompareZeroAndBranch(Instruction::Code opcode, RegLocation rl_src, LIR* taken, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 250 | LIR* fall_through) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 251 | ConditionCode cond; |
| 252 | rl_src = LoadValue(rl_src, kCoreReg); |
| 253 | switch (opcode) { |
| 254 | case Instruction::IF_EQZ: |
| 255 | cond = kCondEq; |
| 256 | break; |
| 257 | case Instruction::IF_NEZ: |
| 258 | cond = kCondNe; |
| 259 | break; |
| 260 | case Instruction::IF_LTZ: |
| 261 | cond = kCondLt; |
| 262 | break; |
| 263 | case Instruction::IF_GEZ: |
| 264 | cond = kCondGe; |
| 265 | break; |
| 266 | case Instruction::IF_GTZ: |
| 267 | cond = kCondGt; |
| 268 | break; |
| 269 | case Instruction::IF_LEZ: |
| 270 | cond = kCondLe; |
| 271 | break; |
| 272 | default: |
| 273 | cond = static_cast<ConditionCode>(0); |
| 274 | LOG(FATAL) << "Unexpected opcode " << opcode; |
| 275 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 276 | OpCmpImmBranch(cond, rl_src.reg, 0, taken); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 279 | void Mir2Lir::GenIntToLong(RegLocation rl_dest, RegLocation rl_src) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 280 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 281 | if (rl_src.location == kLocPhysReg) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 282 | OpRegCopy(rl_result.reg, rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 283 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 284 | LoadValueDirect(rl_src, rl_result.reg.GetLow()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 285 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 286 | OpRegRegImm(kOpAsr, rl_result.reg.GetHigh(), rl_result.reg.GetLow(), 31); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 287 | StoreValueWide(rl_dest, rl_result); |
| 288 | } |
| 289 | |
| 290 | void Mir2Lir::GenIntNarrowing(Instruction::Code opcode, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 291 | RegLocation rl_src) { |
Brian Carlstrom | 6f485c6 | 2013-07-18 15:35:35 -0700 | [diff] [blame] | 292 | rl_src = LoadValue(rl_src, kCoreReg); |
| 293 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 294 | OpKind op = kOpInvalid; |
| 295 | switch (opcode) { |
| 296 | case Instruction::INT_TO_BYTE: |
| 297 | op = kOp2Byte; |
| 298 | break; |
| 299 | case Instruction::INT_TO_SHORT: |
| 300 | op = kOp2Short; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 301 | break; |
Brian Carlstrom | 6f485c6 | 2013-07-18 15:35:35 -0700 | [diff] [blame] | 302 | case Instruction::INT_TO_CHAR: |
| 303 | op = kOp2Char; |
| 304 | break; |
| 305 | default: |
| 306 | LOG(ERROR) << "Bad int conversion type"; |
| 307 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 308 | OpRegReg(op, rl_result.reg, rl_src.reg); |
Brian Carlstrom | 6f485c6 | 2013-07-18 15:35:35 -0700 | [diff] [blame] | 309 | StoreValue(rl_dest, rl_result); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /* |
| 313 | * Let helper function take care of everything. Will call |
| 314 | * Array::AllocFromCode(type_idx, method, count); |
| 315 | * Note: AllocFromCode will handle checks for errNegativeArraySize. |
| 316 | */ |
| 317 | void Mir2Lir::GenNewArray(uint32_t type_idx, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 318 | RegLocation rl_src) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 319 | FlushAllRegs(); /* Everything to home location */ |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 320 | ThreadOffset<4> func_offset(-1); |
Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 321 | const DexFile* dex_file = cu_->dex_file; |
| 322 | CompilerDriver* driver = cu_->compiler_driver; |
| 323 | if (cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, *dex_file, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 324 | type_idx)) { |
Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 325 | bool is_type_initialized; // Ignored as an array does not have an initializer. |
| 326 | bool use_direct_type_ptr; |
| 327 | uintptr_t direct_type_ptr; |
| 328 | if (kEmbedClassInCode && |
| 329 | driver->CanEmbedTypeInCode(*dex_file, type_idx, |
| 330 | &is_type_initialized, &use_direct_type_ptr, &direct_type_ptr)) { |
| 331 | // The fast path. |
| 332 | if (!use_direct_type_ptr) { |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 333 | LoadClassType(type_idx, kArg0); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 334 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocArrayResolved); |
Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 335 | CallRuntimeHelperRegMethodRegLocation(func_offset, TargetReg(kArg0), rl_src, true); |
| 336 | } else { |
| 337 | // Use the direct pointer. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 338 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocArrayResolved); |
Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 339 | CallRuntimeHelperImmMethodRegLocation(func_offset, direct_type_ptr, rl_src, true); |
| 340 | } |
| 341 | } else { |
| 342 | // The slow path. |
| 343 | DCHECK_EQ(func_offset.Int32Value(), -1); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 344 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocArray); |
Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 345 | CallRuntimeHelperImmMethodRegLocation(func_offset, type_idx, rl_src, true); |
| 346 | } |
| 347 | DCHECK_NE(func_offset.Int32Value(), -1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 348 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 349 | func_offset= QUICK_ENTRYPOINT_OFFSET(4, pAllocArrayWithAccessCheck); |
Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 350 | CallRuntimeHelperImmMethodRegLocation(func_offset, type_idx, rl_src, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 351 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 352 | RegLocation rl_result = GetReturn(false); |
| 353 | StoreValue(rl_dest, rl_result); |
| 354 | } |
| 355 | |
| 356 | /* |
| 357 | * Similar to GenNewArray, but with post-allocation initialization. |
| 358 | * Verifier guarantees we're dealing with an array class. Current |
| 359 | * code throws runtime exception "bad Filled array req" for 'D' and 'J'. |
| 360 | * Current code also throws internal unimp if not 'L', '[' or 'I'. |
| 361 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 362 | void Mir2Lir::GenFilledNewArray(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 363 | int elems = info->num_arg_words; |
| 364 | int type_idx = info->index; |
| 365 | FlushAllRegs(); /* Everything to home location */ |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 366 | ThreadOffset<4> func_offset(-1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 367 | if (cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, *cu_->dex_file, |
| 368 | type_idx)) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 369 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pCheckAndAllocArray); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 370 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 371 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pCheckAndAllocArrayWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 372 | } |
| 373 | CallRuntimeHelperImmMethodImm(func_offset, type_idx, elems, true); |
| 374 | FreeTemp(TargetReg(kArg2)); |
| 375 | FreeTemp(TargetReg(kArg1)); |
| 376 | /* |
| 377 | * NOTE: the implicit target for Instruction::FILLED_NEW_ARRAY is the |
| 378 | * return region. Because AllocFromCode placed the new array |
| 379 | * in kRet0, we'll just lock it into place. When debugger support is |
| 380 | * added, it may be necessary to additionally copy all return |
| 381 | * values to a home location in thread-local storage |
| 382 | */ |
| 383 | LockTemp(TargetReg(kRet0)); |
| 384 | |
| 385 | // TODO: use the correct component size, currently all supported types |
| 386 | // share array alignment with ints (see comment at head of function) |
| 387 | size_t component_size = sizeof(int32_t); |
| 388 | |
| 389 | // Having a range of 0 is legal |
| 390 | if (info->is_range && (elems > 0)) { |
| 391 | /* |
| 392 | * Bit of ugliness here. We're going generate a mem copy loop |
| 393 | * on the register range, but it is possible that some regs |
| 394 | * in the range have been promoted. This is unlikely, but |
| 395 | * before generating the copy, we'll just force a flush |
| 396 | * of any regs in the source range that have been promoted to |
| 397 | * home location. |
| 398 | */ |
| 399 | for (int i = 0; i < elems; i++) { |
| 400 | RegLocation loc = UpdateLoc(info->args[i]); |
| 401 | if (loc.location == kLocPhysReg) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 402 | Store32Disp(TargetReg(kSp), SRegOffset(loc.s_reg_low), loc.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | /* |
| 406 | * TUNING note: generated code here could be much improved, but |
| 407 | * this is an uncommon operation and isn't especially performance |
| 408 | * critical. |
| 409 | */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 410 | RegStorage r_src = AllocTemp(); |
| 411 | RegStorage r_dst = AllocTemp(); |
| 412 | RegStorage r_idx = AllocTemp(); |
| 413 | RegStorage r_val; |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 414 | switch (cu_->instruction_set) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 415 | case kThumb2: |
| 416 | r_val = TargetReg(kLr); |
| 417 | break; |
| 418 | case kX86: |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 419 | case kX86_64: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 420 | FreeTemp(TargetReg(kRet0)); |
| 421 | r_val = AllocTemp(); |
| 422 | break; |
| 423 | case kMips: |
| 424 | r_val = AllocTemp(); |
| 425 | break; |
| 426 | default: LOG(FATAL) << "Unexpected instruction set: " << cu_->instruction_set; |
| 427 | } |
| 428 | // Set up source pointer |
| 429 | RegLocation rl_first = info->args[0]; |
| 430 | OpRegRegImm(kOpAdd, r_src, TargetReg(kSp), SRegOffset(rl_first.s_reg_low)); |
| 431 | // Set up the target pointer |
| 432 | OpRegRegImm(kOpAdd, r_dst, TargetReg(kRet0), |
| 433 | mirror::Array::DataOffset(component_size).Int32Value()); |
| 434 | // Set up the loop counter (known to be > 0) |
| 435 | LoadConstant(r_idx, elems - 1); |
| 436 | // Generate the copy loop. Going backwards for convenience |
| 437 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 438 | // Copy next element |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 439 | LoadBaseIndexed(r_src, r_idx, r_val, 2, k32); |
| 440 | StoreBaseIndexed(r_dst, r_idx, r_val, 2, k32); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 441 | FreeTemp(r_val); |
| 442 | OpDecAndBranch(kCondGe, r_idx, target); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 443 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 444 | // Restore the target pointer |
| 445 | OpRegRegImm(kOpAdd, TargetReg(kRet0), r_dst, |
| 446 | -mirror::Array::DataOffset(component_size).Int32Value()); |
| 447 | } |
| 448 | } else if (!info->is_range) { |
| 449 | // TUNING: interleave |
| 450 | for (int i = 0; i < elems; i++) { |
| 451 | RegLocation rl_arg = LoadValue(info->args[i], kCoreReg); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 452 | Store32Disp(TargetReg(kRet0), |
| 453 | mirror::Array::DataOffset(component_size).Int32Value() + i * 4, rl_arg.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 454 | // If the LoadValue caused a temp to be allocated, free it |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 455 | if (IsTemp(rl_arg.reg)) { |
| 456 | FreeTemp(rl_arg.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | } |
| 460 | if (info->result.location != kLocInvalid) { |
| 461 | StoreValue(info->result, GetReturn(false /* not fp */)); |
| 462 | } |
| 463 | } |
| 464 | |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 465 | // |
| 466 | // Slow path to ensure a class is initialized for sget/sput. |
| 467 | // |
| 468 | class StaticFieldSlowPath : public Mir2Lir::LIRSlowPath { |
| 469 | public: |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 470 | StaticFieldSlowPath(Mir2Lir* m2l, LIR* unresolved, LIR* uninit, LIR* cont, int storage_index, |
| 471 | RegStorage r_base) : |
| 472 | LIRSlowPath(m2l, m2l->GetCurrentDexPc(), unresolved, cont), uninit_(uninit), |
| 473 | storage_index_(storage_index), r_base_(r_base) { |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | void Compile() { |
| 477 | LIR* unresolved_target = GenerateTargetLabel(); |
| 478 | uninit_->target = unresolved_target; |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 479 | m2l_->CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(4, pInitializeStaticStorage), |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 480 | storage_index_, true); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 481 | // Copy helper's result into r_base, a no-op on all but MIPS. |
| 482 | m2l_->OpRegCopy(r_base_, m2l_->TargetReg(kRet0)); |
| 483 | |
| 484 | m2l_->OpUnconditionalBranch(cont_); |
| 485 | } |
| 486 | |
| 487 | private: |
| 488 | LIR* const uninit_; |
| 489 | const int storage_index_; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 490 | const RegStorage r_base_; |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 491 | }; |
| 492 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 493 | void Mir2Lir::GenSput(MIR* mir, RegLocation rl_src, bool is_long_or_double, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 494 | bool is_object) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 495 | const MirSFieldLoweringInfo& field_info = mir_graph_->GetSFieldLoweringInfo(mir); |
| 496 | cu_->compiler_driver->ProcessedStaticField(field_info.FastPut(), field_info.IsReferrersClass()); |
| 497 | if (field_info.FastPut() && !SLOW_FIELD_PATH) { |
| 498 | DCHECK_GE(field_info.FieldOffset().Int32Value(), 0); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 499 | RegStorage r_base; |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 500 | if (field_info.IsReferrersClass()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 501 | // Fast path, static storage base is this method's class |
| 502 | RegLocation rl_method = LoadCurrMethod(); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 503 | r_base = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 504 | LoadRefDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), r_base); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 505 | if (IsTemp(rl_method.reg)) { |
| 506 | FreeTemp(rl_method.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 507 | } |
| 508 | } else { |
| 509 | // Medium path, static storage base in a different class which requires checks that the other |
| 510 | // class is initialized. |
| 511 | // TODO: remove initialized check now that we are initializing classes in the compiler driver. |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 512 | DCHECK_NE(field_info.StorageIndex(), DexFile::kDexNoIndex); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 513 | // May do runtime call so everything to home locations. |
| 514 | FlushAllRegs(); |
| 515 | // Using fixed register to sync with possible call to runtime support. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 516 | RegStorage r_method = TargetReg(kArg1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 517 | LockTemp(r_method); |
| 518 | LoadCurrMethodDirect(r_method); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 519 | r_base = TargetReg(kArg0); |
| 520 | LockTemp(r_base); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 521 | LoadRefDisp(r_method, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), r_base); |
Dmitry Petrochenko | 973cc95 | 2014-04-18 14:53:09 +0700 | [diff] [blame^] | 522 | LoadRefDisp(r_base, mirror::Array::DataOffsetOfType<mirror::Object>(field_info.StorageIndex()), r_base); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 523 | // r_base now points at static storage (Class*) or NULL if the type is not yet resolved. |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 524 | if (!field_info.IsInitialized() && |
| 525 | (mir->optimization_flags & MIR_IGNORE_CLINIT_CHECK) == 0) { |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 526 | // Check if r_base is NULL or a not yet initialized class. |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 527 | |
| 528 | // The slow path is invoked if the r_base is NULL or the class pointed |
| 529 | // to by it is not initialized. |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 530 | LIR* unresolved_branch = OpCmpImmBranch(kCondEq, r_base, 0, NULL); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 531 | RegStorage r_tmp = TargetReg(kArg2); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 532 | LockTemp(r_tmp); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 533 | LIR* uninit_branch = OpCmpMemImmBranch(kCondLt, r_tmp, r_base, |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 534 | mirror::Class::StatusOffset().Int32Value(), |
| 535 | mirror::Class::kStatusInitialized, NULL); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 536 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 537 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 538 | AddSlowPath(new (arena_) StaticFieldSlowPath(this, unresolved_branch, uninit_branch, cont, |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 539 | field_info.StorageIndex(), r_base)); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 540 | |
| 541 | FreeTemp(r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 542 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 543 | FreeTemp(r_method); |
| 544 | } |
| 545 | // rBase now holds static storage base |
| 546 | if (is_long_or_double) { |
Yevgeny Rouban | b4b0667 | 2014-04-16 18:13:10 +0700 | [diff] [blame] | 547 | RegisterClass register_kind = kAnyReg; |
| 548 | if (field_info.IsVolatile() && cu_->instruction_set == kX86) { |
| 549 | // Force long/double volatile stores into SSE registers to avoid tearing. |
| 550 | register_kind = kFPReg; |
| 551 | } |
| 552 | rl_src = LoadValueWide(rl_src, register_kind); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 553 | } else { |
| 554 | rl_src = LoadValue(rl_src, kAnyReg); |
| 555 | } |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 556 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 557 | // There might have been a store before this volatile one so insert StoreStore barrier. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 558 | GenMemBarrier(kStoreStore); |
| 559 | } |
| 560 | if (is_long_or_double) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 561 | StoreBaseDispWide(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 562 | } else if (rl_src.ref) { |
| 563 | StoreRefDisp(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 564 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 565 | Store32Disp(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 566 | } |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 567 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 568 | // A load might follow the volatile store so insert a StoreLoad barrier. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 569 | GenMemBarrier(kStoreLoad); |
| 570 | } |
| 571 | if (is_object && !mir_graph_->IsConstantNullRef(rl_src)) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 572 | MarkGCCard(rl_src.reg, r_base); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 573 | } |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 574 | FreeTemp(r_base); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 575 | } else { |
| 576 | FlushAllRegs(); // Everything to home locations |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 577 | ThreadOffset<4> setter_offset = |
| 578 | is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(4, pSet64Static) |
| 579 | : (is_object ? QUICK_ENTRYPOINT_OFFSET(4, pSetObjStatic) |
| 580 | : QUICK_ENTRYPOINT_OFFSET(4, pSet32Static)); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 581 | CallRuntimeHelperImmRegLocation(setter_offset, field_info.FieldIndex(), rl_src, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 585 | void Mir2Lir::GenSget(MIR* mir, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 586 | bool is_long_or_double, bool is_object) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 587 | const MirSFieldLoweringInfo& field_info = mir_graph_->GetSFieldLoweringInfo(mir); |
| 588 | cu_->compiler_driver->ProcessedStaticField(field_info.FastGet(), field_info.IsReferrersClass()); |
| 589 | if (field_info.FastGet() && !SLOW_FIELD_PATH) { |
| 590 | DCHECK_GE(field_info.FieldOffset().Int32Value(), 0); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 591 | RegStorage r_base; |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 592 | if (field_info.IsReferrersClass()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 593 | // Fast path, static storage base is this method's class |
| 594 | RegLocation rl_method = LoadCurrMethod(); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 595 | r_base = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 596 | LoadRefDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), r_base); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 597 | } else { |
| 598 | // Medium path, static storage base in a different class which requires checks that the other |
| 599 | // class is initialized |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 600 | DCHECK_NE(field_info.StorageIndex(), DexFile::kDexNoIndex); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 601 | // May do runtime call so everything to home locations. |
| 602 | FlushAllRegs(); |
| 603 | // Using fixed register to sync with possible call to runtime support. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 604 | RegStorage r_method = TargetReg(kArg1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 605 | LockTemp(r_method); |
| 606 | LoadCurrMethodDirect(r_method); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 607 | r_base = TargetReg(kArg0); |
| 608 | LockTemp(r_base); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 609 | LoadRefDisp(r_method, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), r_base); |
Dmitry Petrochenko | 973cc95 | 2014-04-18 14:53:09 +0700 | [diff] [blame^] | 610 | LoadRefDisp(r_base, mirror::Array::DataOffsetOfType<mirror::Object>(field_info.StorageIndex()), r_base); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 611 | // r_base now points at static storage (Class*) or NULL if the type is not yet resolved. |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 612 | if (!field_info.IsInitialized() && |
| 613 | (mir->optimization_flags & MIR_IGNORE_CLINIT_CHECK) == 0) { |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 614 | // Check if r_base is NULL or a not yet initialized class. |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 615 | |
| 616 | // The slow path is invoked if the r_base is NULL or the class pointed |
| 617 | // to by it is not initialized. |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 618 | LIR* unresolved_branch = OpCmpImmBranch(kCondEq, r_base, 0, NULL); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 619 | RegStorage r_tmp = TargetReg(kArg2); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 620 | LockTemp(r_tmp); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 621 | LIR* uninit_branch = OpCmpMemImmBranch(kCondLt, r_tmp, r_base, |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 622 | mirror::Class::StatusOffset().Int32Value(), |
| 623 | mirror::Class::kStatusInitialized, NULL); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 624 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 625 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 626 | AddSlowPath(new (arena_) StaticFieldSlowPath(this, unresolved_branch, uninit_branch, cont, |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 627 | field_info.StorageIndex(), r_base)); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 628 | |
| 629 | FreeTemp(r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 630 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 631 | FreeTemp(r_method); |
| 632 | } |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 633 | // r_base now holds static storage base |
Yevgeny Rouban | b4b0667 | 2014-04-16 18:13:10 +0700 | [diff] [blame] | 634 | RegisterClass result_reg_kind = kAnyReg; |
| 635 | if (field_info.IsVolatile() && cu_->instruction_set == kX86) { |
| 636 | // Force long/double volatile loads into SSE registers to avoid tearing. |
| 637 | result_reg_kind = kFPReg; |
| 638 | } |
| 639 | RegLocation rl_result = EvalLoc(rl_dest, result_reg_kind, true); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 640 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 641 | if (is_long_or_double) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 642 | LoadBaseDispWide(r_base, field_info.FieldOffset().Int32Value(), rl_result.reg, INVALID_SREG); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 643 | } else if (rl_result.ref) { |
| 644 | LoadRefDisp(r_base, field_info.FieldOffset().Int32Value(), rl_result.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 645 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 646 | Load32Disp(r_base, field_info.FieldOffset().Int32Value(), rl_result.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 647 | } |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 648 | FreeTemp(r_base); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 649 | |
| 650 | if (field_info.IsVolatile()) { |
| 651 | // Without context sensitive analysis, we must issue the most conservative barriers. |
| 652 | // In this case, either a load or store may follow so we issue both barriers. |
| 653 | GenMemBarrier(kLoadLoad); |
| 654 | GenMemBarrier(kLoadStore); |
| 655 | } |
| 656 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 657 | if (is_long_or_double) { |
| 658 | StoreValueWide(rl_dest, rl_result); |
| 659 | } else { |
| 660 | StoreValue(rl_dest, rl_result); |
| 661 | } |
| 662 | } else { |
| 663 | FlushAllRegs(); // Everything to home locations |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 664 | ThreadOffset<4> getterOffset = |
| 665 | is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(4, pGet64Static) |
| 666 | :(is_object ? QUICK_ENTRYPOINT_OFFSET(4, pGetObjStatic) |
| 667 | : QUICK_ENTRYPOINT_OFFSET(4, pGet32Static)); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 668 | CallRuntimeHelperImm(getterOffset, field_info.FieldIndex(), true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 669 | if (is_long_or_double) { |
| 670 | RegLocation rl_result = GetReturnWide(rl_dest.fp); |
| 671 | StoreValueWide(rl_dest, rl_result); |
| 672 | } else { |
| 673 | RegLocation rl_result = GetReturn(rl_dest.fp); |
| 674 | StoreValue(rl_dest, rl_result); |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 679 | // Generate code for all slow paths. |
| 680 | void Mir2Lir::HandleSlowPaths() { |
| 681 | int n = slow_paths_.Size(); |
| 682 | for (int i = 0; i < n; ++i) { |
| 683 | LIRSlowPath* slowpath = slow_paths_.Get(i); |
| 684 | slowpath->Compile(); |
| 685 | } |
| 686 | slow_paths_.Reset(); |
| 687 | } |
| 688 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 689 | void Mir2Lir::HandleSuspendLaunchPads() { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 690 | int num_elems = suspend_launchpads_.Size(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 691 | ThreadOffset<4> helper_offset = QUICK_ENTRYPOINT_OFFSET(4, pTestSuspend); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 692 | for (int i = 0; i < num_elems; i++) { |
| 693 | ResetRegPool(); |
| 694 | ResetDefTracking(); |
| 695 | LIR* lab = suspend_launchpads_.Get(i); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 696 | LIR* resume_lab = reinterpret_cast<LIR*>(UnwrapPointer(lab->operands[0])); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 697 | current_dalvik_offset_ = lab->operands[1]; |
| 698 | AppendLIR(lab); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 699 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 700 | CallHelper(r_tgt, helper_offset, true /* MarkSafepointPC */); |
| 701 | OpUnconditionalBranch(resume_lab); |
| 702 | } |
| 703 | } |
| 704 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 705 | void Mir2Lir::GenIGet(MIR* mir, int opt_flags, OpSize size, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 706 | RegLocation rl_dest, RegLocation rl_obj, bool is_long_or_double, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 707 | bool is_object) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 708 | const MirIFieldLoweringInfo& field_info = mir_graph_->GetIFieldLoweringInfo(mir); |
| 709 | cu_->compiler_driver->ProcessedInstanceField(field_info.FastGet()); |
| 710 | if (field_info.FastGet() && !SLOW_FIELD_PATH) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 711 | RegLocation rl_result; |
| 712 | RegisterClass reg_class = oat_reg_class_by_size(size); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 713 | DCHECK_GE(field_info.FieldOffset().Int32Value(), 0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 714 | rl_obj = LoadValue(rl_obj, kCoreReg); |
| 715 | if (is_long_or_double) { |
| 716 | DCHECK(rl_dest.wide); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 717 | GenNullCheck(rl_obj.reg, opt_flags); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 718 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Yevgeny Rouban | b4b0667 | 2014-04-16 18:13:10 +0700 | [diff] [blame] | 719 | RegisterClass result_reg_kind = kAnyReg; |
| 720 | if (field_info.IsVolatile() && cu_->instruction_set == kX86) { |
| 721 | // Force long/double volatile loads into SSE registers to avoid tearing. |
| 722 | result_reg_kind = kFPReg; |
| 723 | } |
| 724 | rl_result = EvalLoc(rl_dest, result_reg_kind, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 725 | LoadBaseDispWide(rl_obj.reg, field_info.FieldOffset().Int32Value(), rl_result.reg, |
| 726 | rl_obj.s_reg_low); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 727 | MarkPossibleNullPointerException(opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 728 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 729 | // Without context sensitive analysis, we must issue the most conservative barriers. |
| 730 | // In this case, either a load or store may follow so we issue both barriers. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 731 | GenMemBarrier(kLoadLoad); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 732 | GenMemBarrier(kLoadStore); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 733 | } |
| 734 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 735 | RegStorage reg_ptr = AllocTemp(); |
| 736 | OpRegRegImm(kOpAdd, reg_ptr, rl_obj.reg, field_info.FieldOffset().Int32Value()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 737 | rl_result = EvalLoc(rl_dest, reg_class, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 738 | LoadBaseDispWide(reg_ptr, 0, rl_result.reg, INVALID_SREG); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 739 | MarkPossibleNullPointerException(opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 740 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 741 | // Without context sensitive analysis, we must issue the most conservative barriers. |
| 742 | // In this case, either a load or store may follow so we issue both barriers. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 743 | GenMemBarrier(kLoadLoad); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 744 | GenMemBarrier(kLoadStore); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 745 | } |
| 746 | FreeTemp(reg_ptr); |
| 747 | } |
| 748 | StoreValueWide(rl_dest, rl_result); |
| 749 | } else { |
| 750 | rl_result = EvalLoc(rl_dest, reg_class, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 751 | GenNullCheck(rl_obj.reg, opt_flags); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 752 | LoadBaseDisp(rl_obj.reg, field_info.FieldOffset().Int32Value(), rl_result.reg, k32, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 753 | rl_obj.s_reg_low); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 754 | MarkPossibleNullPointerException(opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 755 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 756 | // Without context sensitive analysis, we must issue the most conservative barriers. |
| 757 | // In this case, either a load or store may follow so we issue both barriers. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 758 | GenMemBarrier(kLoadLoad); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 759 | GenMemBarrier(kLoadStore); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 760 | } |
| 761 | StoreValue(rl_dest, rl_result); |
| 762 | } |
| 763 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 764 | ThreadOffset<4> getterOffset = |
| 765 | is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(4, pGet64Instance) |
| 766 | : (is_object ? QUICK_ENTRYPOINT_OFFSET(4, pGetObjInstance) |
| 767 | : QUICK_ENTRYPOINT_OFFSET(4, pGet32Instance)); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 768 | CallRuntimeHelperImmRegLocation(getterOffset, field_info.FieldIndex(), rl_obj, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 769 | if (is_long_or_double) { |
| 770 | RegLocation rl_result = GetReturnWide(rl_dest.fp); |
| 771 | StoreValueWide(rl_dest, rl_result); |
| 772 | } else { |
| 773 | RegLocation rl_result = GetReturn(rl_dest.fp); |
| 774 | StoreValue(rl_dest, rl_result); |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 779 | void Mir2Lir::GenIPut(MIR* mir, int opt_flags, OpSize size, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 780 | RegLocation rl_src, RegLocation rl_obj, bool is_long_or_double, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 781 | bool is_object) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 782 | const MirIFieldLoweringInfo& field_info = mir_graph_->GetIFieldLoweringInfo(mir); |
| 783 | cu_->compiler_driver->ProcessedInstanceField(field_info.FastPut()); |
| 784 | if (field_info.FastPut() && !SLOW_FIELD_PATH) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 785 | RegisterClass reg_class = oat_reg_class_by_size(size); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 786 | DCHECK_GE(field_info.FieldOffset().Int32Value(), 0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 787 | rl_obj = LoadValue(rl_obj, kCoreReg); |
| 788 | if (is_long_or_double) { |
Yevgeny Rouban | b4b0667 | 2014-04-16 18:13:10 +0700 | [diff] [blame] | 789 | RegisterClass src_reg_kind = kAnyReg; |
| 790 | if (field_info.IsVolatile() && cu_->instruction_set == kX86) { |
| 791 | // Force long/double volatile stores into SSE registers to avoid tearing. |
| 792 | src_reg_kind = kFPReg; |
| 793 | } |
| 794 | rl_src = LoadValueWide(rl_src, src_reg_kind); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 795 | GenNullCheck(rl_obj.reg, opt_flags); |
| 796 | RegStorage reg_ptr = AllocTemp(); |
| 797 | OpRegRegImm(kOpAdd, reg_ptr, rl_obj.reg, field_info.FieldOffset().Int32Value()); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 798 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 799 | // There might have been a store before this volatile one so insert StoreStore barrier. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 800 | GenMemBarrier(kStoreStore); |
| 801 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 802 | StoreBaseDispWide(reg_ptr, 0, rl_src.reg); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 803 | MarkPossibleNullPointerException(opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 804 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 805 | // A load might follow the volatile store so insert a StoreLoad barrier. |
| 806 | GenMemBarrier(kStoreLoad); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 807 | } |
| 808 | FreeTemp(reg_ptr); |
| 809 | } else { |
| 810 | rl_src = LoadValue(rl_src, reg_class); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 811 | GenNullCheck(rl_obj.reg, opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 812 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 813 | // There might have been a store before this volatile one so insert StoreStore barrier. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 814 | GenMemBarrier(kStoreStore); |
| 815 | } |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 816 | Store32Disp(rl_obj.reg, field_info.FieldOffset().Int32Value(), rl_src.reg); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 817 | MarkPossibleNullPointerException(opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 818 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 819 | // A load might follow the volatile store so insert a StoreLoad barrier. |
| 820 | GenMemBarrier(kStoreLoad); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 821 | } |
| 822 | if (is_object && !mir_graph_->IsConstantNullRef(rl_src)) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 823 | MarkGCCard(rl_src.reg, rl_obj.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 827 | ThreadOffset<4> setter_offset = |
| 828 | is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(4, pSet64Instance) |
| 829 | : (is_object ? QUICK_ENTRYPOINT_OFFSET(4, pSetObjInstance) |
| 830 | : QUICK_ENTRYPOINT_OFFSET(4, pSet32Instance)); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 831 | CallRuntimeHelperImmRegLocationRegLocation(setter_offset, field_info.FieldIndex(), |
| 832 | rl_obj, rl_src, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 836 | void Mir2Lir::GenArrayObjPut(int opt_flags, RegLocation rl_array, RegLocation rl_index, |
| 837 | RegLocation rl_src) { |
| 838 | bool needs_range_check = !(opt_flags & MIR_IGNORE_RANGE_CHECK); |
| 839 | bool needs_null_check = !((cu_->disable_opt & (1 << kNullCheckElimination)) && |
| 840 | (opt_flags & MIR_IGNORE_NULL_CHECK)); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 841 | ThreadOffset<4> helper = needs_range_check |
| 842 | ? (needs_null_check ? QUICK_ENTRYPOINT_OFFSET(4, pAputObjectWithNullAndBoundCheck) |
| 843 | : QUICK_ENTRYPOINT_OFFSET(4, pAputObjectWithBoundCheck)) |
| 844 | : QUICK_ENTRYPOINT_OFFSET(4, pAputObject); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 845 | CallRuntimeHelperRegLocationRegLocationRegLocation(helper, rl_array, rl_index, rl_src, true); |
| 846 | } |
| 847 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 848 | void Mir2Lir::GenConstClass(uint32_t type_idx, RegLocation rl_dest) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 849 | RegLocation rl_method = LoadCurrMethod(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 850 | RegStorage res_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 851 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 852 | if (!cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, |
| 853 | *cu_->dex_file, |
| 854 | type_idx)) { |
| 855 | // Call out to helper which resolves type and verifies access. |
| 856 | // Resolved type returned in kRet0. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 857 | CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(4, pInitializeTypeAndVerifyAccess), |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 858 | type_idx, rl_method.reg, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 859 | RegLocation rl_result = GetReturn(false); |
| 860 | StoreValue(rl_dest, rl_result); |
| 861 | } else { |
| 862 | // We're don't need access checks, load type from dex cache |
| 863 | int32_t dex_cache_offset = |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 864 | mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 865 | Load32Disp(rl_method.reg, dex_cache_offset, res_reg); |
Dmitry Petrochenko | 973cc95 | 2014-04-18 14:53:09 +0700 | [diff] [blame^] | 866 | int32_t offset_of_type = mirror::Array::DataOffsetOfType<mirror::Class>(type_idx); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 867 | Load32Disp(res_reg, offset_of_type, rl_result.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 868 | if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, |
| 869 | type_idx) || SLOW_TYPE_PATH) { |
| 870 | // Slow path, at runtime test if type is null and if so initialize |
| 871 | FlushAllRegs(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 872 | LIR* branch = OpCmpImmBranch(kCondEq, rl_result.reg, 0, NULL); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 873 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
| 874 | |
| 875 | // Object to generate the slow path for class resolution. |
| 876 | class SlowPath : public LIRSlowPath { |
| 877 | public: |
| 878 | SlowPath(Mir2Lir* m2l, LIR* fromfast, LIR* cont, const int type_idx, |
| 879 | const RegLocation& rl_method, const RegLocation& rl_result) : |
| 880 | LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast, cont), type_idx_(type_idx), |
| 881 | rl_method_(rl_method), rl_result_(rl_result) { |
| 882 | } |
| 883 | |
| 884 | void Compile() { |
| 885 | GenerateTargetLabel(); |
| 886 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 887 | m2l_->CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(4, pInitializeType), type_idx_, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 888 | rl_method_.reg, true); |
| 889 | m2l_->OpRegCopy(rl_result_.reg, m2l_->TargetReg(kRet0)); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 890 | |
| 891 | m2l_->OpUnconditionalBranch(cont_); |
| 892 | } |
| 893 | |
| 894 | private: |
| 895 | const int type_idx_; |
| 896 | const RegLocation rl_method_; |
| 897 | const RegLocation rl_result_; |
| 898 | }; |
| 899 | |
| 900 | // Add to list for future. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 901 | AddSlowPath(new (arena_) SlowPath(this, branch, cont, type_idx, rl_method, rl_result)); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 902 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 903 | StoreValue(rl_dest, rl_result); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 904 | } else { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 905 | // Fast path, we're done - just store result |
| 906 | StoreValue(rl_dest, rl_result); |
| 907 | } |
| 908 | } |
| 909 | } |
| 910 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 911 | void Mir2Lir::GenConstString(uint32_t string_idx, RegLocation rl_dest) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 912 | /* NOTE: Most strings should be available at compile time */ |
Dmitry Petrochenko | 973cc95 | 2014-04-18 14:53:09 +0700 | [diff] [blame^] | 913 | int32_t offset_of_string = mirror::Array::DataOffsetOfType<mirror::String>(string_idx); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 914 | if (!cu_->compiler_driver->CanAssumeStringIsPresentInDexCache( |
| 915 | *cu_->dex_file, string_idx) || SLOW_STRING_PATH) { |
| 916 | // slow path, resolve string if not in dex cache |
| 917 | FlushAllRegs(); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 918 | LockCallTemps(); // Using explicit registers |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 919 | |
| 920 | // If the Method* is already in a register, we can save a copy. |
| 921 | RegLocation rl_method = mir_graph_->GetMethodLoc(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 922 | RegStorage r_method; |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 923 | if (rl_method.location == kLocPhysReg) { |
| 924 | // A temp would conflict with register use below. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 925 | DCHECK(!IsTemp(rl_method.reg)); |
| 926 | r_method = rl_method.reg; |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 927 | } else { |
| 928 | r_method = TargetReg(kArg2); |
| 929 | LoadCurrMethodDirect(r_method); |
| 930 | } |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 931 | LoadRefDisp(r_method, mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), |
| 932 | TargetReg(kArg0)); |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 933 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 934 | // Might call out to helper, which will return resolved string in kRet0 |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 935 | Load32Disp(TargetReg(kArg0), offset_of_string, TargetReg(kRet0)); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 936 | if (cu_->instruction_set == kThumb2 || |
| 937 | cu_->instruction_set == kMips) { |
| 938 | // OpRegImm(kOpCmp, TargetReg(kRet0), 0); // Is resolved? |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 939 | LoadConstant(TargetReg(kArg1), string_idx); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 940 | LIR* fromfast = OpCmpImmBranch(kCondEq, TargetReg(kRet0), 0, NULL); |
| 941 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 942 | GenBarrier(); |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 943 | |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 944 | // Object to generate the slow path for string resolution. |
| 945 | class SlowPath : public LIRSlowPath { |
| 946 | public: |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 947 | SlowPath(Mir2Lir* m2l, LIR* fromfast, LIR* cont, RegStorage r_method) : |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 948 | LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast, cont), r_method_(r_method) { |
| 949 | } |
| 950 | |
| 951 | void Compile() { |
| 952 | GenerateTargetLabel(); |
| 953 | |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 954 | RegStorage r_tgt = m2l_->CallHelperSetup(QUICK_ENTRYPOINT_OFFSET(4, pResolveString)); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 955 | |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 956 | m2l_->OpRegCopy(m2l_->TargetReg(kArg0), r_method_); // .eq |
| 957 | LIR* call_inst = m2l_->OpReg(kOpBlx, r_tgt); |
| 958 | m2l_->MarkSafepointPC(call_inst); |
| 959 | m2l_->FreeTemp(r_tgt); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 960 | |
| 961 | m2l_->OpUnconditionalBranch(cont_); |
| 962 | } |
| 963 | |
| 964 | private: |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 965 | RegStorage r_method_; |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 966 | }; |
| 967 | |
| 968 | // Add to list for future. |
| 969 | AddSlowPath(new (arena_) SlowPath(this, fromfast, cont, r_method)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 970 | } else { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 971 | DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64); |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 972 | LIR* branch = OpCmpImmBranch(kCondNe, TargetReg(kRet0), 0, NULL); |
| 973 | LoadConstant(TargetReg(kArg1), string_idx); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 974 | CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(4, pResolveString), r_method, TargetReg(kArg1), |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 975 | true); |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 976 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 977 | branch->target = target; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 978 | } |
| 979 | GenBarrier(); |
| 980 | StoreValue(rl_dest, GetReturn(false)); |
| 981 | } else { |
| 982 | RegLocation rl_method = LoadCurrMethod(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 983 | RegStorage res_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 984 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 985 | LoadRefDisp(rl_method.reg, mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), res_reg); |
| 986 | Load32Disp(res_reg, offset_of_string, rl_result.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 987 | StoreValue(rl_dest, rl_result); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | /* |
| 992 | * Let helper function take care of everything. Will |
| 993 | * call Class::NewInstanceFromCode(type_idx, method); |
| 994 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 995 | void Mir2Lir::GenNewInstance(uint32_t type_idx, RegLocation rl_dest) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 996 | FlushAllRegs(); /* Everything to home location */ |
| 997 | // alloc will always check for resolution, do we also need to verify |
| 998 | // access because the verifier was unable to? |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 999 | ThreadOffset<4> func_offset(-1); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1000 | const DexFile* dex_file = cu_->dex_file; |
| 1001 | CompilerDriver* driver = cu_->compiler_driver; |
| 1002 | if (driver->CanAccessInstantiableTypeWithoutChecks( |
| 1003 | cu_->method_idx, *dex_file, type_idx)) { |
| 1004 | bool is_type_initialized; |
| 1005 | bool use_direct_type_ptr; |
| 1006 | uintptr_t direct_type_ptr; |
| 1007 | if (kEmbedClassInCode && |
| 1008 | driver->CanEmbedTypeInCode(*dex_file, type_idx, |
| 1009 | &is_type_initialized, &use_direct_type_ptr, &direct_type_ptr)) { |
| 1010 | // The fast path. |
| 1011 | if (!use_direct_type_ptr) { |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 1012 | LoadClassType(type_idx, kArg0); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1013 | if (!is_type_initialized) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1014 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObjectResolved); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1015 | CallRuntimeHelperRegMethod(func_offset, TargetReg(kArg0), true); |
| 1016 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1017 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObjectInitialized); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1018 | CallRuntimeHelperRegMethod(func_offset, TargetReg(kArg0), true); |
| 1019 | } |
| 1020 | } else { |
| 1021 | // Use the direct pointer. |
| 1022 | if (!is_type_initialized) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1023 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObjectResolved); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1024 | CallRuntimeHelperImmMethod(func_offset, direct_type_ptr, true); |
| 1025 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1026 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObjectInitialized); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1027 | CallRuntimeHelperImmMethod(func_offset, direct_type_ptr, true); |
| 1028 | } |
| 1029 | } |
| 1030 | } else { |
| 1031 | // The slow path. |
| 1032 | DCHECK_EQ(func_offset.Int32Value(), -1); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1033 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObject); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1034 | CallRuntimeHelperImmMethod(func_offset, type_idx, true); |
| 1035 | } |
| 1036 | DCHECK_NE(func_offset.Int32Value(), -1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1037 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1038 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObjectWithAccessCheck); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1039 | CallRuntimeHelperImmMethod(func_offset, type_idx, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1040 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1041 | RegLocation rl_result = GetReturn(false); |
| 1042 | StoreValue(rl_dest, rl_result); |
| 1043 | } |
| 1044 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1045 | void Mir2Lir::GenThrow(RegLocation rl_src) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1046 | FlushAllRegs(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1047 | CallRuntimeHelperRegLocation(QUICK_ENTRYPOINT_OFFSET(4, pDeliverException), rl_src, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | // For final classes there are no sub-classes to check and so we can answer the instance-of |
| 1051 | // question with simple comparisons. |
| 1052 | void Mir2Lir::GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest, |
| 1053 | RegLocation rl_src) { |
Mark Mendell | df8ee2e | 2014-01-27 16:37:47 -0800 | [diff] [blame] | 1054 | // X86 has its own implementation. |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1055 | DCHECK(cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64); |
Mark Mendell | df8ee2e | 2014-01-27 16:37:47 -0800 | [diff] [blame] | 1056 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1057 | RegLocation object = LoadValue(rl_src, kCoreReg); |
| 1058 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1059 | RegStorage result_reg = rl_result.reg; |
| 1060 | if (result_reg == object.reg) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1061 | result_reg = AllocTypedTemp(false, kCoreReg); |
| 1062 | } |
| 1063 | LoadConstant(result_reg, 0); // assume false |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1064 | LIR* null_branchover = OpCmpImmBranch(kCondEq, object.reg, 0, NULL); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1065 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1066 | RegStorage check_class = AllocTypedTemp(false, kCoreReg); |
| 1067 | RegStorage object_class = AllocTypedTemp(false, kCoreReg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1068 | |
| 1069 | LoadCurrMethodDirect(check_class); |
| 1070 | if (use_declaring_class) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1071 | LoadRefDisp(check_class, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), check_class); |
| 1072 | LoadRefDisp(object.reg, mirror::Object::ClassOffset().Int32Value(), object_class); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1073 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1074 | LoadRefDisp(check_class, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), |
| 1075 | check_class); |
| 1076 | LoadRefDisp(object.reg, mirror::Object::ClassOffset().Int32Value(), object_class); |
Dmitry Petrochenko | 973cc95 | 2014-04-18 14:53:09 +0700 | [diff] [blame^] | 1077 | int32_t offset_of_type = mirror::Array::DataOffsetOfType<mirror::Class>(type_idx); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1078 | LoadRefDisp(check_class, offset_of_type, check_class); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | LIR* ne_branchover = NULL; |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1082 | // FIXME: what should we be comparing here? compressed or decompressed references? |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1083 | if (cu_->instruction_set == kThumb2) { |
| 1084 | OpRegReg(kOpCmp, check_class, object_class); // Same? |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1085 | LIR* it = OpIT(kCondEq, ""); // if-convert the test |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1086 | LoadConstant(result_reg, 1); // .eq case - load true |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1087 | OpEndIT(it); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1088 | } else { |
| 1089 | ne_branchover = OpCmpBranch(kCondNe, check_class, object_class, NULL); |
| 1090 | LoadConstant(result_reg, 1); // eq case - load true |
| 1091 | } |
| 1092 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 1093 | null_branchover->target = target; |
| 1094 | if (ne_branchover != NULL) { |
| 1095 | ne_branchover->target = target; |
| 1096 | } |
| 1097 | FreeTemp(object_class); |
| 1098 | FreeTemp(check_class); |
| 1099 | if (IsTemp(result_reg)) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1100 | OpRegCopy(rl_result.reg, result_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1101 | FreeTemp(result_reg); |
| 1102 | } |
| 1103 | StoreValue(rl_dest, rl_result); |
| 1104 | } |
| 1105 | |
| 1106 | void Mir2Lir::GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final, |
| 1107 | bool type_known_abstract, bool use_declaring_class, |
| 1108 | bool can_assume_type_is_in_dex_cache, |
| 1109 | uint32_t type_idx, RegLocation rl_dest, |
| 1110 | RegLocation rl_src) { |
Mark Mendell | 6607d97 | 2014-02-10 06:54:18 -0800 | [diff] [blame] | 1111 | // X86 has its own implementation. |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1112 | DCHECK(cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64); |
Mark Mendell | 6607d97 | 2014-02-10 06:54:18 -0800 | [diff] [blame] | 1113 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1114 | FlushAllRegs(); |
| 1115 | // May generate a call - use explicit registers |
| 1116 | LockCallTemps(); |
| 1117 | LoadCurrMethodDirect(TargetReg(kArg1)); // kArg1 <= current Method* |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1118 | RegStorage class_reg = TargetReg(kArg2); // kArg2 will hold the Class* |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1119 | if (needs_access_check) { |
| 1120 | // Check we have access to type_idx and if not throw IllegalAccessError, |
| 1121 | // returns Class* in kArg0 |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1122 | CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(4, pInitializeTypeAndVerifyAccess), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1123 | type_idx, true); |
| 1124 | OpRegCopy(class_reg, TargetReg(kRet0)); // Align usage with fast path |
| 1125 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref |
| 1126 | } else if (use_declaring_class) { |
| 1127 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1128 | LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DeclaringClassOffset().Int32Value(), |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1129 | class_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1130 | } else { |
| 1131 | // Load dex cache entry into class_reg (kArg2) |
| 1132 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1133 | LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), |
| 1134 | class_reg); |
Dmitry Petrochenko | 973cc95 | 2014-04-18 14:53:09 +0700 | [diff] [blame^] | 1135 | int32_t offset_of_type = mirror::Array::DataOffsetOfType<mirror::Class>(type_idx); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1136 | LoadRefDisp(class_reg, offset_of_type, class_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1137 | if (!can_assume_type_is_in_dex_cache) { |
| 1138 | // Need to test presence of type in dex cache at runtime |
| 1139 | LIR* hop_branch = OpCmpImmBranch(kCondNe, class_reg, 0, NULL); |
| 1140 | // Not resolved |
| 1141 | // Call out to helper, which will return resolved type in kRet0 |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1142 | CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(4, pInitializeType), type_idx, true); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 1143 | OpRegCopy(TargetReg(kArg2), TargetReg(kRet0)); // Align usage with fast path |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1144 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); /* reload Ref */ |
| 1145 | // Rejoin code paths |
| 1146 | LIR* hop_target = NewLIR0(kPseudoTargetLabel); |
| 1147 | hop_branch->target = hop_target; |
| 1148 | } |
| 1149 | } |
| 1150 | /* kArg0 is ref, kArg2 is class. If ref==null, use directly as bool result */ |
| 1151 | RegLocation rl_result = GetReturn(false); |
| 1152 | if (cu_->instruction_set == kMips) { |
| 1153 | // On MIPS rArg0 != rl_result, place false in result if branch is taken. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1154 | LoadConstant(rl_result.reg, 0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1155 | } |
| 1156 | LIR* branch1 = OpCmpImmBranch(kCondEq, TargetReg(kArg0), 0, NULL); |
| 1157 | |
| 1158 | /* load object->klass_ */ |
| 1159 | DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1160 | LoadRefDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1161 | /* kArg0 is ref, kArg1 is ref->klass_, kArg2 is class */ |
| 1162 | LIR* branchover = NULL; |
| 1163 | if (type_known_final) { |
| 1164 | // rl_result == ref == null == 0. |
| 1165 | if (cu_->instruction_set == kThumb2) { |
| 1166 | OpRegReg(kOpCmp, TargetReg(kArg1), TargetReg(kArg2)); // Same? |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1167 | LIR* it = OpIT(kCondEq, "E"); // if-convert the test |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1168 | LoadConstant(rl_result.reg, 1); // .eq case - load true |
| 1169 | LoadConstant(rl_result.reg, 0); // .ne case - load false |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1170 | OpEndIT(it); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1171 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1172 | LoadConstant(rl_result.reg, 0); // ne case - load false |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1173 | branchover = OpCmpBranch(kCondNe, TargetReg(kArg1), TargetReg(kArg2), NULL); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1174 | LoadConstant(rl_result.reg, 1); // eq case - load true |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1175 | } |
| 1176 | } else { |
| 1177 | if (cu_->instruction_set == kThumb2) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1178 | RegStorage r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pInstanceofNonTrivial)); |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1179 | LIR* it = nullptr; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1180 | if (!type_known_abstract) { |
| 1181 | /* Uses conditional nullification */ |
| 1182 | OpRegReg(kOpCmp, TargetReg(kArg1), TargetReg(kArg2)); // Same? |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1183 | it = OpIT(kCondEq, "EE"); // if-convert the test |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1184 | LoadConstant(TargetReg(kArg0), 1); // .eq case - load true |
| 1185 | } |
| 1186 | OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .ne case - arg0 <= class |
| 1187 | OpReg(kOpBlx, r_tgt); // .ne case: helper(class, ref->class) |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1188 | if (it != nullptr) { |
| 1189 | OpEndIT(it); |
| 1190 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1191 | FreeTemp(r_tgt); |
| 1192 | } else { |
| 1193 | if (!type_known_abstract) { |
| 1194 | /* Uses branchovers */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1195 | LoadConstant(rl_result.reg, 1); // assume true |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1196 | branchover = OpCmpBranch(kCondEq, TargetReg(kArg1), TargetReg(kArg2), NULL); |
| 1197 | } |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1198 | RegStorage r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pInstanceofNonTrivial)); |
Mark Mendell | 6607d97 | 2014-02-10 06:54:18 -0800 | [diff] [blame] | 1199 | OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .ne case - arg0 <= class |
| 1200 | OpReg(kOpBlx, r_tgt); // .ne case: helper(class, ref->class) |
| 1201 | FreeTemp(r_tgt); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1202 | } |
| 1203 | } |
| 1204 | // TODO: only clobber when type isn't final? |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 1205 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1206 | /* branch targets here */ |
| 1207 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 1208 | StoreValue(rl_dest, rl_result); |
| 1209 | branch1->target = target; |
| 1210 | if (branchover != NULL) { |
| 1211 | branchover->target = target; |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | void Mir2Lir::GenInstanceof(uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src) { |
| 1216 | bool type_known_final, type_known_abstract, use_declaring_class; |
| 1217 | bool needs_access_check = !cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, |
| 1218 | *cu_->dex_file, |
| 1219 | type_idx, |
| 1220 | &type_known_final, |
| 1221 | &type_known_abstract, |
| 1222 | &use_declaring_class); |
| 1223 | bool can_assume_type_is_in_dex_cache = !needs_access_check && |
| 1224 | cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx); |
| 1225 | |
| 1226 | if ((use_declaring_class || can_assume_type_is_in_dex_cache) && type_known_final) { |
| 1227 | GenInstanceofFinal(use_declaring_class, type_idx, rl_dest, rl_src); |
| 1228 | } else { |
| 1229 | GenInstanceofCallingHelper(needs_access_check, type_known_final, type_known_abstract, |
| 1230 | use_declaring_class, can_assume_type_is_in_dex_cache, |
| 1231 | type_idx, rl_dest, rl_src); |
| 1232 | } |
| 1233 | } |
| 1234 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1235 | void Mir2Lir::GenCheckCast(uint32_t insn_idx, uint32_t type_idx, RegLocation rl_src) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1236 | bool type_known_final, type_known_abstract, use_declaring_class; |
| 1237 | bool needs_access_check = !cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, |
| 1238 | *cu_->dex_file, |
| 1239 | type_idx, |
| 1240 | &type_known_final, |
| 1241 | &type_known_abstract, |
| 1242 | &use_declaring_class); |
| 1243 | // Note: currently type_known_final is unused, as optimizing will only improve the performance |
| 1244 | // of the exception throw path. |
| 1245 | DexCompilationUnit* cu = mir_graph_->GetCurrentDexCompilationUnit(); |
Vladimir Marko | 2730db0 | 2014-01-27 11:15:17 +0000 | [diff] [blame] | 1246 | if (!needs_access_check && cu_->compiler_driver->IsSafeCast(cu, insn_idx)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1247 | // Verifier type analysis proved this check cast would never cause an exception. |
| 1248 | return; |
| 1249 | } |
| 1250 | FlushAllRegs(); |
| 1251 | // May generate a call - use explicit registers |
| 1252 | LockCallTemps(); |
| 1253 | LoadCurrMethodDirect(TargetReg(kArg1)); // kArg1 <= current Method* |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1254 | RegStorage class_reg = TargetReg(kArg2); // kArg2 will hold the Class* |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1255 | if (needs_access_check) { |
| 1256 | // Check we have access to type_idx and if not throw IllegalAccessError, |
| 1257 | // returns Class* in kRet0 |
| 1258 | // InitializeTypeAndVerifyAccess(idx, method) |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1259 | CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(4, pInitializeTypeAndVerifyAccess), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1260 | type_idx, TargetReg(kArg1), true); |
| 1261 | OpRegCopy(class_reg, TargetReg(kRet0)); // Align usage with fast path |
| 1262 | } else if (use_declaring_class) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1263 | LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DeclaringClassOffset().Int32Value(), |
| 1264 | class_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1265 | } else { |
| 1266 | // Load dex cache entry into class_reg (kArg2) |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1267 | LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), |
| 1268 | class_reg); |
Dmitry Petrochenko | 973cc95 | 2014-04-18 14:53:09 +0700 | [diff] [blame^] | 1269 | int32_t offset_of_type = mirror::Array::DataOffsetOfType<mirror::Class>(type_idx); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1270 | LoadRefDisp(class_reg, offset_of_type, class_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1271 | if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx)) { |
| 1272 | // Need to test presence of type in dex cache at runtime |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1273 | LIR* hop_branch = OpCmpImmBranch(kCondEq, class_reg, 0, NULL); |
| 1274 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
| 1275 | |
| 1276 | // Slow path to initialize the type. Executed if the type is NULL. |
| 1277 | class SlowPath : public LIRSlowPath { |
| 1278 | public: |
| 1279 | SlowPath(Mir2Lir* m2l, LIR* fromfast, LIR* cont, const int type_idx, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1280 | const RegStorage class_reg) : |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1281 | LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast, cont), type_idx_(type_idx), |
| 1282 | class_reg_(class_reg) { |
| 1283 | } |
| 1284 | |
| 1285 | void Compile() { |
| 1286 | GenerateTargetLabel(); |
| 1287 | |
| 1288 | // Call out to helper, which will return resolved type in kArg0 |
| 1289 | // InitializeTypeFromCode(idx, method) |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1290 | m2l_->CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(4, pInitializeType), type_idx_, |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1291 | m2l_->TargetReg(kArg1), true); |
| 1292 | m2l_->OpRegCopy(class_reg_, m2l_->TargetReg(kRet0)); // Align usage with fast path |
| 1293 | m2l_->OpUnconditionalBranch(cont_); |
| 1294 | } |
| 1295 | public: |
| 1296 | const int type_idx_; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1297 | const RegStorage class_reg_; |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1298 | }; |
| 1299 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1300 | AddSlowPath(new (arena_) SlowPath(this, hop_branch, cont, type_idx, class_reg)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | // At this point, class_reg (kArg2) has class |
| 1304 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1305 | |
| 1306 | // Slow path for the case where the classes are not equal. In this case we need |
| 1307 | // to call a helper function to do the check. |
| 1308 | class SlowPath : public LIRSlowPath { |
| 1309 | public: |
| 1310 | SlowPath(Mir2Lir* m2l, LIR* fromfast, LIR* cont, bool load): |
| 1311 | LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast, cont), load_(load) { |
| 1312 | } |
| 1313 | |
| 1314 | void Compile() { |
| 1315 | GenerateTargetLabel(); |
| 1316 | |
| 1317 | if (load_) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1318 | m2l_->LoadRefDisp(m2l_->TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), |
| 1319 | m2l_->TargetReg(kArg1)); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1320 | } |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1321 | m2l_->CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(4, pCheckCast), m2l_->TargetReg(kArg2), |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1322 | m2l_->TargetReg(kArg1), true); |
| 1323 | |
| 1324 | m2l_->OpUnconditionalBranch(cont_); |
| 1325 | } |
| 1326 | |
| 1327 | private: |
| 1328 | bool load_; |
| 1329 | }; |
| 1330 | |
| 1331 | if (type_known_abstract) { |
| 1332 | // Easier case, run slow path if target is non-null (slow path will load from target) |
| 1333 | LIR* branch = OpCmpImmBranch(kCondNe, TargetReg(kArg0), 0, NULL); |
| 1334 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
| 1335 | AddSlowPath(new (arena_) SlowPath(this, branch, cont, true)); |
| 1336 | } else { |
| 1337 | // Harder, more common case. We need to generate a forward branch over the load |
| 1338 | // if the target is null. If it's non-null we perform the load and branch to the |
| 1339 | // slow path if the classes are not equal. |
| 1340 | |
| 1341 | /* Null is OK - continue */ |
| 1342 | LIR* branch1 = OpCmpImmBranch(kCondEq, TargetReg(kArg0), 0, NULL); |
| 1343 | /* load object->klass_ */ |
| 1344 | DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1345 | LoadRefDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1)); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1346 | |
| 1347 | LIR* branch2 = OpCmpBranch(kCondNe, TargetReg(kArg1), class_reg, NULL); |
| 1348 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
| 1349 | |
| 1350 | // Add the slow path that will not perform load since this is already done. |
| 1351 | AddSlowPath(new (arena_) SlowPath(this, branch2, cont, false)); |
| 1352 | |
| 1353 | // Set the null check to branch to the continuation. |
| 1354 | branch1->target = cont; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | void Mir2Lir::GenLong3Addr(OpKind first_op, OpKind second_op, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1359 | RegLocation rl_src1, RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1360 | RegLocation rl_result; |
| 1361 | if (cu_->instruction_set == kThumb2) { |
| 1362 | /* |
| 1363 | * NOTE: This is the one place in the code in which we might have |
| 1364 | * as many as six live temporary registers. There are 5 in the normal |
| 1365 | * set for Arm. Until we have spill capabilities, temporarily add |
| 1366 | * lr to the temp set. It is safe to do this locally, but note that |
| 1367 | * lr is used explicitly elsewhere in the code generator and cannot |
| 1368 | * normally be used as a general temp register. |
| 1369 | */ |
| 1370 | MarkTemp(TargetReg(kLr)); // Add lr to the temp pool |
| 1371 | FreeTemp(TargetReg(kLr)); // and make it available |
| 1372 | } |
| 1373 | rl_src1 = LoadValueWide(rl_src1, kCoreReg); |
| 1374 | rl_src2 = LoadValueWide(rl_src2, kCoreReg); |
| 1375 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1376 | // The longs may overlap - use intermediate temp if so |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1377 | if ((rl_result.reg.GetLowReg() == rl_src1.reg.GetHighReg()) || (rl_result.reg.GetLowReg() == rl_src2.reg.GetHighReg())) { |
| 1378 | RegStorage t_reg = AllocTemp(); |
| 1379 | OpRegRegReg(first_op, t_reg, rl_src1.reg.GetLow(), rl_src2.reg.GetLow()); |
| 1380 | OpRegRegReg(second_op, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), rl_src2.reg.GetHigh()); |
| 1381 | OpRegCopy(rl_result.reg.GetLow(), t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1382 | FreeTemp(t_reg); |
| 1383 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1384 | OpRegRegReg(first_op, rl_result.reg.GetLow(), rl_src1.reg.GetLow(), rl_src2.reg.GetLow()); |
| 1385 | OpRegRegReg(second_op, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), rl_src2.reg.GetHigh()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1386 | } |
| 1387 | /* |
| 1388 | * NOTE: If rl_dest refers to a frame variable in a large frame, the |
| 1389 | * following StoreValueWide might need to allocate a temp register. |
| 1390 | * To further work around the lack of a spill capability, explicitly |
| 1391 | * free any temps from rl_src1 & rl_src2 that aren't still live in rl_result. |
| 1392 | * Remove when spill is functional. |
| 1393 | */ |
| 1394 | FreeRegLocTemps(rl_result, rl_src1); |
| 1395 | FreeRegLocTemps(rl_result, rl_src2); |
| 1396 | StoreValueWide(rl_dest, rl_result); |
| 1397 | if (cu_->instruction_set == kThumb2) { |
| 1398 | Clobber(TargetReg(kLr)); |
| 1399 | UnmarkTemp(TargetReg(kLr)); // Remove lr from the temp pool |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | void Mir2Lir::GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1405 | RegLocation rl_src1, RegLocation rl_shift) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1406 | ThreadOffset<4> func_offset(-1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1407 | |
| 1408 | switch (opcode) { |
| 1409 | case Instruction::SHL_LONG: |
| 1410 | case Instruction::SHL_LONG_2ADDR: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1411 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pShlLong); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1412 | break; |
| 1413 | case Instruction::SHR_LONG: |
| 1414 | case Instruction::SHR_LONG_2ADDR: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1415 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pShrLong); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1416 | break; |
| 1417 | case Instruction::USHR_LONG: |
| 1418 | case Instruction::USHR_LONG_2ADDR: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1419 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pUshrLong); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1420 | break; |
| 1421 | default: |
| 1422 | LOG(FATAL) << "Unexpected case"; |
| 1423 | } |
| 1424 | FlushAllRegs(); /* Send everything to home location */ |
| 1425 | CallRuntimeHelperRegLocationRegLocation(func_offset, rl_src1, rl_shift, false); |
| 1426 | RegLocation rl_result = GetReturnWide(false); |
| 1427 | StoreValueWide(rl_dest, rl_result); |
| 1428 | } |
| 1429 | |
| 1430 | |
| 1431 | void Mir2Lir::GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1432 | RegLocation rl_src1, RegLocation rl_src2) { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1433 | DCHECK(cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1434 | OpKind op = kOpBkpt; |
| 1435 | bool is_div_rem = false; |
| 1436 | bool check_zero = false; |
| 1437 | bool unary = false; |
| 1438 | RegLocation rl_result; |
| 1439 | bool shift_op = false; |
| 1440 | switch (opcode) { |
| 1441 | case Instruction::NEG_INT: |
| 1442 | op = kOpNeg; |
| 1443 | unary = true; |
| 1444 | break; |
| 1445 | case Instruction::NOT_INT: |
| 1446 | op = kOpMvn; |
| 1447 | unary = true; |
| 1448 | break; |
| 1449 | case Instruction::ADD_INT: |
| 1450 | case Instruction::ADD_INT_2ADDR: |
| 1451 | op = kOpAdd; |
| 1452 | break; |
| 1453 | case Instruction::SUB_INT: |
| 1454 | case Instruction::SUB_INT_2ADDR: |
| 1455 | op = kOpSub; |
| 1456 | break; |
| 1457 | case Instruction::MUL_INT: |
| 1458 | case Instruction::MUL_INT_2ADDR: |
| 1459 | op = kOpMul; |
| 1460 | break; |
| 1461 | case Instruction::DIV_INT: |
| 1462 | case Instruction::DIV_INT_2ADDR: |
| 1463 | check_zero = true; |
| 1464 | op = kOpDiv; |
| 1465 | is_div_rem = true; |
| 1466 | break; |
| 1467 | /* NOTE: returns in kArg1 */ |
| 1468 | case Instruction::REM_INT: |
| 1469 | case Instruction::REM_INT_2ADDR: |
| 1470 | check_zero = true; |
| 1471 | op = kOpRem; |
| 1472 | is_div_rem = true; |
| 1473 | break; |
| 1474 | case Instruction::AND_INT: |
| 1475 | case Instruction::AND_INT_2ADDR: |
| 1476 | op = kOpAnd; |
| 1477 | break; |
| 1478 | case Instruction::OR_INT: |
| 1479 | case Instruction::OR_INT_2ADDR: |
| 1480 | op = kOpOr; |
| 1481 | break; |
| 1482 | case Instruction::XOR_INT: |
| 1483 | case Instruction::XOR_INT_2ADDR: |
| 1484 | op = kOpXor; |
| 1485 | break; |
| 1486 | case Instruction::SHL_INT: |
| 1487 | case Instruction::SHL_INT_2ADDR: |
| 1488 | shift_op = true; |
| 1489 | op = kOpLsl; |
| 1490 | break; |
| 1491 | case Instruction::SHR_INT: |
| 1492 | case Instruction::SHR_INT_2ADDR: |
| 1493 | shift_op = true; |
| 1494 | op = kOpAsr; |
| 1495 | break; |
| 1496 | case Instruction::USHR_INT: |
| 1497 | case Instruction::USHR_INT_2ADDR: |
| 1498 | shift_op = true; |
| 1499 | op = kOpLsr; |
| 1500 | break; |
| 1501 | default: |
| 1502 | LOG(FATAL) << "Invalid word arith op: " << opcode; |
| 1503 | } |
| 1504 | if (!is_div_rem) { |
| 1505 | if (unary) { |
| 1506 | rl_src1 = LoadValue(rl_src1, kCoreReg); |
| 1507 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1508 | OpRegReg(op, rl_result.reg, rl_src1.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1509 | } else { |
| 1510 | if (shift_op) { |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 1511 | rl_src2 = LoadValue(rl_src2, kCoreReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1512 | RegStorage t_reg = AllocTemp(); |
| 1513 | OpRegRegImm(kOpAnd, t_reg, rl_src2.reg, 31); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1514 | rl_src1 = LoadValue(rl_src1, kCoreReg); |
| 1515 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1516 | OpRegRegReg(op, rl_result.reg, rl_src1.reg, t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1517 | FreeTemp(t_reg); |
| 1518 | } else { |
| 1519 | rl_src1 = LoadValue(rl_src1, kCoreReg); |
| 1520 | rl_src2 = LoadValue(rl_src2, kCoreReg); |
| 1521 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1522 | OpRegRegReg(op, rl_result.reg, rl_src1.reg, rl_src2.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | StoreValue(rl_dest, rl_result); |
| 1526 | } else { |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1527 | bool done = false; // Set to true if we happen to find a way to use a real instruction. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1528 | if (cu_->instruction_set == kMips) { |
| 1529 | rl_src1 = LoadValue(rl_src1, kCoreReg); |
| 1530 | rl_src2 = LoadValue(rl_src2, kCoreReg); |
| 1531 | if (check_zero) { |
Mingyao Yang | d15f4e2 | 2014-04-17 18:46:24 -0700 | [diff] [blame] | 1532 | GenDivZeroCheck(rl_src2.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1533 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1534 | rl_result = GenDivRem(rl_dest, rl_src1.reg, rl_src2.reg, op == kOpDiv); |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1535 | done = true; |
| 1536 | } else if (cu_->instruction_set == kThumb2) { |
| 1537 | if (cu_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 1538 | // Use ARM SDIV instruction for division. For remainder we also need to |
| 1539 | // calculate using a MUL and subtract. |
| 1540 | rl_src1 = LoadValue(rl_src1, kCoreReg); |
| 1541 | rl_src2 = LoadValue(rl_src2, kCoreReg); |
| 1542 | if (check_zero) { |
Mingyao Yang | d15f4e2 | 2014-04-17 18:46:24 -0700 | [diff] [blame] | 1543 | GenDivZeroCheck(rl_src2.reg); |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1544 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1545 | rl_result = GenDivRem(rl_dest, rl_src1.reg, rl_src2.reg, op == kOpDiv); |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1546 | done = true; |
| 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | // If we haven't already generated the code use the callout function. |
| 1551 | if (!done) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1552 | ThreadOffset<4> func_offset = QUICK_ENTRYPOINT_OFFSET(4, pIdivmod); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1553 | FlushAllRegs(); /* Send everything to home location */ |
| 1554 | LoadValueDirectFixed(rl_src2, TargetReg(kArg1)); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1555 | RegStorage r_tgt = CallHelperSetup(func_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1556 | LoadValueDirectFixed(rl_src1, TargetReg(kArg0)); |
| 1557 | if (check_zero) { |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 1558 | GenDivZeroCheck(TargetReg(kArg1)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1559 | } |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1560 | // NOTE: callout here is not a safepoint. |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 1561 | CallHelper(r_tgt, func_offset, false /* not a safepoint */); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1562 | if (op == kOpDiv) |
| 1563 | rl_result = GetReturn(false); |
| 1564 | else |
| 1565 | rl_result = GetReturnAlt(); |
| 1566 | } |
| 1567 | StoreValue(rl_dest, rl_result); |
| 1568 | } |
| 1569 | } |
| 1570 | |
| 1571 | /* |
| 1572 | * The following are the first-level codegen routines that analyze the format |
| 1573 | * of each bytecode then either dispatch special purpose codegen routines |
| 1574 | * or produce corresponding Thumb instructions directly. |
| 1575 | */ |
| 1576 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1577 | // Returns true if no more than two bits are set in 'x'. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1578 | static bool IsPopCountLE2(unsigned int x) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1579 | x &= x - 1; |
| 1580 | return (x & (x - 1)) == 0; |
| 1581 | } |
| 1582 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1583 | // Returns true if it added instructions to 'cu' to divide 'rl_src' by 'lit' |
| 1584 | // and store the result in 'rl_dest'. |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1585 | bool Mir2Lir::HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1586 | RegLocation rl_src, RegLocation rl_dest, int lit) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1587 | if ((lit < 2) || ((cu_->instruction_set != kThumb2) && !IsPowerOfTwo(lit))) { |
| 1588 | return false; |
| 1589 | } |
| 1590 | // No divide instruction for Arm, so check for more special cases |
| 1591 | if ((cu_->instruction_set == kThumb2) && !IsPowerOfTwo(lit)) { |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1592 | return SmallLiteralDivRem(dalvik_opcode, is_div, rl_src, rl_dest, lit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1593 | } |
| 1594 | int k = LowestSetBit(lit); |
| 1595 | if (k >= 30) { |
| 1596 | // Avoid special cases. |
| 1597 | return false; |
| 1598 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1599 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1600 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1601 | if (is_div) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1602 | RegStorage t_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1603 | if (lit == 2) { |
| 1604 | // Division by 2 is by far the most common division by constant. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1605 | OpRegRegImm(kOpLsr, t_reg, rl_src.reg, 32 - k); |
| 1606 | OpRegRegReg(kOpAdd, t_reg, t_reg, rl_src.reg); |
| 1607 | OpRegRegImm(kOpAsr, rl_result.reg, t_reg, k); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1608 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1609 | OpRegRegImm(kOpAsr, t_reg, rl_src.reg, 31); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1610 | OpRegRegImm(kOpLsr, t_reg, t_reg, 32 - k); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1611 | OpRegRegReg(kOpAdd, t_reg, t_reg, rl_src.reg); |
| 1612 | OpRegRegImm(kOpAsr, rl_result.reg, t_reg, k); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1613 | } |
| 1614 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1615 | RegStorage t_reg1 = AllocTemp(); |
| 1616 | RegStorage t_reg2 = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1617 | if (lit == 2) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1618 | OpRegRegImm(kOpLsr, t_reg1, rl_src.reg, 32 - k); |
| 1619 | OpRegRegReg(kOpAdd, t_reg2, t_reg1, rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1620 | OpRegRegImm(kOpAnd, t_reg2, t_reg2, lit -1); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1621 | OpRegRegReg(kOpSub, rl_result.reg, t_reg2, t_reg1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1622 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1623 | OpRegRegImm(kOpAsr, t_reg1, rl_src.reg, 31); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1624 | OpRegRegImm(kOpLsr, t_reg1, t_reg1, 32 - k); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1625 | OpRegRegReg(kOpAdd, t_reg2, t_reg1, rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1626 | OpRegRegImm(kOpAnd, t_reg2, t_reg2, lit - 1); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1627 | OpRegRegReg(kOpSub, rl_result.reg, t_reg2, t_reg1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1628 | } |
| 1629 | } |
| 1630 | StoreValue(rl_dest, rl_result); |
| 1631 | return true; |
| 1632 | } |
| 1633 | |
| 1634 | // Returns true if it added instructions to 'cu' to multiply 'rl_src' by 'lit' |
| 1635 | // and store the result in 'rl_dest'. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1636 | bool Mir2Lir::HandleEasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) { |
Ian Rogers | e2143c0 | 2014-03-28 08:47:16 -0700 | [diff] [blame] | 1637 | if (lit < 0) { |
| 1638 | return false; |
| 1639 | } |
| 1640 | if (lit == 0) { |
| 1641 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1642 | LoadConstant(rl_result.reg, 0); |
| 1643 | StoreValue(rl_dest, rl_result); |
| 1644 | return true; |
| 1645 | } |
| 1646 | if (lit == 1) { |
| 1647 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1648 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1649 | OpRegCopy(rl_result.reg, rl_src.reg); |
| 1650 | StoreValue(rl_dest, rl_result); |
| 1651 | return true; |
| 1652 | } |
Zheng Xu | f9719f9 | 2014-04-02 13:31:31 +0100 | [diff] [blame] | 1653 | // There is RegRegRegShift on Arm, so check for more special cases |
| 1654 | if (cu_->instruction_set == kThumb2) { |
Ian Rogers | e2143c0 | 2014-03-28 08:47:16 -0700 | [diff] [blame] | 1655 | return EasyMultiply(rl_src, rl_dest, lit); |
| 1656 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1657 | // Can we simplify this multiplication? |
| 1658 | bool power_of_two = false; |
| 1659 | bool pop_count_le2 = false; |
| 1660 | bool power_of_two_minus_one = false; |
Ian Rogers | e2143c0 | 2014-03-28 08:47:16 -0700 | [diff] [blame] | 1661 | if (IsPowerOfTwo(lit)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1662 | power_of_two = true; |
| 1663 | } else if (IsPopCountLE2(lit)) { |
| 1664 | pop_count_le2 = true; |
| 1665 | } else if (IsPowerOfTwo(lit + 1)) { |
| 1666 | power_of_two_minus_one = true; |
| 1667 | } else { |
| 1668 | return false; |
| 1669 | } |
| 1670 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1671 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1672 | if (power_of_two) { |
| 1673 | // Shift. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1674 | OpRegRegImm(kOpLsl, rl_result.reg, rl_src.reg, LowestSetBit(lit)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1675 | } else if (pop_count_le2) { |
| 1676 | // Shift and add and shift. |
| 1677 | int first_bit = LowestSetBit(lit); |
| 1678 | int second_bit = LowestSetBit(lit ^ (1 << first_bit)); |
| 1679 | GenMultiplyByTwoBitMultiplier(rl_src, rl_result, lit, first_bit, second_bit); |
| 1680 | } else { |
| 1681 | // Reverse subtract: (src << (shift + 1)) - src. |
| 1682 | DCHECK(power_of_two_minus_one); |
| 1683 | // TUNING: rsb dst, src, src lsl#LowestSetBit(lit + 1) |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1684 | RegStorage t_reg = AllocTemp(); |
| 1685 | OpRegRegImm(kOpLsl, t_reg, rl_src.reg, LowestSetBit(lit + 1)); |
| 1686 | OpRegRegReg(kOpSub, rl_result.reg, t_reg, rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1687 | } |
| 1688 | StoreValue(rl_dest, rl_result); |
| 1689 | return true; |
| 1690 | } |
| 1691 | |
| 1692 | void Mir2Lir::GenArithOpIntLit(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1693 | int lit) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1694 | RegLocation rl_result; |
| 1695 | OpKind op = static_cast<OpKind>(0); /* Make gcc happy */ |
| 1696 | int shift_op = false; |
| 1697 | bool is_div = false; |
| 1698 | |
| 1699 | switch (opcode) { |
| 1700 | case Instruction::RSUB_INT_LIT8: |
| 1701 | case Instruction::RSUB_INT: { |
| 1702 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1703 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1704 | if (cu_->instruction_set == kThumb2) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1705 | OpRegRegImm(kOpRsub, rl_result.reg, rl_src.reg, lit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1706 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1707 | OpRegReg(kOpNeg, rl_result.reg, rl_src.reg); |
| 1708 | OpRegImm(kOpAdd, rl_result.reg, lit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1709 | } |
| 1710 | StoreValue(rl_dest, rl_result); |
| 1711 | return; |
| 1712 | } |
| 1713 | |
| 1714 | case Instruction::SUB_INT: |
| 1715 | case Instruction::SUB_INT_2ADDR: |
| 1716 | lit = -lit; |
| 1717 | // Intended fallthrough |
| 1718 | case Instruction::ADD_INT: |
| 1719 | case Instruction::ADD_INT_2ADDR: |
| 1720 | case Instruction::ADD_INT_LIT8: |
| 1721 | case Instruction::ADD_INT_LIT16: |
| 1722 | op = kOpAdd; |
| 1723 | break; |
| 1724 | case Instruction::MUL_INT: |
| 1725 | case Instruction::MUL_INT_2ADDR: |
| 1726 | case Instruction::MUL_INT_LIT8: |
| 1727 | case Instruction::MUL_INT_LIT16: { |
| 1728 | if (HandleEasyMultiply(rl_src, rl_dest, lit)) { |
| 1729 | return; |
| 1730 | } |
| 1731 | op = kOpMul; |
| 1732 | break; |
| 1733 | } |
| 1734 | case Instruction::AND_INT: |
| 1735 | case Instruction::AND_INT_2ADDR: |
| 1736 | case Instruction::AND_INT_LIT8: |
| 1737 | case Instruction::AND_INT_LIT16: |
| 1738 | op = kOpAnd; |
| 1739 | break; |
| 1740 | case Instruction::OR_INT: |
| 1741 | case Instruction::OR_INT_2ADDR: |
| 1742 | case Instruction::OR_INT_LIT8: |
| 1743 | case Instruction::OR_INT_LIT16: |
| 1744 | op = kOpOr; |
| 1745 | break; |
| 1746 | case Instruction::XOR_INT: |
| 1747 | case Instruction::XOR_INT_2ADDR: |
| 1748 | case Instruction::XOR_INT_LIT8: |
| 1749 | case Instruction::XOR_INT_LIT16: |
| 1750 | op = kOpXor; |
| 1751 | break; |
| 1752 | case Instruction::SHL_INT_LIT8: |
| 1753 | case Instruction::SHL_INT: |
| 1754 | case Instruction::SHL_INT_2ADDR: |
| 1755 | lit &= 31; |
| 1756 | shift_op = true; |
| 1757 | op = kOpLsl; |
| 1758 | break; |
| 1759 | case Instruction::SHR_INT_LIT8: |
| 1760 | case Instruction::SHR_INT: |
| 1761 | case Instruction::SHR_INT_2ADDR: |
| 1762 | lit &= 31; |
| 1763 | shift_op = true; |
| 1764 | op = kOpAsr; |
| 1765 | break; |
| 1766 | case Instruction::USHR_INT_LIT8: |
| 1767 | case Instruction::USHR_INT: |
| 1768 | case Instruction::USHR_INT_2ADDR: |
| 1769 | lit &= 31; |
| 1770 | shift_op = true; |
| 1771 | op = kOpLsr; |
| 1772 | break; |
| 1773 | |
| 1774 | case Instruction::DIV_INT: |
| 1775 | case Instruction::DIV_INT_2ADDR: |
| 1776 | case Instruction::DIV_INT_LIT8: |
| 1777 | case Instruction::DIV_INT_LIT16: |
| 1778 | case Instruction::REM_INT: |
| 1779 | case Instruction::REM_INT_2ADDR: |
| 1780 | case Instruction::REM_INT_LIT8: |
| 1781 | case Instruction::REM_INT_LIT16: { |
| 1782 | if (lit == 0) { |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 1783 | GenDivZeroException(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1784 | return; |
| 1785 | } |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1786 | if ((opcode == Instruction::DIV_INT) || |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1787 | (opcode == Instruction::DIV_INT_2ADDR) || |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1788 | (opcode == Instruction::DIV_INT_LIT8) || |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1789 | (opcode == Instruction::DIV_INT_LIT16)) { |
| 1790 | is_div = true; |
| 1791 | } else { |
| 1792 | is_div = false; |
| 1793 | } |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1794 | if (HandleEasyDivRem(opcode, is_div, rl_src, rl_dest, lit)) { |
| 1795 | return; |
| 1796 | } |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1797 | |
| 1798 | bool done = false; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1799 | if (cu_->instruction_set == kMips) { |
| 1800 | rl_src = LoadValue(rl_src, kCoreReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1801 | rl_result = GenDivRemLit(rl_dest, rl_src.reg, lit, is_div); |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1802 | done = true; |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1803 | } else if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Mark Mendell | 2bf31e6 | 2014-01-23 12:13:40 -0800 | [diff] [blame] | 1804 | rl_result = GenDivRemLit(rl_dest, rl_src, lit, is_div); |
| 1805 | done = true; |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1806 | } else if (cu_->instruction_set == kThumb2) { |
| 1807 | if (cu_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 1808 | // Use ARM SDIV instruction for division. For remainder we also need to |
| 1809 | // calculate using a MUL and subtract. |
| 1810 | rl_src = LoadValue(rl_src, kCoreReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1811 | rl_result = GenDivRemLit(rl_dest, rl_src.reg, lit, is_div); |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1812 | done = true; |
| 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | if (!done) { |
| 1817 | FlushAllRegs(); /* Everything to home location. */ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1818 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); |
| 1819 | Clobber(TargetReg(kArg0)); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1820 | ThreadOffset<4> func_offset = QUICK_ENTRYPOINT_OFFSET(4, pIdivmod); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1821 | CallRuntimeHelperRegImm(func_offset, TargetReg(kArg0), lit, false); |
| 1822 | if (is_div) |
| 1823 | rl_result = GetReturn(false); |
| 1824 | else |
| 1825 | rl_result = GetReturnAlt(); |
| 1826 | } |
| 1827 | StoreValue(rl_dest, rl_result); |
| 1828 | return; |
| 1829 | } |
| 1830 | default: |
| 1831 | LOG(FATAL) << "Unexpected opcode " << opcode; |
| 1832 | } |
| 1833 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1834 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1835 | // Avoid shifts by literal 0 - no support in Thumb. Change to copy. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1836 | if (shift_op && (lit == 0)) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1837 | OpRegCopy(rl_result.reg, rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1838 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1839 | OpRegRegImm(op, rl_result.reg, rl_src.reg, lit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1840 | } |
| 1841 | StoreValue(rl_dest, rl_result); |
| 1842 | } |
| 1843 | |
| 1844 | void Mir2Lir::GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1845 | RegLocation rl_src1, RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1846 | RegLocation rl_result; |
| 1847 | OpKind first_op = kOpBkpt; |
| 1848 | OpKind second_op = kOpBkpt; |
| 1849 | bool call_out = false; |
| 1850 | bool check_zero = false; |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1851 | ThreadOffset<4> func_offset(-1); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1852 | int ret_reg = TargetReg(kRet0).GetReg(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1853 | |
| 1854 | switch (opcode) { |
| 1855 | case Instruction::NOT_LONG: |
| 1856 | rl_src2 = LoadValueWide(rl_src2, kCoreReg); |
| 1857 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1858 | // Check for destructive overlap |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1859 | if (rl_result.reg.GetLowReg() == rl_src2.reg.GetHighReg()) { |
| 1860 | RegStorage t_reg = AllocTemp(); |
| 1861 | OpRegCopy(t_reg, rl_src2.reg.GetHigh()); |
| 1862 | OpRegReg(kOpMvn, rl_result.reg.GetLow(), rl_src2.reg.GetLow()); |
| 1863 | OpRegReg(kOpMvn, rl_result.reg.GetHigh(), t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1864 | FreeTemp(t_reg); |
| 1865 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1866 | OpRegReg(kOpMvn, rl_result.reg.GetLow(), rl_src2.reg.GetLow()); |
| 1867 | OpRegReg(kOpMvn, rl_result.reg.GetHigh(), rl_src2.reg.GetHigh()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1868 | } |
| 1869 | StoreValueWide(rl_dest, rl_result); |
| 1870 | return; |
| 1871 | case Instruction::ADD_LONG: |
| 1872 | case Instruction::ADD_LONG_2ADDR: |
| 1873 | if (cu_->instruction_set != kThumb2) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1874 | GenAddLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1875 | return; |
| 1876 | } |
| 1877 | first_op = kOpAdd; |
| 1878 | second_op = kOpAdc; |
| 1879 | break; |
| 1880 | case Instruction::SUB_LONG: |
| 1881 | case Instruction::SUB_LONG_2ADDR: |
| 1882 | if (cu_->instruction_set != kThumb2) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1883 | GenSubLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1884 | return; |
| 1885 | } |
| 1886 | first_op = kOpSub; |
| 1887 | second_op = kOpSbc; |
| 1888 | break; |
| 1889 | case Instruction::MUL_LONG: |
| 1890 | case Instruction::MUL_LONG_2ADDR: |
Mark Mendell | 4708dcd | 2014-01-22 09:05:18 -0800 | [diff] [blame] | 1891 | if (cu_->instruction_set != kMips) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1892 | GenMulLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1893 | return; |
| 1894 | } else { |
| 1895 | call_out = true; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1896 | ret_reg = TargetReg(kRet0).GetReg(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1897 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pLmul); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1898 | } |
| 1899 | break; |
| 1900 | case Instruction::DIV_LONG: |
| 1901 | case Instruction::DIV_LONG_2ADDR: |
| 1902 | call_out = true; |
| 1903 | check_zero = true; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1904 | ret_reg = TargetReg(kRet0).GetReg(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1905 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pLdiv); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1906 | break; |
| 1907 | case Instruction::REM_LONG: |
| 1908 | case Instruction::REM_LONG_2ADDR: |
| 1909 | call_out = true; |
| 1910 | check_zero = true; |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1911 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pLmod); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1912 | /* NOTE - for Arm, result is in kArg2/kArg3 instead of kRet0/kRet1 */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1913 | ret_reg = (cu_->instruction_set == kThumb2) ? TargetReg(kArg2).GetReg() : TargetReg(kRet0).GetReg(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1914 | break; |
| 1915 | case Instruction::AND_LONG_2ADDR: |
| 1916 | case Instruction::AND_LONG: |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1917 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1918 | return GenAndLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1919 | } |
| 1920 | first_op = kOpAnd; |
| 1921 | second_op = kOpAnd; |
| 1922 | break; |
| 1923 | case Instruction::OR_LONG: |
| 1924 | case Instruction::OR_LONG_2ADDR: |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1925 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1926 | GenOrLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1927 | return; |
| 1928 | } |
| 1929 | first_op = kOpOr; |
| 1930 | second_op = kOpOr; |
| 1931 | break; |
| 1932 | case Instruction::XOR_LONG: |
| 1933 | case Instruction::XOR_LONG_2ADDR: |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1934 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1935 | GenXorLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1936 | return; |
| 1937 | } |
| 1938 | first_op = kOpXor; |
| 1939 | second_op = kOpXor; |
| 1940 | break; |
| 1941 | case Instruction::NEG_LONG: { |
| 1942 | GenNegLong(rl_dest, rl_src2); |
| 1943 | return; |
| 1944 | } |
| 1945 | default: |
| 1946 | LOG(FATAL) << "Invalid long arith op"; |
| 1947 | } |
| 1948 | if (!call_out) { |
| 1949 | GenLong3Addr(first_op, second_op, rl_dest, rl_src1, rl_src2); |
| 1950 | } else { |
| 1951 | FlushAllRegs(); /* Send everything to home location */ |
| 1952 | if (check_zero) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1953 | RegStorage r_tmp1 = RegStorage::MakeRegPair(TargetReg(kArg0), TargetReg(kArg1)); |
| 1954 | RegStorage r_tmp2 = RegStorage::MakeRegPair(TargetReg(kArg2), TargetReg(kArg3)); |
| 1955 | LoadValueDirectWideFixed(rl_src2, r_tmp2); |
| 1956 | RegStorage r_tgt = CallHelperSetup(func_offset); |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 1957 | GenDivZeroCheckWide(RegStorage::MakeRegPair(TargetReg(kArg2), TargetReg(kArg3))); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1958 | LoadValueDirectWideFixed(rl_src1, r_tmp1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1959 | // NOTE: callout here is not a safepoint |
| 1960 | CallHelper(r_tgt, func_offset, false /* not safepoint */); |
| 1961 | } else { |
| 1962 | CallRuntimeHelperRegLocationRegLocation(func_offset, rl_src1, rl_src2, false); |
| 1963 | } |
| 1964 | // Adjust return regs in to handle case of rem returning kArg2/kArg3 |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1965 | if (ret_reg == TargetReg(kRet0).GetReg()) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1966 | rl_result = GetReturnWide(false); |
| 1967 | else |
| 1968 | rl_result = GetReturnWideAlt(); |
| 1969 | StoreValueWide(rl_dest, rl_result); |
| 1970 | } |
| 1971 | } |
| 1972 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1973 | void Mir2Lir::GenConversionCall(ThreadOffset<4> func_offset, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1974 | RegLocation rl_dest, RegLocation rl_src) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1975 | /* |
| 1976 | * Don't optimize the register usage since it calls out to support |
| 1977 | * functions |
| 1978 | */ |
| 1979 | FlushAllRegs(); /* Send everything to home location */ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1980 | CallRuntimeHelperRegLocation(func_offset, rl_src, false); |
| 1981 | if (rl_dest.wide) { |
| 1982 | RegLocation rl_result; |
| 1983 | rl_result = GetReturnWide(rl_dest.fp); |
| 1984 | StoreValueWide(rl_dest, rl_result); |
| 1985 | } else { |
| 1986 | RegLocation rl_result; |
| 1987 | rl_result = GetReturn(rl_dest.fp); |
| 1988 | StoreValue(rl_dest, rl_result); |
| 1989 | } |
| 1990 | } |
| 1991 | |
| 1992 | /* Check if we need to check for pending suspend request */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1993 | void Mir2Lir::GenSuspendTest(int opt_flags) { |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 1994 | if (Runtime::Current()->ExplicitSuspendChecks()) { |
| 1995 | if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) { |
| 1996 | return; |
| 1997 | } |
| 1998 | FlushAllRegs(); |
| 1999 | LIR* branch = OpTestSuspend(NULL); |
| 2000 | LIR* ret_lab = NewLIR0(kPseudoTargetLabel); |
| 2001 | LIR* target = RawLIR(current_dalvik_offset_, kPseudoSuspendTarget, WrapPointer(ret_lab), |
| 2002 | current_dalvik_offset_); |
| 2003 | branch->target = target; |
| 2004 | suspend_launchpads_.Insert(target); |
| 2005 | } else { |
| 2006 | if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) { |
| 2007 | return; |
| 2008 | } |
| 2009 | FlushAllRegs(); // TODO: needed? |
| 2010 | LIR* inst = CheckSuspendUsingLoad(); |
| 2011 | MarkSafepointPC(inst); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2012 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | /* Check if we need to check for pending suspend request */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 2016 | void Mir2Lir::GenSuspendTestAndBranch(int opt_flags, LIR* target) { |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 2017 | if (Runtime::Current()->ExplicitSuspendChecks()) { |
| 2018 | if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) { |
| 2019 | OpUnconditionalBranch(target); |
| 2020 | return; |
| 2021 | } |
| 2022 | OpTestSuspend(target); |
| 2023 | LIR* launch_pad = |
| 2024 | RawLIR(current_dalvik_offset_, kPseudoSuspendTarget, WrapPointer(target), |
| 2025 | current_dalvik_offset_); |
| 2026 | FlushAllRegs(); |
| 2027 | OpUnconditionalBranch(launch_pad); |
| 2028 | suspend_launchpads_.Insert(launch_pad); |
| 2029 | } else { |
| 2030 | // For the implicit suspend check, just perform the trigger |
| 2031 | // load and branch to the target. |
| 2032 | if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) { |
| 2033 | OpUnconditionalBranch(target); |
| 2034 | return; |
| 2035 | } |
| 2036 | FlushAllRegs(); |
| 2037 | LIR* inst = CheckSuspendUsingLoad(); |
| 2038 | MarkSafepointPC(inst); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2039 | OpUnconditionalBranch(target); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2040 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 2043 | /* Call out to helper assembly routine that will null check obj and then lock it. */ |
| 2044 | void Mir2Lir::GenMonitorEnter(int opt_flags, RegLocation rl_src) { |
| 2045 | FlushAllRegs(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 2046 | CallRuntimeHelperRegLocation(QUICK_ENTRYPOINT_OFFSET(4, pLockObject), rl_src, true); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | /* Call out to helper assembly routine that will null check obj and then unlock it. */ |
| 2050 | void Mir2Lir::GenMonitorExit(int opt_flags, RegLocation rl_src) { |
| 2051 | FlushAllRegs(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 2052 | CallRuntimeHelperRegLocation(QUICK_ENTRYPOINT_OFFSET(4, pUnlockObject), rl_src, true); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 2055 | /* Generic code for generating a wide constant into a VR. */ |
| 2056 | void Mir2Lir::GenConstWide(RegLocation rl_dest, int64_t value) { |
| 2057 | RegLocation rl_result = EvalLoc(rl_dest, kAnyReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 2058 | LoadConstantWide(rl_result.reg, value); |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 2059 | StoreValueWide(rl_dest, rl_result); |
| 2060 | } |
| 2061 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2062 | } // namespace art |