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); |
Andreas Gampe | b5a14d2 | 2014-04-24 17:30:35 +0000 | [diff] [blame^] | 522 | LoadRefDisp(r_base, mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + |
| 523 | sizeof(int32_t*) * field_info.StorageIndex(), r_base); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 524 | // 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] | 525 | if (!field_info.IsInitialized() && |
| 526 | (mir->optimization_flags & MIR_IGNORE_CLINIT_CHECK) == 0) { |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 527 | // Check if r_base is NULL or a not yet initialized class. |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 528 | |
| 529 | // The slow path is invoked if the r_base is NULL or the class pointed |
| 530 | // to by it is not initialized. |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 531 | LIR* unresolved_branch = OpCmpImmBranch(kCondEq, r_base, 0, NULL); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 532 | RegStorage r_tmp = TargetReg(kArg2); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 533 | LockTemp(r_tmp); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 534 | LIR* uninit_branch = OpCmpMemImmBranch(kCondLt, r_tmp, r_base, |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 535 | mirror::Class::StatusOffset().Int32Value(), |
| 536 | mirror::Class::kStatusInitialized, NULL); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 537 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 538 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 539 | AddSlowPath(new (arena_) StaticFieldSlowPath(this, unresolved_branch, uninit_branch, cont, |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 540 | field_info.StorageIndex(), r_base)); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 541 | |
| 542 | FreeTemp(r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 543 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 544 | FreeTemp(r_method); |
| 545 | } |
| 546 | // rBase now holds static storage base |
| 547 | if (is_long_or_double) { |
Yevgeny Rouban | b4b0667 | 2014-04-16 18:13:10 +0700 | [diff] [blame] | 548 | RegisterClass register_kind = kAnyReg; |
| 549 | if (field_info.IsVolatile() && cu_->instruction_set == kX86) { |
| 550 | // Force long/double volatile stores into SSE registers to avoid tearing. |
| 551 | register_kind = kFPReg; |
| 552 | } |
| 553 | rl_src = LoadValueWide(rl_src, register_kind); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 554 | } else { |
| 555 | rl_src = LoadValue(rl_src, kAnyReg); |
| 556 | } |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 557 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 558 | // 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] | 559 | GenMemBarrier(kStoreStore); |
| 560 | } |
| 561 | if (is_long_or_double) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 562 | StoreBaseDispWide(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 563 | } else if (rl_src.ref) { |
| 564 | StoreRefDisp(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 565 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 566 | Store32Disp(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 567 | } |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 568 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 569 | // A load might follow the volatile store so insert a StoreLoad barrier. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 570 | GenMemBarrier(kStoreLoad); |
| 571 | } |
| 572 | if (is_object && !mir_graph_->IsConstantNullRef(rl_src)) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 573 | MarkGCCard(rl_src.reg, r_base); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 574 | } |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 575 | FreeTemp(r_base); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 576 | } else { |
| 577 | FlushAllRegs(); // Everything to home locations |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 578 | ThreadOffset<4> setter_offset = |
| 579 | is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(4, pSet64Static) |
| 580 | : (is_object ? QUICK_ENTRYPOINT_OFFSET(4, pSetObjStatic) |
| 581 | : QUICK_ENTRYPOINT_OFFSET(4, pSet32Static)); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 582 | CallRuntimeHelperImmRegLocation(setter_offset, field_info.FieldIndex(), rl_src, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 586 | void Mir2Lir::GenSget(MIR* mir, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 587 | bool is_long_or_double, bool is_object) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 588 | const MirSFieldLoweringInfo& field_info = mir_graph_->GetSFieldLoweringInfo(mir); |
| 589 | cu_->compiler_driver->ProcessedStaticField(field_info.FastGet(), field_info.IsReferrersClass()); |
| 590 | if (field_info.FastGet() && !SLOW_FIELD_PATH) { |
| 591 | DCHECK_GE(field_info.FieldOffset().Int32Value(), 0); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 592 | RegStorage r_base; |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 593 | if (field_info.IsReferrersClass()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 594 | // Fast path, static storage base is this method's class |
| 595 | RegLocation rl_method = LoadCurrMethod(); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 596 | r_base = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 597 | LoadRefDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), r_base); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 598 | } else { |
| 599 | // Medium path, static storage base in a different class which requires checks that the other |
| 600 | // class is initialized |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 601 | DCHECK_NE(field_info.StorageIndex(), DexFile::kDexNoIndex); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 602 | // May do runtime call so everything to home locations. |
| 603 | FlushAllRegs(); |
| 604 | // Using fixed register to sync with possible call to runtime support. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 605 | RegStorage r_method = TargetReg(kArg1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 606 | LockTemp(r_method); |
| 607 | LoadCurrMethodDirect(r_method); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 608 | r_base = TargetReg(kArg0); |
| 609 | LockTemp(r_base); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 610 | LoadRefDisp(r_method, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), r_base); |
Andreas Gampe | b5a14d2 | 2014-04-24 17:30:35 +0000 | [diff] [blame^] | 611 | LoadRefDisp(r_base, mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + |
| 612 | sizeof(int32_t*) * field_info.StorageIndex(), r_base); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 613 | // 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] | 614 | if (!field_info.IsInitialized() && |
| 615 | (mir->optimization_flags & MIR_IGNORE_CLINIT_CHECK) == 0) { |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 616 | // Check if r_base is NULL or a not yet initialized class. |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 617 | |
| 618 | // The slow path is invoked if the r_base is NULL or the class pointed |
| 619 | // to by it is not initialized. |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 620 | LIR* unresolved_branch = OpCmpImmBranch(kCondEq, r_base, 0, NULL); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 621 | RegStorage r_tmp = TargetReg(kArg2); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 622 | LockTemp(r_tmp); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 623 | LIR* uninit_branch = OpCmpMemImmBranch(kCondLt, r_tmp, r_base, |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 624 | mirror::Class::StatusOffset().Int32Value(), |
| 625 | mirror::Class::kStatusInitialized, NULL); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 626 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 627 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 628 | AddSlowPath(new (arena_) StaticFieldSlowPath(this, unresolved_branch, uninit_branch, cont, |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 629 | field_info.StorageIndex(), r_base)); |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 630 | |
| 631 | FreeTemp(r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 632 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 633 | FreeTemp(r_method); |
| 634 | } |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 635 | // r_base now holds static storage base |
Yevgeny Rouban | b4b0667 | 2014-04-16 18:13:10 +0700 | [diff] [blame] | 636 | RegisterClass result_reg_kind = kAnyReg; |
| 637 | if (field_info.IsVolatile() && cu_->instruction_set == kX86) { |
| 638 | // Force long/double volatile loads into SSE registers to avoid tearing. |
| 639 | result_reg_kind = kFPReg; |
| 640 | } |
| 641 | RegLocation rl_result = EvalLoc(rl_dest, result_reg_kind, true); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 642 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 643 | if (is_long_or_double) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 644 | LoadBaseDispWide(r_base, field_info.FieldOffset().Int32Value(), rl_result.reg, INVALID_SREG); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 645 | } else if (rl_result.ref) { |
| 646 | LoadRefDisp(r_base, field_info.FieldOffset().Int32Value(), rl_result.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 647 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 648 | Load32Disp(r_base, field_info.FieldOffset().Int32Value(), rl_result.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 649 | } |
Ian Rogers | 5ddb410 | 2014-01-07 08:58:46 -0800 | [diff] [blame] | 650 | FreeTemp(r_base); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 651 | |
| 652 | if (field_info.IsVolatile()) { |
| 653 | // Without context sensitive analysis, we must issue the most conservative barriers. |
| 654 | // In this case, either a load or store may follow so we issue both barriers. |
| 655 | GenMemBarrier(kLoadLoad); |
| 656 | GenMemBarrier(kLoadStore); |
| 657 | } |
| 658 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 659 | if (is_long_or_double) { |
| 660 | StoreValueWide(rl_dest, rl_result); |
| 661 | } else { |
| 662 | StoreValue(rl_dest, rl_result); |
| 663 | } |
| 664 | } else { |
| 665 | FlushAllRegs(); // Everything to home locations |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 666 | ThreadOffset<4> getterOffset = |
| 667 | is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(4, pGet64Static) |
| 668 | :(is_object ? QUICK_ENTRYPOINT_OFFSET(4, pGetObjStatic) |
| 669 | : QUICK_ENTRYPOINT_OFFSET(4, pGet32Static)); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 670 | CallRuntimeHelperImm(getterOffset, field_info.FieldIndex(), true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 671 | if (is_long_or_double) { |
| 672 | RegLocation rl_result = GetReturnWide(rl_dest.fp); |
| 673 | StoreValueWide(rl_dest, rl_result); |
| 674 | } else { |
| 675 | RegLocation rl_result = GetReturn(rl_dest.fp); |
| 676 | StoreValue(rl_dest, rl_result); |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 681 | // Generate code for all slow paths. |
| 682 | void Mir2Lir::HandleSlowPaths() { |
| 683 | int n = slow_paths_.Size(); |
| 684 | for (int i = 0; i < n; ++i) { |
| 685 | LIRSlowPath* slowpath = slow_paths_.Get(i); |
| 686 | slowpath->Compile(); |
| 687 | } |
| 688 | slow_paths_.Reset(); |
| 689 | } |
| 690 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 691 | void Mir2Lir::HandleSuspendLaunchPads() { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 692 | int num_elems = suspend_launchpads_.Size(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 693 | ThreadOffset<4> helper_offset = QUICK_ENTRYPOINT_OFFSET(4, pTestSuspend); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 694 | for (int i = 0; i < num_elems; i++) { |
| 695 | ResetRegPool(); |
| 696 | ResetDefTracking(); |
| 697 | LIR* lab = suspend_launchpads_.Get(i); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 698 | LIR* resume_lab = reinterpret_cast<LIR*>(UnwrapPointer(lab->operands[0])); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 699 | current_dalvik_offset_ = lab->operands[1]; |
| 700 | AppendLIR(lab); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 701 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 702 | CallHelper(r_tgt, helper_offset, true /* MarkSafepointPC */); |
| 703 | OpUnconditionalBranch(resume_lab); |
| 704 | } |
| 705 | } |
| 706 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 707 | void Mir2Lir::GenIGet(MIR* mir, int opt_flags, OpSize size, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 708 | RegLocation rl_dest, RegLocation rl_obj, bool is_long_or_double, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 709 | bool is_object) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 710 | const MirIFieldLoweringInfo& field_info = mir_graph_->GetIFieldLoweringInfo(mir); |
| 711 | cu_->compiler_driver->ProcessedInstanceField(field_info.FastGet()); |
| 712 | if (field_info.FastGet() && !SLOW_FIELD_PATH) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 713 | RegLocation rl_result; |
| 714 | RegisterClass reg_class = oat_reg_class_by_size(size); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 715 | DCHECK_GE(field_info.FieldOffset().Int32Value(), 0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 716 | rl_obj = LoadValue(rl_obj, kCoreReg); |
| 717 | if (is_long_or_double) { |
| 718 | DCHECK(rl_dest.wide); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 719 | GenNullCheck(rl_obj.reg, opt_flags); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 720 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Yevgeny Rouban | b4b0667 | 2014-04-16 18:13:10 +0700 | [diff] [blame] | 721 | RegisterClass result_reg_kind = kAnyReg; |
| 722 | if (field_info.IsVolatile() && cu_->instruction_set == kX86) { |
| 723 | // Force long/double volatile loads into SSE registers to avoid tearing. |
| 724 | result_reg_kind = kFPReg; |
| 725 | } |
| 726 | rl_result = EvalLoc(rl_dest, result_reg_kind, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 727 | LoadBaseDispWide(rl_obj.reg, field_info.FieldOffset().Int32Value(), rl_result.reg, |
| 728 | rl_obj.s_reg_low); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 729 | MarkPossibleNullPointerException(opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 730 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 731 | // Without context sensitive analysis, we must issue the most conservative barriers. |
| 732 | // 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] | 733 | GenMemBarrier(kLoadLoad); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 734 | GenMemBarrier(kLoadStore); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 735 | } |
| 736 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 737 | RegStorage reg_ptr = AllocTemp(); |
| 738 | OpRegRegImm(kOpAdd, reg_ptr, rl_obj.reg, field_info.FieldOffset().Int32Value()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 739 | rl_result = EvalLoc(rl_dest, reg_class, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 740 | LoadBaseDispWide(reg_ptr, 0, rl_result.reg, INVALID_SREG); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 741 | MarkPossibleNullPointerException(opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 742 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 743 | // Without context sensitive analysis, we must issue the most conservative barriers. |
| 744 | // 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] | 745 | GenMemBarrier(kLoadLoad); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 746 | GenMemBarrier(kLoadStore); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 747 | } |
| 748 | FreeTemp(reg_ptr); |
| 749 | } |
| 750 | StoreValueWide(rl_dest, rl_result); |
| 751 | } else { |
| 752 | rl_result = EvalLoc(rl_dest, reg_class, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 753 | GenNullCheck(rl_obj.reg, opt_flags); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 754 | LoadBaseDisp(rl_obj.reg, field_info.FieldOffset().Int32Value(), rl_result.reg, k32, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 755 | rl_obj.s_reg_low); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 756 | MarkPossibleNullPointerException(opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 757 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 758 | // Without context sensitive analysis, we must issue the most conservative barriers. |
| 759 | // 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] | 760 | GenMemBarrier(kLoadLoad); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 761 | GenMemBarrier(kLoadStore); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 762 | } |
| 763 | StoreValue(rl_dest, rl_result); |
| 764 | } |
| 765 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 766 | ThreadOffset<4> getterOffset = |
| 767 | is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(4, pGet64Instance) |
| 768 | : (is_object ? QUICK_ENTRYPOINT_OFFSET(4, pGetObjInstance) |
| 769 | : QUICK_ENTRYPOINT_OFFSET(4, pGet32Instance)); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 770 | CallRuntimeHelperImmRegLocation(getterOffset, field_info.FieldIndex(), rl_obj, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 771 | if (is_long_or_double) { |
| 772 | RegLocation rl_result = GetReturnWide(rl_dest.fp); |
| 773 | StoreValueWide(rl_dest, rl_result); |
| 774 | } else { |
| 775 | RegLocation rl_result = GetReturn(rl_dest.fp); |
| 776 | StoreValue(rl_dest, rl_result); |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 781 | void Mir2Lir::GenIPut(MIR* mir, int opt_flags, OpSize size, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 782 | RegLocation rl_src, RegLocation rl_obj, bool is_long_or_double, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 783 | bool is_object) { |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 784 | const MirIFieldLoweringInfo& field_info = mir_graph_->GetIFieldLoweringInfo(mir); |
| 785 | cu_->compiler_driver->ProcessedInstanceField(field_info.FastPut()); |
| 786 | if (field_info.FastPut() && !SLOW_FIELD_PATH) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 787 | RegisterClass reg_class = oat_reg_class_by_size(size); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 788 | DCHECK_GE(field_info.FieldOffset().Int32Value(), 0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 789 | rl_obj = LoadValue(rl_obj, kCoreReg); |
| 790 | if (is_long_or_double) { |
Yevgeny Rouban | b4b0667 | 2014-04-16 18:13:10 +0700 | [diff] [blame] | 791 | RegisterClass src_reg_kind = kAnyReg; |
| 792 | if (field_info.IsVolatile() && cu_->instruction_set == kX86) { |
| 793 | // Force long/double volatile stores into SSE registers to avoid tearing. |
| 794 | src_reg_kind = kFPReg; |
| 795 | } |
| 796 | rl_src = LoadValueWide(rl_src, src_reg_kind); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 797 | GenNullCheck(rl_obj.reg, opt_flags); |
| 798 | RegStorage reg_ptr = AllocTemp(); |
| 799 | OpRegRegImm(kOpAdd, reg_ptr, rl_obj.reg, field_info.FieldOffset().Int32Value()); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 800 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 801 | // 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] | 802 | GenMemBarrier(kStoreStore); |
| 803 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 804 | StoreBaseDispWide(reg_ptr, 0, rl_src.reg); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 805 | MarkPossibleNullPointerException(opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 806 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 807 | // A load might follow the volatile store so insert a StoreLoad barrier. |
| 808 | GenMemBarrier(kStoreLoad); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 809 | } |
| 810 | FreeTemp(reg_ptr); |
| 811 | } else { |
| 812 | rl_src = LoadValue(rl_src, reg_class); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 813 | GenNullCheck(rl_obj.reg, opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 814 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 815 | // 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] | 816 | GenMemBarrier(kStoreStore); |
| 817 | } |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 818 | Store32Disp(rl_obj.reg, field_info.FieldOffset().Int32Value(), rl_src.reg); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 819 | MarkPossibleNullPointerException(opt_flags); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 820 | if (field_info.IsVolatile()) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 821 | // A load might follow the volatile store so insert a StoreLoad barrier. |
| 822 | GenMemBarrier(kStoreLoad); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 823 | } |
| 824 | if (is_object && !mir_graph_->IsConstantNullRef(rl_src)) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 825 | MarkGCCard(rl_src.reg, rl_obj.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 829 | ThreadOffset<4> setter_offset = |
| 830 | is_long_or_double ? QUICK_ENTRYPOINT_OFFSET(4, pSet64Instance) |
| 831 | : (is_object ? QUICK_ENTRYPOINT_OFFSET(4, pSetObjInstance) |
| 832 | : QUICK_ENTRYPOINT_OFFSET(4, pSet32Instance)); |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 833 | CallRuntimeHelperImmRegLocationRegLocation(setter_offset, field_info.FieldIndex(), |
| 834 | rl_obj, rl_src, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 838 | void Mir2Lir::GenArrayObjPut(int opt_flags, RegLocation rl_array, RegLocation rl_index, |
| 839 | RegLocation rl_src) { |
| 840 | bool needs_range_check = !(opt_flags & MIR_IGNORE_RANGE_CHECK); |
| 841 | bool needs_null_check = !((cu_->disable_opt & (1 << kNullCheckElimination)) && |
| 842 | (opt_flags & MIR_IGNORE_NULL_CHECK)); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 843 | ThreadOffset<4> helper = needs_range_check |
| 844 | ? (needs_null_check ? QUICK_ENTRYPOINT_OFFSET(4, pAputObjectWithNullAndBoundCheck) |
| 845 | : QUICK_ENTRYPOINT_OFFSET(4, pAputObjectWithBoundCheck)) |
| 846 | : QUICK_ENTRYPOINT_OFFSET(4, pAputObject); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 847 | CallRuntimeHelperRegLocationRegLocationRegLocation(helper, rl_array, rl_index, rl_src, true); |
| 848 | } |
| 849 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 850 | void Mir2Lir::GenConstClass(uint32_t type_idx, RegLocation rl_dest) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 851 | RegLocation rl_method = LoadCurrMethod(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 852 | RegStorage res_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 853 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 854 | if (!cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, |
| 855 | *cu_->dex_file, |
| 856 | type_idx)) { |
| 857 | // Call out to helper which resolves type and verifies access. |
| 858 | // Resolved type returned in kRet0. |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 859 | CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(4, pInitializeTypeAndVerifyAccess), |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 860 | type_idx, rl_method.reg, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 861 | RegLocation rl_result = GetReturn(false); |
| 862 | StoreValue(rl_dest, rl_result); |
| 863 | } else { |
| 864 | // We're don't need access checks, load type from dex cache |
| 865 | int32_t dex_cache_offset = |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 866 | mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 867 | Load32Disp(rl_method.reg, dex_cache_offset, res_reg); |
Andreas Gampe | b5a14d2 | 2014-04-24 17:30:35 +0000 | [diff] [blame^] | 868 | int32_t offset_of_type = |
| 869 | mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + (sizeof(mirror::Class*) |
| 870 | * type_idx); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 871 | Load32Disp(res_reg, offset_of_type, rl_result.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 872 | if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, |
| 873 | type_idx) || SLOW_TYPE_PATH) { |
| 874 | // Slow path, at runtime test if type is null and if so initialize |
| 875 | FlushAllRegs(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 876 | LIR* branch = OpCmpImmBranch(kCondEq, rl_result.reg, 0, NULL); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 877 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
| 878 | |
| 879 | // Object to generate the slow path for class resolution. |
| 880 | class SlowPath : public LIRSlowPath { |
| 881 | public: |
| 882 | SlowPath(Mir2Lir* m2l, LIR* fromfast, LIR* cont, const int type_idx, |
| 883 | const RegLocation& rl_method, const RegLocation& rl_result) : |
| 884 | LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast, cont), type_idx_(type_idx), |
| 885 | rl_method_(rl_method), rl_result_(rl_result) { |
| 886 | } |
| 887 | |
| 888 | void Compile() { |
| 889 | GenerateTargetLabel(); |
| 890 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 891 | m2l_->CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(4, pInitializeType), type_idx_, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 892 | rl_method_.reg, true); |
| 893 | m2l_->OpRegCopy(rl_result_.reg, m2l_->TargetReg(kRet0)); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 894 | |
| 895 | m2l_->OpUnconditionalBranch(cont_); |
| 896 | } |
| 897 | |
| 898 | private: |
| 899 | const int type_idx_; |
| 900 | const RegLocation rl_method_; |
| 901 | const RegLocation rl_result_; |
| 902 | }; |
| 903 | |
| 904 | // Add to list for future. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 905 | 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] | 906 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 907 | StoreValue(rl_dest, rl_result); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 908 | } else { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 909 | // Fast path, we're done - just store result |
| 910 | StoreValue(rl_dest, rl_result); |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 915 | void Mir2Lir::GenConstString(uint32_t string_idx, RegLocation rl_dest) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 916 | /* NOTE: Most strings should be available at compile time */ |
Andreas Gampe | b5a14d2 | 2014-04-24 17:30:35 +0000 | [diff] [blame^] | 917 | int32_t offset_of_string = mirror::Array::DataOffset(sizeof(mirror::String*)).Int32Value() + |
| 918 | (sizeof(mirror::String*) * string_idx); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 919 | if (!cu_->compiler_driver->CanAssumeStringIsPresentInDexCache( |
| 920 | *cu_->dex_file, string_idx) || SLOW_STRING_PATH) { |
| 921 | // slow path, resolve string if not in dex cache |
| 922 | FlushAllRegs(); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 923 | LockCallTemps(); // Using explicit registers |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 924 | |
| 925 | // If the Method* is already in a register, we can save a copy. |
| 926 | RegLocation rl_method = mir_graph_->GetMethodLoc(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 927 | RegStorage r_method; |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 928 | if (rl_method.location == kLocPhysReg) { |
| 929 | // A temp would conflict with register use below. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 930 | DCHECK(!IsTemp(rl_method.reg)); |
| 931 | r_method = rl_method.reg; |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 932 | } else { |
| 933 | r_method = TargetReg(kArg2); |
| 934 | LoadCurrMethodDirect(r_method); |
| 935 | } |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 936 | LoadRefDisp(r_method, mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), |
| 937 | TargetReg(kArg0)); |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 938 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 939 | // Might call out to helper, which will return resolved string in kRet0 |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 940 | Load32Disp(TargetReg(kArg0), offset_of_string, TargetReg(kRet0)); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 941 | if (cu_->instruction_set == kThumb2 || |
| 942 | cu_->instruction_set == kMips) { |
| 943 | // OpRegImm(kOpCmp, TargetReg(kRet0), 0); // Is resolved? |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 944 | LoadConstant(TargetReg(kArg1), string_idx); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 945 | LIR* fromfast = OpCmpImmBranch(kCondEq, TargetReg(kRet0), 0, NULL); |
| 946 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 947 | GenBarrier(); |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 948 | |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 949 | // Object to generate the slow path for string resolution. |
| 950 | class SlowPath : public LIRSlowPath { |
| 951 | public: |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 952 | SlowPath(Mir2Lir* m2l, LIR* fromfast, LIR* cont, RegStorage r_method) : |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 953 | LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast, cont), r_method_(r_method) { |
| 954 | } |
| 955 | |
| 956 | void Compile() { |
| 957 | GenerateTargetLabel(); |
| 958 | |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 959 | RegStorage r_tgt = m2l_->CallHelperSetup(QUICK_ENTRYPOINT_OFFSET(4, pResolveString)); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 960 | |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 961 | m2l_->OpRegCopy(m2l_->TargetReg(kArg0), r_method_); // .eq |
| 962 | LIR* call_inst = m2l_->OpReg(kOpBlx, r_tgt); |
| 963 | m2l_->MarkSafepointPC(call_inst); |
| 964 | m2l_->FreeTemp(r_tgt); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 965 | |
| 966 | m2l_->OpUnconditionalBranch(cont_); |
| 967 | } |
| 968 | |
| 969 | private: |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 970 | RegStorage r_method_; |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 971 | }; |
| 972 | |
| 973 | // Add to list for future. |
| 974 | AddSlowPath(new (arena_) SlowPath(this, fromfast, cont, r_method)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 975 | } else { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 976 | DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64); |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 977 | LIR* branch = OpCmpImmBranch(kCondNe, TargetReg(kRet0), 0, NULL); |
| 978 | LoadConstant(TargetReg(kArg1), string_idx); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 979 | CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(4, pResolveString), r_method, TargetReg(kArg1), |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 980 | true); |
Mark Mendell | 766e929 | 2014-01-27 07:55:47 -0800 | [diff] [blame] | 981 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 982 | branch->target = target; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 983 | } |
| 984 | GenBarrier(); |
| 985 | StoreValue(rl_dest, GetReturn(false)); |
| 986 | } else { |
| 987 | RegLocation rl_method = LoadCurrMethod(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 988 | RegStorage res_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 989 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 990 | LoadRefDisp(rl_method.reg, mirror::ArtMethod::DexCacheStringsOffset().Int32Value(), res_reg); |
| 991 | Load32Disp(res_reg, offset_of_string, rl_result.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 992 | StoreValue(rl_dest, rl_result); |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | /* |
| 997 | * Let helper function take care of everything. Will |
| 998 | * call Class::NewInstanceFromCode(type_idx, method); |
| 999 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1000 | void Mir2Lir::GenNewInstance(uint32_t type_idx, RegLocation rl_dest) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1001 | FlushAllRegs(); /* Everything to home location */ |
| 1002 | // alloc will always check for resolution, do we also need to verify |
| 1003 | // access because the verifier was unable to? |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1004 | ThreadOffset<4> func_offset(-1); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1005 | const DexFile* dex_file = cu_->dex_file; |
| 1006 | CompilerDriver* driver = cu_->compiler_driver; |
| 1007 | if (driver->CanAccessInstantiableTypeWithoutChecks( |
| 1008 | cu_->method_idx, *dex_file, type_idx)) { |
| 1009 | bool is_type_initialized; |
| 1010 | bool use_direct_type_ptr; |
| 1011 | uintptr_t direct_type_ptr; |
| 1012 | if (kEmbedClassInCode && |
| 1013 | driver->CanEmbedTypeInCode(*dex_file, type_idx, |
| 1014 | &is_type_initialized, &use_direct_type_ptr, &direct_type_ptr)) { |
| 1015 | // The fast path. |
| 1016 | if (!use_direct_type_ptr) { |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 1017 | LoadClassType(type_idx, kArg0); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1018 | if (!is_type_initialized) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1019 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObjectResolved); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1020 | CallRuntimeHelperRegMethod(func_offset, TargetReg(kArg0), true); |
| 1021 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1022 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObjectInitialized); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1023 | CallRuntimeHelperRegMethod(func_offset, TargetReg(kArg0), true); |
| 1024 | } |
| 1025 | } else { |
| 1026 | // Use the direct pointer. |
| 1027 | if (!is_type_initialized) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1028 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObjectResolved); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1029 | CallRuntimeHelperImmMethod(func_offset, direct_type_ptr, true); |
| 1030 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1031 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObjectInitialized); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1032 | CallRuntimeHelperImmMethod(func_offset, direct_type_ptr, true); |
| 1033 | } |
| 1034 | } |
| 1035 | } else { |
| 1036 | // The slow path. |
| 1037 | DCHECK_EQ(func_offset.Int32Value(), -1); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1038 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObject); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1039 | CallRuntimeHelperImmMethod(func_offset, type_idx, true); |
| 1040 | } |
| 1041 | DCHECK_NE(func_offset.Int32Value(), -1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1042 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1043 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pAllocObjectWithAccessCheck); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 1044 | CallRuntimeHelperImmMethod(func_offset, type_idx, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1045 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1046 | RegLocation rl_result = GetReturn(false); |
| 1047 | StoreValue(rl_dest, rl_result); |
| 1048 | } |
| 1049 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1050 | void Mir2Lir::GenThrow(RegLocation rl_src) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1051 | FlushAllRegs(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1052 | CallRuntimeHelperRegLocation(QUICK_ENTRYPOINT_OFFSET(4, pDeliverException), rl_src, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | // For final classes there are no sub-classes to check and so we can answer the instance-of |
| 1056 | // question with simple comparisons. |
| 1057 | void Mir2Lir::GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest, |
| 1058 | RegLocation rl_src) { |
Mark Mendell | df8ee2e | 2014-01-27 16:37:47 -0800 | [diff] [blame] | 1059 | // X86 has its own implementation. |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1060 | DCHECK(cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64); |
Mark Mendell | df8ee2e | 2014-01-27 16:37:47 -0800 | [diff] [blame] | 1061 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1062 | RegLocation object = LoadValue(rl_src, kCoreReg); |
| 1063 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1064 | RegStorage result_reg = rl_result.reg; |
| 1065 | if (result_reg == object.reg) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1066 | result_reg = AllocTypedTemp(false, kCoreReg); |
| 1067 | } |
| 1068 | LoadConstant(result_reg, 0); // assume false |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1069 | LIR* null_branchover = OpCmpImmBranch(kCondEq, object.reg, 0, NULL); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1070 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1071 | RegStorage check_class = AllocTypedTemp(false, kCoreReg); |
| 1072 | RegStorage object_class = AllocTypedTemp(false, kCoreReg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1073 | |
| 1074 | LoadCurrMethodDirect(check_class); |
| 1075 | if (use_declaring_class) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1076 | LoadRefDisp(check_class, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), check_class); |
| 1077 | LoadRefDisp(object.reg, mirror::Object::ClassOffset().Int32Value(), object_class); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1078 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1079 | LoadRefDisp(check_class, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), |
| 1080 | check_class); |
| 1081 | LoadRefDisp(object.reg, mirror::Object::ClassOffset().Int32Value(), object_class); |
Andreas Gampe | b5a14d2 | 2014-04-24 17:30:35 +0000 | [diff] [blame^] | 1082 | int32_t offset_of_type = |
| 1083 | mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + |
| 1084 | (sizeof(mirror::Class*) * type_idx); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1085 | LoadRefDisp(check_class, offset_of_type, check_class); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | LIR* ne_branchover = NULL; |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1089 | // FIXME: what should we be comparing here? compressed or decompressed references? |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1090 | if (cu_->instruction_set == kThumb2) { |
| 1091 | OpRegReg(kOpCmp, check_class, object_class); // Same? |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1092 | LIR* it = OpIT(kCondEq, ""); // if-convert the test |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1093 | LoadConstant(result_reg, 1); // .eq case - load true |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1094 | OpEndIT(it); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1095 | } else { |
| 1096 | ne_branchover = OpCmpBranch(kCondNe, check_class, object_class, NULL); |
| 1097 | LoadConstant(result_reg, 1); // eq case - load true |
| 1098 | } |
| 1099 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 1100 | null_branchover->target = target; |
| 1101 | if (ne_branchover != NULL) { |
| 1102 | ne_branchover->target = target; |
| 1103 | } |
| 1104 | FreeTemp(object_class); |
| 1105 | FreeTemp(check_class); |
| 1106 | if (IsTemp(result_reg)) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1107 | OpRegCopy(rl_result.reg, result_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1108 | FreeTemp(result_reg); |
| 1109 | } |
| 1110 | StoreValue(rl_dest, rl_result); |
| 1111 | } |
| 1112 | |
| 1113 | void Mir2Lir::GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final, |
| 1114 | bool type_known_abstract, bool use_declaring_class, |
| 1115 | bool can_assume_type_is_in_dex_cache, |
| 1116 | uint32_t type_idx, RegLocation rl_dest, |
| 1117 | RegLocation rl_src) { |
Mark Mendell | 6607d97 | 2014-02-10 06:54:18 -0800 | [diff] [blame] | 1118 | // X86 has its own implementation. |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1119 | DCHECK(cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64); |
Mark Mendell | 6607d97 | 2014-02-10 06:54:18 -0800 | [diff] [blame] | 1120 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1121 | FlushAllRegs(); |
| 1122 | // May generate a call - use explicit registers |
| 1123 | LockCallTemps(); |
| 1124 | LoadCurrMethodDirect(TargetReg(kArg1)); // kArg1 <= current Method* |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1125 | RegStorage class_reg = TargetReg(kArg2); // kArg2 will hold the Class* |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1126 | if (needs_access_check) { |
| 1127 | // Check we have access to type_idx and if not throw IllegalAccessError, |
| 1128 | // returns Class* in kArg0 |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1129 | CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(4, pInitializeTypeAndVerifyAccess), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1130 | type_idx, true); |
| 1131 | OpRegCopy(class_reg, TargetReg(kRet0)); // Align usage with fast path |
| 1132 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref |
| 1133 | } else if (use_declaring_class) { |
| 1134 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1135 | LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DeclaringClassOffset().Int32Value(), |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1136 | class_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1137 | } else { |
| 1138 | // Load dex cache entry into class_reg (kArg2) |
| 1139 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1140 | LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), |
| 1141 | class_reg); |
Andreas Gampe | b5a14d2 | 2014-04-24 17:30:35 +0000 | [diff] [blame^] | 1142 | int32_t offset_of_type = |
| 1143 | mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + (sizeof(mirror::Class*) |
| 1144 | * type_idx); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1145 | LoadRefDisp(class_reg, offset_of_type, class_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1146 | if (!can_assume_type_is_in_dex_cache) { |
| 1147 | // Need to test presence of type in dex cache at runtime |
| 1148 | LIR* hop_branch = OpCmpImmBranch(kCondNe, class_reg, 0, NULL); |
| 1149 | // Not resolved |
| 1150 | // Call out to helper, which will return resolved type in kRet0 |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1151 | CallRuntimeHelperImm(QUICK_ENTRYPOINT_OFFSET(4, pInitializeType), type_idx, true); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 1152 | OpRegCopy(TargetReg(kArg2), TargetReg(kRet0)); // Align usage with fast path |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1153 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); /* reload Ref */ |
| 1154 | // Rejoin code paths |
| 1155 | LIR* hop_target = NewLIR0(kPseudoTargetLabel); |
| 1156 | hop_branch->target = hop_target; |
| 1157 | } |
| 1158 | } |
| 1159 | /* kArg0 is ref, kArg2 is class. If ref==null, use directly as bool result */ |
| 1160 | RegLocation rl_result = GetReturn(false); |
| 1161 | if (cu_->instruction_set == kMips) { |
| 1162 | // On MIPS rArg0 != rl_result, place false in result if branch is taken. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1163 | LoadConstant(rl_result.reg, 0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1164 | } |
| 1165 | LIR* branch1 = OpCmpImmBranch(kCondEq, TargetReg(kArg0), 0, NULL); |
| 1166 | |
| 1167 | /* load object->klass_ */ |
| 1168 | DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1169 | LoadRefDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1170 | /* kArg0 is ref, kArg1 is ref->klass_, kArg2 is class */ |
| 1171 | LIR* branchover = NULL; |
| 1172 | if (type_known_final) { |
| 1173 | // rl_result == ref == null == 0. |
| 1174 | if (cu_->instruction_set == kThumb2) { |
| 1175 | OpRegReg(kOpCmp, TargetReg(kArg1), TargetReg(kArg2)); // Same? |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1176 | LIR* it = OpIT(kCondEq, "E"); // if-convert the test |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1177 | LoadConstant(rl_result.reg, 1); // .eq case - load true |
| 1178 | LoadConstant(rl_result.reg, 0); // .ne case - load false |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1179 | OpEndIT(it); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1180 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1181 | LoadConstant(rl_result.reg, 0); // ne case - load false |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1182 | branchover = OpCmpBranch(kCondNe, TargetReg(kArg1), TargetReg(kArg2), NULL); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1183 | LoadConstant(rl_result.reg, 1); // eq case - load true |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1184 | } |
| 1185 | } else { |
| 1186 | if (cu_->instruction_set == kThumb2) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1187 | RegStorage r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pInstanceofNonTrivial)); |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1188 | LIR* it = nullptr; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1189 | if (!type_known_abstract) { |
| 1190 | /* Uses conditional nullification */ |
| 1191 | OpRegReg(kOpCmp, TargetReg(kArg1), TargetReg(kArg2)); // Same? |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1192 | it = OpIT(kCondEq, "EE"); // if-convert the test |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1193 | LoadConstant(TargetReg(kArg0), 1); // .eq case - load true |
| 1194 | } |
| 1195 | OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .ne case - arg0 <= class |
| 1196 | OpReg(kOpBlx, r_tgt); // .ne case: helper(class, ref->class) |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 1197 | if (it != nullptr) { |
| 1198 | OpEndIT(it); |
| 1199 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1200 | FreeTemp(r_tgt); |
| 1201 | } else { |
| 1202 | if (!type_known_abstract) { |
| 1203 | /* Uses branchovers */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1204 | LoadConstant(rl_result.reg, 1); // assume true |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1205 | branchover = OpCmpBranch(kCondEq, TargetReg(kArg1), TargetReg(kArg2), NULL); |
| 1206 | } |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1207 | RegStorage r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pInstanceofNonTrivial)); |
Mark Mendell | 6607d97 | 2014-02-10 06:54:18 -0800 | [diff] [blame] | 1208 | OpRegCopy(TargetReg(kArg0), TargetReg(kArg2)); // .ne case - arg0 <= class |
| 1209 | OpReg(kOpBlx, r_tgt); // .ne case: helper(class, ref->class) |
| 1210 | FreeTemp(r_tgt); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | // TODO: only clobber when type isn't final? |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 1214 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1215 | /* branch targets here */ |
| 1216 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 1217 | StoreValue(rl_dest, rl_result); |
| 1218 | branch1->target = target; |
| 1219 | if (branchover != NULL) { |
| 1220 | branchover->target = target; |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | void Mir2Lir::GenInstanceof(uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src) { |
| 1225 | bool type_known_final, type_known_abstract, use_declaring_class; |
| 1226 | bool needs_access_check = !cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, |
| 1227 | *cu_->dex_file, |
| 1228 | type_idx, |
| 1229 | &type_known_final, |
| 1230 | &type_known_abstract, |
| 1231 | &use_declaring_class); |
| 1232 | bool can_assume_type_is_in_dex_cache = !needs_access_check && |
| 1233 | cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx); |
| 1234 | |
| 1235 | if ((use_declaring_class || can_assume_type_is_in_dex_cache) && type_known_final) { |
| 1236 | GenInstanceofFinal(use_declaring_class, type_idx, rl_dest, rl_src); |
| 1237 | } else { |
| 1238 | GenInstanceofCallingHelper(needs_access_check, type_known_final, type_known_abstract, |
| 1239 | use_declaring_class, can_assume_type_is_in_dex_cache, |
| 1240 | type_idx, rl_dest, rl_src); |
| 1241 | } |
| 1242 | } |
| 1243 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1244 | 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] | 1245 | bool type_known_final, type_known_abstract, use_declaring_class; |
| 1246 | bool needs_access_check = !cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, |
| 1247 | *cu_->dex_file, |
| 1248 | type_idx, |
| 1249 | &type_known_final, |
| 1250 | &type_known_abstract, |
| 1251 | &use_declaring_class); |
| 1252 | // Note: currently type_known_final is unused, as optimizing will only improve the performance |
| 1253 | // of the exception throw path. |
| 1254 | DexCompilationUnit* cu = mir_graph_->GetCurrentDexCompilationUnit(); |
Vladimir Marko | 2730db0 | 2014-01-27 11:15:17 +0000 | [diff] [blame] | 1255 | if (!needs_access_check && cu_->compiler_driver->IsSafeCast(cu, insn_idx)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1256 | // Verifier type analysis proved this check cast would never cause an exception. |
| 1257 | return; |
| 1258 | } |
| 1259 | FlushAllRegs(); |
| 1260 | // May generate a call - use explicit registers |
| 1261 | LockCallTemps(); |
| 1262 | LoadCurrMethodDirect(TargetReg(kArg1)); // kArg1 <= current Method* |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1263 | RegStorage class_reg = TargetReg(kArg2); // kArg2 will hold the Class* |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1264 | if (needs_access_check) { |
| 1265 | // Check we have access to type_idx and if not throw IllegalAccessError, |
| 1266 | // returns Class* in kRet0 |
| 1267 | // InitializeTypeAndVerifyAccess(idx, method) |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1268 | CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(4, pInitializeTypeAndVerifyAccess), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1269 | type_idx, TargetReg(kArg1), true); |
| 1270 | OpRegCopy(class_reg, TargetReg(kRet0)); // Align usage with fast path |
| 1271 | } else if (use_declaring_class) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1272 | LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DeclaringClassOffset().Int32Value(), |
| 1273 | class_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1274 | } else { |
| 1275 | // Load dex cache entry into class_reg (kArg2) |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1276 | LoadRefDisp(TargetReg(kArg1), mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), |
| 1277 | class_reg); |
Andreas Gampe | b5a14d2 | 2014-04-24 17:30:35 +0000 | [diff] [blame^] | 1278 | int32_t offset_of_type = |
| 1279 | mirror::Array::DataOffset(sizeof(mirror::Class*)).Int32Value() + |
| 1280 | (sizeof(mirror::Class*) * type_idx); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1281 | LoadRefDisp(class_reg, offset_of_type, class_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1282 | if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx)) { |
| 1283 | // Need to test presence of type in dex cache at runtime |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1284 | LIR* hop_branch = OpCmpImmBranch(kCondEq, class_reg, 0, NULL); |
| 1285 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
| 1286 | |
| 1287 | // Slow path to initialize the type. Executed if the type is NULL. |
| 1288 | class SlowPath : public LIRSlowPath { |
| 1289 | public: |
| 1290 | SlowPath(Mir2Lir* m2l, LIR* fromfast, LIR* cont, const int type_idx, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1291 | const RegStorage class_reg) : |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1292 | LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast, cont), type_idx_(type_idx), |
| 1293 | class_reg_(class_reg) { |
| 1294 | } |
| 1295 | |
| 1296 | void Compile() { |
| 1297 | GenerateTargetLabel(); |
| 1298 | |
| 1299 | // Call out to helper, which will return resolved type in kArg0 |
| 1300 | // InitializeTypeFromCode(idx, method) |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1301 | m2l_->CallRuntimeHelperImmReg(QUICK_ENTRYPOINT_OFFSET(4, pInitializeType), type_idx_, |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1302 | m2l_->TargetReg(kArg1), true); |
| 1303 | m2l_->OpRegCopy(class_reg_, m2l_->TargetReg(kRet0)); // Align usage with fast path |
| 1304 | m2l_->OpUnconditionalBranch(cont_); |
| 1305 | } |
| 1306 | public: |
| 1307 | const int type_idx_; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1308 | const RegStorage class_reg_; |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1309 | }; |
| 1310 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1311 | AddSlowPath(new (arena_) SlowPath(this, hop_branch, cont, type_idx, class_reg)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1312 | } |
| 1313 | } |
| 1314 | // At this point, class_reg (kArg2) has class |
| 1315 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); // kArg0 <= ref |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1316 | |
| 1317 | // Slow path for the case where the classes are not equal. In this case we need |
| 1318 | // to call a helper function to do the check. |
| 1319 | class SlowPath : public LIRSlowPath { |
| 1320 | public: |
| 1321 | SlowPath(Mir2Lir* m2l, LIR* fromfast, LIR* cont, bool load): |
| 1322 | LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast, cont), load_(load) { |
| 1323 | } |
| 1324 | |
| 1325 | void Compile() { |
| 1326 | GenerateTargetLabel(); |
| 1327 | |
| 1328 | if (load_) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1329 | m2l_->LoadRefDisp(m2l_->TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), |
| 1330 | m2l_->TargetReg(kArg1)); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1331 | } |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1332 | m2l_->CallRuntimeHelperRegReg(QUICK_ENTRYPOINT_OFFSET(4, pCheckCast), m2l_->TargetReg(kArg2), |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1333 | m2l_->TargetReg(kArg1), true); |
| 1334 | |
| 1335 | m2l_->OpUnconditionalBranch(cont_); |
| 1336 | } |
| 1337 | |
| 1338 | private: |
| 1339 | bool load_; |
| 1340 | }; |
| 1341 | |
| 1342 | if (type_known_abstract) { |
| 1343 | // Easier case, run slow path if target is non-null (slow path will load from target) |
| 1344 | LIR* branch = OpCmpImmBranch(kCondNe, TargetReg(kArg0), 0, NULL); |
| 1345 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
| 1346 | AddSlowPath(new (arena_) SlowPath(this, branch, cont, true)); |
| 1347 | } else { |
| 1348 | // Harder, more common case. We need to generate a forward branch over the load |
| 1349 | // if the target is null. If it's non-null we perform the load and branch to the |
| 1350 | // slow path if the classes are not equal. |
| 1351 | |
| 1352 | /* Null is OK - continue */ |
| 1353 | LIR* branch1 = OpCmpImmBranch(kCondEq, TargetReg(kArg0), 0, NULL); |
| 1354 | /* load object->klass_ */ |
| 1355 | DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1356 | LoadRefDisp(TargetReg(kArg0), mirror::Object::ClassOffset().Int32Value(), TargetReg(kArg1)); |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1357 | |
| 1358 | LIR* branch2 = OpCmpBranch(kCondNe, TargetReg(kArg1), class_reg, NULL); |
| 1359 | LIR* cont = NewLIR0(kPseudoTargetLabel); |
| 1360 | |
| 1361 | // Add the slow path that will not perform load since this is already done. |
| 1362 | AddSlowPath(new (arena_) SlowPath(this, branch2, cont, false)); |
| 1363 | |
| 1364 | // Set the null check to branch to the continuation. |
| 1365 | branch1->target = cont; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | void Mir2Lir::GenLong3Addr(OpKind first_op, OpKind second_op, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1370 | RegLocation rl_src1, RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1371 | RegLocation rl_result; |
| 1372 | if (cu_->instruction_set == kThumb2) { |
| 1373 | /* |
| 1374 | * NOTE: This is the one place in the code in which we might have |
| 1375 | * as many as six live temporary registers. There are 5 in the normal |
| 1376 | * set for Arm. Until we have spill capabilities, temporarily add |
| 1377 | * lr to the temp set. It is safe to do this locally, but note that |
| 1378 | * lr is used explicitly elsewhere in the code generator and cannot |
| 1379 | * normally be used as a general temp register. |
| 1380 | */ |
| 1381 | MarkTemp(TargetReg(kLr)); // Add lr to the temp pool |
| 1382 | FreeTemp(TargetReg(kLr)); // and make it available |
| 1383 | } |
| 1384 | rl_src1 = LoadValueWide(rl_src1, kCoreReg); |
| 1385 | rl_src2 = LoadValueWide(rl_src2, kCoreReg); |
| 1386 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1387 | // The longs may overlap - use intermediate temp if so |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1388 | if ((rl_result.reg.GetLowReg() == rl_src1.reg.GetHighReg()) || (rl_result.reg.GetLowReg() == rl_src2.reg.GetHighReg())) { |
| 1389 | RegStorage t_reg = AllocTemp(); |
| 1390 | OpRegRegReg(first_op, t_reg, rl_src1.reg.GetLow(), rl_src2.reg.GetLow()); |
| 1391 | OpRegRegReg(second_op, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), rl_src2.reg.GetHigh()); |
| 1392 | OpRegCopy(rl_result.reg.GetLow(), t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1393 | FreeTemp(t_reg); |
| 1394 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1395 | OpRegRegReg(first_op, rl_result.reg.GetLow(), rl_src1.reg.GetLow(), rl_src2.reg.GetLow()); |
| 1396 | 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] | 1397 | } |
| 1398 | /* |
| 1399 | * NOTE: If rl_dest refers to a frame variable in a large frame, the |
| 1400 | * following StoreValueWide might need to allocate a temp register. |
| 1401 | * To further work around the lack of a spill capability, explicitly |
| 1402 | * free any temps from rl_src1 & rl_src2 that aren't still live in rl_result. |
| 1403 | * Remove when spill is functional. |
| 1404 | */ |
| 1405 | FreeRegLocTemps(rl_result, rl_src1); |
| 1406 | FreeRegLocTemps(rl_result, rl_src2); |
| 1407 | StoreValueWide(rl_dest, rl_result); |
| 1408 | if (cu_->instruction_set == kThumb2) { |
| 1409 | Clobber(TargetReg(kLr)); |
| 1410 | UnmarkTemp(TargetReg(kLr)); // Remove lr from the temp pool |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | |
| 1415 | void Mir2Lir::GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1416 | RegLocation rl_src1, RegLocation rl_shift) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1417 | ThreadOffset<4> func_offset(-1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1418 | |
| 1419 | switch (opcode) { |
| 1420 | case Instruction::SHL_LONG: |
| 1421 | case Instruction::SHL_LONG_2ADDR: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1422 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pShlLong); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1423 | break; |
| 1424 | case Instruction::SHR_LONG: |
| 1425 | case Instruction::SHR_LONG_2ADDR: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1426 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pShrLong); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1427 | break; |
| 1428 | case Instruction::USHR_LONG: |
| 1429 | case Instruction::USHR_LONG_2ADDR: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1430 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pUshrLong); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1431 | break; |
| 1432 | default: |
| 1433 | LOG(FATAL) << "Unexpected case"; |
| 1434 | } |
| 1435 | FlushAllRegs(); /* Send everything to home location */ |
| 1436 | CallRuntimeHelperRegLocationRegLocation(func_offset, rl_src1, rl_shift, false); |
| 1437 | RegLocation rl_result = GetReturnWide(false); |
| 1438 | StoreValueWide(rl_dest, rl_result); |
| 1439 | } |
| 1440 | |
| 1441 | |
| 1442 | void Mir2Lir::GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1443 | RegLocation rl_src1, RegLocation rl_src2) { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1444 | DCHECK(cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1445 | OpKind op = kOpBkpt; |
| 1446 | bool is_div_rem = false; |
| 1447 | bool check_zero = false; |
| 1448 | bool unary = false; |
| 1449 | RegLocation rl_result; |
| 1450 | bool shift_op = false; |
| 1451 | switch (opcode) { |
| 1452 | case Instruction::NEG_INT: |
| 1453 | op = kOpNeg; |
| 1454 | unary = true; |
| 1455 | break; |
| 1456 | case Instruction::NOT_INT: |
| 1457 | op = kOpMvn; |
| 1458 | unary = true; |
| 1459 | break; |
| 1460 | case Instruction::ADD_INT: |
| 1461 | case Instruction::ADD_INT_2ADDR: |
| 1462 | op = kOpAdd; |
| 1463 | break; |
| 1464 | case Instruction::SUB_INT: |
| 1465 | case Instruction::SUB_INT_2ADDR: |
| 1466 | op = kOpSub; |
| 1467 | break; |
| 1468 | case Instruction::MUL_INT: |
| 1469 | case Instruction::MUL_INT_2ADDR: |
| 1470 | op = kOpMul; |
| 1471 | break; |
| 1472 | case Instruction::DIV_INT: |
| 1473 | case Instruction::DIV_INT_2ADDR: |
| 1474 | check_zero = true; |
| 1475 | op = kOpDiv; |
| 1476 | is_div_rem = true; |
| 1477 | break; |
| 1478 | /* NOTE: returns in kArg1 */ |
| 1479 | case Instruction::REM_INT: |
| 1480 | case Instruction::REM_INT_2ADDR: |
| 1481 | check_zero = true; |
| 1482 | op = kOpRem; |
| 1483 | is_div_rem = true; |
| 1484 | break; |
| 1485 | case Instruction::AND_INT: |
| 1486 | case Instruction::AND_INT_2ADDR: |
| 1487 | op = kOpAnd; |
| 1488 | break; |
| 1489 | case Instruction::OR_INT: |
| 1490 | case Instruction::OR_INT_2ADDR: |
| 1491 | op = kOpOr; |
| 1492 | break; |
| 1493 | case Instruction::XOR_INT: |
| 1494 | case Instruction::XOR_INT_2ADDR: |
| 1495 | op = kOpXor; |
| 1496 | break; |
| 1497 | case Instruction::SHL_INT: |
| 1498 | case Instruction::SHL_INT_2ADDR: |
| 1499 | shift_op = true; |
| 1500 | op = kOpLsl; |
| 1501 | break; |
| 1502 | case Instruction::SHR_INT: |
| 1503 | case Instruction::SHR_INT_2ADDR: |
| 1504 | shift_op = true; |
| 1505 | op = kOpAsr; |
| 1506 | break; |
| 1507 | case Instruction::USHR_INT: |
| 1508 | case Instruction::USHR_INT_2ADDR: |
| 1509 | shift_op = true; |
| 1510 | op = kOpLsr; |
| 1511 | break; |
| 1512 | default: |
| 1513 | LOG(FATAL) << "Invalid word arith op: " << opcode; |
| 1514 | } |
| 1515 | if (!is_div_rem) { |
| 1516 | if (unary) { |
| 1517 | rl_src1 = LoadValue(rl_src1, kCoreReg); |
| 1518 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1519 | OpRegReg(op, rl_result.reg, rl_src1.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1520 | } else { |
| 1521 | if (shift_op) { |
Mark Mendell | feb2b4e | 2014-01-28 12:59:49 -0800 | [diff] [blame] | 1522 | rl_src2 = LoadValue(rl_src2, kCoreReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1523 | RegStorage t_reg = AllocTemp(); |
| 1524 | OpRegRegImm(kOpAnd, t_reg, rl_src2.reg, 31); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1525 | rl_src1 = LoadValue(rl_src1, kCoreReg); |
| 1526 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1527 | OpRegRegReg(op, rl_result.reg, rl_src1.reg, t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1528 | FreeTemp(t_reg); |
| 1529 | } else { |
| 1530 | rl_src1 = LoadValue(rl_src1, kCoreReg); |
| 1531 | rl_src2 = LoadValue(rl_src2, kCoreReg); |
| 1532 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1533 | OpRegRegReg(op, rl_result.reg, rl_src1.reg, rl_src2.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1534 | } |
| 1535 | } |
| 1536 | StoreValue(rl_dest, rl_result); |
| 1537 | } else { |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1538 | 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] | 1539 | if (cu_->instruction_set == kMips) { |
| 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); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -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 | } else if (cu_->instruction_set == kThumb2) { |
| 1548 | if (cu_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 1549 | // Use ARM SDIV instruction for division. For remainder we also need to |
| 1550 | // calculate using a MUL and subtract. |
| 1551 | rl_src1 = LoadValue(rl_src1, kCoreReg); |
| 1552 | rl_src2 = LoadValue(rl_src2, kCoreReg); |
| 1553 | if (check_zero) { |
Mingyao Yang | d15f4e2 | 2014-04-17 18:46:24 -0700 | [diff] [blame] | 1554 | GenDivZeroCheck(rl_src2.reg); |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1555 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1556 | 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] | 1557 | done = true; |
| 1558 | } |
| 1559 | } |
| 1560 | |
| 1561 | // If we haven't already generated the code use the callout function. |
| 1562 | if (!done) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1563 | ThreadOffset<4> func_offset = QUICK_ENTRYPOINT_OFFSET(4, pIdivmod); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1564 | FlushAllRegs(); /* Send everything to home location */ |
| 1565 | LoadValueDirectFixed(rl_src2, TargetReg(kArg1)); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1566 | RegStorage r_tgt = CallHelperSetup(func_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1567 | LoadValueDirectFixed(rl_src1, TargetReg(kArg0)); |
| 1568 | if (check_zero) { |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 1569 | GenDivZeroCheck(TargetReg(kArg1)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1570 | } |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1571 | // NOTE: callout here is not a safepoint. |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 1572 | CallHelper(r_tgt, func_offset, false /* not a safepoint */); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1573 | if (op == kOpDiv) |
| 1574 | rl_result = GetReturn(false); |
| 1575 | else |
| 1576 | rl_result = GetReturnAlt(); |
| 1577 | } |
| 1578 | StoreValue(rl_dest, rl_result); |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | /* |
| 1583 | * The following are the first-level codegen routines that analyze the format |
| 1584 | * of each bytecode then either dispatch special purpose codegen routines |
| 1585 | * or produce corresponding Thumb instructions directly. |
| 1586 | */ |
| 1587 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1588 | // Returns true if no more than two bits are set in 'x'. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1589 | static bool IsPopCountLE2(unsigned int x) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1590 | x &= x - 1; |
| 1591 | return (x & (x - 1)) == 0; |
| 1592 | } |
| 1593 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1594 | // Returns true if it added instructions to 'cu' to divide 'rl_src' by 'lit' |
| 1595 | // and store the result in 'rl_dest'. |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1596 | bool Mir2Lir::HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1597 | RegLocation rl_src, RegLocation rl_dest, int lit) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1598 | if ((lit < 2) || ((cu_->instruction_set != kThumb2) && !IsPowerOfTwo(lit))) { |
| 1599 | return false; |
| 1600 | } |
| 1601 | // No divide instruction for Arm, so check for more special cases |
| 1602 | if ((cu_->instruction_set == kThumb2) && !IsPowerOfTwo(lit)) { |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1603 | return SmallLiteralDivRem(dalvik_opcode, is_div, rl_src, rl_dest, lit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1604 | } |
| 1605 | int k = LowestSetBit(lit); |
| 1606 | if (k >= 30) { |
| 1607 | // Avoid special cases. |
| 1608 | return false; |
| 1609 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1610 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1611 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1612 | if (is_div) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1613 | RegStorage t_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1614 | if (lit == 2) { |
| 1615 | // Division by 2 is by far the most common division by constant. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1616 | OpRegRegImm(kOpLsr, t_reg, rl_src.reg, 32 - k); |
| 1617 | OpRegRegReg(kOpAdd, t_reg, t_reg, rl_src.reg); |
| 1618 | OpRegRegImm(kOpAsr, rl_result.reg, t_reg, k); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1619 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1620 | OpRegRegImm(kOpAsr, t_reg, rl_src.reg, 31); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1621 | OpRegRegImm(kOpLsr, t_reg, t_reg, 32 - k); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1622 | OpRegRegReg(kOpAdd, t_reg, t_reg, rl_src.reg); |
| 1623 | OpRegRegImm(kOpAsr, rl_result.reg, t_reg, k); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1624 | } |
| 1625 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1626 | RegStorage t_reg1 = AllocTemp(); |
| 1627 | RegStorage t_reg2 = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1628 | if (lit == 2) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1629 | OpRegRegImm(kOpLsr, t_reg1, rl_src.reg, 32 - k); |
| 1630 | OpRegRegReg(kOpAdd, t_reg2, t_reg1, rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1631 | OpRegRegImm(kOpAnd, t_reg2, t_reg2, lit -1); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1632 | OpRegRegReg(kOpSub, rl_result.reg, t_reg2, t_reg1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1633 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1634 | OpRegRegImm(kOpAsr, t_reg1, rl_src.reg, 31); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1635 | OpRegRegImm(kOpLsr, t_reg1, t_reg1, 32 - k); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1636 | OpRegRegReg(kOpAdd, t_reg2, t_reg1, rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1637 | OpRegRegImm(kOpAnd, t_reg2, t_reg2, lit - 1); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1638 | OpRegRegReg(kOpSub, rl_result.reg, t_reg2, t_reg1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1639 | } |
| 1640 | } |
| 1641 | StoreValue(rl_dest, rl_result); |
| 1642 | return true; |
| 1643 | } |
| 1644 | |
| 1645 | // Returns true if it added instructions to 'cu' to multiply 'rl_src' by 'lit' |
| 1646 | // and store the result in 'rl_dest'. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1647 | bool Mir2Lir::HandleEasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) { |
Ian Rogers | e2143c0 | 2014-03-28 08:47:16 -0700 | [diff] [blame] | 1648 | if (lit < 0) { |
| 1649 | return false; |
| 1650 | } |
| 1651 | if (lit == 0) { |
| 1652 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1653 | LoadConstant(rl_result.reg, 0); |
| 1654 | StoreValue(rl_dest, rl_result); |
| 1655 | return true; |
| 1656 | } |
| 1657 | if (lit == 1) { |
| 1658 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1659 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1660 | OpRegCopy(rl_result.reg, rl_src.reg); |
| 1661 | StoreValue(rl_dest, rl_result); |
| 1662 | return true; |
| 1663 | } |
Zheng Xu | f9719f9 | 2014-04-02 13:31:31 +0100 | [diff] [blame] | 1664 | // There is RegRegRegShift on Arm, so check for more special cases |
| 1665 | if (cu_->instruction_set == kThumb2) { |
Ian Rogers | e2143c0 | 2014-03-28 08:47:16 -0700 | [diff] [blame] | 1666 | return EasyMultiply(rl_src, rl_dest, lit); |
| 1667 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1668 | // Can we simplify this multiplication? |
| 1669 | bool power_of_two = false; |
| 1670 | bool pop_count_le2 = false; |
| 1671 | bool power_of_two_minus_one = false; |
Ian Rogers | e2143c0 | 2014-03-28 08:47:16 -0700 | [diff] [blame] | 1672 | if (IsPowerOfTwo(lit)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1673 | power_of_two = true; |
| 1674 | } else if (IsPopCountLE2(lit)) { |
| 1675 | pop_count_le2 = true; |
| 1676 | } else if (IsPowerOfTwo(lit + 1)) { |
| 1677 | power_of_two_minus_one = true; |
| 1678 | } else { |
| 1679 | return false; |
| 1680 | } |
| 1681 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1682 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1683 | if (power_of_two) { |
| 1684 | // Shift. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1685 | OpRegRegImm(kOpLsl, rl_result.reg, rl_src.reg, LowestSetBit(lit)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1686 | } else if (pop_count_le2) { |
| 1687 | // Shift and add and shift. |
| 1688 | int first_bit = LowestSetBit(lit); |
| 1689 | int second_bit = LowestSetBit(lit ^ (1 << first_bit)); |
| 1690 | GenMultiplyByTwoBitMultiplier(rl_src, rl_result, lit, first_bit, second_bit); |
| 1691 | } else { |
| 1692 | // Reverse subtract: (src << (shift + 1)) - src. |
| 1693 | DCHECK(power_of_two_minus_one); |
| 1694 | // TUNING: rsb dst, src, src lsl#LowestSetBit(lit + 1) |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1695 | RegStorage t_reg = AllocTemp(); |
| 1696 | OpRegRegImm(kOpLsl, t_reg, rl_src.reg, LowestSetBit(lit + 1)); |
| 1697 | OpRegRegReg(kOpSub, rl_result.reg, t_reg, rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1698 | } |
| 1699 | StoreValue(rl_dest, rl_result); |
| 1700 | return true; |
| 1701 | } |
| 1702 | |
| 1703 | void Mir2Lir::GenArithOpIntLit(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1704 | int lit) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1705 | RegLocation rl_result; |
| 1706 | OpKind op = static_cast<OpKind>(0); /* Make gcc happy */ |
| 1707 | int shift_op = false; |
| 1708 | bool is_div = false; |
| 1709 | |
| 1710 | switch (opcode) { |
| 1711 | case Instruction::RSUB_INT_LIT8: |
| 1712 | case Instruction::RSUB_INT: { |
| 1713 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1714 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1715 | if (cu_->instruction_set == kThumb2) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1716 | OpRegRegImm(kOpRsub, rl_result.reg, rl_src.reg, lit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1717 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1718 | OpRegReg(kOpNeg, rl_result.reg, rl_src.reg); |
| 1719 | OpRegImm(kOpAdd, rl_result.reg, lit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1720 | } |
| 1721 | StoreValue(rl_dest, rl_result); |
| 1722 | return; |
| 1723 | } |
| 1724 | |
| 1725 | case Instruction::SUB_INT: |
| 1726 | case Instruction::SUB_INT_2ADDR: |
| 1727 | lit = -lit; |
| 1728 | // Intended fallthrough |
| 1729 | case Instruction::ADD_INT: |
| 1730 | case Instruction::ADD_INT_2ADDR: |
| 1731 | case Instruction::ADD_INT_LIT8: |
| 1732 | case Instruction::ADD_INT_LIT16: |
| 1733 | op = kOpAdd; |
| 1734 | break; |
| 1735 | case Instruction::MUL_INT: |
| 1736 | case Instruction::MUL_INT_2ADDR: |
| 1737 | case Instruction::MUL_INT_LIT8: |
| 1738 | case Instruction::MUL_INT_LIT16: { |
| 1739 | if (HandleEasyMultiply(rl_src, rl_dest, lit)) { |
| 1740 | return; |
| 1741 | } |
| 1742 | op = kOpMul; |
| 1743 | break; |
| 1744 | } |
| 1745 | case Instruction::AND_INT: |
| 1746 | case Instruction::AND_INT_2ADDR: |
| 1747 | case Instruction::AND_INT_LIT8: |
| 1748 | case Instruction::AND_INT_LIT16: |
| 1749 | op = kOpAnd; |
| 1750 | break; |
| 1751 | case Instruction::OR_INT: |
| 1752 | case Instruction::OR_INT_2ADDR: |
| 1753 | case Instruction::OR_INT_LIT8: |
| 1754 | case Instruction::OR_INT_LIT16: |
| 1755 | op = kOpOr; |
| 1756 | break; |
| 1757 | case Instruction::XOR_INT: |
| 1758 | case Instruction::XOR_INT_2ADDR: |
| 1759 | case Instruction::XOR_INT_LIT8: |
| 1760 | case Instruction::XOR_INT_LIT16: |
| 1761 | op = kOpXor; |
| 1762 | break; |
| 1763 | case Instruction::SHL_INT_LIT8: |
| 1764 | case Instruction::SHL_INT: |
| 1765 | case Instruction::SHL_INT_2ADDR: |
| 1766 | lit &= 31; |
| 1767 | shift_op = true; |
| 1768 | op = kOpLsl; |
| 1769 | break; |
| 1770 | case Instruction::SHR_INT_LIT8: |
| 1771 | case Instruction::SHR_INT: |
| 1772 | case Instruction::SHR_INT_2ADDR: |
| 1773 | lit &= 31; |
| 1774 | shift_op = true; |
| 1775 | op = kOpAsr; |
| 1776 | break; |
| 1777 | case Instruction::USHR_INT_LIT8: |
| 1778 | case Instruction::USHR_INT: |
| 1779 | case Instruction::USHR_INT_2ADDR: |
| 1780 | lit &= 31; |
| 1781 | shift_op = true; |
| 1782 | op = kOpLsr; |
| 1783 | break; |
| 1784 | |
| 1785 | case Instruction::DIV_INT: |
| 1786 | case Instruction::DIV_INT_2ADDR: |
| 1787 | case Instruction::DIV_INT_LIT8: |
| 1788 | case Instruction::DIV_INT_LIT16: |
| 1789 | case Instruction::REM_INT: |
| 1790 | case Instruction::REM_INT_2ADDR: |
| 1791 | case Instruction::REM_INT_LIT8: |
| 1792 | case Instruction::REM_INT_LIT16: { |
| 1793 | if (lit == 0) { |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 1794 | GenDivZeroException(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1795 | return; |
| 1796 | } |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1797 | if ((opcode == Instruction::DIV_INT) || |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1798 | (opcode == Instruction::DIV_INT_2ADDR) || |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1799 | (opcode == Instruction::DIV_INT_LIT8) || |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1800 | (opcode == Instruction::DIV_INT_LIT16)) { |
| 1801 | is_div = true; |
| 1802 | } else { |
| 1803 | is_div = false; |
| 1804 | } |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 1805 | if (HandleEasyDivRem(opcode, is_div, rl_src, rl_dest, lit)) { |
| 1806 | return; |
| 1807 | } |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1808 | |
| 1809 | bool done = false; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1810 | if (cu_->instruction_set == kMips) { |
| 1811 | rl_src = LoadValue(rl_src, kCoreReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1812 | rl_result = GenDivRemLit(rl_dest, rl_src.reg, lit, is_div); |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1813 | done = true; |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1814 | } else if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Mark Mendell | 2bf31e6 | 2014-01-23 12:13:40 -0800 | [diff] [blame] | 1815 | rl_result = GenDivRemLit(rl_dest, rl_src, lit, is_div); |
| 1816 | done = true; |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1817 | } else if (cu_->instruction_set == kThumb2) { |
| 1818 | if (cu_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 1819 | // Use ARM SDIV instruction for division. For remainder we also need to |
| 1820 | // calculate using a MUL and subtract. |
| 1821 | rl_src = LoadValue(rl_src, kCoreReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1822 | rl_result = GenDivRemLit(rl_dest, rl_src.reg, lit, is_div); |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1823 | done = true; |
| 1824 | } |
| 1825 | } |
| 1826 | |
| 1827 | if (!done) { |
| 1828 | FlushAllRegs(); /* Everything to home location. */ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1829 | LoadValueDirectFixed(rl_src, TargetReg(kArg0)); |
| 1830 | Clobber(TargetReg(kArg0)); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1831 | ThreadOffset<4> func_offset = QUICK_ENTRYPOINT_OFFSET(4, pIdivmod); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1832 | CallRuntimeHelperRegImm(func_offset, TargetReg(kArg0), lit, false); |
| 1833 | if (is_div) |
| 1834 | rl_result = GetReturn(false); |
| 1835 | else |
| 1836 | rl_result = GetReturnAlt(); |
| 1837 | } |
| 1838 | StoreValue(rl_dest, rl_result); |
| 1839 | return; |
| 1840 | } |
| 1841 | default: |
| 1842 | LOG(FATAL) << "Unexpected opcode " << opcode; |
| 1843 | } |
| 1844 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1845 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame] | 1846 | // Avoid shifts by literal 0 - no support in Thumb. Change to copy. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1847 | if (shift_op && (lit == 0)) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1848 | OpRegCopy(rl_result.reg, rl_src.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1849 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1850 | OpRegRegImm(op, rl_result.reg, rl_src.reg, lit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1851 | } |
| 1852 | StoreValue(rl_dest, rl_result); |
| 1853 | } |
| 1854 | |
| 1855 | void Mir2Lir::GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1856 | RegLocation rl_src1, RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1857 | RegLocation rl_result; |
| 1858 | OpKind first_op = kOpBkpt; |
| 1859 | OpKind second_op = kOpBkpt; |
| 1860 | bool call_out = false; |
| 1861 | bool check_zero = false; |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1862 | ThreadOffset<4> func_offset(-1); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1863 | int ret_reg = TargetReg(kRet0).GetReg(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1864 | |
| 1865 | switch (opcode) { |
| 1866 | case Instruction::NOT_LONG: |
| 1867 | rl_src2 = LoadValueWide(rl_src2, kCoreReg); |
| 1868 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1869 | // Check for destructive overlap |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1870 | if (rl_result.reg.GetLowReg() == rl_src2.reg.GetHighReg()) { |
| 1871 | RegStorage t_reg = AllocTemp(); |
| 1872 | OpRegCopy(t_reg, rl_src2.reg.GetHigh()); |
| 1873 | OpRegReg(kOpMvn, rl_result.reg.GetLow(), rl_src2.reg.GetLow()); |
| 1874 | OpRegReg(kOpMvn, rl_result.reg.GetHigh(), t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1875 | FreeTemp(t_reg); |
| 1876 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1877 | OpRegReg(kOpMvn, rl_result.reg.GetLow(), rl_src2.reg.GetLow()); |
| 1878 | OpRegReg(kOpMvn, rl_result.reg.GetHigh(), rl_src2.reg.GetHigh()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1879 | } |
| 1880 | StoreValueWide(rl_dest, rl_result); |
| 1881 | return; |
| 1882 | case Instruction::ADD_LONG: |
| 1883 | case Instruction::ADD_LONG_2ADDR: |
| 1884 | if (cu_->instruction_set != kThumb2) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1885 | GenAddLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1886 | return; |
| 1887 | } |
| 1888 | first_op = kOpAdd; |
| 1889 | second_op = kOpAdc; |
| 1890 | break; |
| 1891 | case Instruction::SUB_LONG: |
| 1892 | case Instruction::SUB_LONG_2ADDR: |
| 1893 | if (cu_->instruction_set != kThumb2) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1894 | GenSubLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1895 | return; |
| 1896 | } |
| 1897 | first_op = kOpSub; |
| 1898 | second_op = kOpSbc; |
| 1899 | break; |
| 1900 | case Instruction::MUL_LONG: |
| 1901 | case Instruction::MUL_LONG_2ADDR: |
Mark Mendell | 4708dcd | 2014-01-22 09:05:18 -0800 | [diff] [blame] | 1902 | if (cu_->instruction_set != kMips) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1903 | GenMulLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1904 | return; |
| 1905 | } else { |
| 1906 | call_out = true; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1907 | ret_reg = TargetReg(kRet0).GetReg(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1908 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pLmul); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1909 | } |
| 1910 | break; |
| 1911 | case Instruction::DIV_LONG: |
| 1912 | case Instruction::DIV_LONG_2ADDR: |
| 1913 | call_out = true; |
| 1914 | check_zero = true; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1915 | ret_reg = TargetReg(kRet0).GetReg(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1916 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pLdiv); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1917 | break; |
| 1918 | case Instruction::REM_LONG: |
| 1919 | case Instruction::REM_LONG_2ADDR: |
| 1920 | call_out = true; |
| 1921 | check_zero = true; |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1922 | func_offset = QUICK_ENTRYPOINT_OFFSET(4, pLmod); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1923 | /* NOTE - for Arm, result is in kArg2/kArg3 instead of kRet0/kRet1 */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1924 | ret_reg = (cu_->instruction_set == kThumb2) ? TargetReg(kArg2).GetReg() : TargetReg(kRet0).GetReg(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1925 | break; |
| 1926 | case Instruction::AND_LONG_2ADDR: |
| 1927 | case Instruction::AND_LONG: |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1928 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1929 | return GenAndLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1930 | } |
| 1931 | first_op = kOpAnd; |
| 1932 | second_op = kOpAnd; |
| 1933 | break; |
| 1934 | case Instruction::OR_LONG: |
| 1935 | case Instruction::OR_LONG_2ADDR: |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1936 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1937 | GenOrLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1938 | return; |
| 1939 | } |
| 1940 | first_op = kOpOr; |
| 1941 | second_op = kOpOr; |
| 1942 | break; |
| 1943 | case Instruction::XOR_LONG: |
| 1944 | case Instruction::XOR_LONG_2ADDR: |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1945 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 1946 | GenXorLong(opcode, rl_dest, rl_src1, rl_src2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1947 | return; |
| 1948 | } |
| 1949 | first_op = kOpXor; |
| 1950 | second_op = kOpXor; |
| 1951 | break; |
| 1952 | case Instruction::NEG_LONG: { |
| 1953 | GenNegLong(rl_dest, rl_src2); |
| 1954 | return; |
| 1955 | } |
| 1956 | default: |
| 1957 | LOG(FATAL) << "Invalid long arith op"; |
| 1958 | } |
| 1959 | if (!call_out) { |
| 1960 | GenLong3Addr(first_op, second_op, rl_dest, rl_src1, rl_src2); |
| 1961 | } else { |
| 1962 | FlushAllRegs(); /* Send everything to home location */ |
| 1963 | if (check_zero) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1964 | RegStorage r_tmp1 = RegStorage::MakeRegPair(TargetReg(kArg0), TargetReg(kArg1)); |
| 1965 | RegStorage r_tmp2 = RegStorage::MakeRegPair(TargetReg(kArg2), TargetReg(kArg3)); |
| 1966 | LoadValueDirectWideFixed(rl_src2, r_tmp2); |
| 1967 | RegStorage r_tgt = CallHelperSetup(func_offset); |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 1968 | GenDivZeroCheckWide(RegStorage::MakeRegPair(TargetReg(kArg2), TargetReg(kArg3))); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1969 | LoadValueDirectWideFixed(rl_src1, r_tmp1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1970 | // NOTE: callout here is not a safepoint |
| 1971 | CallHelper(r_tgt, func_offset, false /* not safepoint */); |
| 1972 | } else { |
| 1973 | CallRuntimeHelperRegLocationRegLocation(func_offset, rl_src1, rl_src2, false); |
| 1974 | } |
| 1975 | // Adjust return regs in to handle case of rem returning kArg2/kArg3 |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1976 | if (ret_reg == TargetReg(kRet0).GetReg()) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1977 | rl_result = GetReturnWide(false); |
| 1978 | else |
| 1979 | rl_result = GetReturnWideAlt(); |
| 1980 | StoreValueWide(rl_dest, rl_result); |
| 1981 | } |
| 1982 | } |
| 1983 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1984 | void Mir2Lir::GenConversionCall(ThreadOffset<4> func_offset, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1985 | RegLocation rl_dest, RegLocation rl_src) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1986 | /* |
| 1987 | * Don't optimize the register usage since it calls out to support |
| 1988 | * functions |
| 1989 | */ |
| 1990 | FlushAllRegs(); /* Send everything to home location */ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1991 | CallRuntimeHelperRegLocation(func_offset, rl_src, false); |
| 1992 | if (rl_dest.wide) { |
| 1993 | RegLocation rl_result; |
| 1994 | rl_result = GetReturnWide(rl_dest.fp); |
| 1995 | StoreValueWide(rl_dest, rl_result); |
| 1996 | } else { |
| 1997 | RegLocation rl_result; |
| 1998 | rl_result = GetReturn(rl_dest.fp); |
| 1999 | StoreValue(rl_dest, rl_result); |
| 2000 | } |
| 2001 | } |
| 2002 | |
| 2003 | /* Check if we need to check for pending suspend request */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 2004 | void Mir2Lir::GenSuspendTest(int opt_flags) { |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 2005 | if (Runtime::Current()->ExplicitSuspendChecks()) { |
| 2006 | if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) { |
| 2007 | return; |
| 2008 | } |
| 2009 | FlushAllRegs(); |
| 2010 | LIR* branch = OpTestSuspend(NULL); |
| 2011 | LIR* ret_lab = NewLIR0(kPseudoTargetLabel); |
| 2012 | LIR* target = RawLIR(current_dalvik_offset_, kPseudoSuspendTarget, WrapPointer(ret_lab), |
| 2013 | current_dalvik_offset_); |
| 2014 | branch->target = target; |
| 2015 | suspend_launchpads_.Insert(target); |
| 2016 | } else { |
| 2017 | if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) { |
| 2018 | return; |
| 2019 | } |
| 2020 | FlushAllRegs(); // TODO: needed? |
| 2021 | LIR* inst = CheckSuspendUsingLoad(); |
| 2022 | MarkSafepointPC(inst); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2023 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | /* Check if we need to check for pending suspend request */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 2027 | void Mir2Lir::GenSuspendTestAndBranch(int opt_flags, LIR* target) { |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 2028 | if (Runtime::Current()->ExplicitSuspendChecks()) { |
| 2029 | if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) { |
| 2030 | OpUnconditionalBranch(target); |
| 2031 | return; |
| 2032 | } |
| 2033 | OpTestSuspend(target); |
| 2034 | LIR* launch_pad = |
| 2035 | RawLIR(current_dalvik_offset_, kPseudoSuspendTarget, WrapPointer(target), |
| 2036 | current_dalvik_offset_); |
| 2037 | FlushAllRegs(); |
| 2038 | OpUnconditionalBranch(launch_pad); |
| 2039 | suspend_launchpads_.Insert(launch_pad); |
| 2040 | } else { |
| 2041 | // For the implicit suspend check, just perform the trigger |
| 2042 | // load and branch to the target. |
| 2043 | if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK)) { |
| 2044 | OpUnconditionalBranch(target); |
| 2045 | return; |
| 2046 | } |
| 2047 | FlushAllRegs(); |
| 2048 | LIR* inst = CheckSuspendUsingLoad(); |
| 2049 | MarkSafepointPC(inst); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2050 | OpUnconditionalBranch(target); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2051 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 2054 | /* Call out to helper assembly routine that will null check obj and then lock it. */ |
| 2055 | void Mir2Lir::GenMonitorEnter(int opt_flags, RegLocation rl_src) { |
| 2056 | FlushAllRegs(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 2057 | CallRuntimeHelperRegLocation(QUICK_ENTRYPOINT_OFFSET(4, pLockObject), rl_src, true); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | /* Call out to helper assembly routine that will null check obj and then unlock it. */ |
| 2061 | void Mir2Lir::GenMonitorExit(int opt_flags, RegLocation rl_src) { |
| 2062 | FlushAllRegs(); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 2063 | CallRuntimeHelperRegLocation(QUICK_ENTRYPOINT_OFFSET(4, pUnlockObject), rl_src, true); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 2066 | /* Generic code for generating a wide constant into a VR. */ |
| 2067 | void Mir2Lir::GenConstWide(RegLocation rl_dest, int64_t value) { |
| 2068 | RegLocation rl_result = EvalLoc(rl_dest, kAnyReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 2069 | LoadConstantWide(rl_result.reg, value); |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 2070 | StoreValueWide(rl_dest, rl_result); |
| 2071 | } |
| 2072 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 2073 | } // namespace art |