blob: 3c9b7a3ed34105634712f440666b55ade1d916cf [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
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 */
Andreas Gampe7e499922015-01-06 08:28:12 -080016
Andreas Gampe0b9203e2015-01-22 20:39:27 -080017#include "mir_to_lir-inl.h"
18
Andreas Gampe7e499922015-01-06 08:28:12 -080019#include <functional>
20
Ian Rogersd582fa42014-11-05 23:46:43 -080021#include "arch/arm/instruction_set_features_arm.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080022#include "base/macros.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070023#include "dex/compiler_ir.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080024#include "dex/mir_graph.h"
Brian Carlstrom60d7a652014-03-13 18:10:08 -070025#include "dex/quick/arm/arm_lir.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080026#include "driver/compiler_driver.h"
Ian Rogers166db042013-07-26 12:05:57 -070027#include "entrypoints/quick/quick_entrypoints.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070028#include "mirror/array.h"
Andreas Gampe9c3b0892014-04-24 17:33:34 +000029#include "mirror/object_array-inl.h"
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080030#include "mirror/object-inl.h"
Andreas Gampeaa910d52014-07-30 18:59:05 -070031#include "mirror/object_reference.h"
Andreas Gampe7e499922015-01-06 08:28:12 -080032#include "utils.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070033#include "verifier/method_verifier.h"
34
35namespace art {
36
Andreas Gampe9c3b0892014-04-24 17:33:34 +000037// Shortcuts to repeatedly used long types.
38typedef mirror::ObjectArray<mirror::Object> ObjArray;
39typedef mirror::ObjectArray<mirror::Class> ClassArray;
40
Brian Carlstrom7940e442013-07-12 13:46:57 -070041/*
42 * This source files contains "gen" codegen routines that should
43 * be applicable to most targets. Only mid-level support utilities
44 * and "op" calls may be used here.
45 */
46
Andreas Gampe0b9203e2015-01-22 20:39:27 -080047ALWAYS_INLINE static inline bool ForceSlowFieldPath(CompilationUnit* cu) {
48 return (cu->enable_debug & (1 << kDebugSlowFieldPath)) != 0;
49}
50
51ALWAYS_INLINE static inline bool ForceSlowStringPath(CompilationUnit* cu) {
52 return (cu->enable_debug & (1 << kDebugSlowStringPath)) != 0;
53}
54
55ALWAYS_INLINE static inline bool ForceSlowTypePath(CompilationUnit* cu) {
56 return (cu->enable_debug & (1 << kDebugSlowTypePath)) != 0;
57}
58
Brian Carlstrom7940e442013-07-12 13:46:57 -070059/*
buzbeeb48819d2013-09-14 16:15:25 -070060 * Generate a kPseudoBarrier marker to indicate the boundary of special
Brian Carlstrom7940e442013-07-12 13:46:57 -070061 * blocks.
62 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070063void Mir2Lir::GenBarrier() {
Brian Carlstrom7940e442013-07-12 13:46:57 -070064 LIR* barrier = NewLIR0(kPseudoBarrier);
65 /* Mark all resources as being clobbered */
buzbeeb48819d2013-09-14 16:15:25 -070066 DCHECK(!barrier->flags.use_def_invalid);
Vladimir Marko8dea81c2014-06-06 14:50:36 +010067 barrier->u.m.def_mask = &kEncodeAll;
Brian Carlstrom7940e442013-07-12 13:46:57 -070068}
69
Mingyao Yange643a172014-04-08 11:02:52 -070070void Mir2Lir::GenDivZeroException() {
71 LIR* branch = OpUnconditionalBranch(nullptr);
72 AddDivZeroCheckSlowPath(branch);
73}
74
75void Mir2Lir::GenDivZeroCheck(ConditionCode c_code) {
Mingyao Yang42894562014-04-07 12:42:16 -070076 LIR* branch = OpCondBranch(c_code, nullptr);
77 AddDivZeroCheckSlowPath(branch);
78}
79
Mingyao Yange643a172014-04-08 11:02:52 -070080void Mir2Lir::GenDivZeroCheck(RegStorage reg) {
81 LIR* branch = OpCmpImmBranch(kCondEq, reg, 0, nullptr);
Mingyao Yang42894562014-04-07 12:42:16 -070082 AddDivZeroCheckSlowPath(branch);
83}
84
85void Mir2Lir::AddDivZeroCheckSlowPath(LIR* branch) {
86 class DivZeroCheckSlowPath : public Mir2Lir::LIRSlowPath {
87 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -080088 DivZeroCheckSlowPath(Mir2Lir* m2l, LIR* branch_in)
89 : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch_in) {
Mingyao Yang42894562014-04-07 12:42:16 -070090 }
91
Mingyao Yange643a172014-04-08 11:02:52 -070092 void Compile() OVERRIDE {
Mingyao Yang42894562014-04-07 12:42:16 -070093 m2l_->ResetRegPool();
94 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -070095 GenerateTargetLabel(kPseudoThrowTarget);
Andreas Gampe98430592014-07-27 19:44:50 -070096 m2l_->CallRuntimeHelper(kQuickThrowDivZero, true);
Mingyao Yang42894562014-04-07 12:42:16 -070097 }
98 };
99
100 AddSlowPath(new (arena_) DivZeroCheckSlowPath(this, branch));
101}
Dave Allisonb373e092014-02-20 16:06:36 -0800102
Mingyao Yang80365d92014-04-18 12:10:58 -0700103void Mir2Lir::GenArrayBoundsCheck(RegStorage index, RegStorage length) {
104 class ArrayBoundsCheckSlowPath : public Mir2Lir::LIRSlowPath {
105 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800106 ArrayBoundsCheckSlowPath(Mir2Lir* m2l, LIR* branch_in, RegStorage index_in,
107 RegStorage length_in)
108 : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch_in),
109 index_(index_in), length_(length_in) {
Mingyao Yang80365d92014-04-18 12:10:58 -0700110 }
111
112 void Compile() OVERRIDE {
113 m2l_->ResetRegPool();
114 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -0700115 GenerateTargetLabel(kPseudoThrowTarget);
Andreas Gampe98430592014-07-27 19:44:50 -0700116 m2l_->CallRuntimeHelperRegReg(kQuickThrowArrayBounds, index_, length_, true);
Mingyao Yang80365d92014-04-18 12:10:58 -0700117 }
118
119 private:
120 const RegStorage index_;
121 const RegStorage length_;
122 };
123
124 LIR* branch = OpCmpBranch(kCondUge, index, length, nullptr);
125 AddSlowPath(new (arena_) ArrayBoundsCheckSlowPath(this, branch, index, length));
126}
127
128void Mir2Lir::GenArrayBoundsCheck(int index, RegStorage length) {
129 class ArrayBoundsCheckSlowPath : public Mir2Lir::LIRSlowPath {
130 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800131 ArrayBoundsCheckSlowPath(Mir2Lir* m2l, LIR* branch_in, int index_in, RegStorage length_in)
132 : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch_in),
133 index_(index_in), length_(length_in) {
Mingyao Yang80365d92014-04-18 12:10:58 -0700134 }
135
136 void Compile() OVERRIDE {
137 m2l_->ResetRegPool();
138 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -0700139 GenerateTargetLabel(kPseudoThrowTarget);
Mingyao Yang80365d92014-04-18 12:10:58 -0700140
Andreas Gampeccc60262014-07-04 18:02:38 -0700141 RegStorage arg1_32 = m2l_->TargetReg(kArg1, kNotWide);
142 RegStorage arg0_32 = m2l_->TargetReg(kArg0, kNotWide);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700143
144 m2l_->OpRegCopy(arg1_32, length_);
145 m2l_->LoadConstant(arg0_32, index_);
Andreas Gampe98430592014-07-27 19:44:50 -0700146 m2l_->CallRuntimeHelperRegReg(kQuickThrowArrayBounds, arg0_32, arg1_32, true);
Mingyao Yang80365d92014-04-18 12:10:58 -0700147 }
148
149 private:
150 const int32_t index_;
151 const RegStorage length_;
152 };
153
154 LIR* branch = OpCmpImmBranch(kCondLs, length, index, nullptr);
155 AddSlowPath(new (arena_) ArrayBoundsCheckSlowPath(this, branch, index, length));
156}
157
Mingyao Yange643a172014-04-08 11:02:52 -0700158LIR* Mir2Lir::GenNullCheck(RegStorage reg) {
159 class NullCheckSlowPath : public Mir2Lir::LIRSlowPath {
160 public:
161 NullCheckSlowPath(Mir2Lir* m2l, LIR* branch)
162 : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch) {
163 }
164
165 void Compile() OVERRIDE {
166 m2l_->ResetRegPool();
167 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -0700168 GenerateTargetLabel(kPseudoThrowTarget);
Andreas Gampe98430592014-07-27 19:44:50 -0700169 m2l_->CallRuntimeHelper(kQuickThrowNullPointer, true);
Mingyao Yange643a172014-04-08 11:02:52 -0700170 }
171 };
172
173 LIR* branch = OpCmpImmBranch(kCondEq, reg, 0, nullptr);
174 AddSlowPath(new (arena_) NullCheckSlowPath(this, branch));
175 return branch;
176}
177
Brian Carlstrom7940e442013-07-12 13:46:57 -0700178/* Perform null-check on a register. */
buzbee2700f7e2014-03-07 09:46:20 -0800179LIR* Mir2Lir::GenNullCheck(RegStorage m_reg, int opt_flags) {
Dave Allison69dfe512014-07-11 17:11:58 +0000180 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Dave Allisonf9439142014-03-27 15:10:22 -0700181 return GenExplicitNullCheck(m_reg, opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700182 }
Pavel Vyssotski9c3617a2014-11-13 18:25:23 +0600183 // If null check has not been eliminated, reset redundant store tracking.
184 if ((opt_flags & MIR_IGNORE_NULL_CHECK) == 0) {
185 ResetDefTracking();
186 }
Dave Allisonb373e092014-02-20 16:06:36 -0800187 return nullptr;
188}
189
Dave Allisonf9439142014-03-27 15:10:22 -0700190/* Perform an explicit null-check on a register. */
191LIR* Mir2Lir::GenExplicitNullCheck(RegStorage m_reg, int opt_flags) {
192 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) {
193 return NULL;
194 }
Mingyao Yange643a172014-04-08 11:02:52 -0700195 return GenNullCheck(m_reg);
Dave Allisonf9439142014-03-27 15:10:22 -0700196}
197
Dave Allisonb373e092014-02-20 16:06:36 -0800198void Mir2Lir::MarkPossibleNullPointerException(int opt_flags) {
Dave Allison69dfe512014-07-11 17:11:58 +0000199 if (cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Dave Allisonb373e092014-02-20 16:06:36 -0800200 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) {
201 return;
202 }
Dave Allison69dfe512014-07-11 17:11:58 +0000203 // Insert after last instruction.
Dave Allisonb373e092014-02-20 16:06:36 -0800204 MarkSafepointPC(last_lir_insn_);
205 }
206}
207
Andreas Gampe3c12c512014-06-24 18:46:29 +0000208void Mir2Lir::MarkPossibleNullPointerExceptionAfter(int opt_flags, LIR* after) {
Dave Allison69dfe512014-07-11 17:11:58 +0000209 if (cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Andreas Gampe3c12c512014-06-24 18:46:29 +0000210 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) {
211 return;
212 }
213 MarkSafepointPCAfter(after);
214 }
215}
216
Dave Allisonb373e092014-02-20 16:06:36 -0800217void Mir2Lir::MarkPossibleStackOverflowException() {
Dave Allison69dfe512014-07-11 17:11:58 +0000218 if (cu_->compiler_driver->GetCompilerOptions().GetImplicitStackOverflowChecks()) {
Dave Allisonb373e092014-02-20 16:06:36 -0800219 MarkSafepointPC(last_lir_insn_);
220 }
221}
222
buzbee2700f7e2014-03-07 09:46:20 -0800223void Mir2Lir::ForceImplicitNullCheck(RegStorage reg, int opt_flags) {
Dave Allison69dfe512014-07-11 17:11:58 +0000224 if (cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Dave Allisonb373e092014-02-20 16:06:36 -0800225 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) {
226 return;
227 }
228 // Force an implicit null check by performing a memory operation (load) from the given
229 // register with offset 0. This will cause a signal if the register contains 0 (null).
buzbee2700f7e2014-03-07 09:46:20 -0800230 RegStorage tmp = AllocTemp();
231 // TODO: for Mips, would be best to use rZERO as the bogus register target.
buzbee695d13a2014-04-19 13:32:20 -0700232 LIR* load = Load32Disp(reg, 0, tmp);
Dave Allisonb373e092014-02-20 16:06:36 -0800233 FreeTemp(tmp);
234 MarkSafepointPC(load);
235 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700236}
237
Brian Carlstrom7940e442013-07-12 13:46:57 -0700238void Mir2Lir::GenCompareAndBranch(Instruction::Code opcode, RegLocation rl_src1,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700239 RegLocation rl_src2, LIR* taken) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700240 ConditionCode cond;
buzbee7c02e912014-10-03 13:14:17 -0700241 RegisterClass reg_class = (rl_src1.ref || rl_src2.ref) ? kRefReg : kCoreReg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700242 switch (opcode) {
243 case Instruction::IF_EQ:
244 cond = kCondEq;
245 break;
246 case Instruction::IF_NE:
247 cond = kCondNe;
248 break;
249 case Instruction::IF_LT:
250 cond = kCondLt;
251 break;
252 case Instruction::IF_GE:
253 cond = kCondGe;
254 break;
255 case Instruction::IF_GT:
256 cond = kCondGt;
257 break;
258 case Instruction::IF_LE:
259 cond = kCondLe;
260 break;
261 default:
262 cond = static_cast<ConditionCode>(0);
263 LOG(FATAL) << "Unexpected opcode " << opcode;
264 }
265
266 // Normalize such that if either operand is constant, src2 will be constant
267 if (rl_src1.is_const) {
268 RegLocation rl_temp = rl_src1;
269 rl_src1 = rl_src2;
270 rl_src2 = rl_temp;
271 cond = FlipComparisonOrder(cond);
272 }
273
buzbee7c02e912014-10-03 13:14:17 -0700274 rl_src1 = LoadValue(rl_src1, reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700275 // Is this really an immediate comparison?
276 if (rl_src2.is_const) {
277 // If it's already live in a register or not easily materialized, just keep going
278 RegLocation rl_temp = UpdateLoc(rl_src2);
Andreas Gampeb07c1f92014-07-26 01:40:39 -0700279 int32_t constant_value = mir_graph_->ConstantValue(rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700280 if ((rl_temp.location == kLocDalvikFrame) &&
Matteo Franchinc763e352014-07-04 12:53:27 +0100281 InexpensiveConstantInt(constant_value, opcode)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700282 // OK - convert this to a compare immediate and branch
buzbee2700f7e2014-03-07 09:46:20 -0800283 OpCmpImmBranch(cond, rl_src1.reg, mir_graph_->ConstantValue(rl_src2), taken);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700284 return;
285 }
Andreas Gampeb07c1f92014-07-26 01:40:39 -0700286
287 // It's also commonly more efficient to have a test against zero with Eq/Ne. This is not worse
288 // for x86, and allows a cbz/cbnz for Arm and Mips. At the same time, it works around a register
289 // mismatch for 64b systems, where a reference is compared against null, as dex bytecode uses
290 // the 32b literal 0 for null.
291 if (constant_value == 0 && (cond == kCondEq || cond == kCondNe)) {
292 // Use the OpCmpImmBranch and ignore the value in the register.
293 OpCmpImmBranch(cond, rl_src1.reg, 0, taken);
294 return;
295 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700296 }
Andreas Gampeb07c1f92014-07-26 01:40:39 -0700297
buzbee7c02e912014-10-03 13:14:17 -0700298 rl_src2 = LoadValue(rl_src2, reg_class);
buzbee2700f7e2014-03-07 09:46:20 -0800299 OpCmpBranch(cond, rl_src1.reg, rl_src2.reg, taken);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700300}
301
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700302void Mir2Lir::GenCompareZeroAndBranch(Instruction::Code opcode, RegLocation rl_src, LIR* taken) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700303 ConditionCode cond;
buzbee7c02e912014-10-03 13:14:17 -0700304 RegisterClass reg_class = rl_src.ref ? kRefReg : kCoreReg;
305 rl_src = LoadValue(rl_src, reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700306 switch (opcode) {
307 case Instruction::IF_EQZ:
308 cond = kCondEq;
309 break;
310 case Instruction::IF_NEZ:
311 cond = kCondNe;
312 break;
313 case Instruction::IF_LTZ:
314 cond = kCondLt;
315 break;
316 case Instruction::IF_GEZ:
317 cond = kCondGe;
318 break;
319 case Instruction::IF_GTZ:
320 cond = kCondGt;
321 break;
322 case Instruction::IF_LEZ:
323 cond = kCondLe;
324 break;
325 default:
326 cond = static_cast<ConditionCode>(0);
327 LOG(FATAL) << "Unexpected opcode " << opcode;
328 }
buzbee2700f7e2014-03-07 09:46:20 -0800329 OpCmpImmBranch(cond, rl_src.reg, 0, taken);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700330}
331
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700332void Mir2Lir::GenIntToLong(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700333 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
334 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800335 OpRegCopy(rl_result.reg, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700336 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800337 LoadValueDirect(rl_src, rl_result.reg.GetLow());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700338 }
buzbee2700f7e2014-03-07 09:46:20 -0800339 OpRegRegImm(kOpAsr, rl_result.reg.GetHigh(), rl_result.reg.GetLow(), 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700340 StoreValueWide(rl_dest, rl_result);
341}
342
Yevgeny Rouban6af82062014-11-26 18:11:54 +0600343void Mir2Lir::GenLongToInt(RegLocation rl_dest, RegLocation rl_src) {
344 rl_src = UpdateLocWide(rl_src);
345 rl_src = NarrowRegLoc(rl_src);
346 StoreValue(rl_dest, rl_src);
347}
348
Brian Carlstrom7940e442013-07-12 13:46:57 -0700349void Mir2Lir::GenIntNarrowing(Instruction::Code opcode, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700350 RegLocation rl_src) {
Brian Carlstrom6f485c62013-07-18 15:35:35 -0700351 rl_src = LoadValue(rl_src, kCoreReg);
352 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
353 OpKind op = kOpInvalid;
354 switch (opcode) {
355 case Instruction::INT_TO_BYTE:
356 op = kOp2Byte;
357 break;
358 case Instruction::INT_TO_SHORT:
359 op = kOp2Short;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700360 break;
Brian Carlstrom6f485c62013-07-18 15:35:35 -0700361 case Instruction::INT_TO_CHAR:
362 op = kOp2Char;
363 break;
364 default:
365 LOG(ERROR) << "Bad int conversion type";
366 }
buzbee2700f7e2014-03-07 09:46:20 -0800367 OpRegReg(op, rl_result.reg, rl_src.reg);
Brian Carlstrom6f485c62013-07-18 15:35:35 -0700368 StoreValue(rl_dest, rl_result);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700369}
370
Andreas Gampe98430592014-07-27 19:44:50 -0700371/*
372 * Let helper function take care of everything. Will call
373 * Array::AllocFromCode(type_idx, method, count);
374 * Note: AllocFromCode will handle checks for errNegativeArraySize.
375 */
376void Mir2Lir::GenNewArray(uint32_t type_idx, RegLocation rl_dest,
377 RegLocation rl_src) {
378 FlushAllRegs(); /* Everything to home location */
379 const DexFile* dex_file = cu_->dex_file;
380 CompilerDriver* driver = cu_->compiler_driver;
381 if (cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, *dex_file, type_idx)) {
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800382 bool is_type_initialized; // Ignored as an array does not have an initializer.
383 bool use_direct_type_ptr;
384 uintptr_t direct_type_ptr;
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700385 bool is_finalizable;
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800386 if (kEmbedClassInCode &&
Mathieu Chartier8668c3c2014-04-24 16:48:11 -0700387 driver->CanEmbedTypeInCode(*dex_file, type_idx, &is_type_initialized, &use_direct_type_ptr,
388 &direct_type_ptr, &is_finalizable)) {
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800389 // The fast path.
390 if (!use_direct_type_ptr) {
Fred Shihe7f82e22014-08-06 10:46:37 -0700391 LoadClassType(*dex_file, type_idx, kArg0);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800392 CallRuntimeHelperRegRegLocationMethod(kQuickAllocArrayResolved, TargetReg(kArg0, kNotWide),
Andreas Gampe98430592014-07-27 19:44:50 -0700393 rl_src, true);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800394 } else {
395 // Use the direct pointer.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800396 CallRuntimeHelperImmRegLocationMethod(kQuickAllocArrayResolved, direct_type_ptr, rl_src,
Andreas Gampe98430592014-07-27 19:44:50 -0700397 true);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800398 }
399 } else {
400 // The slow path.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800401 CallRuntimeHelperImmRegLocationMethod(kQuickAllocArray, type_idx, rl_src, true);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800402 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700403 } else {
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800404 CallRuntimeHelperImmRegLocationMethod(kQuickAllocArrayWithAccessCheck, type_idx, rl_src, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700405 }
Andreas Gampe98430592014-07-27 19:44:50 -0700406 StoreValue(rl_dest, GetReturn(kRefReg));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700407}
408
409/*
410 * Similar to GenNewArray, but with post-allocation initialization.
411 * Verifier guarantees we're dealing with an array class. Current
412 * code throws runtime exception "bad Filled array req" for 'D' and 'J'.
413 * Current code also throws internal unimp if not 'L', '[' or 'I'.
414 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700415void Mir2Lir::GenFilledNewArray(CallInfo* info) {
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000416 size_t elems = info->num_arg_words;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700417 int type_idx = info->index;
418 FlushAllRegs(); /* Everything to home location */
Andreas Gampe98430592014-07-27 19:44:50 -0700419 QuickEntrypointEnum target;
420 if (cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx, *cu_->dex_file,
421 type_idx)) {
422 target = kQuickCheckAndAllocArray;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700423 } else {
Andreas Gampe98430592014-07-27 19:44:50 -0700424 target = kQuickCheckAndAllocArrayWithAccessCheck;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700425 }
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800426 CallRuntimeHelperImmImmMethod(target, type_idx, elems, true);
Andreas Gampeccc60262014-07-04 18:02:38 -0700427 FreeTemp(TargetReg(kArg2, kNotWide));
428 FreeTemp(TargetReg(kArg1, kNotWide));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700429 /*
430 * NOTE: the implicit target for Instruction::FILLED_NEW_ARRAY is the
431 * return region. Because AllocFromCode placed the new array
432 * in kRet0, we'll just lock it into place. When debugger support is
433 * added, it may be necessary to additionally copy all return
434 * values to a home location in thread-local storage
435 */
Andreas Gampeccc60262014-07-04 18:02:38 -0700436 RegStorage ref_reg = TargetReg(kRet0, kRef);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700437 LockTemp(ref_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700438
439 // TODO: use the correct component size, currently all supported types
440 // share array alignment with ints (see comment at head of function)
441 size_t component_size = sizeof(int32_t);
442
Vladimir Markobf535be2014-11-19 18:52:35 +0000443 if (elems > 5) {
444 DCHECK(info->is_range); // Non-range insn can't encode more than 5 elems.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700445 /*
446 * Bit of ugliness here. We're going generate a mem copy loop
447 * on the register range, but it is possible that some regs
448 * in the range have been promoted. This is unlikely, but
449 * before generating the copy, we'll just force a flush
450 * of any regs in the source range that have been promoted to
451 * home location.
452 */
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000453 for (size_t i = 0; i < elems; i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700454 RegLocation loc = UpdateLoc(info->args[i]);
455 if (loc.location == kLocPhysReg) {
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100456 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Serguei Katkov27503542014-11-06 14:45:44 +0600457 if (loc.ref) {
458 StoreRefDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, kNotVolatile);
459 } else {
460 Store32Disp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg);
461 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700462 }
463 }
464 /*
465 * TUNING note: generated code here could be much improved, but
466 * this is an uncommon operation and isn't especially performance
467 * critical.
468 */
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700469 // This is addressing the stack, which may be out of the 4G area.
buzbee33ae5582014-06-12 14:56:32 -0700470 RegStorage r_src = AllocTempRef();
471 RegStorage r_dst = AllocTempRef();
472 RegStorage r_idx = AllocTempRef(); // Not really a reference, but match src/dst.
buzbee2700f7e2014-03-07 09:46:20 -0800473 RegStorage r_val;
Brian Carlstromdf629502013-07-17 22:39:56 -0700474 switch (cu_->instruction_set) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700475 case kThumb2:
buzbee33ae5582014-06-12 14:56:32 -0700476 case kArm64:
Andreas Gampeccc60262014-07-04 18:02:38 -0700477 r_val = TargetReg(kLr, kNotWide);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700478 break;
479 case kX86:
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700480 case kX86_64:
Chao-ying Fua77ee512014-07-01 17:43:41 -0700481 FreeTemp(ref_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700482 r_val = AllocTemp();
483 break;
484 case kMips:
485 r_val = AllocTemp();
486 break;
487 default: LOG(FATAL) << "Unexpected instruction set: " << cu_->instruction_set;
488 }
489 // Set up source pointer
490 RegLocation rl_first = info->args[0];
Chao-ying Fua77ee512014-07-01 17:43:41 -0700491 OpRegRegImm(kOpAdd, r_src, TargetPtrReg(kSp), SRegOffset(rl_first.s_reg_low));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700492 // Set up the target pointer
Chao-ying Fua77ee512014-07-01 17:43:41 -0700493 OpRegRegImm(kOpAdd, r_dst, ref_reg,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700494 mirror::Array::DataOffset(component_size).Int32Value());
495 // Set up the loop counter (known to be > 0)
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000496 LoadConstant(r_idx, static_cast<int>(elems - 1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700497 // Generate the copy loop. Going backwards for convenience
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800498 LIR* loop_head_target = NewLIR0(kPseudoTargetLabel);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700499 // Copy next element
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100500 {
501 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
502 LoadBaseIndexed(r_src, r_idx, r_val, 2, k32);
503 // NOTE: No dalvik register annotation, local optimizations will be stopped
504 // by the loop boundaries.
505 }
buzbee695d13a2014-04-19 13:32:20 -0700506 StoreBaseIndexed(r_dst, r_idx, r_val, 2, k32);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700507 FreeTemp(r_val);
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800508 OpDecAndBranch(kCondGe, r_idx, loop_head_target);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700509 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700510 // Restore the target pointer
Chao-ying Fua77ee512014-07-01 17:43:41 -0700511 OpRegRegImm(kOpAdd, ref_reg, r_dst,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700512 -mirror::Array::DataOffset(component_size).Int32Value());
513 }
Vladimir Markobf535be2014-11-19 18:52:35 +0000514 FreeTemp(r_idx);
515 FreeTemp(r_dst);
516 FreeTemp(r_src);
517 } else {
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000518 DCHECK_LE(elems, 5u); // Usually but not necessarily non-range.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700519 // TUNING: interleave
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000520 for (size_t i = 0; i < elems; i++) {
Serguei Katkov27503542014-11-06 14:45:44 +0600521 RegLocation rl_arg;
522 if (info->args[i].ref) {
523 rl_arg = LoadValue(info->args[i], kRefReg);
524 StoreRefDisp(ref_reg,
525 mirror::Array::DataOffset(component_size).Int32Value() + i * 4, rl_arg.reg,
526 kNotVolatile);
527 } else {
528 rl_arg = LoadValue(info->args[i], kCoreReg);
529 Store32Disp(ref_reg,
530 mirror::Array::DataOffset(component_size).Int32Value() + i * 4, rl_arg.reg);
531 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700532 // If the LoadValue caused a temp to be allocated, free it
buzbee2700f7e2014-03-07 09:46:20 -0800533 if (IsTemp(rl_arg.reg)) {
534 FreeTemp(rl_arg.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700535 }
536 }
537 }
Vladimir Markobf535be2014-11-19 18:52:35 +0000538 if (elems != 0 && info->args[0].ref) {
539 // If there is at least one potentially non-null value, unconditionally mark the GC card.
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000540 for (size_t i = 0; i < elems; i++) {
Vladimir Markobf535be2014-11-19 18:52:35 +0000541 if (!mir_graph_->IsConstantNullRef(info->args[i])) {
542 UnconditionallyMarkGCCard(ref_reg);
543 break;
544 }
545 }
546 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700547 if (info->result.location != kLocInvalid) {
buzbeea0cd2d72014-06-01 09:33:49 -0700548 StoreValue(info->result, GetReturn(kRefReg));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700549 }
550}
551
Ian Rogers832336b2014-10-08 15:35:22 -0700552/*
553 * Array data table format:
554 * ushort ident = 0x0300 magic value
555 * ushort width width of each element in the table
556 * uint size number of elements in the table
557 * ubyte data[size*width] table of data values (may contain a single-byte
558 * padding at the end)
559 *
560 * Total size is 4+(width * size + 1)/2 16-bit code units.
561 */
562void Mir2Lir::GenFillArrayData(MIR* mir, DexOffset table_offset, RegLocation rl_src) {
563 if (kIsDebugBuild) {
564 const uint16_t* table = mir_graph_->GetTable(mir, table_offset);
565 const Instruction::ArrayDataPayload* payload =
566 reinterpret_cast<const Instruction::ArrayDataPayload*>(table);
567 CHECK_EQ(payload->ident, static_cast<uint16_t>(Instruction::kArrayDataSignature));
568 }
569 uint32_t table_offset_from_start = mir->offset + static_cast<int32_t>(table_offset);
570 CallRuntimeHelperImmRegLocation(kQuickHandleFillArrayData, table_offset_from_start, rl_src, true);
571}
572
Dave Allisonbcec6fb2014-01-17 12:52:22 -0800573//
574// Slow path to ensure a class is initialized for sget/sput.
575//
576class StaticFieldSlowPath : public Mir2Lir::LIRSlowPath {
577 public:
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100578 // There are up to two branches to the static field slow path, the "unresolved" when the type
579 // entry in the dex cache is null, and the "uninit" when the class is not yet initialized.
580 // At least one will be non-null here, otherwise we wouldn't generate the slow path.
buzbee2700f7e2014-03-07 09:46:20 -0800581 StaticFieldSlowPath(Mir2Lir* m2l, LIR* unresolved, LIR* uninit, LIR* cont, int storage_index,
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100582 RegStorage r_base)
583 : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), unresolved != nullptr ? unresolved : uninit, cont),
584 second_branch_(unresolved != nullptr ? uninit : nullptr),
585 storage_index_(storage_index), r_base_(r_base) {
Dave Allisonbcec6fb2014-01-17 12:52:22 -0800586 }
587
588 void Compile() {
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100589 LIR* target = GenerateTargetLabel();
590 if (second_branch_ != nullptr) {
591 second_branch_->target = target;
592 }
Andreas Gampe98430592014-07-27 19:44:50 -0700593 m2l_->CallRuntimeHelperImm(kQuickInitializeStaticStorage, storage_index_, true);
Dave Allisonbcec6fb2014-01-17 12:52:22 -0800594 // Copy helper's result into r_base, a no-op on all but MIPS.
Andreas Gampeccc60262014-07-04 18:02:38 -0700595 m2l_->OpRegCopy(r_base_, m2l_->TargetReg(kRet0, kRef));
Dave Allisonbcec6fb2014-01-17 12:52:22 -0800596
597 m2l_->OpUnconditionalBranch(cont_);
598 }
599
600 private:
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100601 // Second branch to the slow path, or null if there's only one branch.
602 LIR* const second_branch_;
603
Dave Allisonbcec6fb2014-01-17 12:52:22 -0800604 const int storage_index_;
buzbee2700f7e2014-03-07 09:46:20 -0800605 const RegStorage r_base_;
Dave Allisonbcec6fb2014-01-17 12:52:22 -0800606};
607
Fred Shih37f05ef2014-07-16 18:38:08 -0700608void Mir2Lir::GenSput(MIR* mir, RegLocation rl_src, OpSize size) {
Vladimir Markobe0e5462014-02-26 11:24:15 +0000609 const MirSFieldLoweringInfo& field_info = mir_graph_->GetSFieldLoweringInfo(mir);
Vladimir Markoaf6925b2014-10-31 16:37:32 +0000610 DCHECK_EQ(SPutMemAccessType(mir->dalvikInsn.opcode), field_info.MemAccessType());
Vladimir Markobe0e5462014-02-26 11:24:15 +0000611 cu_->compiler_driver->ProcessedStaticField(field_info.FastPut(), field_info.IsReferrersClass());
Andreas Gampe0b9203e2015-01-22 20:39:27 -0800612 if (!ForceSlowFieldPath(cu_) && field_info.FastPut()) {
Vladimir Markobe0e5462014-02-26 11:24:15 +0000613 DCHECK_GE(field_info.FieldOffset().Int32Value(), 0);
buzbee2700f7e2014-03-07 09:46:20 -0800614 RegStorage r_base;
Vladimir Markobe0e5462014-02-26 11:24:15 +0000615 if (field_info.IsReferrersClass()) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700616 // Fast path, static storage base is this method's class
Matteo Franchin0955f7e2014-05-23 17:32:52 +0100617 RegLocation rl_method = LoadCurrMethod();
buzbeea0cd2d72014-06-01 09:33:49 -0700618 r_base = AllocTempRef();
Andreas Gampe3c12c512014-06-24 18:46:29 +0000619 LoadRefDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), r_base,
620 kNotVolatile);
buzbee2700f7e2014-03-07 09:46:20 -0800621 if (IsTemp(rl_method.reg)) {
622 FreeTemp(rl_method.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700623 }
624 } else {
625 // Medium path, static storage base in a different class which requires checks that the other
626 // class is initialized.
627 // TODO: remove initialized check now that we are initializing classes in the compiler driver.
Vladimir Markobe0e5462014-02-26 11:24:15 +0000628 DCHECK_NE(field_info.StorageIndex(), DexFile::kDexNoIndex);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700629 // May do runtime call so everything to home locations.
630 FlushAllRegs();
631 // Using fixed register to sync with possible call to runtime support.
Andreas Gampeccc60262014-07-04 18:02:38 -0700632 RegStorage r_method = TargetReg(kArg1, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700633 LockTemp(r_method);
634 LoadCurrMethodDirect(r_method);
Andreas Gampeccc60262014-07-04 18:02:38 -0700635 r_base = TargetReg(kArg0, kRef);
Ian Rogers5ddb4102014-01-07 08:58:46 -0800636 LockTemp(r_base);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000637 LoadRefDisp(r_method, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), r_base,
638 kNotVolatile);
Andreas Gampe9c3b0892014-04-24 17:33:34 +0000639 int32_t offset_of_field = ObjArray::OffsetOfElement(field_info.StorageIndex()).Int32Value();
Andreas Gampe3c12c512014-06-24 18:46:29 +0000640 LoadRefDisp(r_base, offset_of_field, r_base, kNotVolatile);
Ian Rogers5ddb4102014-01-07 08:58:46 -0800641 // r_base now points at static storage (Class*) or NULL if the type is not yet resolved.
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100642 LIR* unresolved_branch = nullptr;
643 if (!field_info.IsClassInDexCache() &&
644 (mir->optimization_flags & MIR_CLASS_IS_IN_DEX_CACHE) == 0) {
645 // Check if r_base is NULL.
646 unresolved_branch = OpCmpImmBranch(kCondEq, r_base, 0, NULL);
647 }
648 LIR* uninit_branch = nullptr;
649 if (!field_info.IsClassInitialized() &&
650 (mir->optimization_flags & MIR_CLASS_IS_INITIALIZED) == 0) {
651 // Check if r_base is not yet initialized class.
Andreas Gampeccc60262014-07-04 18:02:38 -0700652 RegStorage r_tmp = TargetReg(kArg2, kNotWide);
Ian Rogers5ddb4102014-01-07 08:58:46 -0800653 LockTemp(r_tmp);
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100654 uninit_branch = OpCmpMemImmBranch(kCondLt, r_tmp, r_base,
Mark Mendell766e9292014-01-27 07:55:47 -0800655 mirror::Class::StatusOffset().Int32Value(),
Dave Allison69dfe512014-07-11 17:11:58 +0000656 mirror::Class::kStatusInitialized, nullptr, nullptr);
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100657 FreeTemp(r_tmp);
658 }
659 if (unresolved_branch != nullptr || uninit_branch != nullptr) {
660 // The slow path is invoked if the r_base is NULL or the class pointed
661 // to by it is not initialized.
Dave Allisonbcec6fb2014-01-17 12:52:22 -0800662 LIR* cont = NewLIR0(kPseudoTargetLabel);
buzbee2700f7e2014-03-07 09:46:20 -0800663 AddSlowPath(new (arena_) StaticFieldSlowPath(this, unresolved_branch, uninit_branch, cont,
Vladimir Markobe0e5462014-02-26 11:24:15 +0000664 field_info.StorageIndex(), r_base));
Ian Rogers5ddb4102014-01-07 08:58:46 -0800665
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100666 if (uninit_branch != nullptr) {
667 // Ensure load of status and store of value don't re-order.
668 // TODO: Presumably the actual value store is control-dependent on the status load,
669 // and will thus not be reordered in any case, since stores are never speculated.
670 // Does later code "know" that the class is now initialized? If so, we still
671 // need the barrier to guard later static loads.
672 GenMemBarrier(kLoadAny);
673 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700674 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700675 FreeTemp(r_method);
676 }
677 // rBase now holds static storage base
Fred Shih37f05ef2014-07-16 18:38:08 -0700678 RegisterClass reg_class = RegClassForFieldLoadStore(size, field_info.IsVolatile());
679 if (IsWide(size)) {
Vladimir Marko674744e2014-04-24 15:18:26 +0100680 rl_src = LoadValueWide(rl_src, reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700681 } else {
Vladimir Marko674744e2014-04-24 15:18:26 +0100682 rl_src = LoadValue(rl_src, reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700683 }
Fred Shih37f05ef2014-07-16 18:38:08 -0700684 if (IsRef(size)) {
Andreas Gampe3c12c512014-06-24 18:46:29 +0000685 StoreRefDisp(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg,
686 field_info.IsVolatile() ? kVolatile : kNotVolatile);
Vladimir Marko674744e2014-04-24 15:18:26 +0100687 } else {
Fred Shih37f05ef2014-07-16 18:38:08 -0700688 StoreBaseDisp(r_base, field_info.FieldOffset().Int32Value(), rl_src.reg, size,
Andreas Gampe3c12c512014-06-24 18:46:29 +0000689 field_info.IsVolatile() ? kVolatile : kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700690 }
Fred Shih37f05ef2014-07-16 18:38:08 -0700691 if (IsRef(size) && !mir_graph_->IsConstantNullRef(rl_src)) {
Vladimir Marko743b98c2014-11-24 19:45:41 +0000692 MarkGCCard(mir->optimization_flags, rl_src.reg, r_base);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700693 }
Ian Rogers5ddb4102014-01-07 08:58:46 -0800694 FreeTemp(r_base);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700695 } else {
696 FlushAllRegs(); // Everything to home locations
Fred Shih37f05ef2014-07-16 18:38:08 -0700697 QuickEntrypointEnum target;
698 switch (size) {
699 case kReference:
700 target = kQuickSetObjStatic;
701 break;
702 case k64:
703 case kDouble:
704 target = kQuickSet64Static;
705 break;
706 case k32:
707 case kSingle:
708 target = kQuickSet32Static;
709 break;
710 case kSignedHalf:
711 case kUnsignedHalf:
712 target = kQuickSet16Static;
713 break;
714 case kSignedByte:
715 case kUnsignedByte:
716 target = kQuickSet8Static;
717 break;
718 case kWord: // Intentional fallthrough.
719 default:
720 LOG(FATAL) << "Can't determine entrypoint for: " << size;
721 target = kQuickSet32Static;
722 }
Andreas Gampe98430592014-07-27 19:44:50 -0700723 CallRuntimeHelperImmRegLocation(target, field_info.FieldIndex(), rl_src, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700724 }
725}
726
Fred Shih37f05ef2014-07-16 18:38:08 -0700727void Mir2Lir::GenSget(MIR* mir, RegLocation rl_dest, OpSize size, Primitive::Type type) {
Vladimir Markobe0e5462014-02-26 11:24:15 +0000728 const MirSFieldLoweringInfo& field_info = mir_graph_->GetSFieldLoweringInfo(mir);
Vladimir Markoaf6925b2014-10-31 16:37:32 +0000729 DCHECK_EQ(SGetMemAccessType(mir->dalvikInsn.opcode), field_info.MemAccessType());
Vladimir Markobe0e5462014-02-26 11:24:15 +0000730 cu_->compiler_driver->ProcessedStaticField(field_info.FastGet(), field_info.IsReferrersClass());
Fred Shih37f05ef2014-07-16 18:38:08 -0700731
Andreas Gampe0b9203e2015-01-22 20:39:27 -0800732 if (!ForceSlowFieldPath(cu_) && field_info.FastGet()) {
Vladimir Markobe0e5462014-02-26 11:24:15 +0000733 DCHECK_GE(field_info.FieldOffset().Int32Value(), 0);
buzbee2700f7e2014-03-07 09:46:20 -0800734 RegStorage r_base;
Vladimir Markobe0e5462014-02-26 11:24:15 +0000735 if (field_info.IsReferrersClass()) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700736 // Fast path, static storage base is this method's class
737 RegLocation rl_method = LoadCurrMethod();
buzbeea0cd2d72014-06-01 09:33:49 -0700738 r_base = AllocTempRef();
Andreas Gampe3c12c512014-06-24 18:46:29 +0000739 LoadRefDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), r_base,
740 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700741 } else {
742 // Medium path, static storage base in a different class which requires checks that the other
743 // class is initialized
Vladimir Markobe0e5462014-02-26 11:24:15 +0000744 DCHECK_NE(field_info.StorageIndex(), DexFile::kDexNoIndex);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700745 // May do runtime call so everything to home locations.
746 FlushAllRegs();
747 // Using fixed register to sync with possible call to runtime support.
Andreas Gampeccc60262014-07-04 18:02:38 -0700748 RegStorage r_method = TargetReg(kArg1, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700749 LockTemp(r_method);
750 LoadCurrMethodDirect(r_method);
Andreas Gampeccc60262014-07-04 18:02:38 -0700751 r_base = TargetReg(kArg0, kRef);
Ian Rogers5ddb4102014-01-07 08:58:46 -0800752 LockTemp(r_base);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000753 LoadRefDisp(r_method, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(), r_base,
754 kNotVolatile);
Andreas Gampe9c3b0892014-04-24 17:33:34 +0000755 int32_t offset_of_field = ObjArray::OffsetOfElement(field_info.StorageIndex()).Int32Value();
Andreas Gampe3c12c512014-06-24 18:46:29 +0000756 LoadRefDisp(r_base, offset_of_field, r_base, kNotVolatile);
Ian Rogers5ddb4102014-01-07 08:58:46 -0800757 // r_base now points at static storage (Class*) or NULL if the type is not yet resolved.
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100758 LIR* unresolved_branch = nullptr;
759 if (!field_info.IsClassInDexCache() &&
760 (mir->optimization_flags & MIR_CLASS_IS_IN_DEX_CACHE) == 0) {
761 // Check if r_base is NULL.
762 unresolved_branch = OpCmpImmBranch(kCondEq, r_base, 0, NULL);
763 }
764 LIR* uninit_branch = nullptr;
765 if (!field_info.IsClassInitialized() &&
766 (mir->optimization_flags & MIR_CLASS_IS_INITIALIZED) == 0) {
767 // Check if r_base is not yet initialized class.
Andreas Gampeccc60262014-07-04 18:02:38 -0700768 RegStorage r_tmp = TargetReg(kArg2, kNotWide);
Ian Rogers5ddb4102014-01-07 08:58:46 -0800769 LockTemp(r_tmp);
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100770 uninit_branch = OpCmpMemImmBranch(kCondLt, r_tmp, r_base,
Mark Mendell766e9292014-01-27 07:55:47 -0800771 mirror::Class::StatusOffset().Int32Value(),
Dave Allison69dfe512014-07-11 17:11:58 +0000772 mirror::Class::kStatusInitialized, nullptr, nullptr);
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100773 FreeTemp(r_tmp);
774 }
775 if (unresolved_branch != nullptr || uninit_branch != nullptr) {
776 // The slow path is invoked if the r_base is NULL or the class pointed
777 // to by it is not initialized.
Dave Allisonbcec6fb2014-01-17 12:52:22 -0800778 LIR* cont = NewLIR0(kPseudoTargetLabel);
buzbee2700f7e2014-03-07 09:46:20 -0800779 AddSlowPath(new (arena_) StaticFieldSlowPath(this, unresolved_branch, uninit_branch, cont,
Vladimir Markobe0e5462014-02-26 11:24:15 +0000780 field_info.StorageIndex(), r_base));
Ian Rogers5ddb4102014-01-07 08:58:46 -0800781
Vladimir Marko66c6d7b2014-10-16 15:41:48 +0100782 if (uninit_branch != nullptr) {
783 // Ensure load of status and load of value don't re-order.
784 GenMemBarrier(kLoadAny);
785 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700786 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700787 FreeTemp(r_method);
788 }
Ian Rogers5ddb4102014-01-07 08:58:46 -0800789 // r_base now holds static storage base
Fred Shih37f05ef2014-07-16 18:38:08 -0700790 RegisterClass reg_class = RegClassForFieldLoadStore(size, field_info.IsVolatile());
Vladimir Marko674744e2014-04-24 15:18:26 +0100791 RegLocation rl_result = EvalLoc(rl_dest, reg_class, true);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800792
Vladimir Marko674744e2014-04-24 15:18:26 +0100793 int field_offset = field_info.FieldOffset().Int32Value();
Fred Shih37f05ef2014-07-16 18:38:08 -0700794 if (IsRef(size)) {
795 // TODO: DCHECK?
Andreas Gampe3c12c512014-06-24 18:46:29 +0000796 LoadRefDisp(r_base, field_offset, rl_result.reg, field_info.IsVolatile() ? kVolatile :
797 kNotVolatile);
Vladimir Marko674744e2014-04-24 15:18:26 +0100798 } else {
Fred Shih37f05ef2014-07-16 18:38:08 -0700799 LoadBaseDisp(r_base, field_offset, rl_result.reg, size, field_info.IsVolatile() ?
Andreas Gampe3c12c512014-06-24 18:46:29 +0000800 kVolatile : kNotVolatile);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800801 }
Vladimir Marko674744e2014-04-24 15:18:26 +0100802 FreeTemp(r_base);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800803
Fred Shih37f05ef2014-07-16 18:38:08 -0700804 if (IsWide(size)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700805 StoreValueWide(rl_dest, rl_result);
806 } else {
807 StoreValue(rl_dest, rl_result);
808 }
809 } else {
Fred Shih37f05ef2014-07-16 18:38:08 -0700810 DCHECK(SizeMatchesTypeForEntrypoint(size, type));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700811 FlushAllRegs(); // Everything to home locations
Fred Shih37f05ef2014-07-16 18:38:08 -0700812 QuickEntrypointEnum target;
813 switch (type) {
814 case Primitive::kPrimNot:
815 target = kQuickGetObjStatic;
816 break;
817 case Primitive::kPrimLong:
818 case Primitive::kPrimDouble:
819 target = kQuickGet64Static;
820 break;
821 case Primitive::kPrimInt:
822 case Primitive::kPrimFloat:
823 target = kQuickGet32Static;
824 break;
825 case Primitive::kPrimShort:
826 target = kQuickGetShortStatic;
827 break;
828 case Primitive::kPrimChar:
829 target = kQuickGetCharStatic;
830 break;
831 case Primitive::kPrimByte:
832 target = kQuickGetByteStatic;
833 break;
834 case Primitive::kPrimBoolean:
835 target = kQuickGetBooleanStatic;
836 break;
837 case Primitive::kPrimVoid: // Intentional fallthrough.
838 default:
839 LOG(FATAL) << "Can't determine entrypoint for: " << type;
840 target = kQuickGet32Static;
841 }
Andreas Gampe98430592014-07-27 19:44:50 -0700842 CallRuntimeHelperImm(target, field_info.FieldIndex(), true);
843
Douglas Leung2db3e262014-06-25 16:02:55 -0700844 // FIXME: pGetXXStatic always return an int or int64 regardless of rl_dest.fp.
Fred Shih37f05ef2014-07-16 18:38:08 -0700845 if (IsWide(size)) {
Douglas Leung2db3e262014-06-25 16:02:55 -0700846 RegLocation rl_result = GetReturnWide(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700847 StoreValueWide(rl_dest, rl_result);
848 } else {
Douglas Leung2db3e262014-06-25 16:02:55 -0700849 RegLocation rl_result = GetReturn(rl_dest.ref ? kRefReg : kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700850 StoreValue(rl_dest, rl_result);
851 }
852 }
853}
854
Dave Allisonbcec6fb2014-01-17 12:52:22 -0800855// Generate code for all slow paths.
856void Mir2Lir::HandleSlowPaths() {
Chao-ying Fu8159af62014-07-07 17:13:52 -0700857 // We should check slow_paths_.Size() every time, because a new slow path
858 // may be created during slowpath->Compile().
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100859 for (LIRSlowPath* slowpath : slow_paths_) {
Dave Allisonbcec6fb2014-01-17 12:52:22 -0800860 slowpath->Compile();
861 }
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100862 slow_paths_.clear();
Dave Allisonbcec6fb2014-01-17 12:52:22 -0800863}
864
Fred Shih37f05ef2014-07-16 18:38:08 -0700865void Mir2Lir::GenIGet(MIR* mir, int opt_flags, OpSize size, Primitive::Type type,
866 RegLocation rl_dest, RegLocation rl_obj) {
Vladimir Markobe0e5462014-02-26 11:24:15 +0000867 const MirIFieldLoweringInfo& field_info = mir_graph_->GetIFieldLoweringInfo(mir);
Vladimir Markoaf6925b2014-10-31 16:37:32 +0000868 DCHECK_EQ(IGetMemAccessType(mir->dalvikInsn.opcode), field_info.MemAccessType());
Vladimir Markobe0e5462014-02-26 11:24:15 +0000869 cu_->compiler_driver->ProcessedInstanceField(field_info.FastGet());
Andreas Gampe0b9203e2015-01-22 20:39:27 -0800870 if (!ForceSlowFieldPath(cu_) && field_info.FastGet()) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700871 RegisterClass reg_class = RegClassForFieldLoadStore(size, field_info.IsVolatile());
Andreas Gampeaa910d52014-07-30 18:59:05 -0700872 // A load of the class will lead to an iget with offset 0.
Vladimir Markobe0e5462014-02-26 11:24:15 +0000873 DCHECK_GE(field_info.FieldOffset().Int32Value(), 0);
buzbeea0cd2d72014-06-01 09:33:49 -0700874 rl_obj = LoadValue(rl_obj, kRefReg);
Vladimir Marko674744e2014-04-24 15:18:26 +0100875 GenNullCheck(rl_obj.reg, opt_flags);
876 RegLocation rl_result = EvalLoc(rl_dest, reg_class, true);
877 int field_offset = field_info.FieldOffset().Int32Value();
Andreas Gampe3c12c512014-06-24 18:46:29 +0000878 LIR* load_lir;
Fred Shih37f05ef2014-07-16 18:38:08 -0700879 if (IsRef(size)) {
Andreas Gampe3c12c512014-06-24 18:46:29 +0000880 load_lir = LoadRefDisp(rl_obj.reg, field_offset, rl_result.reg, field_info.IsVolatile() ?
881 kVolatile : kNotVolatile);
Vladimir Marko674744e2014-04-24 15:18:26 +0100882 } else {
Fred Shih37f05ef2014-07-16 18:38:08 -0700883 load_lir = LoadBaseDisp(rl_obj.reg, field_offset, rl_result.reg, size,
Andreas Gampe3c12c512014-06-24 18:46:29 +0000884 field_info.IsVolatile() ? kVolatile : kNotVolatile);
Vladimir Marko674744e2014-04-24 15:18:26 +0100885 }
Andreas Gampe3c12c512014-06-24 18:46:29 +0000886 MarkPossibleNullPointerExceptionAfter(opt_flags, load_lir);
Fred Shih37f05ef2014-07-16 18:38:08 -0700887 if (IsWide(size)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700888 StoreValueWide(rl_dest, rl_result);
889 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700890 StoreValue(rl_dest, rl_result);
891 }
892 } else {
Fred Shih37f05ef2014-07-16 18:38:08 -0700893 DCHECK(SizeMatchesTypeForEntrypoint(size, type));
894 QuickEntrypointEnum target;
895 switch (type) {
896 case Primitive::kPrimNot:
897 target = kQuickGetObjInstance;
898 break;
899 case Primitive::kPrimLong:
900 case Primitive::kPrimDouble:
901 target = kQuickGet64Instance;
902 break;
903 case Primitive::kPrimFloat:
904 case Primitive::kPrimInt:
905 target = kQuickGet32Instance;
906 break;
907 case Primitive::kPrimShort:
908 target = kQuickGetShortInstance;
909 break;
910 case Primitive::kPrimChar:
911 target = kQuickGetCharInstance;
912 break;
913 case Primitive::kPrimByte:
914 target = kQuickGetByteInstance;
915 break;
916 case Primitive::kPrimBoolean:
917 target = kQuickGetBooleanInstance;
918 break;
919 case Primitive::kPrimVoid: // Intentional fallthrough.
920 default:
921 LOG(FATAL) << "Can't determine entrypoint for: " << type;
922 target = kQuickGet32Instance;
923 }
Andreas Gampe98430592014-07-27 19:44:50 -0700924 // Second argument of pGetXXInstance is always a reference.
925 DCHECK_EQ(static_cast<unsigned int>(rl_obj.wide), 0U);
926 CallRuntimeHelperImmRegLocation(target, field_info.FieldIndex(), rl_obj, true);
927
Serguei Katkov4eca9f52014-07-08 00:45:45 +0700928 // FIXME: pGetXXInstance always return an int or int64 regardless of rl_dest.fp.
Fred Shih37f05ef2014-07-16 18:38:08 -0700929 if (IsWide(size)) {
Serguei Katkov4eca9f52014-07-08 00:45:45 +0700930 RegLocation rl_result = GetReturnWide(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700931 StoreValueWide(rl_dest, rl_result);
932 } else {
Serguei Katkov4eca9f52014-07-08 00:45:45 +0700933 RegLocation rl_result = GetReturn(rl_dest.ref ? kRefReg : kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700934 StoreValue(rl_dest, rl_result);
935 }
936 }
937}
938
Vladimir Markobe0e5462014-02-26 11:24:15 +0000939void Mir2Lir::GenIPut(MIR* mir, int opt_flags, OpSize size,
Fred Shih37f05ef2014-07-16 18:38:08 -0700940 RegLocation rl_src, RegLocation rl_obj) {
Vladimir Markobe0e5462014-02-26 11:24:15 +0000941 const MirIFieldLoweringInfo& field_info = mir_graph_->GetIFieldLoweringInfo(mir);
Vladimir Markoaf6925b2014-10-31 16:37:32 +0000942 DCHECK_EQ(IPutMemAccessType(mir->dalvikInsn.opcode), field_info.MemAccessType());
Vladimir Markobe0e5462014-02-26 11:24:15 +0000943 cu_->compiler_driver->ProcessedInstanceField(field_info.FastPut());
Andreas Gampe0b9203e2015-01-22 20:39:27 -0800944 if (!ForceSlowFieldPath(cu_) && field_info.FastPut()) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700945 RegisterClass reg_class = RegClassForFieldLoadStore(size, field_info.IsVolatile());
Andreas Gampeaa910d52014-07-30 18:59:05 -0700946 // Dex code never writes to the class field.
947 DCHECK_GE(static_cast<uint32_t>(field_info.FieldOffset().Int32Value()),
948 sizeof(mirror::HeapReference<mirror::Class>));
buzbeea0cd2d72014-06-01 09:33:49 -0700949 rl_obj = LoadValue(rl_obj, kRefReg);
Fred Shih37f05ef2014-07-16 18:38:08 -0700950 if (IsWide(size)) {
Vladimir Marko674744e2014-04-24 15:18:26 +0100951 rl_src = LoadValueWide(rl_src, reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700952 } else {
953 rl_src = LoadValue(rl_src, reg_class);
Vladimir Marko674744e2014-04-24 15:18:26 +0100954 }
955 GenNullCheck(rl_obj.reg, opt_flags);
956 int field_offset = field_info.FieldOffset().Int32Value();
Vladimir Markoee5e2732015-01-13 17:34:28 +0000957 LIR* null_ck_insn;
Fred Shih37f05ef2014-07-16 18:38:08 -0700958 if (IsRef(size)) {
Vladimir Markoee5e2732015-01-13 17:34:28 +0000959 null_ck_insn = StoreRefDisp(rl_obj.reg, field_offset, rl_src.reg, field_info.IsVolatile() ?
Andreas Gampe3c12c512014-06-24 18:46:29 +0000960 kVolatile : kNotVolatile);
Vladimir Marko674744e2014-04-24 15:18:26 +0100961 } else {
Vladimir Markoee5e2732015-01-13 17:34:28 +0000962 null_ck_insn = StoreBaseDisp(rl_obj.reg, field_offset, rl_src.reg, size,
963 field_info.IsVolatile() ? kVolatile : kNotVolatile);
Vladimir Marko674744e2014-04-24 15:18:26 +0100964 }
Vladimir Markoee5e2732015-01-13 17:34:28 +0000965 MarkPossibleNullPointerExceptionAfter(opt_flags, null_ck_insn);
Fred Shih37f05ef2014-07-16 18:38:08 -0700966 if (IsRef(size) && !mir_graph_->IsConstantNullRef(rl_src)) {
Vladimir Marko743b98c2014-11-24 19:45:41 +0000967 MarkGCCard(opt_flags, rl_src.reg, rl_obj.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700968 }
969 } else {
Fred Shih37f05ef2014-07-16 18:38:08 -0700970 QuickEntrypointEnum target;
971 switch (size) {
972 case kReference:
973 target = kQuickSetObjInstance;
974 break;
975 case k64:
976 case kDouble:
977 target = kQuickSet64Instance;
978 break;
979 case k32:
980 case kSingle:
981 target = kQuickSet32Instance;
982 break;
983 case kSignedHalf:
984 case kUnsignedHalf:
985 target = kQuickSet16Instance;
986 break;
987 case kSignedByte:
988 case kUnsignedByte:
989 target = kQuickSet8Instance;
990 break;
991 case kWord: // Intentional fallthrough.
992 default:
993 LOG(FATAL) << "Can't determine entrypoint for: " << size;
994 target = kQuickSet32Instance;
995 }
Andreas Gampe98430592014-07-27 19:44:50 -0700996 CallRuntimeHelperImmRegLocationRegLocation(target, field_info.FieldIndex(), rl_obj, rl_src,
997 true);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700998 }
999}
1000
Ian Rogersa9a82542013-10-04 11:17:26 -07001001void Mir2Lir::GenArrayObjPut(int opt_flags, RegLocation rl_array, RegLocation rl_index,
1002 RegLocation rl_src) {
1003 bool needs_range_check = !(opt_flags & MIR_IGNORE_RANGE_CHECK);
1004 bool needs_null_check = !((cu_->disable_opt & (1 << kNullCheckElimination)) &&
1005 (opt_flags & MIR_IGNORE_NULL_CHECK));
Andreas Gampe98430592014-07-27 19:44:50 -07001006 QuickEntrypointEnum target = needs_range_check
1007 ? (needs_null_check ? kQuickAputObjectWithNullAndBoundCheck
1008 : kQuickAputObjectWithBoundCheck)
1009 : kQuickAputObject;
1010 CallRuntimeHelperRegLocationRegLocationRegLocation(target, rl_array, rl_index, rl_src, true);
Ian Rogersa9a82542013-10-04 11:17:26 -07001011}
1012
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001013void Mir2Lir::GenConstClass(uint32_t type_idx, RegLocation rl_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001014 RegLocation rl_method = LoadCurrMethod();
Andreas Gampe4b537a82014-06-30 22:24:53 -07001015 CheckRegLocation(rl_method);
buzbee33ae5582014-06-12 14:56:32 -07001016 RegStorage res_reg = AllocTempRef();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001017 if (!cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx,
Andreas Gampe4b537a82014-06-30 22:24:53 -07001018 *cu_->dex_file,
1019 type_idx)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001020 // Call out to helper which resolves type and verifies access.
1021 // Resolved type returned in kRet0.
Andreas Gampe98430592014-07-27 19:44:50 -07001022 CallRuntimeHelperImmReg(kQuickInitializeTypeAndVerifyAccess, type_idx, rl_method.reg, true);
buzbeea0cd2d72014-06-01 09:33:49 -07001023 RegLocation rl_result = GetReturn(kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001024 StoreValue(rl_dest, rl_result);
1025 } else {
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001026 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001027 // We're don't need access checks, load type from dex cache
1028 int32_t dex_cache_offset =
Brian Carlstromea46f952013-07-30 01:26:50 -07001029 mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value();
Andreas Gampe3c12c512014-06-24 18:46:29 +00001030 LoadRefDisp(rl_method.reg, dex_cache_offset, res_reg, kNotVolatile);
Andreas Gampe9c3b0892014-04-24 17:33:34 +00001031 int32_t offset_of_type = ClassArray::OffsetOfElement(type_idx).Int32Value();
Andreas Gampe3c12c512014-06-24 18:46:29 +00001032 LoadRefDisp(res_reg, offset_of_type, rl_result.reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001033 if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file,
Andreas Gampe0b9203e2015-01-22 20:39:27 -08001034 type_idx) || ForceSlowTypePath(cu_)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001035 // Slow path, at runtime test if type is null and if so initialize
1036 FlushAllRegs();
buzbee2700f7e2014-03-07 09:46:20 -08001037 LIR* branch = OpCmpImmBranch(kCondEq, rl_result.reg, 0, NULL);
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001038 LIR* cont = NewLIR0(kPseudoTargetLabel);
1039
1040 // Object to generate the slow path for class resolution.
1041 class SlowPath : public LIRSlowPath {
1042 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001043 SlowPath(Mir2Lir* m2l, LIR* fromfast, LIR* cont_in, const int type_idx_in,
1044 const RegLocation& rl_method_in, const RegLocation& rl_result_in) :
1045 LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast, cont_in),
1046 type_idx_(type_idx_in), rl_method_(rl_method_in), rl_result_(rl_result_in) {
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001047 }
1048
1049 void Compile() {
1050 GenerateTargetLabel();
1051
Andreas Gampe98430592014-07-27 19:44:50 -07001052 m2l_->CallRuntimeHelperImmReg(kQuickInitializeType, type_idx_, rl_method_.reg, true);
Andreas Gampeccc60262014-07-04 18:02:38 -07001053 m2l_->OpRegCopy(rl_result_.reg, m2l_->TargetReg(kRet0, kRef));
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001054 m2l_->OpUnconditionalBranch(cont_);
1055 }
1056
1057 private:
1058 const int type_idx_;
1059 const RegLocation rl_method_;
1060 const RegLocation rl_result_;
1061 };
1062
1063 // Add to list for future.
buzbee2700f7e2014-03-07 09:46:20 -08001064 AddSlowPath(new (arena_) SlowPath(this, branch, cont, type_idx, rl_method, rl_result));
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001065
Brian Carlstrom7940e442013-07-12 13:46:57 -07001066 StoreValue(rl_dest, rl_result);
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001067 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001068 // Fast path, we're done - just store result
1069 StoreValue(rl_dest, rl_result);
1070 }
1071 }
1072}
1073
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001074void Mir2Lir::GenConstString(uint32_t string_idx, RegLocation rl_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001075 /* NOTE: Most strings should be available at compile time */
Andreas Gampe9c3b0892014-04-24 17:33:34 +00001076 int32_t offset_of_string = mirror::ObjectArray<mirror::String>::OffsetOfElement(string_idx).
1077 Int32Value();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001078 if (!cu_->compiler_driver->CanAssumeStringIsPresentInDexCache(
Andreas Gampe0b9203e2015-01-22 20:39:27 -08001079 *cu_->dex_file, string_idx) || ForceSlowStringPath(cu_)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001080 // slow path, resolve string if not in dex cache
1081 FlushAllRegs();
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001082 LockCallTemps(); // Using explicit registers
Mark Mendell766e9292014-01-27 07:55:47 -08001083
1084 // If the Method* is already in a register, we can save a copy.
1085 RegLocation rl_method = mir_graph_->GetMethodLoc();
buzbee2700f7e2014-03-07 09:46:20 -08001086 RegStorage r_method;
Mark Mendell766e9292014-01-27 07:55:47 -08001087 if (rl_method.location == kLocPhysReg) {
1088 // A temp would conflict with register use below.
buzbee2700f7e2014-03-07 09:46:20 -08001089 DCHECK(!IsTemp(rl_method.reg));
1090 r_method = rl_method.reg;
Mark Mendell766e9292014-01-27 07:55:47 -08001091 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -07001092 r_method = TargetReg(kArg2, kRef);
Mark Mendell766e9292014-01-27 07:55:47 -08001093 LoadCurrMethodDirect(r_method);
1094 }
Mathieu Chartiereace4582014-11-24 18:29:54 -08001095 // Method to declaring class.
1096 LoadRefDisp(r_method, mirror::ArtMethod::DeclaringClassOffset().Int32Value(),
1097 TargetReg(kArg0, kRef), kNotVolatile);
1098 // Declaring class to dex cache strings.
1099 LoadRefDisp(TargetReg(kArg0, kRef), mirror::Class::DexCacheStringsOffset().Int32Value(),
Andreas Gampeccc60262014-07-04 18:02:38 -07001100 TargetReg(kArg0, kRef), kNotVolatile);
Mark Mendell766e9292014-01-27 07:55:47 -08001101
Brian Carlstrom7940e442013-07-12 13:46:57 -07001102 // Might call out to helper, which will return resolved string in kRet0
Andreas Gampeccc60262014-07-04 18:02:38 -07001103 LoadRefDisp(TargetReg(kArg0, kRef), offset_of_string, TargetReg(kRet0, kRef), kNotVolatile);
1104 LIR* fromfast = OpCmpImmBranch(kCondEq, TargetReg(kRet0, kRef), 0, NULL);
Mingyao Yang3b004ba2014-04-29 15:55:37 -07001105 LIR* cont = NewLIR0(kPseudoTargetLabel);
Mark Mendell766e9292014-01-27 07:55:47 -08001106
Mingyao Yang3b004ba2014-04-29 15:55:37 -07001107 {
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001108 // Object to generate the slow path for string resolution.
1109 class SlowPath : public LIRSlowPath {
1110 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001111 SlowPath(Mir2Lir* m2l, LIR* fromfast_in, LIR* cont_in, RegStorage r_method_in,
1112 int32_t string_idx_in) :
1113 LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast_in, cont_in),
1114 r_method_(r_method_in), string_idx_(string_idx_in) {
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001115 }
1116
1117 void Compile() {
1118 GenerateTargetLabel();
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001119 m2l_->CallRuntimeHelperImmReg(kQuickResolveString, string_idx_, r_method_, true);
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001120 m2l_->OpUnconditionalBranch(cont_);
1121 }
1122
1123 private:
Mingyao Yang3b004ba2014-04-29 15:55:37 -07001124 const RegStorage r_method_;
1125 const int32_t string_idx_;
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001126 };
1127
Mingyao Yang3b004ba2014-04-29 15:55:37 -07001128 AddSlowPath(new (arena_) SlowPath(this, fromfast, cont, r_method, string_idx));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001129 }
Mingyao Yang3b004ba2014-04-29 15:55:37 -07001130
Brian Carlstrom7940e442013-07-12 13:46:57 -07001131 GenBarrier();
buzbeea0cd2d72014-06-01 09:33:49 -07001132 StoreValue(rl_dest, GetReturn(kRefReg));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001133 } else {
1134 RegLocation rl_method = LoadCurrMethod();
buzbeea0cd2d72014-06-01 09:33:49 -07001135 RegStorage res_reg = AllocTempRef();
1136 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
Mathieu Chartiereace4582014-11-24 18:29:54 -08001137 LoadRefDisp(rl_method.reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), res_reg,
1138 kNotVolatile);
1139 LoadRefDisp(res_reg, mirror::Class::DexCacheStringsOffset().Int32Value(), res_reg,
Andreas Gampe3c12c512014-06-24 18:46:29 +00001140 kNotVolatile);
1141 LoadRefDisp(res_reg, offset_of_string, rl_result.reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001142 StoreValue(rl_dest, rl_result);
1143 }
1144}
1145
Andreas Gampe98430592014-07-27 19:44:50 -07001146/*
1147 * Let helper function take care of everything. Will
1148 * call Class::NewInstanceFromCode(type_idx, method);
1149 */
1150void Mir2Lir::GenNewInstance(uint32_t type_idx, RegLocation rl_dest) {
1151 FlushAllRegs(); /* Everything to home location */
Brian Carlstrom7940e442013-07-12 13:46:57 -07001152 // alloc will always check for resolution, do we also need to verify
1153 // access because the verifier was unable to?
Andreas Gampe98430592014-07-27 19:44:50 -07001154 const DexFile* dex_file = cu_->dex_file;
1155 CompilerDriver* driver = cu_->compiler_driver;
1156 if (driver->CanAccessInstantiableTypeWithoutChecks(cu_->method_idx, *dex_file, type_idx)) {
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -08001157 bool is_type_initialized;
1158 bool use_direct_type_ptr;
1159 uintptr_t direct_type_ptr;
Mathieu Chartier8668c3c2014-04-24 16:48:11 -07001160 bool is_finalizable;
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -08001161 if (kEmbedClassInCode &&
Mathieu Chartier8668c3c2014-04-24 16:48:11 -07001162 driver->CanEmbedTypeInCode(*dex_file, type_idx, &is_type_initialized, &use_direct_type_ptr,
1163 &direct_type_ptr, &is_finalizable) &&
1164 !is_finalizable) {
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -08001165 // The fast path.
1166 if (!use_direct_type_ptr) {
Fred Shihe7f82e22014-08-06 10:46:37 -07001167 LoadClassType(*dex_file, type_idx, kArg0);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -08001168 if (!is_type_initialized) {
Andreas Gampe98430592014-07-27 19:44:50 -07001169 CallRuntimeHelperRegMethod(kQuickAllocObjectResolved, TargetReg(kArg0, kRef), true);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -08001170 } else {
Andreas Gampe98430592014-07-27 19:44:50 -07001171 CallRuntimeHelperRegMethod(kQuickAllocObjectInitialized, TargetReg(kArg0, kRef), true);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -08001172 }
1173 } else {
1174 // Use the direct pointer.
1175 if (!is_type_initialized) {
Andreas Gampe98430592014-07-27 19:44:50 -07001176 CallRuntimeHelperImmMethod(kQuickAllocObjectResolved, direct_type_ptr, true);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -08001177 } else {
Andreas Gampe98430592014-07-27 19:44:50 -07001178 CallRuntimeHelperImmMethod(kQuickAllocObjectInitialized, direct_type_ptr, true);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -08001179 }
1180 }
1181 } else {
1182 // The slow path.
Andreas Gampe98430592014-07-27 19:44:50 -07001183 CallRuntimeHelperImmMethod(kQuickAllocObject, type_idx, true);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -08001184 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001185 } else {
Andreas Gampe98430592014-07-27 19:44:50 -07001186 CallRuntimeHelperImmMethod(kQuickAllocObjectWithAccessCheck, type_idx, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001187 }
Andreas Gampe98430592014-07-27 19:44:50 -07001188 StoreValue(rl_dest, GetReturn(kRefReg));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001189}
1190
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001191void Mir2Lir::GenThrow(RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001192 FlushAllRegs();
Andreas Gampe98430592014-07-27 19:44:50 -07001193 CallRuntimeHelperRegLocation(kQuickDeliverException, rl_src, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001194}
1195
1196// For final classes there are no sub-classes to check and so we can answer the instance-of
1197// question with simple comparisons.
1198void Mir2Lir::GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
1199 RegLocation rl_src) {
Mark Mendelldf8ee2e2014-01-27 16:37:47 -08001200 // X86 has its own implementation.
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001201 DCHECK(cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64);
Mark Mendelldf8ee2e2014-01-27 16:37:47 -08001202
buzbeea0cd2d72014-06-01 09:33:49 -07001203 RegLocation object = LoadValue(rl_src, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001204 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001205 RegStorage result_reg = rl_result.reg;
buzbeeb5860fb2014-06-21 15:31:01 -07001206 if (IsSameReg(result_reg, object.reg)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001207 result_reg = AllocTypedTemp(false, kCoreReg);
buzbeeb5860fb2014-06-21 15:31:01 -07001208 DCHECK(!IsSameReg(result_reg, object.reg));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001209 }
1210 LoadConstant(result_reg, 0); // assume false
buzbee2700f7e2014-03-07 09:46:20 -08001211 LIR* null_branchover = OpCmpImmBranch(kCondEq, object.reg, 0, NULL);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001212
buzbeea0cd2d72014-06-01 09:33:49 -07001213 RegStorage check_class = AllocTypedTemp(false, kRefReg);
1214 RegStorage object_class = AllocTypedTemp(false, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001215
1216 LoadCurrMethodDirect(check_class);
1217 if (use_declaring_class) {
Andreas Gampe3c12c512014-06-24 18:46:29 +00001218 LoadRefDisp(check_class, mirror::ArtMethod::DeclaringClassOffset().Int32Value(), check_class,
1219 kNotVolatile);
1220 LoadRefDisp(object.reg, mirror::Object::ClassOffset().Int32Value(), object_class,
1221 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001222 } else {
buzbee695d13a2014-04-19 13:32:20 -07001223 LoadRefDisp(check_class, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(),
Andreas Gampe3c12c512014-06-24 18:46:29 +00001224 check_class, kNotVolatile);
1225 LoadRefDisp(object.reg, mirror::Object::ClassOffset().Int32Value(), object_class,
1226 kNotVolatile);
Andreas Gampe9c3b0892014-04-24 17:33:34 +00001227 int32_t offset_of_type = ClassArray::OffsetOfElement(type_idx).Int32Value();
Andreas Gampe3c12c512014-06-24 18:46:29 +00001228 LoadRefDisp(check_class, offset_of_type, check_class, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001229 }
1230
buzbee695d13a2014-04-19 13:32:20 -07001231 // FIXME: what should we be comparing here? compressed or decompressed references?
Brian Carlstrom7940e442013-07-12 13:46:57 -07001232 if (cu_->instruction_set == kThumb2) {
1233 OpRegReg(kOpCmp, check_class, object_class); // Same?
Dave Allison3da67a52014-04-02 17:03:45 -07001234 LIR* it = OpIT(kCondEq, ""); // if-convert the test
Brian Carlstrom7940e442013-07-12 13:46:57 -07001235 LoadConstant(result_reg, 1); // .eq case - load true
Dave Allison3da67a52014-04-02 17:03:45 -07001236 OpEndIT(it);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001237 } else {
Andreas Gampe90969af2014-07-15 23:02:11 -07001238 GenSelectConst32(check_class, object_class, kCondEq, 1, 0, result_reg, kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001239 }
1240 LIR* target = NewLIR0(kPseudoTargetLabel);
1241 null_branchover->target = target;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001242 FreeTemp(object_class);
1243 FreeTemp(check_class);
1244 if (IsTemp(result_reg)) {
buzbee2700f7e2014-03-07 09:46:20 -08001245 OpRegCopy(rl_result.reg, result_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001246 FreeTemp(result_reg);
1247 }
1248 StoreValue(rl_dest, rl_result);
1249}
1250
1251void Mir2Lir::GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final,
1252 bool type_known_abstract, bool use_declaring_class,
1253 bool can_assume_type_is_in_dex_cache,
1254 uint32_t type_idx, RegLocation rl_dest,
1255 RegLocation rl_src) {
1256 FlushAllRegs();
1257 // May generate a call - use explicit registers
1258 LockCallTemps();
Andreas Gampeccc60262014-07-04 18:02:38 -07001259 RegStorage method_reg = TargetReg(kArg1, kRef);
Andreas Gampe4b537a82014-06-30 22:24:53 -07001260 LoadCurrMethodDirect(method_reg); // kArg1 <= current Method*
Andreas Gampeccc60262014-07-04 18:02:38 -07001261 RegStorage class_reg = TargetReg(kArg2, kRef); // kArg2 will hold the Class*
Serguei Katkov9ee45192014-07-17 14:39:03 +07001262 RegStorage ref_reg = TargetReg(kArg0, kRef); // kArg0 will hold the ref.
1263 RegStorage ret_reg = GetReturn(kRefReg).reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001264 if (needs_access_check) {
1265 // Check we have access to type_idx and if not throw IllegalAccessError,
1266 // returns Class* in kArg0
Andreas Gampe98430592014-07-27 19:44:50 -07001267 CallRuntimeHelperImm(kQuickInitializeTypeAndVerifyAccess, type_idx, true);
Serguei Katkov9ee45192014-07-17 14:39:03 +07001268 OpRegCopy(class_reg, ret_reg); // Align usage with fast path
1269 LoadValueDirectFixed(rl_src, ref_reg); // kArg0 <= ref
Brian Carlstrom7940e442013-07-12 13:46:57 -07001270 } else if (use_declaring_class) {
Serguei Katkov9ee45192014-07-17 14:39:03 +07001271 LoadValueDirectFixed(rl_src, ref_reg); // kArg0 <= ref
Andreas Gampe4b537a82014-06-30 22:24:53 -07001272 LoadRefDisp(method_reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(),
Andreas Gampe3c12c512014-06-24 18:46:29 +00001273 class_reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001274 } else {
Andreas Gampe90969af2014-07-15 23:02:11 -07001275 if (can_assume_type_is_in_dex_cache) {
1276 // Conditionally, as in the other case we will also load it.
Serguei Katkov9ee45192014-07-17 14:39:03 +07001277 LoadValueDirectFixed(rl_src, ref_reg); // kArg0 <= ref
Andreas Gampe90969af2014-07-15 23:02:11 -07001278 }
1279
Brian Carlstrom7940e442013-07-12 13:46:57 -07001280 // Load dex cache entry into class_reg (kArg2)
Andreas Gampe4b537a82014-06-30 22:24:53 -07001281 LoadRefDisp(method_reg, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(),
Andreas Gampe3c12c512014-06-24 18:46:29 +00001282 class_reg, kNotVolatile);
Andreas Gampe9c3b0892014-04-24 17:33:34 +00001283 int32_t offset_of_type = ClassArray::OffsetOfElement(type_idx).Int32Value();
Andreas Gampe3c12c512014-06-24 18:46:29 +00001284 LoadRefDisp(class_reg, offset_of_type, class_reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001285 if (!can_assume_type_is_in_dex_cache) {
Andreas Gampe90969af2014-07-15 23:02:11 -07001286 LIR* slow_path_branch = OpCmpImmBranch(kCondEq, class_reg, 0, NULL);
1287 LIR* slow_path_target = NewLIR0(kPseudoTargetLabel);
1288
1289 // Should load value here.
Serguei Katkov9ee45192014-07-17 14:39:03 +07001290 LoadValueDirectFixed(rl_src, ref_reg); // kArg0 <= ref
Andreas Gampe90969af2014-07-15 23:02:11 -07001291
1292 class InitTypeSlowPath : public Mir2Lir::LIRSlowPath {
1293 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001294 InitTypeSlowPath(Mir2Lir* m2l, LIR* branch, LIR* cont, uint32_t type_idx_in,
1295 RegLocation rl_src_in)
1296 : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch, cont), type_idx_(type_idx_in),
1297 rl_src_(rl_src_in) {
Andreas Gampe90969af2014-07-15 23:02:11 -07001298 }
1299
1300 void Compile() OVERRIDE {
1301 GenerateTargetLabel();
1302
Andreas Gampe98430592014-07-27 19:44:50 -07001303 m2l_->CallRuntimeHelperImm(kQuickInitializeType, type_idx_, true);
Andreas Gampe90969af2014-07-15 23:02:11 -07001304 m2l_->OpRegCopy(m2l_->TargetReg(kArg2, kRef),
1305 m2l_->TargetReg(kRet0, kRef)); // Align usage with fast path
Andreas Gampe90969af2014-07-15 23:02:11 -07001306 m2l_->OpUnconditionalBranch(cont_);
1307 }
1308
1309 private:
1310 uint32_t type_idx_;
1311 RegLocation rl_src_;
1312 };
1313
1314 AddSlowPath(new (arena_) InitTypeSlowPath(this, slow_path_branch, slow_path_target,
1315 type_idx, rl_src));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001316 }
1317 }
1318 /* kArg0 is ref, kArg2 is class. If ref==null, use directly as bool result */
Andreas Gampe4b537a82014-06-30 22:24:53 -07001319 RegLocation rl_result = GetReturn(kCoreReg);
Serguei Katkov9ee45192014-07-17 14:39:03 +07001320 if (!IsSameReg(rl_result.reg, ref_reg)) {
1321 // On MIPS and x86_64 rArg0 != rl_result, place false in result if branch is taken.
buzbee2700f7e2014-03-07 09:46:20 -08001322 LoadConstant(rl_result.reg, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001323 }
Serguei Katkov9ee45192014-07-17 14:39:03 +07001324 LIR* branch1 = OpCmpImmBranch(kCondEq, ref_reg, 0, NULL);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001325
1326 /* load object->klass_ */
Serguei Katkov9ee45192014-07-17 14:39:03 +07001327 RegStorage ref_class_reg = TargetReg(kArg1, kRef); // kArg1 will hold the Class* of ref.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001328 DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0);
Serguei Katkov9ee45192014-07-17 14:39:03 +07001329 LoadRefDisp(ref_reg, mirror::Object::ClassOffset().Int32Value(),
1330 ref_class_reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001331 /* kArg0 is ref, kArg1 is ref->klass_, kArg2 is class */
1332 LIR* branchover = NULL;
1333 if (type_known_final) {
Serguei Katkov9ee45192014-07-17 14:39:03 +07001334 // rl_result == ref == class.
1335 GenSelectConst32(ref_class_reg, class_reg, kCondEq, 1, 0, rl_result.reg,
Andreas Gampe90969af2014-07-15 23:02:11 -07001336 kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001337 } else {
1338 if (cu_->instruction_set == kThumb2) {
Andreas Gampe98430592014-07-27 19:44:50 -07001339 RegStorage r_tgt = LoadHelper(kQuickInstanceofNonTrivial);
Dave Allison3da67a52014-04-02 17:03:45 -07001340 LIR* it = nullptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001341 if (!type_known_abstract) {
1342 /* Uses conditional nullification */
Serguei Katkov9ee45192014-07-17 14:39:03 +07001343 OpRegReg(kOpCmp, ref_class_reg, class_reg); // Same?
Dave Allison3da67a52014-04-02 17:03:45 -07001344 it = OpIT(kCondEq, "EE"); // if-convert the test
Serguei Katkov9ee45192014-07-17 14:39:03 +07001345 LoadConstant(rl_result.reg, 1); // .eq case - load true
Brian Carlstrom7940e442013-07-12 13:46:57 -07001346 }
Serguei Katkov9ee45192014-07-17 14:39:03 +07001347 OpRegCopy(ref_reg, class_reg); // .ne case - arg0 <= class
Brian Carlstrom7940e442013-07-12 13:46:57 -07001348 OpReg(kOpBlx, r_tgt); // .ne case: helper(class, ref->class)
Dave Allison3da67a52014-04-02 17:03:45 -07001349 if (it != nullptr) {
1350 OpEndIT(it);
1351 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001352 FreeTemp(r_tgt);
1353 } else {
1354 if (!type_known_abstract) {
1355 /* Uses branchovers */
buzbee2700f7e2014-03-07 09:46:20 -08001356 LoadConstant(rl_result.reg, 1); // assume true
Andreas Gampeccc60262014-07-04 18:02:38 -07001357 branchover = OpCmpBranch(kCondEq, TargetReg(kArg1, kRef), TargetReg(kArg2, kRef), NULL);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001358 }
Andreas Gampe90969af2014-07-15 23:02:11 -07001359
Serguei Katkov9ee45192014-07-17 14:39:03 +07001360 OpRegCopy(TargetReg(kArg0, kRef), class_reg); // .ne case - arg0 <= class
Andreas Gampe98430592014-07-27 19:44:50 -07001361 CallRuntimeHelper(kQuickInstanceofNonTrivial, false);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001362 }
1363 }
1364 // TODO: only clobber when type isn't final?
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001365 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001366 /* branch targets here */
1367 LIR* target = NewLIR0(kPseudoTargetLabel);
1368 StoreValue(rl_dest, rl_result);
1369 branch1->target = target;
Andreas Gampe98430592014-07-27 19:44:50 -07001370 if (branchover != nullptr) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001371 branchover->target = target;
1372 }
1373}
1374
1375void Mir2Lir::GenInstanceof(uint32_t type_idx, RegLocation rl_dest, RegLocation rl_src) {
1376 bool type_known_final, type_known_abstract, use_declaring_class;
1377 bool needs_access_check = !cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx,
1378 *cu_->dex_file,
1379 type_idx,
1380 &type_known_final,
1381 &type_known_abstract,
1382 &use_declaring_class);
1383 bool can_assume_type_is_in_dex_cache = !needs_access_check &&
1384 cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx);
1385
1386 if ((use_declaring_class || can_assume_type_is_in_dex_cache) && type_known_final) {
1387 GenInstanceofFinal(use_declaring_class, type_idx, rl_dest, rl_src);
1388 } else {
1389 GenInstanceofCallingHelper(needs_access_check, type_known_final, type_known_abstract,
1390 use_declaring_class, can_assume_type_is_in_dex_cache,
1391 type_idx, rl_dest, rl_src);
1392 }
1393}
1394
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001395void Mir2Lir::GenCheckCast(uint32_t insn_idx, uint32_t type_idx, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001396 bool type_known_final, type_known_abstract, use_declaring_class;
1397 bool needs_access_check = !cu_->compiler_driver->CanAccessTypeWithoutChecks(cu_->method_idx,
1398 *cu_->dex_file,
1399 type_idx,
1400 &type_known_final,
1401 &type_known_abstract,
1402 &use_declaring_class);
1403 // Note: currently type_known_final is unused, as optimizing will only improve the performance
1404 // of the exception throw path.
1405 DexCompilationUnit* cu = mir_graph_->GetCurrentDexCompilationUnit();
Vladimir Marko2730db02014-01-27 11:15:17 +00001406 if (!needs_access_check && cu_->compiler_driver->IsSafeCast(cu, insn_idx)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001407 // Verifier type analysis proved this check cast would never cause an exception.
1408 return;
1409 }
1410 FlushAllRegs();
1411 // May generate a call - use explicit registers
1412 LockCallTemps();
Andreas Gampeccc60262014-07-04 18:02:38 -07001413 RegStorage method_reg = TargetReg(kArg1, kRef);
Andreas Gampe4b537a82014-06-30 22:24:53 -07001414 LoadCurrMethodDirect(method_reg); // kArg1 <= current Method*
Andreas Gampeccc60262014-07-04 18:02:38 -07001415 RegStorage class_reg = TargetReg(kArg2, kRef); // kArg2 will hold the Class*
Brian Carlstrom7940e442013-07-12 13:46:57 -07001416 if (needs_access_check) {
1417 // Check we have access to type_idx and if not throw IllegalAccessError,
1418 // returns Class* in kRet0
1419 // InitializeTypeAndVerifyAccess(idx, method)
Andreas Gampe98430592014-07-27 19:44:50 -07001420 CallRuntimeHelperImm(kQuickInitializeTypeAndVerifyAccess, type_idx, true);
Andreas Gampeccc60262014-07-04 18:02:38 -07001421 OpRegCopy(class_reg, TargetReg(kRet0, kRef)); // Align usage with fast path
Brian Carlstrom7940e442013-07-12 13:46:57 -07001422 } else if (use_declaring_class) {
Andreas Gampe4b537a82014-06-30 22:24:53 -07001423 LoadRefDisp(method_reg, mirror::ArtMethod::DeclaringClassOffset().Int32Value(),
Andreas Gampe3c12c512014-06-24 18:46:29 +00001424 class_reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001425 } else {
1426 // Load dex cache entry into class_reg (kArg2)
Andreas Gampe4b537a82014-06-30 22:24:53 -07001427 LoadRefDisp(method_reg, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value(),
Andreas Gampe3c12c512014-06-24 18:46:29 +00001428 class_reg, kNotVolatile);
Andreas Gampe9c3b0892014-04-24 17:33:34 +00001429 int32_t offset_of_type = ClassArray::OffsetOfElement(type_idx).Int32Value();
Andreas Gampe3c12c512014-06-24 18:46:29 +00001430 LoadRefDisp(class_reg, offset_of_type, class_reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001431 if (!cu_->compiler_driver->CanAssumeTypeIsPresentInDexCache(*cu_->dex_file, type_idx)) {
1432 // Need to test presence of type in dex cache at runtime
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001433 LIR* hop_branch = OpCmpImmBranch(kCondEq, class_reg, 0, NULL);
1434 LIR* cont = NewLIR0(kPseudoTargetLabel);
1435
1436 // Slow path to initialize the type. Executed if the type is NULL.
1437 class SlowPath : public LIRSlowPath {
1438 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001439 SlowPath(Mir2Lir* m2l, LIR* fromfast, LIR* cont_in, const int type_idx_in,
1440 const RegStorage class_reg_in) :
1441 LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast, cont_in),
1442 type_idx_(type_idx_in), class_reg_(class_reg_in) {
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001443 }
1444
1445 void Compile() {
1446 GenerateTargetLabel();
1447
1448 // Call out to helper, which will return resolved type in kArg0
1449 // InitializeTypeFromCode(idx, method)
Andreas Gampe98430592014-07-27 19:44:50 -07001450 m2l_->CallRuntimeHelperImmReg(kQuickInitializeType, type_idx_,
1451 m2l_->TargetReg(kArg1, kRef), true);
Andreas Gampeccc60262014-07-04 18:02:38 -07001452 m2l_->OpRegCopy(class_reg_, m2l_->TargetReg(kRet0, kRef)); // Align usage with fast path
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001453 m2l_->OpUnconditionalBranch(cont_);
1454 }
Andreas Gampe2f244e92014-05-08 03:35:25 -07001455
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001456 public:
1457 const int type_idx_;
buzbee2700f7e2014-03-07 09:46:20 -08001458 const RegStorage class_reg_;
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001459 };
1460
buzbee2700f7e2014-03-07 09:46:20 -08001461 AddSlowPath(new (arena_) SlowPath(this, hop_branch, cont, type_idx, class_reg));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001462 }
1463 }
1464 // At this point, class_reg (kArg2) has class
Andreas Gampeccc60262014-07-04 18:02:38 -07001465 LoadValueDirectFixed(rl_src, TargetReg(kArg0, kRef)); // kArg0 <= ref
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001466
1467 // Slow path for the case where the classes are not equal. In this case we need
1468 // to call a helper function to do the check.
1469 class SlowPath : public LIRSlowPath {
1470 public:
1471 SlowPath(Mir2Lir* m2l, LIR* fromfast, LIR* cont, bool load):
1472 LIRSlowPath(m2l, m2l->GetCurrentDexPc(), fromfast, cont), load_(load) {
1473 }
1474
1475 void Compile() {
1476 GenerateTargetLabel();
1477
1478 if (load_) {
Andreas Gampeccc60262014-07-04 18:02:38 -07001479 m2l_->LoadRefDisp(m2l_->TargetReg(kArg0, kRef), mirror::Object::ClassOffset().Int32Value(),
1480 m2l_->TargetReg(kArg1, kRef), kNotVolatile);
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001481 }
Andreas Gampe98430592014-07-27 19:44:50 -07001482 m2l_->CallRuntimeHelperRegReg(kQuickCheckCast, m2l_->TargetReg(kArg2, kRef),
1483 m2l_->TargetReg(kArg1, kRef), true);
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001484 m2l_->OpUnconditionalBranch(cont_);
1485 }
1486
1487 private:
Mingyao Yang3b004ba2014-04-29 15:55:37 -07001488 const bool load_;
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001489 };
1490
1491 if (type_known_abstract) {
1492 // Easier case, run slow path if target is non-null (slow path will load from target)
Andreas Gampeccc60262014-07-04 18:02:38 -07001493 LIR* branch = OpCmpImmBranch(kCondNe, TargetReg(kArg0, kRef), 0, nullptr);
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001494 LIR* cont = NewLIR0(kPseudoTargetLabel);
1495 AddSlowPath(new (arena_) SlowPath(this, branch, cont, true));
1496 } else {
1497 // Harder, more common case. We need to generate a forward branch over the load
1498 // if the target is null. If it's non-null we perform the load and branch to the
1499 // slow path if the classes are not equal.
1500
1501 /* Null is OK - continue */
Andreas Gampeccc60262014-07-04 18:02:38 -07001502 LIR* branch1 = OpCmpImmBranch(kCondEq, TargetReg(kArg0, kRef), 0, nullptr);
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001503 /* load object->klass_ */
1504 DCHECK_EQ(mirror::Object::ClassOffset().Int32Value(), 0);
Andreas Gampeccc60262014-07-04 18:02:38 -07001505 LoadRefDisp(TargetReg(kArg0, kRef), mirror::Object::ClassOffset().Int32Value(),
1506 TargetReg(kArg1, kRef), kNotVolatile);
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001507
Andreas Gampeccc60262014-07-04 18:02:38 -07001508 LIR* branch2 = OpCmpBranch(kCondNe, TargetReg(kArg1, kRef), class_reg, nullptr);
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001509 LIR* cont = NewLIR0(kPseudoTargetLabel);
1510
1511 // Add the slow path that will not perform load since this is already done.
1512 AddSlowPath(new (arena_) SlowPath(this, branch2, cont, false));
1513
1514 // Set the null check to branch to the continuation.
1515 branch1->target = cont;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001516 }
1517}
1518
1519void Mir2Lir::GenLong3Addr(OpKind first_op, OpKind second_op, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001520 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001521 RegLocation rl_result;
1522 if (cu_->instruction_set == kThumb2) {
1523 /*
1524 * NOTE: This is the one place in the code in which we might have
1525 * as many as six live temporary registers. There are 5 in the normal
1526 * set for Arm. Until we have spill capabilities, temporarily add
1527 * lr to the temp set. It is safe to do this locally, but note that
1528 * lr is used explicitly elsewhere in the code generator and cannot
1529 * normally be used as a general temp register.
1530 */
Andreas Gampeccc60262014-07-04 18:02:38 -07001531 MarkTemp(TargetReg(kLr, kNotWide)); // Add lr to the temp pool
1532 FreeTemp(TargetReg(kLr, kNotWide)); // and make it available
Brian Carlstrom7940e442013-07-12 13:46:57 -07001533 }
1534 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
1535 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
1536 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1537 // The longs may overlap - use intermediate temp if so
buzbee2700f7e2014-03-07 09:46:20 -08001538 if ((rl_result.reg.GetLowReg() == rl_src1.reg.GetHighReg()) || (rl_result.reg.GetLowReg() == rl_src2.reg.GetHighReg())) {
1539 RegStorage t_reg = AllocTemp();
1540 OpRegRegReg(first_op, t_reg, rl_src1.reg.GetLow(), rl_src2.reg.GetLow());
1541 OpRegRegReg(second_op, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), rl_src2.reg.GetHigh());
1542 OpRegCopy(rl_result.reg.GetLow(), t_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001543 FreeTemp(t_reg);
1544 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001545 OpRegRegReg(first_op, rl_result.reg.GetLow(), rl_src1.reg.GetLow(), rl_src2.reg.GetLow());
1546 OpRegRegReg(second_op, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), rl_src2.reg.GetHigh());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001547 }
1548 /*
1549 * NOTE: If rl_dest refers to a frame variable in a large frame, the
1550 * following StoreValueWide might need to allocate a temp register.
1551 * To further work around the lack of a spill capability, explicitly
1552 * free any temps from rl_src1 & rl_src2 that aren't still live in rl_result.
1553 * Remove when spill is functional.
1554 */
1555 FreeRegLocTemps(rl_result, rl_src1);
1556 FreeRegLocTemps(rl_result, rl_src2);
1557 StoreValueWide(rl_dest, rl_result);
1558 if (cu_->instruction_set == kThumb2) {
Andreas Gampeccc60262014-07-04 18:02:38 -07001559 Clobber(TargetReg(kLr, kNotWide));
1560 UnmarkTemp(TargetReg(kLr, kNotWide)); // Remove lr from the temp pool
Brian Carlstrom7940e442013-07-12 13:46:57 -07001561 }
1562}
1563
Andreas Gampe98430592014-07-27 19:44:50 -07001564void Mir2Lir::GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
1565 RegLocation rl_src1, RegLocation rl_shift) {
1566 QuickEntrypointEnum target;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001567 switch (opcode) {
1568 case Instruction::SHL_LONG:
1569 case Instruction::SHL_LONG_2ADDR:
Andreas Gampe98430592014-07-27 19:44:50 -07001570 target = kQuickShlLong;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001571 break;
1572 case Instruction::SHR_LONG:
1573 case Instruction::SHR_LONG_2ADDR:
Andreas Gampe98430592014-07-27 19:44:50 -07001574 target = kQuickShrLong;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001575 break;
1576 case Instruction::USHR_LONG:
1577 case Instruction::USHR_LONG_2ADDR:
Andreas Gampe98430592014-07-27 19:44:50 -07001578 target = kQuickUshrLong;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001579 break;
1580 default:
1581 LOG(FATAL) << "Unexpected case";
Andreas Gampe98430592014-07-27 19:44:50 -07001582 target = kQuickShlLong;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001583 }
Andreas Gampe98430592014-07-27 19:44:50 -07001584 FlushAllRegs(); /* Send everything to home location */
1585 CallRuntimeHelperRegLocationRegLocation(target, rl_src1, rl_shift, false);
buzbeea0cd2d72014-06-01 09:33:49 -07001586 RegLocation rl_result = GetReturnWide(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001587 StoreValueWide(rl_dest, rl_result);
1588}
1589
1590
1591void Mir2Lir::GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07001592 RegLocation rl_src1, RegLocation rl_src2, int flags) {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001593 DCHECK(cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001594 OpKind op = kOpBkpt;
1595 bool is_div_rem = false;
1596 bool check_zero = false;
1597 bool unary = false;
1598 RegLocation rl_result;
1599 bool shift_op = false;
1600 switch (opcode) {
1601 case Instruction::NEG_INT:
1602 op = kOpNeg;
1603 unary = true;
1604 break;
1605 case Instruction::NOT_INT:
1606 op = kOpMvn;
1607 unary = true;
1608 break;
1609 case Instruction::ADD_INT:
1610 case Instruction::ADD_INT_2ADDR:
1611 op = kOpAdd;
1612 break;
1613 case Instruction::SUB_INT:
1614 case Instruction::SUB_INT_2ADDR:
1615 op = kOpSub;
1616 break;
1617 case Instruction::MUL_INT:
1618 case Instruction::MUL_INT_2ADDR:
1619 op = kOpMul;
1620 break;
1621 case Instruction::DIV_INT:
1622 case Instruction::DIV_INT_2ADDR:
1623 check_zero = true;
1624 op = kOpDiv;
1625 is_div_rem = true;
1626 break;
1627 /* NOTE: returns in kArg1 */
1628 case Instruction::REM_INT:
1629 case Instruction::REM_INT_2ADDR:
1630 check_zero = true;
1631 op = kOpRem;
1632 is_div_rem = true;
1633 break;
1634 case Instruction::AND_INT:
1635 case Instruction::AND_INT_2ADDR:
1636 op = kOpAnd;
1637 break;
1638 case Instruction::OR_INT:
1639 case Instruction::OR_INT_2ADDR:
1640 op = kOpOr;
1641 break;
1642 case Instruction::XOR_INT:
1643 case Instruction::XOR_INT_2ADDR:
1644 op = kOpXor;
1645 break;
1646 case Instruction::SHL_INT:
1647 case Instruction::SHL_INT_2ADDR:
1648 shift_op = true;
1649 op = kOpLsl;
1650 break;
1651 case Instruction::SHR_INT:
1652 case Instruction::SHR_INT_2ADDR:
1653 shift_op = true;
1654 op = kOpAsr;
1655 break;
1656 case Instruction::USHR_INT:
1657 case Instruction::USHR_INT_2ADDR:
1658 shift_op = true;
1659 op = kOpLsr;
1660 break;
1661 default:
1662 LOG(FATAL) << "Invalid word arith op: " << opcode;
1663 }
1664 if (!is_div_rem) {
1665 if (unary) {
1666 rl_src1 = LoadValue(rl_src1, kCoreReg);
1667 rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001668 OpRegReg(op, rl_result.reg, rl_src1.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001669 } else {
Serban Constantinescued65c5e2014-05-22 15:10:18 +01001670 if ((shift_op) && (cu_->instruction_set != kArm64)) {
Mark Mendellfeb2b4e2014-01-28 12:59:49 -08001671 rl_src2 = LoadValue(rl_src2, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -08001672 RegStorage t_reg = AllocTemp();
1673 OpRegRegImm(kOpAnd, t_reg, rl_src2.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001674 rl_src1 = LoadValue(rl_src1, kCoreReg);
1675 rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001676 OpRegRegReg(op, rl_result.reg, rl_src1.reg, t_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001677 FreeTemp(t_reg);
1678 } else {
1679 rl_src1 = LoadValue(rl_src1, kCoreReg);
1680 rl_src2 = LoadValue(rl_src2, kCoreReg);
1681 rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001682 OpRegRegReg(op, rl_result.reg, rl_src1.reg, rl_src2.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001683 }
1684 }
1685 StoreValue(rl_dest, rl_result);
1686 } else {
Dave Allison70202782013-10-22 17:52:19 -07001687 bool done = false; // Set to true if we happen to find a way to use a real instruction.
Serban Constantinescued65c5e2014-05-22 15:10:18 +01001688 if (cu_->instruction_set == kMips || cu_->instruction_set == kArm64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001689 rl_src1 = LoadValue(rl_src1, kCoreReg);
1690 rl_src2 = LoadValue(rl_src2, kCoreReg);
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07001691 if (check_zero && (flags & MIR_IGNORE_DIV_ZERO_CHECK) == 0) {
Mingyao Yangd15f4e22014-04-17 18:46:24 -07001692 GenDivZeroCheck(rl_src2.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001693 }
buzbee2700f7e2014-03-07 09:46:20 -08001694 rl_result = GenDivRem(rl_dest, rl_src1.reg, rl_src2.reg, op == kOpDiv);
Dave Allison70202782013-10-22 17:52:19 -07001695 done = true;
1696 } else if (cu_->instruction_set == kThumb2) {
Andreas Gampe0b9203e2015-01-22 20:39:27 -08001697 if (cu_->compiler_driver->GetInstructionSetFeatures()->AsArmInstructionSetFeatures()->
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001698 HasDivideInstruction()) {
Dave Allison70202782013-10-22 17:52:19 -07001699 // Use ARM SDIV instruction for division. For remainder we also need to
1700 // calculate using a MUL and subtract.
1701 rl_src1 = LoadValue(rl_src1, kCoreReg);
1702 rl_src2 = LoadValue(rl_src2, kCoreReg);
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07001703 if (check_zero && (flags & MIR_IGNORE_DIV_ZERO_CHECK) == 0) {
Mingyao Yangd15f4e22014-04-17 18:46:24 -07001704 GenDivZeroCheck(rl_src2.reg);
Dave Allison70202782013-10-22 17:52:19 -07001705 }
buzbee2700f7e2014-03-07 09:46:20 -08001706 rl_result = GenDivRem(rl_dest, rl_src1.reg, rl_src2.reg, op == kOpDiv);
Dave Allison70202782013-10-22 17:52:19 -07001707 done = true;
1708 }
1709 }
1710
1711 // If we haven't already generated the code use the callout function.
1712 if (!done) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001713 FlushAllRegs(); /* Send everything to home location */
Andreas Gampeccc60262014-07-04 18:02:38 -07001714 LoadValueDirectFixed(rl_src2, TargetReg(kArg1, kNotWide));
Andreas Gampe98430592014-07-27 19:44:50 -07001715 RegStorage r_tgt = CallHelperSetup(kQuickIdivmod);
Andreas Gampeccc60262014-07-04 18:02:38 -07001716 LoadValueDirectFixed(rl_src1, TargetReg(kArg0, kNotWide));
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07001717 if (check_zero && (flags & MIR_IGNORE_DIV_ZERO_CHECK) == 0) {
Andreas Gampeccc60262014-07-04 18:02:38 -07001718 GenDivZeroCheck(TargetReg(kArg1, kNotWide));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001719 }
Dave Allison70202782013-10-22 17:52:19 -07001720 // NOTE: callout here is not a safepoint.
Andreas Gampe98430592014-07-27 19:44:50 -07001721 CallHelper(r_tgt, kQuickIdivmod, false /* not a safepoint */);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001722 if (op == kOpDiv)
buzbeea0cd2d72014-06-01 09:33:49 -07001723 rl_result = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001724 else
1725 rl_result = GetReturnAlt();
1726 }
1727 StoreValue(rl_dest, rl_result);
1728 }
1729}
1730
1731/*
1732 * The following are the first-level codegen routines that analyze the format
1733 * of each bytecode then either dispatch special purpose codegen routines
1734 * or produce corresponding Thumb instructions directly.
1735 */
1736
Brian Carlstrom7940e442013-07-12 13:46:57 -07001737// Returns true if no more than two bits are set in 'x'.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001738static bool IsPopCountLE2(unsigned int x) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001739 x &= x - 1;
1740 return (x & (x - 1)) == 0;
1741}
1742
Brian Carlstrom7940e442013-07-12 13:46:57 -07001743// Returns true if it added instructions to 'cu' to divide 'rl_src' by 'lit'
1744// and store the result in 'rl_dest'.
Andreas Gamped500b532015-01-16 22:09:55 -08001745bool Mir2Lir::HandleEasyDivRem(Instruction::Code dalvik_opcode ATTRIBUTE_UNUSED, bool is_div,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001746 RegLocation rl_src, RegLocation rl_dest, int lit) {
Andreas Gamped500b532015-01-16 22:09:55 -08001747 if ((lit < 2) || (!IsPowerOfTwo(lit))) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001748 return false;
1749 }
Andreas Gampe7e499922015-01-06 08:28:12 -08001750 int k = CTZ(lit);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001751 if (k >= 30) {
1752 // Avoid special cases.
1753 return false;
1754 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001755 rl_src = LoadValue(rl_src, kCoreReg);
1756 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee11b63d12013-08-27 07:34:17 -07001757 if (is_div) {
buzbee2700f7e2014-03-07 09:46:20 -08001758 RegStorage t_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001759 if (lit == 2) {
1760 // Division by 2 is by far the most common division by constant.
buzbee2700f7e2014-03-07 09:46:20 -08001761 OpRegRegImm(kOpLsr, t_reg, rl_src.reg, 32 - k);
1762 OpRegRegReg(kOpAdd, t_reg, t_reg, rl_src.reg);
1763 OpRegRegImm(kOpAsr, rl_result.reg, t_reg, k);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001764 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001765 OpRegRegImm(kOpAsr, t_reg, rl_src.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001766 OpRegRegImm(kOpLsr, t_reg, t_reg, 32 - k);
buzbee2700f7e2014-03-07 09:46:20 -08001767 OpRegRegReg(kOpAdd, t_reg, t_reg, rl_src.reg);
1768 OpRegRegImm(kOpAsr, rl_result.reg, t_reg, k);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001769 }
1770 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001771 RegStorage t_reg1 = AllocTemp();
1772 RegStorage t_reg2 = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001773 if (lit == 2) {
buzbee2700f7e2014-03-07 09:46:20 -08001774 OpRegRegImm(kOpLsr, t_reg1, rl_src.reg, 32 - k);
1775 OpRegRegReg(kOpAdd, t_reg2, t_reg1, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001776 OpRegRegImm(kOpAnd, t_reg2, t_reg2, lit -1);
buzbee2700f7e2014-03-07 09:46:20 -08001777 OpRegRegReg(kOpSub, rl_result.reg, t_reg2, t_reg1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001778 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001779 OpRegRegImm(kOpAsr, t_reg1, rl_src.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001780 OpRegRegImm(kOpLsr, t_reg1, t_reg1, 32 - k);
buzbee2700f7e2014-03-07 09:46:20 -08001781 OpRegRegReg(kOpAdd, t_reg2, t_reg1, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001782 OpRegRegImm(kOpAnd, t_reg2, t_reg2, lit - 1);
buzbee2700f7e2014-03-07 09:46:20 -08001783 OpRegRegReg(kOpSub, rl_result.reg, t_reg2, t_reg1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001784 }
1785 }
1786 StoreValue(rl_dest, rl_result);
1787 return true;
1788}
1789
1790// Returns true if it added instructions to 'cu' to multiply 'rl_src' by 'lit'
1791// and store the result in 'rl_dest'.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001792bool Mir2Lir::HandleEasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) {
Ian Rogerse2143c02014-03-28 08:47:16 -07001793 if (lit < 0) {
1794 return false;
1795 }
1796 if (lit == 0) {
1797 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1798 LoadConstant(rl_result.reg, 0);
1799 StoreValue(rl_dest, rl_result);
1800 return true;
1801 }
1802 if (lit == 1) {
1803 rl_src = LoadValue(rl_src, kCoreReg);
1804 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1805 OpRegCopy(rl_result.reg, rl_src.reg);
1806 StoreValue(rl_dest, rl_result);
1807 return true;
1808 }
Zheng Xuf9719f92014-04-02 13:31:31 +01001809 // There is RegRegRegShift on Arm, so check for more special cases
1810 if (cu_->instruction_set == kThumb2) {
Ian Rogerse2143c02014-03-28 08:47:16 -07001811 return EasyMultiply(rl_src, rl_dest, lit);
1812 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001813 // Can we simplify this multiplication?
1814 bool power_of_two = false;
1815 bool pop_count_le2 = false;
1816 bool power_of_two_minus_one = false;
Ian Rogerse2143c02014-03-28 08:47:16 -07001817 if (IsPowerOfTwo(lit)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001818 power_of_two = true;
1819 } else if (IsPopCountLE2(lit)) {
1820 pop_count_le2 = true;
1821 } else if (IsPowerOfTwo(lit + 1)) {
1822 power_of_two_minus_one = true;
1823 } else {
1824 return false;
1825 }
1826 rl_src = LoadValue(rl_src, kCoreReg);
1827 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1828 if (power_of_two) {
1829 // Shift.
Andreas Gampe7e499922015-01-06 08:28:12 -08001830 OpRegRegImm(kOpLsl, rl_result.reg, rl_src.reg, CTZ(lit));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001831 } else if (pop_count_le2) {
1832 // Shift and add and shift.
Andreas Gampe7e499922015-01-06 08:28:12 -08001833 int first_bit = CTZ(lit);
1834 int second_bit = CTZ(lit ^ (1 << first_bit));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001835 GenMultiplyByTwoBitMultiplier(rl_src, rl_result, lit, first_bit, second_bit);
1836 } else {
1837 // Reverse subtract: (src << (shift + 1)) - src.
1838 DCHECK(power_of_two_minus_one);
Andreas Gampe7e499922015-01-06 08:28:12 -08001839 // TUNING: rsb dst, src, src lsl#CTZ(lit + 1)
buzbee2700f7e2014-03-07 09:46:20 -08001840 RegStorage t_reg = AllocTemp();
Andreas Gampe7e499922015-01-06 08:28:12 -08001841 OpRegRegImm(kOpLsl, t_reg, rl_src.reg, CTZ(lit + 1));
buzbee2700f7e2014-03-07 09:46:20 -08001842 OpRegRegReg(kOpSub, rl_result.reg, t_reg, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001843 }
1844 StoreValue(rl_dest, rl_result);
1845 return true;
1846}
1847
Ningsheng Jian675e09b2014-10-23 13:48:36 +08001848// Returns true if it generates instructions.
1849bool Mir2Lir::HandleEasyFloatingPointDiv(RegLocation rl_dest, RegLocation rl_src1,
1850 RegLocation rl_src2) {
1851 if (!rl_src2.is_const ||
1852 ((cu_->instruction_set != kThumb2) && (cu_->instruction_set != kArm64))) {
1853 return false;
1854 }
1855
1856 if (!rl_src2.wide) {
1857 int32_t divisor = mir_graph_->ConstantValue(rl_src2);
1858 if (CanDivideByReciprocalMultiplyFloat(divisor)) {
1859 // Generate multiply by reciprocal instead of div.
1860 float recip = 1.0f/bit_cast<int32_t, float>(divisor);
1861 GenMultiplyByConstantFloat(rl_dest, rl_src1, bit_cast<float, int32_t>(recip));
1862 return true;
1863 }
1864 } else {
1865 int64_t divisor = mir_graph_->ConstantValueWide(rl_src2);
1866 if (CanDivideByReciprocalMultiplyDouble(divisor)) {
1867 // Generate multiply by reciprocal instead of div.
1868 double recip = 1.0/bit_cast<double, int64_t>(divisor);
1869 GenMultiplyByConstantDouble(rl_dest, rl_src1, bit_cast<double, int64_t>(recip));
1870 return true;
1871 }
1872 }
1873 return false;
1874}
1875
Brian Carlstrom7940e442013-07-12 13:46:57 -07001876void Mir2Lir::GenArithOpIntLit(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001877 int lit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001878 RegLocation rl_result;
1879 OpKind op = static_cast<OpKind>(0); /* Make gcc happy */
1880 int shift_op = false;
1881 bool is_div = false;
1882
1883 switch (opcode) {
1884 case Instruction::RSUB_INT_LIT8:
1885 case Instruction::RSUB_INT: {
1886 rl_src = LoadValue(rl_src, kCoreReg);
1887 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1888 if (cu_->instruction_set == kThumb2) {
buzbee2700f7e2014-03-07 09:46:20 -08001889 OpRegRegImm(kOpRsub, rl_result.reg, rl_src.reg, lit);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001890 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001891 OpRegReg(kOpNeg, rl_result.reg, rl_src.reg);
1892 OpRegImm(kOpAdd, rl_result.reg, lit);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001893 }
1894 StoreValue(rl_dest, rl_result);
1895 return;
1896 }
1897
1898 case Instruction::SUB_INT:
1899 case Instruction::SUB_INT_2ADDR:
1900 lit = -lit;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001901 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001902 case Instruction::ADD_INT:
1903 case Instruction::ADD_INT_2ADDR:
1904 case Instruction::ADD_INT_LIT8:
1905 case Instruction::ADD_INT_LIT16:
1906 op = kOpAdd;
1907 break;
1908 case Instruction::MUL_INT:
1909 case Instruction::MUL_INT_2ADDR:
1910 case Instruction::MUL_INT_LIT8:
1911 case Instruction::MUL_INT_LIT16: {
1912 if (HandleEasyMultiply(rl_src, rl_dest, lit)) {
1913 return;
1914 }
1915 op = kOpMul;
1916 break;
1917 }
1918 case Instruction::AND_INT:
1919 case Instruction::AND_INT_2ADDR:
1920 case Instruction::AND_INT_LIT8:
1921 case Instruction::AND_INT_LIT16:
1922 op = kOpAnd;
1923 break;
1924 case Instruction::OR_INT:
1925 case Instruction::OR_INT_2ADDR:
1926 case Instruction::OR_INT_LIT8:
1927 case Instruction::OR_INT_LIT16:
1928 op = kOpOr;
1929 break;
1930 case Instruction::XOR_INT:
1931 case Instruction::XOR_INT_2ADDR:
1932 case Instruction::XOR_INT_LIT8:
1933 case Instruction::XOR_INT_LIT16:
1934 op = kOpXor;
1935 break;
1936 case Instruction::SHL_INT_LIT8:
1937 case Instruction::SHL_INT:
1938 case Instruction::SHL_INT_2ADDR:
1939 lit &= 31;
1940 shift_op = true;
1941 op = kOpLsl;
1942 break;
1943 case Instruction::SHR_INT_LIT8:
1944 case Instruction::SHR_INT:
1945 case Instruction::SHR_INT_2ADDR:
1946 lit &= 31;
1947 shift_op = true;
1948 op = kOpAsr;
1949 break;
1950 case Instruction::USHR_INT_LIT8:
1951 case Instruction::USHR_INT:
1952 case Instruction::USHR_INT_2ADDR:
1953 lit &= 31;
1954 shift_op = true;
1955 op = kOpLsr;
1956 break;
1957
1958 case Instruction::DIV_INT:
1959 case Instruction::DIV_INT_2ADDR:
1960 case Instruction::DIV_INT_LIT8:
1961 case Instruction::DIV_INT_LIT16:
1962 case Instruction::REM_INT:
1963 case Instruction::REM_INT_2ADDR:
1964 case Instruction::REM_INT_LIT8:
1965 case Instruction::REM_INT_LIT16: {
1966 if (lit == 0) {
Mingyao Yange643a172014-04-08 11:02:52 -07001967 GenDivZeroException();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001968 return;
1969 }
buzbee11b63d12013-08-27 07:34:17 -07001970 if ((opcode == Instruction::DIV_INT) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -07001971 (opcode == Instruction::DIV_INT_2ADDR) ||
buzbee11b63d12013-08-27 07:34:17 -07001972 (opcode == Instruction::DIV_INT_LIT8) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -07001973 (opcode == Instruction::DIV_INT_LIT16)) {
1974 is_div = true;
1975 } else {
1976 is_div = false;
1977 }
buzbee11b63d12013-08-27 07:34:17 -07001978 if (HandleEasyDivRem(opcode, is_div, rl_src, rl_dest, lit)) {
1979 return;
1980 }
Dave Allison70202782013-10-22 17:52:19 -07001981
1982 bool done = false;
Serban Constantinescued65c5e2014-05-22 15:10:18 +01001983 if (cu_->instruction_set == kMips || cu_->instruction_set == kArm64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001984 rl_src = LoadValue(rl_src, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -08001985 rl_result = GenDivRemLit(rl_dest, rl_src.reg, lit, is_div);
Dave Allison70202782013-10-22 17:52:19 -07001986 done = true;
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001987 } else if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
Mark Mendell2bf31e62014-01-23 12:13:40 -08001988 rl_result = GenDivRemLit(rl_dest, rl_src, lit, is_div);
1989 done = true;
Dave Allison70202782013-10-22 17:52:19 -07001990 } else if (cu_->instruction_set == kThumb2) {
Andreas Gampe0b9203e2015-01-22 20:39:27 -08001991 if (cu_->compiler_driver->GetInstructionSetFeatures()->AsArmInstructionSetFeatures()->
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001992 HasDivideInstruction()) {
Dave Allison70202782013-10-22 17:52:19 -07001993 // Use ARM SDIV instruction for division. For remainder we also need to
1994 // calculate using a MUL and subtract.
1995 rl_src = LoadValue(rl_src, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -08001996 rl_result = GenDivRemLit(rl_dest, rl_src.reg, lit, is_div);
Dave Allison70202782013-10-22 17:52:19 -07001997 done = true;
1998 }
1999 }
2000
2001 if (!done) {
2002 FlushAllRegs(); /* Everything to home location. */
Andreas Gampeccc60262014-07-04 18:02:38 -07002003 LoadValueDirectFixed(rl_src, TargetReg(kArg0, kNotWide));
2004 Clobber(TargetReg(kArg0, kNotWide));
Andreas Gampe98430592014-07-27 19:44:50 -07002005 CallRuntimeHelperRegImm(kQuickIdivmod, TargetReg(kArg0, kNotWide), lit, false);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002006 if (is_div)
buzbeea0cd2d72014-06-01 09:33:49 -07002007 rl_result = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002008 else
2009 rl_result = GetReturnAlt();
2010 }
2011 StoreValue(rl_dest, rl_result);
2012 return;
2013 }
2014 default:
2015 LOG(FATAL) << "Unexpected opcode " << opcode;
2016 }
2017 rl_src = LoadValue(rl_src, kCoreReg);
2018 rl_result = EvalLoc(rl_dest, kCoreReg, true);
Dave Allison70202782013-10-22 17:52:19 -07002019 // Avoid shifts by literal 0 - no support in Thumb. Change to copy.
Brian Carlstrom7940e442013-07-12 13:46:57 -07002020 if (shift_op && (lit == 0)) {
buzbee2700f7e2014-03-07 09:46:20 -08002021 OpRegCopy(rl_result.reg, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002022 } else {
buzbee2700f7e2014-03-07 09:46:20 -08002023 OpRegRegImm(op, rl_result.reg, rl_src.reg, lit);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002024 }
2025 StoreValue(rl_dest, rl_result);
2026}
2027
Andreas Gampe98430592014-07-27 19:44:50 -07002028void Mir2Lir::GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07002029 RegLocation rl_src1, RegLocation rl_src2, int flags) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07002030 RegLocation rl_result;
2031 OpKind first_op = kOpBkpt;
2032 OpKind second_op = kOpBkpt;
2033 bool call_out = false;
2034 bool check_zero = false;
Andreas Gampe98430592014-07-27 19:44:50 -07002035 int ret_reg = TargetReg(kRet0, kNotWide).GetReg();
2036 QuickEntrypointEnum target;
Brian Carlstrom7940e442013-07-12 13:46:57 -07002037
2038 switch (opcode) {
2039 case Instruction::NOT_LONG:
Andreas Gampe98430592014-07-27 19:44:50 -07002040 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
2041 rl_result = EvalLoc(rl_dest, kCoreReg, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002042 // Check for destructive overlap
buzbee2700f7e2014-03-07 09:46:20 -08002043 if (rl_result.reg.GetLowReg() == rl_src2.reg.GetHighReg()) {
Andreas Gampe98430592014-07-27 19:44:50 -07002044 RegStorage t_reg = AllocTemp();
2045 OpRegCopy(t_reg, rl_src2.reg.GetHigh());
2046 OpRegReg(kOpMvn, rl_result.reg.GetLow(), rl_src2.reg.GetLow());
2047 OpRegReg(kOpMvn, rl_result.reg.GetHigh(), t_reg);
2048 FreeTemp(t_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002049 } else {
Andreas Gampe98430592014-07-27 19:44:50 -07002050 OpRegReg(kOpMvn, rl_result.reg.GetLow(), rl_src2.reg.GetLow());
2051 OpRegReg(kOpMvn, rl_result.reg.GetHigh(), rl_src2.reg.GetHigh());
Brian Carlstrom7940e442013-07-12 13:46:57 -07002052 }
Andreas Gampe98430592014-07-27 19:44:50 -07002053 StoreValueWide(rl_dest, rl_result);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002054 return;
2055 case Instruction::ADD_LONG:
2056 case Instruction::ADD_LONG_2ADDR:
Brian Carlstrom7940e442013-07-12 13:46:57 -07002057 first_op = kOpAdd;
2058 second_op = kOpAdc;
2059 break;
2060 case Instruction::SUB_LONG:
2061 case Instruction::SUB_LONG_2ADDR:
Brian Carlstrom7940e442013-07-12 13:46:57 -07002062 first_op = kOpSub;
2063 second_op = kOpSbc;
2064 break;
2065 case Instruction::MUL_LONG:
2066 case Instruction::MUL_LONG_2ADDR:
Andreas Gampec76c6142014-08-04 16:30:03 -07002067 call_out = true;
2068 ret_reg = TargetReg(kRet0, kNotWide).GetReg();
2069 target = kQuickLmul;
Brian Carlstrom7940e442013-07-12 13:46:57 -07002070 break;
2071 case Instruction::DIV_LONG:
2072 case Instruction::DIV_LONG_2ADDR:
2073 call_out = true;
2074 check_zero = true;
Andreas Gampe98430592014-07-27 19:44:50 -07002075 ret_reg = TargetReg(kRet0, kNotWide).GetReg();
2076 target = kQuickLdiv;
Brian Carlstrom7940e442013-07-12 13:46:57 -07002077 break;
2078 case Instruction::REM_LONG:
2079 case Instruction::REM_LONG_2ADDR:
2080 call_out = true;
2081 check_zero = true;
Andreas Gampe98430592014-07-27 19:44:50 -07002082 target = kQuickLmod;
Brian Carlstrom7940e442013-07-12 13:46:57 -07002083 /* NOTE - for Arm, result is in kArg2/kArg3 instead of kRet0/kRet1 */
Andreas Gampe98430592014-07-27 19:44:50 -07002084 ret_reg = (cu_->instruction_set == kThumb2) ? TargetReg(kArg2, kNotWide).GetReg() :
2085 TargetReg(kRet0, kNotWide).GetReg();
Brian Carlstrom7940e442013-07-12 13:46:57 -07002086 break;
2087 case Instruction::AND_LONG_2ADDR:
2088 case Instruction::AND_LONG:
Brian Carlstrom7940e442013-07-12 13:46:57 -07002089 first_op = kOpAnd;
2090 second_op = kOpAnd;
2091 break;
2092 case Instruction::OR_LONG:
2093 case Instruction::OR_LONG_2ADDR:
Brian Carlstrom7940e442013-07-12 13:46:57 -07002094 first_op = kOpOr;
2095 second_op = kOpOr;
2096 break;
2097 case Instruction::XOR_LONG:
2098 case Instruction::XOR_LONG_2ADDR:
Brian Carlstrom7940e442013-07-12 13:46:57 -07002099 first_op = kOpXor;
2100 second_op = kOpXor;
2101 break;
Brian Carlstrom7940e442013-07-12 13:46:57 -07002102 default:
2103 LOG(FATAL) << "Invalid long arith op";
2104 }
2105 if (!call_out) {
Andreas Gampe98430592014-07-27 19:44:50 -07002106 GenLong3Addr(first_op, second_op, rl_dest, rl_src1, rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002107 } else {
Andreas Gampe98430592014-07-27 19:44:50 -07002108 FlushAllRegs(); /* Send everything to home location */
Brian Carlstrom7940e442013-07-12 13:46:57 -07002109 if (check_zero) {
Andreas Gampe98430592014-07-27 19:44:50 -07002110 RegStorage r_tmp1 = TargetReg(kArg0, kWide);
2111 RegStorage r_tmp2 = TargetReg(kArg2, kWide);
2112 LoadValueDirectWideFixed(rl_src2, r_tmp2);
2113 RegStorage r_tgt = CallHelperSetup(target);
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07002114 if ((flags & MIR_IGNORE_DIV_ZERO_CHECK) == 0) {
2115 GenDivZeroCheckWide(r_tmp2);
2116 }
Andreas Gampe98430592014-07-27 19:44:50 -07002117 LoadValueDirectWideFixed(rl_src1, r_tmp1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002118 // NOTE: callout here is not a safepoint
Andreas Gampe98430592014-07-27 19:44:50 -07002119 CallHelper(r_tgt, target, false /* not safepoint */);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002120 } else {
Andreas Gampe98430592014-07-27 19:44:50 -07002121 CallRuntimeHelperRegLocationRegLocation(target, rl_src1, rl_src2, false);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002122 }
2123 // Adjust return regs in to handle case of rem returning kArg2/kArg3
Andreas Gampe98430592014-07-27 19:44:50 -07002124 if (ret_reg == TargetReg(kRet0, kNotWide).GetReg())
2125 rl_result = GetReturnWide(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002126 else
Andreas Gampe98430592014-07-27 19:44:50 -07002127 rl_result = GetReturnWideAlt();
2128 StoreValueWide(rl_dest, rl_result);
Andreas Gampe2f244e92014-05-08 03:35:25 -07002129 }
2130}
2131
Mark Mendelle87f9b52014-04-30 14:13:18 -04002132void Mir2Lir::GenConst(RegLocation rl_dest, int value) {
2133 RegLocation rl_result = EvalLoc(rl_dest, kAnyReg, true);
2134 LoadConstantNoClobber(rl_result.reg, value);
2135 StoreValue(rl_dest, rl_result);
2136 if (value == 0) {
2137 Workaround7250540(rl_dest, rl_result.reg);
2138 }
2139}
2140
Andreas Gampe98430592014-07-27 19:44:50 -07002141void Mir2Lir::GenConversionCall(QuickEntrypointEnum trampoline, RegLocation rl_dest,
2142 RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07002143 /*
2144 * Don't optimize the register usage since it calls out to support
2145 * functions
2146 */
Andreas Gampe2f244e92014-05-08 03:35:25 -07002147
Brian Carlstrom7940e442013-07-12 13:46:57 -07002148 FlushAllRegs(); /* Send everything to home location */
Andreas Gampe98430592014-07-27 19:44:50 -07002149 CallRuntimeHelperRegLocation(trampoline, rl_src, false);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002150 if (rl_dest.wide) {
2151 RegLocation rl_result;
buzbeea0cd2d72014-06-01 09:33:49 -07002152 rl_result = GetReturnWide(LocToRegClass(rl_dest));
Brian Carlstrom7940e442013-07-12 13:46:57 -07002153 StoreValueWide(rl_dest, rl_result);
2154 } else {
2155 RegLocation rl_result;
buzbeea0cd2d72014-06-01 09:33:49 -07002156 rl_result = GetReturn(LocToRegClass(rl_dest));
Brian Carlstrom7940e442013-07-12 13:46:57 -07002157 StoreValue(rl_dest, rl_result);
2158 }
2159}
2160
Vladimir Marko6ce3eba2015-02-16 13:05:59 +00002161class Mir2Lir::SuspendCheckSlowPath : public Mir2Lir::LIRSlowPath {
Mingyao Yang6ffcfa02014-04-25 11:06:00 -07002162 public:
2163 SuspendCheckSlowPath(Mir2Lir* m2l, LIR* branch, LIR* cont)
2164 : LIRSlowPath(m2l, m2l->GetCurrentDexPc(), branch, cont) {
2165 }
2166
2167 void Compile() OVERRIDE {
2168 m2l_->ResetRegPool();
2169 m2l_->ResetDefTracking();
2170 GenerateTargetLabel(kPseudoSuspendTarget);
Andreas Gampe98430592014-07-27 19:44:50 -07002171 m2l_->CallRuntimeHelper(kQuickTestSuspend, true);
Mingyao Yang6ffcfa02014-04-25 11:06:00 -07002172 if (cont_ != nullptr) {
2173 m2l_->OpUnconditionalBranch(cont_);
2174 }
2175 }
2176};
2177
Brian Carlstrom7940e442013-07-12 13:46:57 -07002178/* Check if we need to check for pending suspend request */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07002179void Mir2Lir::GenSuspendTest(int opt_flags) {
Vladimir Marko8b858e12014-11-27 14:52:37 +00002180 if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK) != 0) {
2181 return;
2182 }
Dave Allison69dfe512014-07-11 17:11:58 +00002183 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitSuspendChecks()) {
Dave Allisonb373e092014-02-20 16:06:36 -08002184 FlushAllRegs();
2185 LIR* branch = OpTestSuspend(NULL);
Mingyao Yang6ffcfa02014-04-25 11:06:00 -07002186 LIR* cont = NewLIR0(kPseudoTargetLabel);
2187 AddSlowPath(new (arena_) SuspendCheckSlowPath(this, branch, cont));
Dave Allisonb373e092014-02-20 16:06:36 -08002188 } else {
Dave Allisonb373e092014-02-20 16:06:36 -08002189 FlushAllRegs(); // TODO: needed?
2190 LIR* inst = CheckSuspendUsingLoad();
2191 MarkSafepointPC(inst);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002192 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07002193}
2194
2195/* Check if we need to check for pending suspend request */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07002196void Mir2Lir::GenSuspendTestAndBranch(int opt_flags, LIR* target) {
Vladimir Marko8b858e12014-11-27 14:52:37 +00002197 if (NO_SUSPEND || (opt_flags & MIR_IGNORE_SUSPEND_CHECK) != 0) {
2198 OpUnconditionalBranch(target);
2199 return;
2200 }
Dave Allison69dfe512014-07-11 17:11:58 +00002201 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitSuspendChecks()) {
Dave Allisonb373e092014-02-20 16:06:36 -08002202 OpTestSuspend(target);
Dave Allisonb373e092014-02-20 16:06:36 -08002203 FlushAllRegs();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -07002204 LIR* branch = OpUnconditionalBranch(nullptr);
2205 AddSlowPath(new (arena_) SuspendCheckSlowPath(this, branch, target));
Dave Allisonb373e092014-02-20 16:06:36 -08002206 } else {
2207 // For the implicit suspend check, just perform the trigger
2208 // load and branch to the target.
Dave Allisonb373e092014-02-20 16:06:36 -08002209 FlushAllRegs();
2210 LIR* inst = CheckSuspendUsingLoad();
2211 MarkSafepointPC(inst);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002212 OpUnconditionalBranch(target);
Brian Carlstrom7940e442013-07-12 13:46:57 -07002213 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07002214}
2215
Ian Rogersd9c4fc92013-10-01 19:45:43 -07002216/* Call out to helper assembly routine that will null check obj and then lock it. */
2217void Mir2Lir::GenMonitorEnter(int opt_flags, RegLocation rl_src) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002218 UNUSED(opt_flags); // TODO: avoid null check with specialized non-null helper.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07002219 FlushAllRegs();
Andreas Gampe98430592014-07-27 19:44:50 -07002220 CallRuntimeHelperRegLocation(kQuickLockObject, rl_src, true);
Ian Rogersd9c4fc92013-10-01 19:45:43 -07002221}
2222
2223/* Call out to helper assembly routine that will null check obj and then unlock it. */
2224void Mir2Lir::GenMonitorExit(int opt_flags, RegLocation rl_src) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002225 UNUSED(opt_flags); // TODO: avoid null check with specialized non-null helper.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07002226 FlushAllRegs();
Andreas Gampe98430592014-07-27 19:44:50 -07002227 CallRuntimeHelperRegLocation(kQuickUnlockObject, rl_src, true);
Ian Rogersd9c4fc92013-10-01 19:45:43 -07002228}
2229
Bill Buzbeed61ba4b2014-01-13 21:44:01 +00002230/* Generic code for generating a wide constant into a VR. */
2231void Mir2Lir::GenConstWide(RegLocation rl_dest, int64_t value) {
2232 RegLocation rl_result = EvalLoc(rl_dest, kAnyReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08002233 LoadConstantWide(rl_result.reg, value);
Bill Buzbeed61ba4b2014-01-13 21:44:01 +00002234 StoreValueWide(rl_dest, rl_result);
2235}
2236
Andreas Gampe48971b32014-08-06 10:09:01 -07002237void Mir2Lir::GenSmallPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) {
Chao-ying Fuda96aed2014-10-27 14:42:00 -07002238 BasicBlock* bb = mir_graph_->GetBasicBlock(mir->bb);
2239 DCHECK(bb != nullptr);
2240 ArenaVector<SuccessorBlockInfo*>::const_iterator succ_bb_iter = bb->successor_blocks.cbegin();
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -07002241 const uint16_t* table = mir_graph_->GetTable(mir, table_offset);
Andreas Gampe48971b32014-08-06 10:09:01 -07002242 const uint16_t entries = table[1];
2243 // Chained cmp-and-branch.
2244 const int32_t* as_int32 = reinterpret_cast<const int32_t*>(&table[2]);
Ian Rogers7d4ecd52014-10-30 15:10:02 -07002245 int32_t starting_key = as_int32[0];
Andreas Gampe48971b32014-08-06 10:09:01 -07002246 rl_src = LoadValue(rl_src, kCoreReg);
2247 int i = 0;
Chao-ying Fuda96aed2014-10-27 14:42:00 -07002248 for (; i < entries; ++i, ++succ_bb_iter) {
Ian Rogers7d4ecd52014-10-30 15:10:02 -07002249 if (!InexpensiveConstantInt(starting_key + i, Instruction::Code::IF_EQ)) {
Andreas Gampe48971b32014-08-06 10:09:01 -07002250 // Switch to using a temp and add.
2251 break;
2252 }
Chao-ying Fuda96aed2014-10-27 14:42:00 -07002253 SuccessorBlockInfo* successor_block_info = *succ_bb_iter;
2254 DCHECK(successor_block_info != nullptr);
2255 int case_block_id = successor_block_info->block;
2256 DCHECK_EQ(starting_key + i, successor_block_info->key);
2257 OpCmpImmBranch(kCondEq, rl_src.reg, starting_key + i, &block_label_list_[case_block_id]);
Andreas Gampe48971b32014-08-06 10:09:01 -07002258 }
2259 if (i < entries) {
2260 // The rest do not seem to be inexpensive. Try to allocate a temp and use add.
2261 RegStorage key_temp = AllocTypedTemp(false, kCoreReg, false);
2262 if (key_temp.Valid()) {
Ian Rogers7d4ecd52014-10-30 15:10:02 -07002263 LoadConstantNoClobber(key_temp, starting_key + i);
Chao-ying Fuda96aed2014-10-27 14:42:00 -07002264 for (; i < entries - 1; ++i, ++succ_bb_iter) {
2265 SuccessorBlockInfo* successor_block_info = *succ_bb_iter;
2266 DCHECK(successor_block_info != nullptr);
2267 int case_block_id = successor_block_info->block;
2268 DCHECK_EQ(starting_key + i, successor_block_info->key);
2269 OpCmpBranch(kCondEq, rl_src.reg, key_temp, &block_label_list_[case_block_id]);
Andreas Gampe48971b32014-08-06 10:09:01 -07002270 OpRegImm(kOpAdd, key_temp, 1); // Increment key.
2271 }
Chao-ying Fuda96aed2014-10-27 14:42:00 -07002272 SuccessorBlockInfo* successor_block_info = *succ_bb_iter;
2273 DCHECK(successor_block_info != nullptr);
2274 int case_block_id = successor_block_info->block;
2275 DCHECK_EQ(starting_key + i, successor_block_info->key);
2276 OpCmpBranch(kCondEq, rl_src.reg, key_temp, &block_label_list_[case_block_id]);
Andreas Gampe48971b32014-08-06 10:09:01 -07002277 } else {
2278 // No free temp, just finish the old loop.
Chao-ying Fuda96aed2014-10-27 14:42:00 -07002279 for (; i < entries; ++i, ++succ_bb_iter) {
2280 SuccessorBlockInfo* successor_block_info = *succ_bb_iter;
2281 DCHECK(successor_block_info != nullptr);
2282 int case_block_id = successor_block_info->block;
2283 DCHECK_EQ(starting_key + i, successor_block_info->key);
2284 OpCmpImmBranch(kCondEq, rl_src.reg, starting_key + i, &block_label_list_[case_block_id]);
Andreas Gampe48971b32014-08-06 10:09:01 -07002285 }
2286 }
2287 }
2288}
2289
2290void Mir2Lir::GenPackedSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -07002291 const uint16_t* table = mir_graph_->GetTable(mir, table_offset);
Andreas Gampe48971b32014-08-06 10:09:01 -07002292 if (cu_->verbose) {
Chao-ying Fuda96aed2014-10-27 14:42:00 -07002293 DumpPackedSwitchTable(table);
Andreas Gampe48971b32014-08-06 10:09:01 -07002294 }
2295
2296 const uint16_t entries = table[1];
2297 if (entries <= kSmallSwitchThreshold) {
2298 GenSmallPackedSwitch(mir, table_offset, rl_src);
2299 } else {
2300 // Use the backend-specific implementation.
2301 GenLargePackedSwitch(mir, table_offset, rl_src);
2302 }
2303}
2304
2305void Mir2Lir::GenSmallSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) {
Chao-ying Fuda96aed2014-10-27 14:42:00 -07002306 BasicBlock* bb = mir_graph_->GetBasicBlock(mir->bb);
2307 DCHECK(bb != nullptr);
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -07002308 const uint16_t* table = mir_graph_->GetTable(mir, table_offset);
Andreas Gampe48971b32014-08-06 10:09:01 -07002309 const uint16_t entries = table[1];
2310 // Chained cmp-and-branch.
Andreas Gampe48971b32014-08-06 10:09:01 -07002311 rl_src = LoadValue(rl_src, kCoreReg);
Chao-ying Fuda96aed2014-10-27 14:42:00 -07002312 int i = 0;
2313 for (SuccessorBlockInfo* successor_block_info : bb->successor_blocks) {
2314 int case_block_id = successor_block_info->block;
2315 int key = successor_block_info->key;
2316 OpCmpImmBranch(kCondEq, rl_src.reg, key, &block_label_list_[case_block_id]);
2317 i++;
Andreas Gampe48971b32014-08-06 10:09:01 -07002318 }
Chao-ying Fuda96aed2014-10-27 14:42:00 -07002319 DCHECK_EQ(i, entries);
Andreas Gampe48971b32014-08-06 10:09:01 -07002320}
2321
2322void Mir2Lir::GenSparseSwitch(MIR* mir, DexOffset table_offset, RegLocation rl_src) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -07002323 const uint16_t* table = mir_graph_->GetTable(mir, table_offset);
Andreas Gampe48971b32014-08-06 10:09:01 -07002324 if (cu_->verbose) {
2325 DumpSparseSwitchTable(table);
2326 }
2327
2328 const uint16_t entries = table[1];
2329 if (entries <= kSmallSwitchThreshold) {
2330 GenSmallSparseSwitch(mir, table_offset, rl_src);
2331 } else {
2332 // Use the backend-specific implementation.
2333 GenLargeSparseSwitch(mir, table_offset, rl_src);
2334 }
2335}
2336
Fred Shih37f05ef2014-07-16 18:38:08 -07002337bool Mir2Lir::SizeMatchesTypeForEntrypoint(OpSize size, Primitive::Type type) {
2338 switch (size) {
2339 case kReference:
2340 return type == Primitive::kPrimNot;
2341 case k64:
2342 case kDouble:
2343 return type == Primitive::kPrimLong || type == Primitive::kPrimDouble;
2344 case k32:
2345 case kSingle:
2346 return type == Primitive::kPrimInt || type == Primitive::kPrimFloat;
2347 case kSignedHalf:
2348 return type == Primitive::kPrimShort;
2349 case kUnsignedHalf:
2350 return type == Primitive::kPrimChar;
2351 case kSignedByte:
2352 return type == Primitive::kPrimByte;
2353 case kUnsignedByte:
2354 return type == Primitive::kPrimBoolean;
2355 case kWord: // Intentional fallthrough.
2356 default:
2357 return false; // There are no sane types with this op size.
2358 }
2359}
2360
Brian Carlstrom7940e442013-07-12 13:46:57 -07002361} // namespace art