blob: 363fbeffb60b38de2ef7e2c1004328bfbd79a88e [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_arm.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000018
Calin Juravle34166012014-12-19 17:22:29 +000019#include "arch/arm/instruction_set_features_arm.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070020#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010021#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080022#include "intrinsics.h"
23#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070024#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000025#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010026#include "mirror/class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070027#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010028#include "utils/arm/assembler_arm.h"
29#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000030#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010031#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000032
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000033namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010034
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000035namespace arm {
36
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000037static bool ExpectedPairLayout(Location location) {
38 // We expected this for both core and fpu register pairs.
39 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
40}
41
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010042static constexpr int kCurrentMethodStackOffset = 0;
43
Calin Juravled6fb6cf2014-11-11 19:07:44 +000044static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010045static constexpr size_t kRuntimeParameterCoreRegistersLength =
46 arraysize(kRuntimeParameterCoreRegisters);
Calin Juravled2ec87d2014-12-08 14:24:46 +000047static constexpr SRegister kRuntimeParameterFpuRegisters[] = { S0, S1, S2, S3 };
Roland Levillain624279f2014-12-04 11:54:28 +000048static constexpr size_t kRuntimeParameterFpuRegistersLength =
49 arraysize(kRuntimeParameterFpuRegisters);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000050// We unconditionally allocate R5 to ensure we can do long operations
51// with baseline.
52static constexpr Register kCoreSavedRegisterForBaseline = R5;
53static constexpr Register kCoreCalleeSaves[] =
54 { R5, R6, R7, R8, R10, R11, PC };
55static constexpr SRegister kFpuCalleeSaves[] =
56 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010057
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000058// D31 cannot be split into two S registers, and the register allocator only works on
59// S registers. Therefore there is no need to block it.
60static constexpr DRegister DTMP = D31;
61
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000062class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010063 public:
64 InvokeRuntimeCallingConvention()
65 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010066 kRuntimeParameterCoreRegistersLength,
67 kRuntimeParameterFpuRegisters,
68 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010069
70 private:
71 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
72};
73
Nicolas Geoffraye5038322014-07-04 09:41:32 +010074#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010075#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010076
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010077class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010078 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010079 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010080
Alexandre Rames67555f72014-11-18 10:55:16 +000081 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010082 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010083 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010084 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000085 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010086 }
87
88 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010089 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010090 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
91};
92
Calin Juravled0d48522014-11-04 16:40:20 +000093class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
94 public:
95 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
96
Alexandre Rames67555f72014-11-18 10:55:16 +000097 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000098 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
99 __ Bind(GetEntryLabel());
100 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000101 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +0000102 }
103
104 private:
105 HDivZeroCheck* const instruction_;
106 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
107};
108
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100109class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000110 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000111 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100112 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000113
Alexandre Rames67555f72014-11-18 10:55:16 +0000114 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100115 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000116 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000117 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100118 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000119 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000120 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100121 if (successor_ == nullptr) {
122 __ b(GetReturnLabel());
123 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100124 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100125 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000126 }
127
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100128 Label* GetReturnLabel() {
129 DCHECK(successor_ == nullptr);
130 return &return_label_;
131 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132
133 private:
134 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100135 // If not null, the block to branch to after the suspend check.
136 HBasicBlock* const successor_;
137
138 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000139 Label return_label_;
140
141 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
142};
143
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100144class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100145 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100146 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
147 Location index_location,
148 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100149 : instruction_(instruction),
150 index_location_(index_location),
151 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152
Alexandre Rames67555f72014-11-18 10:55:16 +0000153 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100154 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100155 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000156 // We're moving two locations to locations that could overlap, so we need a parallel
157 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100158 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000159 codegen->EmitParallelMoves(
160 index_location_,
161 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
162 length_location_,
163 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100164 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000165 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100166 }
167
168 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100169 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100170 const Location index_location_;
171 const Location length_location_;
172
173 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
174};
175
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000176class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100177 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000178 LoadClassSlowPathARM(HLoadClass* cls,
179 HInstruction* at,
180 uint32_t dex_pc,
181 bool do_clinit)
182 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
183 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
184 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100185
Alexandre Rames67555f72014-11-18 10:55:16 +0000186 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000187 LocationSummary* locations = at_->GetLocations();
188
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100189 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
190 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000191 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100192
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100193 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000194 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100195 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000196 int32_t entry_point_offset = do_clinit_
197 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
198 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000199 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200
201 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000202 Location out = locations->Out();
203 if (out.IsValid()) {
204 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000205 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
206 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000207 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100208 __ b(GetExitLabel());
209 }
210
211 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000212 // The class this slow path will load.
213 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100214
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000215 // The instruction where this slow path is happening.
216 // (Might be the load class or an initialization check).
217 HInstruction* const at_;
218
219 // The dex PC of `at_`.
220 const uint32_t dex_pc_;
221
222 // Whether to initialize the class.
223 const bool do_clinit_;
224
225 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100226};
227
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000228class LoadStringSlowPathARM : public SlowPathCodeARM {
229 public:
230 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
231
Alexandre Rames67555f72014-11-18 10:55:16 +0000232 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000233 LocationSummary* locations = instruction_->GetLocations();
234 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
235
236 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
237 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000238 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000239
240 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800241 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
242 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000243 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000244 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000245 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
246
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000247 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000248 __ b(GetExitLabel());
249 }
250
251 private:
252 HLoadString* const instruction_;
253
254 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
255};
256
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000257class TypeCheckSlowPathARM : public SlowPathCodeARM {
258 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000259 TypeCheckSlowPathARM(HInstruction* instruction,
260 Location class_to_check,
261 Location object_class,
262 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000263 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000264 class_to_check_(class_to_check),
265 object_class_(object_class),
266 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000267
Alexandre Rames67555f72014-11-18 10:55:16 +0000268 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000269 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000270 DCHECK(instruction_->IsCheckCast()
271 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000272
273 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
274 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000275 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000276
277 // We're moving two locations to locations that could overlap, so we need a parallel
278 // move resolver.
279 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000280 codegen->EmitParallelMoves(
281 class_to_check_,
282 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
283 object_class_,
284 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000286 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000287 arm_codegen->InvokeRuntime(
288 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000289 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
290 } else {
291 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000292 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000293 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000294
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000295 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000296 __ b(GetExitLabel());
297 }
298
299 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000300 HInstruction* const instruction_;
301 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000302 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000303 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000304
305 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
306};
307
Mingyao Yange295e6e2015-03-07 06:37:59 -0800308class DeoptimizationSlowPathARM : public SlowPathCodeARM {
309 public:
310 explicit DeoptimizationSlowPathARM(HInstruction* instruction)
311 : instruction_(instruction) {}
312
313 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
314 __ Bind(GetEntryLabel());
315 SaveLiveRegisters(codegen, instruction_->GetLocations());
316 DCHECK(instruction_->IsDeoptimize());
317 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
318 uint32_t dex_pc = deoptimize->GetDexPc();
319 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
320 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
321 }
322
323 private:
324 HInstruction* const instruction_;
325 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
326};
327
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000328#undef __
329
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100330#undef __
331#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700332
333inline Condition ARMCondition(IfCondition cond) {
334 switch (cond) {
335 case kCondEQ: return EQ;
336 case kCondNE: return NE;
337 case kCondLT: return LT;
338 case kCondLE: return LE;
339 case kCondGT: return GT;
340 case kCondGE: return GE;
341 default:
342 LOG(FATAL) << "Unknown if condition";
343 }
344 return EQ; // Unreachable.
345}
346
347inline Condition ARMOppositeCondition(IfCondition cond) {
348 switch (cond) {
349 case kCondEQ: return NE;
350 case kCondNE: return EQ;
351 case kCondLT: return GE;
352 case kCondLE: return GT;
353 case kCondGT: return LE;
354 case kCondGE: return LT;
355 default:
356 LOG(FATAL) << "Unknown if condition";
357 }
358 return EQ; // Unreachable.
359}
360
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100361void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
362 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
363}
364
365void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000366 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100367}
368
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100369size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
370 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
371 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100372}
373
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100374size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
375 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
376 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100377}
378
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000379size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
380 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
381 return kArmWordSize;
382}
383
384size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
385 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
386 return kArmWordSize;
387}
388
Calin Juravle34166012014-12-19 17:22:29 +0000389CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000390 const ArmInstructionSetFeatures& isa_features,
391 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000392 : CodeGenerator(graph,
393 kNumberOfCoreRegisters,
394 kNumberOfSRegisters,
395 kNumberOfRegisterPairs,
396 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
397 arraysize(kCoreCalleeSaves)),
398 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
399 arraysize(kFpuCalleeSaves)),
400 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100401 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100402 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100403 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100404 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000405 assembler_(true),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000406 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000407 // Save the PC register to mimic Quick.
408 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100409}
410
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100411Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100412 switch (type) {
413 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100414 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100415 ArmManagedRegister pair =
416 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100417 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
418 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
419
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100420 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
421 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100422 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100423 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100424 }
425
426 case Primitive::kPrimByte:
427 case Primitive::kPrimBoolean:
428 case Primitive::kPrimChar:
429 case Primitive::kPrimShort:
430 case Primitive::kPrimInt:
431 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100432 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100433 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100434 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
435 ArmManagedRegister current =
436 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
437 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100438 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100439 }
440 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100441 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100442 }
443
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000444 case Primitive::kPrimFloat: {
445 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100446 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100447 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100448
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000449 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000450 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
451 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000452 return Location::FpuRegisterPairLocation(reg, reg + 1);
453 }
454
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100455 case Primitive::kPrimVoid:
456 LOG(FATAL) << "Unreachable type " << type;
457 }
458
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100459 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100460}
461
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000462void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100463 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100464 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100465
466 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100467 blocked_core_registers_[SP] = true;
468 blocked_core_registers_[LR] = true;
469 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100470
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100471 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100472 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100473
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100474 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100475 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100476
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000477 if (is_baseline) {
478 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
479 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
480 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000481
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000482 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
483
484 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
485 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
486 }
487 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100488
489 UpdateBlockedPairRegisters();
490}
491
492void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
493 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
494 ArmManagedRegister current =
495 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
496 if (blocked_core_registers_[current.AsRegisterPairLow()]
497 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
498 blocked_register_pairs_[i] = true;
499 }
500 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100501}
502
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100503InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
504 : HGraphVisitor(graph),
505 assembler_(codegen->GetAssembler()),
506 codegen_(codegen) {}
507
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000508static uint32_t LeastSignificantBit(uint32_t mask) {
509 // ffs starts at 1.
510 return ffs(mask) - 1;
511}
512
513void CodeGeneratorARM::ComputeSpillMask() {
514 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000515 // Save one extra register for baseline. Note that on thumb2, there is no easy
516 // instruction to restore just the PC, so this actually helps both baseline
517 // and non-baseline to save and restore at least two registers at entry and exit.
518 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000519 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
520 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
521 // We use vpush and vpop for saving and restoring floating point registers, which take
522 // a SRegister and the number of registers to save/restore after that SRegister. We
523 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
524 // but in the range.
525 if (fpu_spill_mask_ != 0) {
526 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
527 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
528 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
529 fpu_spill_mask_ |= (1 << i);
530 }
531 }
532}
533
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000534void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000535 bool skip_overflow_check =
536 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000537 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000538 __ Bind(&frame_entry_label_);
539
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000540 if (HasEmptyFrame()) {
541 return;
542 }
543
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100544 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000545 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
546 __ LoadFromOffset(kLoadWord, IP, IP, 0);
547 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100548 }
549
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000550 // PC is in the list of callee-save to mimic Quick, but we need to push
551 // LR at entry instead.
552 __ PushList((core_spill_mask_ & (~(1 << PC))) | 1 << LR);
553 if (fpu_spill_mask_ != 0) {
554 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
555 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
556 }
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000557 __ AddConstant(SP, -(GetFrameSize() - FrameEntrySpillSize()));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100558 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000559}
560
561void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000562 if (HasEmptyFrame()) {
563 __ bx(LR);
564 return;
565 }
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000566 __ AddConstant(SP, GetFrameSize() - FrameEntrySpillSize());
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000567 if (fpu_spill_mask_ != 0) {
568 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
569 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
570 }
571 __ PopList(core_spill_mask_);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000572}
573
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100574void CodeGeneratorARM::Bind(HBasicBlock* block) {
575 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000576}
577
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100578Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
579 switch (load->GetType()) {
580 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100581 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100582 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
583 break;
584
585 case Primitive::kPrimInt:
586 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100587 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100588 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100589
590 case Primitive::kPrimBoolean:
591 case Primitive::kPrimByte:
592 case Primitive::kPrimChar:
593 case Primitive::kPrimShort:
594 case Primitive::kPrimVoid:
595 LOG(FATAL) << "Unexpected type " << load->GetType();
596 }
597
598 LOG(FATAL) << "Unreachable";
599 return Location();
600}
601
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100602Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
603 switch (type) {
604 case Primitive::kPrimBoolean:
605 case Primitive::kPrimByte:
606 case Primitive::kPrimChar:
607 case Primitive::kPrimShort:
608 case Primitive::kPrimInt:
609 case Primitive::kPrimNot: {
610 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000611 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100612 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100613 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100614 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000615 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100616 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100617 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100618
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000619 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100620 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000621 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100622 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000623 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100624 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000625 if (calling_convention.GetRegisterAt(index) == R1) {
626 // Skip R1, and use R2_R3 instead.
627 gp_index_++;
628 index++;
629 }
630 }
631 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
632 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000633 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000634 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000635 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100636 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000637 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
638 }
639 }
640
641 case Primitive::kPrimFloat: {
642 uint32_t stack_index = stack_index_++;
643 if (float_index_ % 2 == 0) {
644 float_index_ = std::max(double_index_, float_index_);
645 }
646 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
647 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
648 } else {
649 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
650 }
651 }
652
653 case Primitive::kPrimDouble: {
654 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
655 uint32_t stack_index = stack_index_;
656 stack_index_ += 2;
657 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
658 uint32_t index = double_index_;
659 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000660 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000661 calling_convention.GetFpuRegisterAt(index),
662 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000663 DCHECK(ExpectedPairLayout(result));
664 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000665 } else {
666 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100667 }
668 }
669
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100670 case Primitive::kPrimVoid:
671 LOG(FATAL) << "Unexpected parameter type " << type;
672 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100673 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100674 return Location();
675}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100676
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000677Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
678 switch (type) {
679 case Primitive::kPrimBoolean:
680 case Primitive::kPrimByte:
681 case Primitive::kPrimChar:
682 case Primitive::kPrimShort:
683 case Primitive::kPrimInt:
684 case Primitive::kPrimNot: {
685 return Location::RegisterLocation(R0);
686 }
687
688 case Primitive::kPrimFloat: {
689 return Location::FpuRegisterLocation(S0);
690 }
691
692 case Primitive::kPrimLong: {
693 return Location::RegisterPairLocation(R0, R1);
694 }
695
696 case Primitive::kPrimDouble: {
697 return Location::FpuRegisterPairLocation(S0, S1);
698 }
699
700 case Primitive::kPrimVoid:
701 return Location();
702 }
703 UNREACHABLE();
704 return Location();
705}
706
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100707void CodeGeneratorARM::Move32(Location destination, Location source) {
708 if (source.Equals(destination)) {
709 return;
710 }
711 if (destination.IsRegister()) {
712 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000713 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100714 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000715 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100716 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000717 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100718 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100719 } else if (destination.IsFpuRegister()) {
720 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000721 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100722 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000723 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100724 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000725 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100726 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100727 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000728 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100729 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000730 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100731 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000732 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100733 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000734 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100735 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
736 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100737 }
738 }
739}
740
741void CodeGeneratorARM::Move64(Location destination, Location source) {
742 if (source.Equals(destination)) {
743 return;
744 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100745 if (destination.IsRegisterPair()) {
746 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000747 EmitParallelMoves(
748 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
749 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
750 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
751 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100752 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000753 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100754 } else {
755 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000756 DCHECK(ExpectedPairLayout(destination));
757 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
758 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100759 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000760 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100761 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000762 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
763 SP,
764 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100765 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000766 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100767 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100768 } else {
769 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100770 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000771 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100772 if (source.AsRegisterPairLow<Register>() == R1) {
773 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100774 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
775 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100776 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100777 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100778 SP, destination.GetStackIndex());
779 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000780 } else if (source.IsFpuRegisterPair()) {
781 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
782 SP,
783 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100784 } else {
785 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000786 EmitParallelMoves(
787 Location::StackSlot(source.GetStackIndex()),
788 Location::StackSlot(destination.GetStackIndex()),
789 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
790 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100791 }
792 }
793}
794
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100795void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100796 LocationSummary* locations = instruction->GetLocations();
797 if (locations != nullptr && locations->Out().Equals(location)) {
798 return;
799 }
800
Calin Juravlea21f5982014-11-13 15:53:04 +0000801 if (locations != nullptr && locations->Out().IsConstant()) {
802 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000803 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
804 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000805 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000806 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000807 } else {
808 DCHECK(location.IsStackSlot());
809 __ LoadImmediate(IP, value);
810 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
811 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000812 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000813 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000814 int64_t value = const_to_move->AsLongConstant()->GetValue();
815 if (location.IsRegisterPair()) {
816 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
817 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
818 } else {
819 DCHECK(location.IsDoubleStackSlot());
820 __ LoadImmediate(IP, Low32Bits(value));
821 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
822 __ LoadImmediate(IP, High32Bits(value));
823 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
824 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100825 }
Roland Levillain476df552014-10-09 17:51:36 +0100826 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100827 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
828 switch (instruction->GetType()) {
829 case Primitive::kPrimBoolean:
830 case Primitive::kPrimByte:
831 case Primitive::kPrimChar:
832 case Primitive::kPrimShort:
833 case Primitive::kPrimInt:
834 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100835 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100836 Move32(location, Location::StackSlot(stack_slot));
837 break;
838
839 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100840 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100841 Move64(location, Location::DoubleStackSlot(stack_slot));
842 break;
843
844 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100845 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100846 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000847 } else if (instruction->IsTemporary()) {
848 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000849 if (temp_location.IsStackSlot()) {
850 Move32(location, temp_location);
851 } else {
852 DCHECK(temp_location.IsDoubleStackSlot());
853 Move64(location, temp_location);
854 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000855 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100856 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100857 switch (instruction->GetType()) {
858 case Primitive::kPrimBoolean:
859 case Primitive::kPrimByte:
860 case Primitive::kPrimChar:
861 case Primitive::kPrimShort:
862 case Primitive::kPrimNot:
863 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100864 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100865 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100866 break;
867
868 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100869 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100870 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100871 break;
872
873 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100874 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100875 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000876 }
877}
878
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100879void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
880 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000881 uint32_t dex_pc,
882 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100883 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
884 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000885 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100886 DCHECK(instruction->IsSuspendCheck()
887 || instruction->IsBoundsCheck()
888 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000889 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000890 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100891 || !IsLeafMethod());
892}
893
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000894void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000895 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000896}
897
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000898void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000899 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100900 DCHECK(!successor->IsExitBlock());
901
902 HBasicBlock* block = got->GetBlock();
903 HInstruction* previous = got->GetPrevious();
904
905 HLoopInformation* info = block->GetLoopInformation();
906 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
907 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
908 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
909 return;
910 }
911
912 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
913 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
914 }
915 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000916 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000917 }
918}
919
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000920void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000921 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000922}
923
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000924void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700925 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000926}
927
Mingyao Yange295e6e2015-03-07 06:37:59 -0800928void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
929 Label* true_target,
930 Label* false_target,
931 Label* always_true_target) {
932 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100933 if (cond->IsIntConstant()) {
934 // Constant condition, statically compared against 1.
935 int32_t cond_value = cond->AsIntConstant()->GetValue();
936 if (cond_value == 1) {
Mingyao Yange295e6e2015-03-07 06:37:59 -0800937 if (always_true_target != nullptr) {
938 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100939 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100940 return;
941 } else {
942 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100943 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100944 } else {
945 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
946 // Condition has been materialized, compare the output to 0
Mingyao Yange295e6e2015-03-07 06:37:59 -0800947 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
948 __ cmp(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100949 ShifterOperand(0));
Mingyao Yange295e6e2015-03-07 06:37:59 -0800950 __ b(true_target, NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100951 } else {
952 // Condition has not been materialized, use its inputs as the
953 // comparison and its condition as the branch condition.
954 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000955 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000956 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100957 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000958 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100959 } else {
960 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000961 HConstant* constant = locations->InAt(1).GetConstant();
962 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100963 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000964 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
965 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100966 } else {
967 Register temp = IP;
968 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000969 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100970 }
971 }
Mingyao Yange295e6e2015-03-07 06:37:59 -0800972 __ b(true_target);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100973 }
Dave Allison20dfc792014-06-16 20:44:29 -0700974 }
Mingyao Yange295e6e2015-03-07 06:37:59 -0800975 if (false_target != nullptr) {
976 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000977 }
978}
979
Mingyao Yange295e6e2015-03-07 06:37:59 -0800980void LocationsBuilderARM::VisitIf(HIf* if_instr) {
981 LocationSummary* locations =
982 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
983 HInstruction* cond = if_instr->InputAt(0);
984 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
985 locations->SetInAt(0, Location::RequiresRegister());
986 }
987}
988
989void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
990 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
991 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
992 Label* always_true_target = true_target;
993 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
994 if_instr->IfTrueSuccessor())) {
995 always_true_target = nullptr;
996 }
997 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
998 if_instr->IfFalseSuccessor())) {
999 false_target = nullptr;
1000 }
1001 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1002}
1003
1004void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1005 LocationSummary* locations = new (GetGraph()->GetArena())
1006 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1007 HInstruction* cond = deoptimize->InputAt(0);
1008 DCHECK(cond->IsCondition());
1009 if (cond->AsCondition()->NeedsMaterialization()) {
1010 locations->SetInAt(0, Location::RequiresRegister());
1011 }
1012}
1013
1014void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1015 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1016 DeoptimizationSlowPathARM(deoptimize);
1017 codegen_->AddSlowPath(slow_path);
1018 Label* slow_path_entry = slow_path->GetEntryLabel();
1019 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1020}
Dave Allison20dfc792014-06-16 20:44:29 -07001021
1022void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001023 LocationSummary* locations =
1024 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001025 locations->SetInAt(0, Location::RequiresRegister());
1026 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001027 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001028 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001029 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001030}
1031
Dave Allison20dfc792014-06-16 20:44:29 -07001032void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001033 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001034 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001035 Register left = locations->InAt(0).AsRegister<Register>();
1036
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001037 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001038 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001039 } else {
1040 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -08001041 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001042 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001043 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1044 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001045 } else {
1046 Register temp = IP;
1047 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001048 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001049 }
Dave Allison20dfc792014-06-16 20:44:29 -07001050 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001051 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001052 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001053 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001054 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001055 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001056}
1057
1058void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1059 VisitCondition(comp);
1060}
1061
1062void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1063 VisitCondition(comp);
1064}
1065
1066void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1067 VisitCondition(comp);
1068}
1069
1070void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1071 VisitCondition(comp);
1072}
1073
1074void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1075 VisitCondition(comp);
1076}
1077
1078void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1079 VisitCondition(comp);
1080}
1081
1082void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1083 VisitCondition(comp);
1084}
1085
1086void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1087 VisitCondition(comp);
1088}
1089
1090void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1091 VisitCondition(comp);
1092}
1093
1094void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1095 VisitCondition(comp);
1096}
1097
1098void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1099 VisitCondition(comp);
1100}
1101
1102void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1103 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001104}
1105
1106void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001107 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001108}
1109
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001110void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1111 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001112}
1113
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001114void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001115 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001116}
1117
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001118void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001119 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001120 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001121}
1122
1123void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001124 LocationSummary* locations =
1125 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001126 switch (store->InputAt(1)->GetType()) {
1127 case Primitive::kPrimBoolean:
1128 case Primitive::kPrimByte:
1129 case Primitive::kPrimChar:
1130 case Primitive::kPrimShort:
1131 case Primitive::kPrimInt:
1132 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001133 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001134 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1135 break;
1136
1137 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001138 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001139 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1140 break;
1141
1142 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001143 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001144 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001145}
1146
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001147void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001148 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001149}
1150
1151void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001152 LocationSummary* locations =
1153 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001154 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001155}
1156
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001157void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001158 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001159 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001160}
1161
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001162void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1163 LocationSummary* locations =
1164 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1165 locations->SetOut(Location::ConstantLocation(constant));
1166}
1167
1168void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1169 // Will be generated at use site.
1170 UNUSED(constant);
1171}
1172
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001173void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001174 LocationSummary* locations =
1175 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001176 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001177}
1178
1179void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1180 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001181 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001182}
1183
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001184void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1185 LocationSummary* locations =
1186 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1187 locations->SetOut(Location::ConstantLocation(constant));
1188}
1189
1190void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1191 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001192 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001193}
1194
1195void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1196 LocationSummary* locations =
1197 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1198 locations->SetOut(Location::ConstantLocation(constant));
1199}
1200
1201void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1202 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001203 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001204}
1205
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001206void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001207 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001208}
1209
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001210void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001211 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001212 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001213}
1214
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001215void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001216 LocationSummary* locations =
1217 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001218 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001219}
1220
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001221void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001222 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001223 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001224}
1225
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001226void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001227 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1228 codegen_->GetInstructionSetFeatures());
1229 if (intrinsic.TryDispatch(invoke)) {
1230 return;
1231 }
1232
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001233 HandleInvoke(invoke);
1234}
1235
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001236void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001237 DCHECK(RequiresCurrentMethod());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001238 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001239}
1240
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001241static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1242 if (invoke->GetLocations()->Intrinsified()) {
1243 IntrinsicCodeGeneratorARM intrinsic(codegen);
1244 intrinsic.Dispatch(invoke);
1245 return true;
1246 }
1247 return false;
1248}
1249
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001250void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001251 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1252 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001253 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001254
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001255 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
1256
1257 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001258 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001259}
1260
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001261void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001262 LocationSummary* locations =
1263 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001264 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001265
1266 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001267 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001268 HInstruction* input = invoke->InputAt(i);
1269 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1270 }
1271
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001272 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001273}
1274
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001275void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001276 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1277 codegen_->GetInstructionSetFeatures());
1278 if (intrinsic.TryDispatch(invoke)) {
1279 return;
1280 }
1281
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001282 HandleInvoke(invoke);
1283}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001284
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001285void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001286 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1287 return;
1288 }
1289
Roland Levillain271ab9c2014-11-27 15:23:57 +00001290 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001291 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1292 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1293 LocationSummary* locations = invoke->GetLocations();
1294 Location receiver = locations->InAt(0);
1295 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1296 // temp = object->GetClass();
1297 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001298 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1299 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001300 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001301 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001302 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001303 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001304 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001305 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001306 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001307 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001308 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001309 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001310 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001311 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001312 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001313 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001314}
1315
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001316void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1317 HandleInvoke(invoke);
1318 // Add the hidden argument.
1319 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1320}
1321
1322void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1323 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001324 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001325 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1326 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1327 LocationSummary* locations = invoke->GetLocations();
1328 Location receiver = locations->InAt(0);
1329 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1330
1331 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001332 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1333 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001334
1335 // temp = object->GetClass();
1336 if (receiver.IsStackSlot()) {
1337 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1338 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1339 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001340 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001341 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001342 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001343 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001344 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001345 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001346 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1347 // LR = temp->GetEntryPoint();
1348 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1349 // LR();
1350 __ blx(LR);
1351 DCHECK(!codegen_->IsLeafMethod());
1352 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1353}
1354
Roland Levillain88cb1752014-10-20 16:36:47 +01001355void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1356 LocationSummary* locations =
1357 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1358 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001359 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001360 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001361 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1362 break;
1363 }
1364 case Primitive::kPrimLong: {
1365 locations->SetInAt(0, Location::RequiresRegister());
1366 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001367 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001368 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001369
Roland Levillain88cb1752014-10-20 16:36:47 +01001370 case Primitive::kPrimFloat:
1371 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001372 locations->SetInAt(0, Location::RequiresFpuRegister());
1373 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001374 break;
1375
1376 default:
1377 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1378 }
1379}
1380
1381void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1382 LocationSummary* locations = neg->GetLocations();
1383 Location out = locations->Out();
1384 Location in = locations->InAt(0);
1385 switch (neg->GetResultType()) {
1386 case Primitive::kPrimInt:
1387 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001388 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001389 break;
1390
1391 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001392 DCHECK(in.IsRegisterPair());
1393 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1394 __ rsbs(out.AsRegisterPairLow<Register>(),
1395 in.AsRegisterPairLow<Register>(),
1396 ShifterOperand(0));
1397 // We cannot emit an RSC (Reverse Subtract with Carry)
1398 // instruction here, as it does not exist in the Thumb-2
1399 // instruction set. We use the following approach
1400 // using SBC and SUB instead.
1401 //
1402 // out.hi = -C
1403 __ sbc(out.AsRegisterPairHigh<Register>(),
1404 out.AsRegisterPairHigh<Register>(),
1405 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1406 // out.hi = out.hi - in.hi
1407 __ sub(out.AsRegisterPairHigh<Register>(),
1408 out.AsRegisterPairHigh<Register>(),
1409 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1410 break;
1411
Roland Levillain88cb1752014-10-20 16:36:47 +01001412 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001413 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001414 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001415 break;
1416
Roland Levillain88cb1752014-10-20 16:36:47 +01001417 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001418 DCHECK(in.IsFpuRegisterPair());
1419 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1420 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001421 break;
1422
1423 default:
1424 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1425 }
1426}
1427
Roland Levillaindff1f282014-11-05 14:15:05 +00001428void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001429 Primitive::Type result_type = conversion->GetResultType();
1430 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001431 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001432
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001433 // The float-to-long and double-to-long type conversions rely on a
1434 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001435 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001436 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1437 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001438 ? LocationSummary::kCall
1439 : LocationSummary::kNoCall;
1440 LocationSummary* locations =
1441 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1442
Roland Levillaindff1f282014-11-05 14:15:05 +00001443 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001444 case Primitive::kPrimByte:
1445 switch (input_type) {
1446 case Primitive::kPrimShort:
1447 case Primitive::kPrimInt:
1448 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001449 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001450 locations->SetInAt(0, Location::RequiresRegister());
1451 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1452 break;
1453
1454 default:
1455 LOG(FATAL) << "Unexpected type conversion from " << input_type
1456 << " to " << result_type;
1457 }
1458 break;
1459
Roland Levillain01a8d712014-11-14 16:27:39 +00001460 case Primitive::kPrimShort:
1461 switch (input_type) {
1462 case Primitive::kPrimByte:
1463 case Primitive::kPrimInt:
1464 case Primitive::kPrimChar:
1465 // Processing a Dex `int-to-short' instruction.
1466 locations->SetInAt(0, Location::RequiresRegister());
1467 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1468 break;
1469
1470 default:
1471 LOG(FATAL) << "Unexpected type conversion from " << input_type
1472 << " to " << result_type;
1473 }
1474 break;
1475
Roland Levillain946e1432014-11-11 17:35:19 +00001476 case Primitive::kPrimInt:
1477 switch (input_type) {
1478 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001479 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001480 locations->SetInAt(0, Location::Any());
1481 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1482 break;
1483
1484 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001485 // Processing a Dex `float-to-int' instruction.
1486 locations->SetInAt(0, Location::RequiresFpuRegister());
1487 locations->SetOut(Location::RequiresRegister());
1488 locations->AddTemp(Location::RequiresFpuRegister());
1489 break;
1490
Roland Levillain946e1432014-11-11 17:35:19 +00001491 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001492 // Processing a Dex `double-to-int' instruction.
1493 locations->SetInAt(0, Location::RequiresFpuRegister());
1494 locations->SetOut(Location::RequiresRegister());
1495 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001496 break;
1497
1498 default:
1499 LOG(FATAL) << "Unexpected type conversion from " << input_type
1500 << " to " << result_type;
1501 }
1502 break;
1503
Roland Levillaindff1f282014-11-05 14:15:05 +00001504 case Primitive::kPrimLong:
1505 switch (input_type) {
1506 case Primitive::kPrimByte:
1507 case Primitive::kPrimShort:
1508 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001509 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001510 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001511 locations->SetInAt(0, Location::RequiresRegister());
1512 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1513 break;
1514
Roland Levillain624279f2014-12-04 11:54:28 +00001515 case Primitive::kPrimFloat: {
1516 // Processing a Dex `float-to-long' instruction.
1517 InvokeRuntimeCallingConvention calling_convention;
1518 locations->SetInAt(0, Location::FpuRegisterLocation(
1519 calling_convention.GetFpuRegisterAt(0)));
1520 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1521 break;
1522 }
1523
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001524 case Primitive::kPrimDouble: {
1525 // Processing a Dex `double-to-long' instruction.
1526 InvokeRuntimeCallingConvention calling_convention;
1527 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1528 calling_convention.GetFpuRegisterAt(0),
1529 calling_convention.GetFpuRegisterAt(1)));
1530 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001531 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001532 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001533
1534 default:
1535 LOG(FATAL) << "Unexpected type conversion from " << input_type
1536 << " to " << result_type;
1537 }
1538 break;
1539
Roland Levillain981e4542014-11-14 11:47:14 +00001540 case Primitive::kPrimChar:
1541 switch (input_type) {
1542 case Primitive::kPrimByte:
1543 case Primitive::kPrimShort:
1544 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001545 // Processing a Dex `int-to-char' instruction.
1546 locations->SetInAt(0, Location::RequiresRegister());
1547 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1548 break;
1549
1550 default:
1551 LOG(FATAL) << "Unexpected type conversion from " << input_type
1552 << " to " << result_type;
1553 }
1554 break;
1555
Roland Levillaindff1f282014-11-05 14:15:05 +00001556 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001557 switch (input_type) {
1558 case Primitive::kPrimByte:
1559 case Primitive::kPrimShort:
1560 case Primitive::kPrimInt:
1561 case Primitive::kPrimChar:
1562 // Processing a Dex `int-to-float' instruction.
1563 locations->SetInAt(0, Location::RequiresRegister());
1564 locations->SetOut(Location::RequiresFpuRegister());
1565 break;
1566
1567 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001568 // Processing a Dex `long-to-float' instruction.
1569 locations->SetInAt(0, Location::RequiresRegister());
1570 locations->SetOut(Location::RequiresFpuRegister());
1571 locations->AddTemp(Location::RequiresRegister());
1572 locations->AddTemp(Location::RequiresRegister());
1573 locations->AddTemp(Location::RequiresFpuRegister());
1574 locations->AddTemp(Location::RequiresFpuRegister());
1575 break;
1576
Roland Levillaincff13742014-11-17 14:32:17 +00001577 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001578 // Processing a Dex `double-to-float' instruction.
1579 locations->SetInAt(0, Location::RequiresFpuRegister());
1580 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001581 break;
1582
1583 default:
1584 LOG(FATAL) << "Unexpected type conversion from " << input_type
1585 << " to " << result_type;
1586 };
1587 break;
1588
Roland Levillaindff1f282014-11-05 14:15:05 +00001589 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001590 switch (input_type) {
1591 case Primitive::kPrimByte:
1592 case Primitive::kPrimShort:
1593 case Primitive::kPrimInt:
1594 case Primitive::kPrimChar:
1595 // Processing a Dex `int-to-double' instruction.
1596 locations->SetInAt(0, Location::RequiresRegister());
1597 locations->SetOut(Location::RequiresFpuRegister());
1598 break;
1599
1600 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001601 // Processing a Dex `long-to-double' instruction.
1602 locations->SetInAt(0, Location::RequiresRegister());
1603 locations->SetOut(Location::RequiresFpuRegister());
1604 locations->AddTemp(Location::RequiresRegister());
1605 locations->AddTemp(Location::RequiresRegister());
1606 locations->AddTemp(Location::RequiresFpuRegister());
1607 break;
1608
Roland Levillaincff13742014-11-17 14:32:17 +00001609 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001610 // Processing a Dex `float-to-double' instruction.
1611 locations->SetInAt(0, Location::RequiresFpuRegister());
1612 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001613 break;
1614
1615 default:
1616 LOG(FATAL) << "Unexpected type conversion from " << input_type
1617 << " to " << result_type;
1618 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001619 break;
1620
1621 default:
1622 LOG(FATAL) << "Unexpected type conversion from " << input_type
1623 << " to " << result_type;
1624 }
1625}
1626
1627void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1628 LocationSummary* locations = conversion->GetLocations();
1629 Location out = locations->Out();
1630 Location in = locations->InAt(0);
1631 Primitive::Type result_type = conversion->GetResultType();
1632 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001633 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001634 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001635 case Primitive::kPrimByte:
1636 switch (input_type) {
1637 case Primitive::kPrimShort:
1638 case Primitive::kPrimInt:
1639 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001640 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001641 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001642 break;
1643
1644 default:
1645 LOG(FATAL) << "Unexpected type conversion from " << input_type
1646 << " to " << result_type;
1647 }
1648 break;
1649
Roland Levillain01a8d712014-11-14 16:27:39 +00001650 case Primitive::kPrimShort:
1651 switch (input_type) {
1652 case Primitive::kPrimByte:
1653 case Primitive::kPrimInt:
1654 case Primitive::kPrimChar:
1655 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001656 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001657 break;
1658
1659 default:
1660 LOG(FATAL) << "Unexpected type conversion from " << input_type
1661 << " to " << result_type;
1662 }
1663 break;
1664
Roland Levillain946e1432014-11-11 17:35:19 +00001665 case Primitive::kPrimInt:
1666 switch (input_type) {
1667 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001668 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001669 DCHECK(out.IsRegister());
1670 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001671 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001672 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001673 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001674 } else {
1675 DCHECK(in.IsConstant());
1676 DCHECK(in.GetConstant()->IsLongConstant());
1677 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001678 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001679 }
1680 break;
1681
Roland Levillain3f8f9362014-12-02 17:45:01 +00001682 case Primitive::kPrimFloat: {
1683 // Processing a Dex `float-to-int' instruction.
1684 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1685 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1686 __ vcvtis(temp, temp);
1687 __ vmovrs(out.AsRegister<Register>(), temp);
1688 break;
1689 }
1690
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001691 case Primitive::kPrimDouble: {
1692 // Processing a Dex `double-to-int' instruction.
1693 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1694 DRegister temp_d = FromLowSToD(temp_s);
1695 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1696 __ vcvtid(temp_s, temp_d);
1697 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001698 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001699 }
Roland Levillain946e1432014-11-11 17:35:19 +00001700
1701 default:
1702 LOG(FATAL) << "Unexpected type conversion from " << input_type
1703 << " to " << result_type;
1704 }
1705 break;
1706
Roland Levillaindff1f282014-11-05 14:15:05 +00001707 case Primitive::kPrimLong:
1708 switch (input_type) {
1709 case Primitive::kPrimByte:
1710 case Primitive::kPrimShort:
1711 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001712 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001713 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001714 DCHECK(out.IsRegisterPair());
1715 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001716 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001717 // Sign extension.
1718 __ Asr(out.AsRegisterPairHigh<Register>(),
1719 out.AsRegisterPairLow<Register>(),
1720 31);
1721 break;
1722
1723 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001724 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001725 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1726 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001727 conversion->GetDexPc(),
1728 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001729 break;
1730
Roland Levillaindff1f282014-11-05 14:15:05 +00001731 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001732 // Processing a Dex `double-to-long' instruction.
1733 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1734 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001735 conversion->GetDexPc(),
1736 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001737 break;
1738
1739 default:
1740 LOG(FATAL) << "Unexpected type conversion from " << input_type
1741 << " to " << result_type;
1742 }
1743 break;
1744
Roland Levillain981e4542014-11-14 11:47:14 +00001745 case Primitive::kPrimChar:
1746 switch (input_type) {
1747 case Primitive::kPrimByte:
1748 case Primitive::kPrimShort:
1749 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001750 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001751 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001752 break;
1753
1754 default:
1755 LOG(FATAL) << "Unexpected type conversion from " << input_type
1756 << " to " << result_type;
1757 }
1758 break;
1759
Roland Levillaindff1f282014-11-05 14:15:05 +00001760 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001761 switch (input_type) {
1762 case Primitive::kPrimByte:
1763 case Primitive::kPrimShort:
1764 case Primitive::kPrimInt:
1765 case Primitive::kPrimChar: {
1766 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001767 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1768 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001769 break;
1770 }
1771
Roland Levillain6d0e4832014-11-27 18:31:21 +00001772 case Primitive::kPrimLong: {
1773 // Processing a Dex `long-to-float' instruction.
1774 Register low = in.AsRegisterPairLow<Register>();
1775 Register high = in.AsRegisterPairHigh<Register>();
1776 SRegister output = out.AsFpuRegister<SRegister>();
1777 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1778 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1779 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1780 DRegister temp1_d = FromLowSToD(temp1_s);
1781 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1782 DRegister temp2_d = FromLowSToD(temp2_s);
1783
1784 // Operations use doubles for precision reasons (each 32-bit
1785 // half of a long fits in the 53-bit mantissa of a double,
1786 // but not in the 24-bit mantissa of a float). This is
1787 // especially important for the low bits. The result is
1788 // eventually converted to float.
1789
1790 // temp1_d = int-to-double(high)
1791 __ vmovsr(temp1_s, high);
1792 __ vcvtdi(temp1_d, temp1_s);
1793 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1794 // as an immediate value into `temp2_d` does not work, as
1795 // this instruction only transfers 8 significant bits of its
1796 // immediate operand. Instead, use two 32-bit core
1797 // registers to load `k2Pow32EncodingForDouble` into
1798 // `temp2_d`.
1799 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1800 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1801 __ vmovdrr(temp2_d, constant_low, constant_high);
1802 // temp1_d = temp1_d * 2^32
1803 __ vmuld(temp1_d, temp1_d, temp2_d);
1804 // temp2_d = unsigned-to-double(low)
1805 __ vmovsr(temp2_s, low);
1806 __ vcvtdu(temp2_d, temp2_s);
1807 // temp1_d = temp1_d + temp2_d
1808 __ vaddd(temp1_d, temp1_d, temp2_d);
1809 // output = double-to-float(temp1_d);
1810 __ vcvtsd(output, temp1_d);
1811 break;
1812 }
1813
Roland Levillaincff13742014-11-17 14:32:17 +00001814 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001815 // Processing a Dex `double-to-float' instruction.
1816 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1817 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001818 break;
1819
1820 default:
1821 LOG(FATAL) << "Unexpected type conversion from " << input_type
1822 << " to " << result_type;
1823 };
1824 break;
1825
Roland Levillaindff1f282014-11-05 14:15:05 +00001826 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001827 switch (input_type) {
1828 case Primitive::kPrimByte:
1829 case Primitive::kPrimShort:
1830 case Primitive::kPrimInt:
1831 case Primitive::kPrimChar: {
1832 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001833 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001834 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1835 out.AsFpuRegisterPairLow<SRegister>());
1836 break;
1837 }
1838
Roland Levillain647b9ed2014-11-27 12:06:00 +00001839 case Primitive::kPrimLong: {
1840 // Processing a Dex `long-to-double' instruction.
1841 Register low = in.AsRegisterPairLow<Register>();
1842 Register high = in.AsRegisterPairHigh<Register>();
1843 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1844 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001845 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1846 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001847 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1848 DRegister temp_d = FromLowSToD(temp_s);
1849
Roland Levillain647b9ed2014-11-27 12:06:00 +00001850 // out_d = int-to-double(high)
1851 __ vmovsr(out_s, high);
1852 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001853 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1854 // as an immediate value into `temp_d` does not work, as
1855 // this instruction only transfers 8 significant bits of its
1856 // immediate operand. Instead, use two 32-bit core
1857 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1858 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1859 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001860 __ vmovdrr(temp_d, constant_low, constant_high);
1861 // out_d = out_d * 2^32
1862 __ vmuld(out_d, out_d, temp_d);
1863 // temp_d = unsigned-to-double(low)
1864 __ vmovsr(temp_s, low);
1865 __ vcvtdu(temp_d, temp_s);
1866 // out_d = out_d + temp_d
1867 __ vaddd(out_d, out_d, temp_d);
1868 break;
1869 }
1870
Roland Levillaincff13742014-11-17 14:32:17 +00001871 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001872 // Processing a Dex `float-to-double' instruction.
1873 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1874 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001875 break;
1876
1877 default:
1878 LOG(FATAL) << "Unexpected type conversion from " << input_type
1879 << " to " << result_type;
1880 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001881 break;
1882
1883 default:
1884 LOG(FATAL) << "Unexpected type conversion from " << input_type
1885 << " to " << result_type;
1886 }
1887}
1888
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001889void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001890 LocationSummary* locations =
1891 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001892 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001893 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001894 locations->SetInAt(0, Location::RequiresRegister());
1895 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001896 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1897 break;
1898 }
1899
1900 case Primitive::kPrimLong: {
1901 locations->SetInAt(0, Location::RequiresRegister());
1902 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001903 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001904 break;
1905 }
1906
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001907 case Primitive::kPrimFloat:
1908 case Primitive::kPrimDouble: {
1909 locations->SetInAt(0, Location::RequiresFpuRegister());
1910 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001911 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001912 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001913 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001914
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001915 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001916 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001917 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001918}
1919
1920void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1921 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001922 Location out = locations->Out();
1923 Location first = locations->InAt(0);
1924 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001925 switch (add->GetResultType()) {
1926 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001927 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001928 __ add(out.AsRegister<Register>(),
1929 first.AsRegister<Register>(),
1930 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001931 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001932 __ AddConstant(out.AsRegister<Register>(),
1933 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001934 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001935 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001936 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001937
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001938 case Primitive::kPrimLong: {
1939 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001940 __ adds(out.AsRegisterPairLow<Register>(),
1941 first.AsRegisterPairLow<Register>(),
1942 ShifterOperand(second.AsRegisterPairLow<Register>()));
1943 __ adc(out.AsRegisterPairHigh<Register>(),
1944 first.AsRegisterPairHigh<Register>(),
1945 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001946 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001947 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001948
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001949 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001950 __ vadds(out.AsFpuRegister<SRegister>(),
1951 first.AsFpuRegister<SRegister>(),
1952 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001953 break;
1954
1955 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001956 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1957 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1958 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001959 break;
1960
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001961 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001962 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001963 }
1964}
1965
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001966void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001967 LocationSummary* locations =
1968 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001969 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001970 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001971 locations->SetInAt(0, Location::RequiresRegister());
1972 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001973 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1974 break;
1975 }
1976
1977 case Primitive::kPrimLong: {
1978 locations->SetInAt(0, Location::RequiresRegister());
1979 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001980 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001981 break;
1982 }
Calin Juravle11351682014-10-23 15:38:15 +01001983 case Primitive::kPrimFloat:
1984 case Primitive::kPrimDouble: {
1985 locations->SetInAt(0, Location::RequiresFpuRegister());
1986 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001987 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001988 break;
Calin Juravle11351682014-10-23 15:38:15 +01001989 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001990 default:
Calin Juravle11351682014-10-23 15:38:15 +01001991 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001992 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001993}
1994
1995void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1996 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001997 Location out = locations->Out();
1998 Location first = locations->InAt(0);
1999 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002000 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002001 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002002 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002003 __ sub(out.AsRegister<Register>(),
2004 first.AsRegister<Register>(),
2005 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002006 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002007 __ AddConstant(out.AsRegister<Register>(),
2008 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002009 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002010 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002011 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002012 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002013
Calin Juravle11351682014-10-23 15:38:15 +01002014 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002015 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002016 __ subs(out.AsRegisterPairLow<Register>(),
2017 first.AsRegisterPairLow<Register>(),
2018 ShifterOperand(second.AsRegisterPairLow<Register>()));
2019 __ sbc(out.AsRegisterPairHigh<Register>(),
2020 first.AsRegisterPairHigh<Register>(),
2021 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002022 break;
Calin Juravle11351682014-10-23 15:38:15 +01002023 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002024
Calin Juravle11351682014-10-23 15:38:15 +01002025 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002026 __ vsubs(out.AsFpuRegister<SRegister>(),
2027 first.AsFpuRegister<SRegister>(),
2028 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002029 break;
Calin Juravle11351682014-10-23 15:38:15 +01002030 }
2031
2032 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002033 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2034 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2035 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002036 break;
2037 }
2038
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002039
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002040 default:
Calin Juravle11351682014-10-23 15:38:15 +01002041 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002042 }
2043}
2044
Calin Juravle34bacdf2014-10-07 20:23:36 +01002045void LocationsBuilderARM::VisitMul(HMul* mul) {
2046 LocationSummary* locations =
2047 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2048 switch (mul->GetResultType()) {
2049 case Primitive::kPrimInt:
2050 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002051 locations->SetInAt(0, Location::RequiresRegister());
2052 locations->SetInAt(1, Location::RequiresRegister());
2053 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002054 break;
2055 }
2056
Calin Juravleb5bfa962014-10-21 18:02:24 +01002057 case Primitive::kPrimFloat:
2058 case Primitive::kPrimDouble: {
2059 locations->SetInAt(0, Location::RequiresFpuRegister());
2060 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002061 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002062 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002063 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002064
2065 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002066 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002067 }
2068}
2069
2070void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2071 LocationSummary* locations = mul->GetLocations();
2072 Location out = locations->Out();
2073 Location first = locations->InAt(0);
2074 Location second = locations->InAt(1);
2075 switch (mul->GetResultType()) {
2076 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002077 __ mul(out.AsRegister<Register>(),
2078 first.AsRegister<Register>(),
2079 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002080 break;
2081 }
2082 case Primitive::kPrimLong: {
2083 Register out_hi = out.AsRegisterPairHigh<Register>();
2084 Register out_lo = out.AsRegisterPairLow<Register>();
2085 Register in1_hi = first.AsRegisterPairHigh<Register>();
2086 Register in1_lo = first.AsRegisterPairLow<Register>();
2087 Register in2_hi = second.AsRegisterPairHigh<Register>();
2088 Register in2_lo = second.AsRegisterPairLow<Register>();
2089
2090 // Extra checks to protect caused by the existence of R1_R2.
2091 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2092 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2093 DCHECK_NE(out_hi, in1_lo);
2094 DCHECK_NE(out_hi, in2_lo);
2095
2096 // input: in1 - 64 bits, in2 - 64 bits
2097 // output: out
2098 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2099 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2100 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2101
2102 // IP <- in1.lo * in2.hi
2103 __ mul(IP, in1_lo, in2_hi);
2104 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2105 __ mla(out_hi, in1_hi, in2_lo, IP);
2106 // out.lo <- (in1.lo * in2.lo)[31:0];
2107 __ umull(out_lo, IP, in1_lo, in2_lo);
2108 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2109 __ add(out_hi, out_hi, ShifterOperand(IP));
2110 break;
2111 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002112
2113 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002114 __ vmuls(out.AsFpuRegister<SRegister>(),
2115 first.AsFpuRegister<SRegister>(),
2116 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002117 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002118 }
2119
2120 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002121 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2122 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2123 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002124 break;
2125 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002126
2127 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002128 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002129 }
2130}
2131
Calin Juravle7c4954d2014-10-28 16:57:40 +00002132void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002133 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2134 ? LocationSummary::kCall
2135 : LocationSummary::kNoCall;
2136 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2137
Calin Juravle7c4954d2014-10-28 16:57:40 +00002138 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002139 case Primitive::kPrimInt: {
2140 locations->SetInAt(0, Location::RequiresRegister());
2141 locations->SetInAt(1, Location::RequiresRegister());
2142 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2143 break;
2144 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002145 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002146 InvokeRuntimeCallingConvention calling_convention;
2147 locations->SetInAt(0, Location::RegisterPairLocation(
2148 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2149 locations->SetInAt(1, Location::RegisterPairLocation(
2150 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002151 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002152 break;
2153 }
2154 case Primitive::kPrimFloat:
2155 case Primitive::kPrimDouble: {
2156 locations->SetInAt(0, Location::RequiresFpuRegister());
2157 locations->SetInAt(1, Location::RequiresFpuRegister());
2158 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2159 break;
2160 }
2161
2162 default:
2163 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2164 }
2165}
2166
2167void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2168 LocationSummary* locations = div->GetLocations();
2169 Location out = locations->Out();
2170 Location first = locations->InAt(0);
2171 Location second = locations->InAt(1);
2172
2173 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002174 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002175 __ sdiv(out.AsRegister<Register>(),
2176 first.AsRegister<Register>(),
2177 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002178 break;
2179 }
2180
Calin Juravle7c4954d2014-10-28 16:57:40 +00002181 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002182 InvokeRuntimeCallingConvention calling_convention;
2183 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2184 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2185 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2186 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2187 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002188 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002189
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002190 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002191 break;
2192 }
2193
2194 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002195 __ vdivs(out.AsFpuRegister<SRegister>(),
2196 first.AsFpuRegister<SRegister>(),
2197 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002198 break;
2199 }
2200
2201 case Primitive::kPrimDouble: {
2202 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2203 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2204 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2205 break;
2206 }
2207
2208 default:
2209 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2210 }
2211}
2212
Calin Juravlebacfec32014-11-14 15:54:36 +00002213void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002214 Primitive::Type type = rem->GetResultType();
2215 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2216 ? LocationSummary::kNoCall
2217 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002218 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2219
Calin Juravled2ec87d2014-12-08 14:24:46 +00002220 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002221 case Primitive::kPrimInt: {
2222 locations->SetInAt(0, Location::RequiresRegister());
2223 locations->SetInAt(1, Location::RequiresRegister());
2224 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2225 locations->AddTemp(Location::RequiresRegister());
2226 break;
2227 }
2228 case Primitive::kPrimLong: {
2229 InvokeRuntimeCallingConvention calling_convention;
2230 locations->SetInAt(0, Location::RegisterPairLocation(
2231 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2232 locations->SetInAt(1, Location::RegisterPairLocation(
2233 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2234 // The runtime helper puts the output in R2,R3.
2235 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2236 break;
2237 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002238 case Primitive::kPrimFloat: {
2239 InvokeRuntimeCallingConvention calling_convention;
2240 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2241 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2242 locations->SetOut(Location::FpuRegisterLocation(S0));
2243 break;
2244 }
2245
Calin Juravlebacfec32014-11-14 15:54:36 +00002246 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002247 InvokeRuntimeCallingConvention calling_convention;
2248 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2249 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2250 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2251 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2252 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002253 break;
2254 }
2255
2256 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002257 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002258 }
2259}
2260
2261void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2262 LocationSummary* locations = rem->GetLocations();
2263 Location out = locations->Out();
2264 Location first = locations->InAt(0);
2265 Location second = locations->InAt(1);
2266
Calin Juravled2ec87d2014-12-08 14:24:46 +00002267 Primitive::Type type = rem->GetResultType();
2268 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002269 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002270 Register reg1 = first.AsRegister<Register>();
2271 Register reg2 = second.AsRegister<Register>();
2272 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002273
2274 // temp = reg1 / reg2 (integer division)
2275 // temp = temp * reg2
2276 // dest = reg1 - temp
2277 __ sdiv(temp, reg1, reg2);
2278 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002279 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002280 break;
2281 }
2282
2283 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002284 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002285 break;
2286 }
2287
Calin Juravled2ec87d2014-12-08 14:24:46 +00002288 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002289 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002290 break;
2291 }
2292
Calin Juravlebacfec32014-11-14 15:54:36 +00002293 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002294 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002295 break;
2296 }
2297
2298 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002299 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002300 }
2301}
2302
Calin Juravled0d48522014-11-04 16:40:20 +00002303void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2304 LocationSummary* locations =
2305 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002306 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002307 if (instruction->HasUses()) {
2308 locations->SetOut(Location::SameAsFirstInput());
2309 }
2310}
2311
2312void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2313 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2314 codegen_->AddSlowPath(slow_path);
2315
2316 LocationSummary* locations = instruction->GetLocations();
2317 Location value = locations->InAt(0);
2318
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002319 switch (instruction->GetType()) {
2320 case Primitive::kPrimInt: {
2321 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002322 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002323 __ b(slow_path->GetEntryLabel(), EQ);
2324 } else {
2325 DCHECK(value.IsConstant()) << value;
2326 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2327 __ b(slow_path->GetEntryLabel());
2328 }
2329 }
2330 break;
2331 }
2332 case Primitive::kPrimLong: {
2333 if (value.IsRegisterPair()) {
2334 __ orrs(IP,
2335 value.AsRegisterPairLow<Register>(),
2336 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2337 __ b(slow_path->GetEntryLabel(), EQ);
2338 } else {
2339 DCHECK(value.IsConstant()) << value;
2340 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2341 __ b(slow_path->GetEntryLabel());
2342 }
2343 }
2344 break;
2345 default:
2346 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2347 }
2348 }
Calin Juravled0d48522014-11-04 16:40:20 +00002349}
2350
Calin Juravle9aec02f2014-11-18 23:06:35 +00002351void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2352 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2353
2354 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2355 ? LocationSummary::kCall
2356 : LocationSummary::kNoCall;
2357 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2358
2359 switch (op->GetResultType()) {
2360 case Primitive::kPrimInt: {
2361 locations->SetInAt(0, Location::RequiresRegister());
2362 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002363 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002364 break;
2365 }
2366 case Primitive::kPrimLong: {
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002367 InvokeRuntimeCallingConvention calling_convention;
2368 locations->SetInAt(0, Location::RegisterPairLocation(
2369 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2370 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2371 // The runtime helper puts the output in R0,R1.
2372 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002373 break;
2374 }
2375 default:
2376 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2377 }
2378}
2379
2380void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2381 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2382
2383 LocationSummary* locations = op->GetLocations();
2384 Location out = locations->Out();
2385 Location first = locations->InAt(0);
2386 Location second = locations->InAt(1);
2387
2388 Primitive::Type type = op->GetResultType();
2389 switch (type) {
2390 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002391 Register out_reg = out.AsRegister<Register>();
2392 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002393 // Arm doesn't mask the shift count so we need to do it ourselves.
2394 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002395 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002396 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2397 if (op->IsShl()) {
2398 __ Lsl(out_reg, first_reg, second_reg);
2399 } else if (op->IsShr()) {
2400 __ Asr(out_reg, first_reg, second_reg);
2401 } else {
2402 __ Lsr(out_reg, first_reg, second_reg);
2403 }
2404 } else {
2405 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2406 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2407 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2408 __ Mov(out_reg, first_reg);
2409 } else if (op->IsShl()) {
2410 __ Lsl(out_reg, first_reg, shift_value);
2411 } else if (op->IsShr()) {
2412 __ Asr(out_reg, first_reg, shift_value);
2413 } else {
2414 __ Lsr(out_reg, first_reg, shift_value);
2415 }
2416 }
2417 break;
2418 }
2419 case Primitive::kPrimLong: {
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002420 // TODO: Inline the assembly instead of calling the runtime.
2421 InvokeRuntimeCallingConvention calling_convention;
2422 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2423 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2424 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
2425 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2426 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002427
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002428 int32_t entry_point_offset;
Calin Juravle9aec02f2014-11-18 23:06:35 +00002429 if (op->IsShl()) {
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002430 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002431 } else if (op->IsShr()) {
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002432 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002433 } else {
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002434 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002435 }
Calin Juravlef3b4aeb2015-03-17 21:16:38 +00002436 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2437 __ blx(LR);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002438 break;
2439 }
2440 default:
2441 LOG(FATAL) << "Unexpected operation type " << type;
2442 }
2443}
2444
2445void LocationsBuilderARM::VisitShl(HShl* shl) {
2446 HandleShift(shl);
2447}
2448
2449void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2450 HandleShift(shl);
2451}
2452
2453void LocationsBuilderARM::VisitShr(HShr* shr) {
2454 HandleShift(shr);
2455}
2456
2457void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2458 HandleShift(shr);
2459}
2460
2461void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2462 HandleShift(ushr);
2463}
2464
2465void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2466 HandleShift(ushr);
2467}
2468
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002469void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002470 LocationSummary* locations =
2471 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002472 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002473 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2474 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2475 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002476}
2477
2478void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2479 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002480 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002481 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002482 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2483 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002484 instruction->GetDexPc(),
2485 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002486}
2487
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002488void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2489 LocationSummary* locations =
2490 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2491 InvokeRuntimeCallingConvention calling_convention;
2492 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002493 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002494 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002495 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002496}
2497
2498void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2499 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002500 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002501 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002502 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2503 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002504 instruction->GetDexPc(),
2505 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002506}
2507
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002508void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002509 LocationSummary* locations =
2510 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002511 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2512 if (location.IsStackSlot()) {
2513 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2514 } else if (location.IsDoubleStackSlot()) {
2515 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002516 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002517 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002518}
2519
2520void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002521 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002522 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002523}
2524
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002525void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002526 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002527 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002528 locations->SetInAt(0, Location::RequiresRegister());
2529 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002530}
2531
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002532void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2533 LocationSummary* locations = not_->GetLocations();
2534 Location out = locations->Out();
2535 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002536 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002537 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002538 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002539 break;
2540
2541 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002542 __ mvn(out.AsRegisterPairLow<Register>(),
2543 ShifterOperand(in.AsRegisterPairLow<Register>()));
2544 __ mvn(out.AsRegisterPairHigh<Register>(),
2545 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002546 break;
2547
2548 default:
2549 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2550 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002551}
2552
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002553void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002554 LocationSummary* locations =
2555 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002556 switch (compare->InputAt(0)->GetType()) {
2557 case Primitive::kPrimLong: {
2558 locations->SetInAt(0, Location::RequiresRegister());
2559 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002560 // Output overlaps because it is written before doing the low comparison.
2561 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002562 break;
2563 }
2564 case Primitive::kPrimFloat:
2565 case Primitive::kPrimDouble: {
2566 locations->SetInAt(0, Location::RequiresFpuRegister());
2567 locations->SetInAt(1, Location::RequiresFpuRegister());
2568 locations->SetOut(Location::RequiresRegister());
2569 break;
2570 }
2571 default:
2572 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2573 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002574}
2575
2576void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002577 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002578 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002579 Location left = locations->InAt(0);
2580 Location right = locations->InAt(1);
2581
2582 Label less, greater, done;
2583 Primitive::Type type = compare->InputAt(0)->GetType();
2584 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002585 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002586 __ cmp(left.AsRegisterPairHigh<Register>(),
2587 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002588 __ b(&less, LT);
2589 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002590 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2591 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002592 __ cmp(left.AsRegisterPairLow<Register>(),
2593 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002594 break;
2595 }
2596 case Primitive::kPrimFloat:
2597 case Primitive::kPrimDouble: {
2598 __ LoadImmediate(out, 0);
2599 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002600 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002601 } else {
2602 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2603 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2604 }
2605 __ vmstat(); // transfer FP status register to ARM APSR.
2606 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002607 break;
2608 }
2609 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002610 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002611 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002612 __ b(&done, EQ);
2613 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2614
2615 __ Bind(&greater);
2616 __ LoadImmediate(out, 1);
2617 __ b(&done);
2618
2619 __ Bind(&less);
2620 __ LoadImmediate(out, -1);
2621
2622 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002623}
2624
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002625void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002626 LocationSummary* locations =
2627 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002628 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2629 locations->SetInAt(i, Location::Any());
2630 }
2631 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002632}
2633
2634void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002635 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002636 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002637}
2638
Calin Juravle52c48962014-12-16 17:02:57 +00002639void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2640 // TODO (ported from quick): revisit Arm barrier kinds
2641 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2642 switch (kind) {
2643 case MemBarrierKind::kAnyStore:
2644 case MemBarrierKind::kLoadAny:
2645 case MemBarrierKind::kAnyAny: {
2646 flavour = DmbOptions::ISH;
2647 break;
2648 }
2649 case MemBarrierKind::kStoreStore: {
2650 flavour = DmbOptions::ISHST;
2651 break;
2652 }
2653 default:
2654 LOG(FATAL) << "Unexpected memory barrier " << kind;
2655 }
2656 __ dmb(flavour);
2657}
2658
2659void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2660 uint32_t offset,
2661 Register out_lo,
2662 Register out_hi) {
2663 if (offset != 0) {
2664 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002665 __ add(IP, addr, ShifterOperand(out_lo));
2666 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002667 }
2668 __ ldrexd(out_lo, out_hi, addr);
2669}
2670
2671void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2672 uint32_t offset,
2673 Register value_lo,
2674 Register value_hi,
2675 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002676 Register temp2,
2677 HInstruction* instruction) {
Calin Juravle52c48962014-12-16 17:02:57 +00002678 Label fail;
2679 if (offset != 0) {
2680 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002681 __ add(IP, addr, ShifterOperand(temp1));
2682 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002683 }
2684 __ Bind(&fail);
2685 // We need a load followed by store. (The address used in a STREX instruction must
2686 // be the same as the address in the most recently executed LDREX instruction.)
2687 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002688 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002689 __ strexd(temp1, value_lo, value_hi, addr);
2690 __ cmp(temp1, ShifterOperand(0));
2691 __ b(&fail, NE);
2692}
2693
2694void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2695 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2696
Nicolas Geoffray39468442014-09-02 15:17:15 +01002697 LocationSummary* locations =
2698 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002699 locations->SetInAt(0, Location::RequiresRegister());
2700 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002701
Calin Juravle34166012014-12-19 17:22:29 +00002702
Calin Juravle52c48962014-12-16 17:02:57 +00002703 Primitive::Type field_type = field_info.GetFieldType();
2704 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002705 bool generate_volatile = field_info.IsVolatile()
2706 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002707 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002708 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002709 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2710 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002711 locations->AddTemp(Location::RequiresRegister());
2712 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002713 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002714 // Arm encoding have some additional constraints for ldrexd/strexd:
2715 // - registers need to be consecutive
2716 // - the first register should be even but not R14.
2717 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2718 // enable Arm encoding.
2719 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2720
2721 locations->AddTemp(Location::RequiresRegister());
2722 locations->AddTemp(Location::RequiresRegister());
2723 if (field_type == Primitive::kPrimDouble) {
2724 // For doubles we need two more registers to copy the value.
2725 locations->AddTemp(Location::RegisterLocation(R2));
2726 locations->AddTemp(Location::RegisterLocation(R3));
2727 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002728 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002729}
2730
Calin Juravle52c48962014-12-16 17:02:57 +00002731void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2732 const FieldInfo& field_info) {
2733 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2734
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002735 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002736 Register base = locations->InAt(0).AsRegister<Register>();
2737 Location value = locations->InAt(1);
2738
2739 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002740 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002741 Primitive::Type field_type = field_info.GetFieldType();
2742 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2743
2744 if (is_volatile) {
2745 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2746 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002747
2748 switch (field_type) {
2749 case Primitive::kPrimBoolean:
2750 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002751 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002752 break;
2753 }
2754
2755 case Primitive::kPrimShort:
2756 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002757 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002758 break;
2759 }
2760
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002761 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002762 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00002763 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002764 break;
2765 }
2766
2767 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002768 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002769 GenerateWideAtomicStore(base, offset,
2770 value.AsRegisterPairLow<Register>(),
2771 value.AsRegisterPairHigh<Register>(),
2772 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002773 locations->GetTemp(1).AsRegister<Register>(),
2774 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002775 } else {
2776 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002777 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002778 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002779 break;
2780 }
2781
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002782 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002783 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002784 break;
2785 }
2786
2787 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002788 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002789 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002790 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2791 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2792
2793 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2794
2795 GenerateWideAtomicStore(base, offset,
2796 value_reg_lo,
2797 value_reg_hi,
2798 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002799 locations->GetTemp(3).AsRegister<Register>(),
2800 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002801 } else {
2802 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002803 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002804 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002805 break;
2806 }
2807
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002808 case Primitive::kPrimVoid:
2809 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002810 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002811 }
Calin Juravle52c48962014-12-16 17:02:57 +00002812
Calin Juravle77520bc2015-01-12 18:45:46 +00002813 // Longs and doubles are handled in the switch.
2814 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
2815 codegen_->MaybeRecordImplicitNullCheck(instruction);
2816 }
2817
2818 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
2819 Register temp = locations->GetTemp(0).AsRegister<Register>();
2820 Register card = locations->GetTemp(1).AsRegister<Register>();
2821 codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>());
2822 }
2823
Calin Juravle52c48962014-12-16 17:02:57 +00002824 if (is_volatile) {
2825 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2826 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002827}
2828
Calin Juravle52c48962014-12-16 17:02:57 +00002829void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2830 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002831 LocationSummary* locations =
2832 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002833 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002834
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002835 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00002836 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002837 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002838 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
2839 locations->SetOut(Location::RequiresRegister(),
2840 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
2841 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00002842 // Arm encoding have some additional constraints for ldrexd/strexd:
2843 // - registers need to be consecutive
2844 // - the first register should be even but not R14.
2845 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2846 // enable Arm encoding.
2847 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2848 locations->AddTemp(Location::RequiresRegister());
2849 locations->AddTemp(Location::RequiresRegister());
2850 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002851}
2852
Calin Juravle52c48962014-12-16 17:02:57 +00002853void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2854 const FieldInfo& field_info) {
2855 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002856
Calin Juravle52c48962014-12-16 17:02:57 +00002857 LocationSummary* locations = instruction->GetLocations();
2858 Register base = locations->InAt(0).AsRegister<Register>();
2859 Location out = locations->Out();
2860 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002861 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002862 Primitive::Type field_type = field_info.GetFieldType();
2863 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2864
2865 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002866 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002867 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002868 break;
2869 }
2870
2871 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002872 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002873 break;
2874 }
2875
2876 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002877 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002878 break;
2879 }
2880
2881 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002882 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002883 break;
2884 }
2885
2886 case Primitive::kPrimInt:
2887 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002888 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002889 break;
2890 }
2891
2892 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002893 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002894 GenerateWideAtomicLoad(base, offset,
2895 out.AsRegisterPairLow<Register>(),
2896 out.AsRegisterPairHigh<Register>());
2897 } else {
2898 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2899 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002900 break;
2901 }
2902
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002903 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002904 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002905 break;
2906 }
2907
2908 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002909 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002910 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002911 Register lo = locations->GetTemp(0).AsRegister<Register>();
2912 Register hi = locations->GetTemp(1).AsRegister<Register>();
2913 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00002914 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002915 __ vmovdrr(out_reg, lo, hi);
2916 } else {
2917 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002918 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002919 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002920 break;
2921 }
2922
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002923 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002924 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002925 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002926 }
Calin Juravle52c48962014-12-16 17:02:57 +00002927
Calin Juravle77520bc2015-01-12 18:45:46 +00002928 // Doubles are handled in the switch.
2929 if (field_type != Primitive::kPrimDouble) {
2930 codegen_->MaybeRecordImplicitNullCheck(instruction);
2931 }
2932
Calin Juravle52c48962014-12-16 17:02:57 +00002933 if (is_volatile) {
2934 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2935 }
2936}
2937
2938void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2939 HandleFieldSet(instruction, instruction->GetFieldInfo());
2940}
2941
2942void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2943 HandleFieldSet(instruction, instruction->GetFieldInfo());
2944}
2945
2946void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2947 HandleFieldGet(instruction, instruction->GetFieldInfo());
2948}
2949
2950void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2951 HandleFieldGet(instruction, instruction->GetFieldInfo());
2952}
2953
2954void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2955 HandleFieldGet(instruction, instruction->GetFieldInfo());
2956}
2957
2958void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2959 HandleFieldGet(instruction, instruction->GetFieldInfo());
2960}
2961
2962void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2963 HandleFieldSet(instruction, instruction->GetFieldInfo());
2964}
2965
2966void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2967 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002968}
2969
2970void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002971 LocationSummary* locations =
2972 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00002973 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002974 if (instruction->HasUses()) {
2975 locations->SetOut(Location::SameAsFirstInput());
2976 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002977}
2978
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002979void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002980 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2981 return;
2982 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002983 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002984
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002985 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
2986 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2987}
2988
2989void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002990 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002991 codegen_->AddSlowPath(slow_path);
2992
2993 LocationSummary* locations = instruction->GetLocations();
2994 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002995
Calin Juravle77520bc2015-01-12 18:45:46 +00002996 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
2997 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002998}
2999
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003000void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3001 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3002 GenerateImplicitNullCheck(instruction);
3003 } else {
3004 GenerateExplicitNullCheck(instruction);
3005 }
3006}
3007
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003008void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003009 LocationSummary* locations =
3010 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003011 locations->SetInAt(0, Location::RequiresRegister());
3012 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3013 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003014}
3015
3016void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3017 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003018 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003019 Location index = locations->InAt(1);
3020
3021 switch (instruction->GetType()) {
3022 case Primitive::kPrimBoolean: {
3023 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003024 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003025 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003026 size_t offset =
3027 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003028 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3029 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003030 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003031 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3032 }
3033 break;
3034 }
3035
3036 case Primitive::kPrimByte: {
3037 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003038 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003039 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003040 size_t offset =
3041 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003042 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3043 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003044 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003045 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3046 }
3047 break;
3048 }
3049
3050 case Primitive::kPrimShort: {
3051 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003052 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003053 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003054 size_t offset =
3055 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003056 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3057 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003058 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003059 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3060 }
3061 break;
3062 }
3063
3064 case Primitive::kPrimChar: {
3065 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003066 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003067 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003068 size_t offset =
3069 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003070 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3071 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003072 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003073 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3074 }
3075 break;
3076 }
3077
3078 case Primitive::kPrimInt:
3079 case Primitive::kPrimNot: {
3080 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3081 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003082 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003083 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003084 size_t offset =
3085 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003086 __ LoadFromOffset(kLoadWord, out, obj, offset);
3087 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003088 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003089 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3090 }
3091 break;
3092 }
3093
3094 case Primitive::kPrimLong: {
3095 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003096 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003097 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003098 size_t offset =
3099 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003100 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003101 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003102 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003103 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003104 }
3105 break;
3106 }
3107
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003108 case Primitive::kPrimFloat: {
3109 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3110 Location out = locations->Out();
3111 DCHECK(out.IsFpuRegister());
3112 if (index.IsConstant()) {
3113 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3114 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3115 } else {
3116 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3117 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3118 }
3119 break;
3120 }
3121
3122 case Primitive::kPrimDouble: {
3123 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3124 Location out = locations->Out();
3125 DCHECK(out.IsFpuRegisterPair());
3126 if (index.IsConstant()) {
3127 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3128 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3129 } else {
3130 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3131 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3132 }
3133 break;
3134 }
3135
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003136 case Primitive::kPrimVoid:
3137 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003138 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003139 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003140 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003141}
3142
3143void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003144 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003145
3146 bool needs_write_barrier =
3147 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3148 bool needs_runtime_call = instruction->NeedsTypeCheck();
3149
Nicolas Geoffray39468442014-09-02 15:17:15 +01003150 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003151 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3152 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003153 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003154 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3155 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3156 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003157 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003158 locations->SetInAt(0, Location::RequiresRegister());
3159 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3160 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003161
3162 if (needs_write_barrier) {
3163 // Temporary registers for the write barrier.
3164 locations->AddTemp(Location::RequiresRegister());
3165 locations->AddTemp(Location::RequiresRegister());
3166 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003167 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003168}
3169
3170void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3171 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003172 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003173 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003174 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003175 bool needs_runtime_call = locations->WillCall();
3176 bool needs_write_barrier =
3177 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003178
3179 switch (value_type) {
3180 case Primitive::kPrimBoolean:
3181 case Primitive::kPrimByte: {
3182 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003183 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003184 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003185 size_t offset =
3186 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003187 __ StoreToOffset(kStoreByte, value, obj, offset);
3188 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003189 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003190 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3191 }
3192 break;
3193 }
3194
3195 case Primitive::kPrimShort:
3196 case Primitive::kPrimChar: {
3197 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003198 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003199 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003200 size_t offset =
3201 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003202 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3203 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003204 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003205 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3206 }
3207 break;
3208 }
3209
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003210 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003211 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003212 if (!needs_runtime_call) {
3213 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003214 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003215 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003216 size_t offset =
3217 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003218 __ StoreToOffset(kStoreWord, value, obj, offset);
3219 } else {
3220 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003221 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003222 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3223 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003224 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003225 if (needs_write_barrier) {
3226 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003227 Register temp = locations->GetTemp(0).AsRegister<Register>();
3228 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003229 codegen_->MarkGCCard(temp, card, obj, value);
3230 }
3231 } else {
3232 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003233 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3234 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003235 instruction->GetDexPc(),
3236 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003237 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003238 break;
3239 }
3240
3241 case Primitive::kPrimLong: {
3242 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003243 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003244 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003245 size_t offset =
3246 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003247 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003248 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003249 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003250 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003251 }
3252 break;
3253 }
3254
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003255 case Primitive::kPrimFloat: {
3256 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3257 Location value = locations->InAt(2);
3258 DCHECK(value.IsFpuRegister());
3259 if (index.IsConstant()) {
3260 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3261 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3262 } else {
3263 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3264 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3265 }
3266 break;
3267 }
3268
3269 case Primitive::kPrimDouble: {
3270 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3271 Location value = locations->InAt(2);
3272 DCHECK(value.IsFpuRegisterPair());
3273 if (index.IsConstant()) {
3274 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3275 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3276 } else {
3277 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3278 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3279 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003280
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003281 break;
3282 }
3283
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003284 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003285 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003286 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003287 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003288
3289 // Ints and objects are handled in the switch.
3290 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3291 codegen_->MaybeRecordImplicitNullCheck(instruction);
3292 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003293}
3294
3295void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003296 LocationSummary* locations =
3297 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003298 locations->SetInAt(0, Location::RequiresRegister());
3299 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003300}
3301
3302void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3303 LocationSummary* locations = instruction->GetLocations();
3304 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003305 Register obj = locations->InAt(0).AsRegister<Register>();
3306 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003307 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003308 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003309}
3310
3311void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003312 LocationSummary* locations =
3313 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003314 locations->SetInAt(0, Location::RequiresRegister());
3315 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003316 if (instruction->HasUses()) {
3317 locations->SetOut(Location::SameAsFirstInput());
3318 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003319}
3320
3321void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3322 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003323 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003324 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003325 codegen_->AddSlowPath(slow_path);
3326
Roland Levillain271ab9c2014-11-27 15:23:57 +00003327 Register index = locations->InAt(0).AsRegister<Register>();
3328 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003329
3330 __ cmp(index, ShifterOperand(length));
3331 __ b(slow_path->GetEntryLabel(), CS);
3332}
3333
3334void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3335 Label is_null;
3336 __ CompareAndBranchIfZero(value, &is_null);
3337 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3338 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3339 __ strb(card, Address(card, temp));
3340 __ Bind(&is_null);
3341}
3342
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003343void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3344 temp->SetLocations(nullptr);
3345}
3346
3347void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3348 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003349 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003350}
3351
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003352void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003353 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003354 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003355}
3356
3357void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003358 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3359}
3360
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003361void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3362 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3363}
3364
3365void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003366 HBasicBlock* block = instruction->GetBlock();
3367 if (block->GetLoopInformation() != nullptr) {
3368 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3369 // The back edge will generate the suspend check.
3370 return;
3371 }
3372 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3373 // The goto will generate the suspend check.
3374 return;
3375 }
3376 GenerateSuspendCheck(instruction, nullptr);
3377}
3378
3379void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3380 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003381 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003382 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003383 codegen_->AddSlowPath(slow_path);
3384
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003385 __ LoadFromOffset(
3386 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3387 __ cmp(IP, ShifterOperand(0));
3388 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003389 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003390 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003391 __ Bind(slow_path->GetReturnLabel());
3392 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003393 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003394 __ b(slow_path->GetEntryLabel());
3395 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003396}
3397
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003398ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3399 return codegen_->GetAssembler();
3400}
3401
3402void ParallelMoveResolverARM::EmitMove(size_t index) {
3403 MoveOperands* move = moves_.Get(index);
3404 Location source = move->GetSource();
3405 Location destination = move->GetDestination();
3406
3407 if (source.IsRegister()) {
3408 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003409 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003410 } else {
3411 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003412 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003413 SP, destination.GetStackIndex());
3414 }
3415 } else if (source.IsStackSlot()) {
3416 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003417 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003418 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003419 } else if (destination.IsFpuRegister()) {
3420 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003421 } else {
3422 DCHECK(destination.IsStackSlot());
3423 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3424 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3425 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003426 } else if (source.IsFpuRegister()) {
3427 if (destination.IsFpuRegister()) {
3428 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003429 } else {
3430 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003431 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3432 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003433 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003434 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003435 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3436 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003437 } else if (destination.IsRegisterPair()) {
3438 DCHECK(ExpectedPairLayout(destination));
3439 __ LoadFromOffset(
3440 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3441 } else {
3442 DCHECK(destination.IsFpuRegisterPair()) << destination;
3443 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3444 SP,
3445 source.GetStackIndex());
3446 }
3447 } else if (source.IsRegisterPair()) {
3448 if (destination.IsRegisterPair()) {
3449 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3450 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3451 } else {
3452 DCHECK(destination.IsDoubleStackSlot()) << destination;
3453 DCHECK(ExpectedPairLayout(source));
3454 __ StoreToOffset(
3455 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3456 }
3457 } else if (source.IsFpuRegisterPair()) {
3458 if (destination.IsFpuRegisterPair()) {
3459 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3460 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3461 } else {
3462 DCHECK(destination.IsDoubleStackSlot()) << destination;
3463 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3464 SP,
3465 destination.GetStackIndex());
3466 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003467 } else {
3468 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003469 HConstant* constant = source.GetConstant();
3470 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3471 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003472 if (destination.IsRegister()) {
3473 __ LoadImmediate(destination.AsRegister<Register>(), value);
3474 } else {
3475 DCHECK(destination.IsStackSlot());
3476 __ LoadImmediate(IP, value);
3477 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3478 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003479 } else if (constant->IsLongConstant()) {
3480 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003481 if (destination.IsRegisterPair()) {
3482 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3483 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003484 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003485 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003486 __ LoadImmediate(IP, Low32Bits(value));
3487 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3488 __ LoadImmediate(IP, High32Bits(value));
3489 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3490 }
3491 } else if (constant->IsDoubleConstant()) {
3492 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003493 if (destination.IsFpuRegisterPair()) {
3494 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003495 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003496 DCHECK(destination.IsDoubleStackSlot()) << destination;
3497 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003498 __ LoadImmediate(IP, Low32Bits(int_value));
3499 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3500 __ LoadImmediate(IP, High32Bits(int_value));
3501 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3502 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003503 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003504 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003505 float value = constant->AsFloatConstant()->GetValue();
3506 if (destination.IsFpuRegister()) {
3507 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3508 } else {
3509 DCHECK(destination.IsStackSlot());
3510 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3511 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3512 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003513 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003514 }
3515}
3516
3517void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3518 __ Mov(IP, reg);
3519 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3520 __ StoreToOffset(kStoreWord, IP, SP, mem);
3521}
3522
3523void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3524 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3525 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3526 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3527 SP, mem1 + stack_offset);
3528 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3529 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3530 SP, mem2 + stack_offset);
3531 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3532}
3533
3534void ParallelMoveResolverARM::EmitSwap(size_t index) {
3535 MoveOperands* move = moves_.Get(index);
3536 Location source = move->GetSource();
3537 Location destination = move->GetDestination();
3538
3539 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003540 DCHECK_NE(source.AsRegister<Register>(), IP);
3541 DCHECK_NE(destination.AsRegister<Register>(), IP);
3542 __ Mov(IP, source.AsRegister<Register>());
3543 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3544 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003545 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003546 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003547 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003548 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003549 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3550 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003551 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003552 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003553 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003554 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003555 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003556 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003557 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003558 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003559 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3560 destination.AsRegisterPairHigh<Register>(),
3561 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003562 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003563 Register low_reg = source.IsRegisterPair()
3564 ? source.AsRegisterPairLow<Register>()
3565 : destination.AsRegisterPairLow<Register>();
3566 int mem = source.IsRegisterPair()
3567 ? destination.GetStackIndex()
3568 : source.GetStackIndex();
3569 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003570 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003571 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003572 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003573 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003574 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3575 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003576 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003577 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003578 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003579 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3580 DRegister reg = source.IsFpuRegisterPair()
3581 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3582 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3583 int mem = source.IsFpuRegisterPair()
3584 ? destination.GetStackIndex()
3585 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003586 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003587 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003588 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003589 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3590 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3591 : destination.AsFpuRegister<SRegister>();
3592 int mem = source.IsFpuRegister()
3593 ? destination.GetStackIndex()
3594 : source.GetStackIndex();
3595
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003596 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003597 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003598 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003599 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003600 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3601 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003602 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003603 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003604 }
3605}
3606
3607void ParallelMoveResolverARM::SpillScratch(int reg) {
3608 __ Push(static_cast<Register>(reg));
3609}
3610
3611void ParallelMoveResolverARM::RestoreScratch(int reg) {
3612 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003613}
3614
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003615void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003616 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3617 ? LocationSummary::kCallOnSlowPath
3618 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003619 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003620 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003621 locations->SetOut(Location::RequiresRegister());
3622}
3623
3624void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003625 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003626 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003627 DCHECK(!cls->CanCallRuntime());
3628 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003629 codegen_->LoadCurrentMethod(out);
3630 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3631 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003632 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003633 codegen_->LoadCurrentMethod(out);
3634 __ LoadFromOffset(
3635 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3636 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003637
3638 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3639 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3640 codegen_->AddSlowPath(slow_path);
3641 __ cmp(out, ShifterOperand(0));
3642 __ b(slow_path->GetEntryLabel(), EQ);
3643 if (cls->MustGenerateClinitCheck()) {
3644 GenerateClassInitializationCheck(slow_path, out);
3645 } else {
3646 __ Bind(slow_path->GetExitLabel());
3647 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003648 }
3649}
3650
3651void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3652 LocationSummary* locations =
3653 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3654 locations->SetInAt(0, Location::RequiresRegister());
3655 if (check->HasUses()) {
3656 locations->SetOut(Location::SameAsFirstInput());
3657 }
3658}
3659
3660void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003661 // We assume the class is not null.
3662 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3663 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003664 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003665 GenerateClassInitializationCheck(slow_path,
3666 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003667}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003668
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003669void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3670 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003671 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3672 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3673 __ b(slow_path->GetEntryLabel(), LT);
3674 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3675 // properly. Therefore, we do a memory fence.
3676 __ dmb(ISH);
3677 __ Bind(slow_path->GetExitLabel());
3678}
3679
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003680void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3681 LocationSummary* locations =
3682 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3683 locations->SetOut(Location::RequiresRegister());
3684}
3685
3686void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3687 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3688 codegen_->AddSlowPath(slow_path);
3689
Roland Levillain271ab9c2014-11-27 15:23:57 +00003690 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003691 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003692 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3693 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003694 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3695 __ cmp(out, ShifterOperand(0));
3696 __ b(slow_path->GetEntryLabel(), EQ);
3697 __ Bind(slow_path->GetExitLabel());
3698}
3699
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003700void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3701 LocationSummary* locations =
3702 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3703 locations->SetOut(Location::RequiresRegister());
3704}
3705
3706void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003707 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003708 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3709 __ LoadFromOffset(kLoadWord, out, TR, offset);
3710 __ LoadImmediate(IP, 0);
3711 __ StoreToOffset(kStoreWord, IP, TR, offset);
3712}
3713
3714void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3715 LocationSummary* locations =
3716 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3717 InvokeRuntimeCallingConvention calling_convention;
3718 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3719}
3720
3721void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3722 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003723 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003724}
3725
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003726void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003727 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3728 ? LocationSummary::kNoCall
3729 : LocationSummary::kCallOnSlowPath;
3730 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3731 locations->SetInAt(0, Location::RequiresRegister());
3732 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003733 // The out register is used as a temporary, so it overlaps with the inputs.
3734 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003735}
3736
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003737void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003738 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003739 Register obj = locations->InAt(0).AsRegister<Register>();
3740 Register cls = locations->InAt(1).AsRegister<Register>();
3741 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003742 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3743 Label done, zero;
3744 SlowPathCodeARM* slow_path = nullptr;
3745
3746 // Return 0 if `obj` is null.
3747 // TODO: avoid this check if we know obj is not null.
3748 __ cmp(obj, ShifterOperand(0));
3749 __ b(&zero, EQ);
3750 // Compare the class of `obj` with `cls`.
3751 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3752 __ cmp(out, ShifterOperand(cls));
3753 if (instruction->IsClassFinal()) {
3754 // Classes must be equal for the instanceof to succeed.
3755 __ b(&zero, NE);
3756 __ LoadImmediate(out, 1);
3757 __ b(&done);
3758 } else {
3759 // If the classes are not equal, we go into a slow path.
3760 DCHECK(locations->OnlyCallsOnSlowPath());
3761 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003762 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003763 codegen_->AddSlowPath(slow_path);
3764 __ b(slow_path->GetEntryLabel(), NE);
3765 __ LoadImmediate(out, 1);
3766 __ b(&done);
3767 }
3768 __ Bind(&zero);
3769 __ LoadImmediate(out, 0);
3770 if (slow_path != nullptr) {
3771 __ Bind(slow_path->GetExitLabel());
3772 }
3773 __ Bind(&done);
3774}
3775
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003776void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3777 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3778 instruction, LocationSummary::kCallOnSlowPath);
3779 locations->SetInAt(0, Location::RequiresRegister());
3780 locations->SetInAt(1, Location::RequiresRegister());
3781 locations->AddTemp(Location::RequiresRegister());
3782}
3783
3784void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3785 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003786 Register obj = locations->InAt(0).AsRegister<Register>();
3787 Register cls = locations->InAt(1).AsRegister<Register>();
3788 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003789 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3790
3791 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3792 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3793 codegen_->AddSlowPath(slow_path);
3794
3795 // TODO: avoid this check if we know obj is not null.
3796 __ cmp(obj, ShifterOperand(0));
3797 __ b(slow_path->GetExitLabel(), EQ);
3798 // Compare the class of `obj` with `cls`.
3799 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3800 __ cmp(temp, ShifterOperand(cls));
3801 __ b(slow_path->GetEntryLabel(), NE);
3802 __ Bind(slow_path->GetExitLabel());
3803}
3804
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003805void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3806 LocationSummary* locations =
3807 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3808 InvokeRuntimeCallingConvention calling_convention;
3809 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3810}
3811
3812void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3813 codegen_->InvokeRuntime(instruction->IsEnter()
3814 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3815 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003816 instruction->GetDexPc(),
3817 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003818}
3819
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003820void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3821void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3822void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3823
3824void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3825 LocationSummary* locations =
3826 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3827 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3828 || instruction->GetResultType() == Primitive::kPrimLong);
3829 locations->SetInAt(0, Location::RequiresRegister());
3830 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003831 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003832}
3833
3834void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3835 HandleBitwiseOperation(instruction);
3836}
3837
3838void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3839 HandleBitwiseOperation(instruction);
3840}
3841
3842void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3843 HandleBitwiseOperation(instruction);
3844}
3845
3846void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3847 LocationSummary* locations = instruction->GetLocations();
3848
3849 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003850 Register first = locations->InAt(0).AsRegister<Register>();
3851 Register second = locations->InAt(1).AsRegister<Register>();
3852 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003853 if (instruction->IsAnd()) {
3854 __ and_(out, first, ShifterOperand(second));
3855 } else if (instruction->IsOr()) {
3856 __ orr(out, first, ShifterOperand(second));
3857 } else {
3858 DCHECK(instruction->IsXor());
3859 __ eor(out, first, ShifterOperand(second));
3860 }
3861 } else {
3862 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3863 Location first = locations->InAt(0);
3864 Location second = locations->InAt(1);
3865 Location out = locations->Out();
3866 if (instruction->IsAnd()) {
3867 __ and_(out.AsRegisterPairLow<Register>(),
3868 first.AsRegisterPairLow<Register>(),
3869 ShifterOperand(second.AsRegisterPairLow<Register>()));
3870 __ and_(out.AsRegisterPairHigh<Register>(),
3871 first.AsRegisterPairHigh<Register>(),
3872 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3873 } else if (instruction->IsOr()) {
3874 __ orr(out.AsRegisterPairLow<Register>(),
3875 first.AsRegisterPairLow<Register>(),
3876 ShifterOperand(second.AsRegisterPairLow<Register>()));
3877 __ orr(out.AsRegisterPairHigh<Register>(),
3878 first.AsRegisterPairHigh<Register>(),
3879 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3880 } else {
3881 DCHECK(instruction->IsXor());
3882 __ eor(out.AsRegisterPairLow<Register>(),
3883 first.AsRegisterPairLow<Register>(),
3884 ShifterOperand(second.AsRegisterPairLow<Register>()));
3885 __ eor(out.AsRegisterPairHigh<Register>(),
3886 first.AsRegisterPairHigh<Register>(),
3887 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3888 }
3889 }
3890}
3891
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003892void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
3893 DCHECK_EQ(temp, kArtMethodRegister);
3894
3895 // TODO: Implement all kinds of calls:
3896 // 1) boot -> boot
3897 // 2) app -> boot
3898 // 3) app -> app
3899 //
3900 // Currently we implement the app -> app logic, which looks up in the resolve cache.
3901
3902 // temp = method;
3903 LoadCurrentMethod(temp);
3904 if (!invoke->IsRecursive()) {
3905 // temp = temp->dex_cache_resolved_methods_;
3906 __ LoadFromOffset(
3907 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
3908 // temp = temp[index_in_cache]
3909 __ LoadFromOffset(
3910 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
3911 // LR = temp[offset_of_quick_compiled_code]
3912 __ LoadFromOffset(kLoadWord, LR, temp,
3913 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
3914 kArmWordSize).Int32Value());
3915 // LR()
3916 __ blx(LR);
3917 } else {
3918 __ bl(GetFrameEntryLabel());
3919 }
3920
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003921 DCHECK(!IsLeafMethod());
3922}
3923
Calin Juravleb1498f62015-02-16 13:13:29 +00003924void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
3925 // Nothing to do, this should be removed during prepare for register allocator.
3926 UNUSED(instruction);
3927 LOG(FATAL) << "Unreachable";
3928}
3929
3930void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
3931 // Nothing to do, this should be removed during prepare for register allocator.
3932 UNUSED(instruction);
3933 LOG(FATAL) << "Unreachable";
3934}
3935
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003936} // namespace arm
3937} // namespace art