blob: 71696799f81007d4e272a7accb84f97bdeb8371f [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"
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "art_method.h"
Zheng Xuc6667102015-05-15 16:08:45 +080021#include "code_generator_utils.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070022#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010023#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080024#include "intrinsics.h"
25#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070026#include "mirror/array-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070027#include "mirror/class-inl.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070028#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010029#include "utils/arm/assembler_arm.h"
30#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000031#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010032#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000033
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000034namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010035
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000036namespace arm {
37
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000038static bool ExpectedPairLayout(Location location) {
39 // We expected this for both core and fpu register pairs.
40 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
41}
42
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010043static constexpr int kCurrentMethodStackOffset = 0;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +010044static constexpr Register kMethodRegisterArgument = R0;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010045
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000046// We unconditionally allocate R5 to ensure we can do long operations
47// with baseline.
48static constexpr Register kCoreSavedRegisterForBaseline = R5;
49static constexpr Register kCoreCalleeSaves[] =
50 { R5, R6, R7, R8, R10, R11, PC };
51static constexpr SRegister kFpuCalleeSaves[] =
52 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010053
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000054// D31 cannot be split into two S registers, and the register allocator only works on
55// S registers. Therefore there is no need to block it.
56static constexpr DRegister DTMP = D31;
57
Roland Levillain62a46b22015-06-01 18:24:13 +010058#define __ down_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010059#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010060
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010061class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010063 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064
Alexandre Rames67555f72014-11-18 10:55:16 +000065 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010066 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010067 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010068 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000069 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010070 }
71
Alexandre Rames9931f312015-06-19 14:47:01 +010072 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
73
Nicolas Geoffraye5038322014-07-04 09:41:32 +010074 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010075 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010076 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
77};
78
Calin Juravled0d48522014-11-04 16:40:20 +000079class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
80 public:
81 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
82
Alexandre Rames67555f72014-11-18 10:55:16 +000083 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000084 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
85 __ Bind(GetEntryLabel());
86 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000087 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +000088 }
89
Alexandre Rames9931f312015-06-19 14:47:01 +010090 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
91
Calin Juravled0d48522014-11-04 16:40:20 +000092 private:
93 HDivZeroCheck* const instruction_;
94 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
95};
96
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010097class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000098 public:
Alexandre Rames67555f72014-11-18 10:55:16 +000099 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100100 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000101
Alexandre Rames67555f72014-11-18 10:55:16 +0000102 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100103 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000104 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000105 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100106 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000107 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000108 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100109 if (successor_ == nullptr) {
110 __ b(GetReturnLabel());
111 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100112 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100113 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000114 }
115
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100116 Label* GetReturnLabel() {
117 DCHECK(successor_ == nullptr);
118 return &return_label_;
119 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000120
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100121 HBasicBlock* GetSuccessor() const {
122 return successor_;
123 }
124
Alexandre Rames9931f312015-06-19 14:47:01 +0100125 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; }
126
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000127 private:
128 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100129 // If not null, the block to branch to after the suspend check.
130 HBasicBlock* const successor_;
131
132 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000133 Label return_label_;
134
135 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
136};
137
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100138class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100139 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100140 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
141 Location index_location,
142 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100143 : instruction_(instruction),
144 index_location_(index_location),
145 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100146
Alexandre Rames67555f72014-11-18 10:55:16 +0000147 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100148 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100149 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000150 // We're moving two locations to locations that could overlap, so we need a parallel
151 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000153 codegen->EmitParallelMoves(
154 index_location_,
155 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100156 Primitive::kPrimInt,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000157 length_location_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100158 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
159 Primitive::kPrimInt);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100160 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000161 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100162 }
163
Alexandre Rames9931f312015-06-19 14:47:01 +0100164 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; }
165
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100166 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100167 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100168 const Location index_location_;
169 const Location length_location_;
170
171 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
172};
173
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000174class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100175 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000176 LoadClassSlowPathARM(HLoadClass* cls,
177 HInstruction* at,
178 uint32_t dex_pc,
179 bool do_clinit)
180 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
181 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
182 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100183
Alexandre Rames67555f72014-11-18 10:55:16 +0000184 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000185 LocationSummary* locations = at_->GetLocations();
186
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100187 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
188 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000189 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100191 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000192 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000193 int32_t entry_point_offset = do_clinit_
194 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
195 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000196 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000197
198 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000199 Location out = locations->Out();
200 if (out.IsValid()) {
201 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000202 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
203 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000204 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100205 __ b(GetExitLabel());
206 }
207
Alexandre Rames9931f312015-06-19 14:47:01 +0100208 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
209
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000211 // The class this slow path will load.
212 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100213
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000214 // The instruction where this slow path is happening.
215 // (Might be the load class or an initialization check).
216 HInstruction* const at_;
217
218 // The dex PC of `at_`.
219 const uint32_t dex_pc_;
220
221 // Whether to initialize the class.
222 const bool do_clinit_;
223
224 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100225};
226
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000227class LoadStringSlowPathARM : public SlowPathCodeARM {
228 public:
229 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
230
Alexandre Rames67555f72014-11-18 10:55:16 +0000231 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000232 LocationSummary* locations = instruction_->GetLocations();
233 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
234
235 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
236 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000237 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000238
239 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800240 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000241 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000242 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000243 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
244
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000245 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000246 __ b(GetExitLabel());
247 }
248
Alexandre Rames9931f312015-06-19 14:47:01 +0100249 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
250
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000251 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)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100283 Primitive::kPrimNot,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000284 object_class_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100285 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
286 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000287
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000288 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000289 arm_codegen->InvokeRuntime(
290 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000291 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
292 } else {
293 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000294 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000295 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000296
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000297 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000298 __ b(GetExitLabel());
299 }
300
Alexandre Rames9931f312015-06-19 14:47:01 +0100301 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
302
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000303 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000304 HInstruction* const instruction_;
305 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000306 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000307 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000308
309 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
310};
311
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700312class DeoptimizationSlowPathARM : public SlowPathCodeARM {
313 public:
314 explicit DeoptimizationSlowPathARM(HInstruction* instruction)
315 : instruction_(instruction) {}
316
317 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
318 __ Bind(GetEntryLabel());
319 SaveLiveRegisters(codegen, instruction_->GetLocations());
320 DCHECK(instruction_->IsDeoptimize());
321 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
322 uint32_t dex_pc = deoptimize->GetDexPc();
323 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
324 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
325 }
326
Alexandre Rames9931f312015-06-19 14:47:01 +0100327 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
328
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700329 private:
330 HInstruction* const instruction_;
331 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
332};
333
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000334#undef __
335
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100336#undef __
Roland Levillain62a46b22015-06-01 18:24:13 +0100337#define __ down_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700338
339inline Condition ARMCondition(IfCondition cond) {
340 switch (cond) {
341 case kCondEQ: return EQ;
342 case kCondNE: return NE;
343 case kCondLT: return LT;
344 case kCondLE: return LE;
345 case kCondGT: return GT;
346 case kCondGE: return GE;
347 default:
348 LOG(FATAL) << "Unknown if condition";
349 }
350 return EQ; // Unreachable.
351}
352
353inline Condition ARMOppositeCondition(IfCondition cond) {
354 switch (cond) {
355 case kCondEQ: return NE;
356 case kCondNE: return EQ;
357 case kCondLT: return GE;
358 case kCondLE: return GT;
359 case kCondGT: return LE;
360 case kCondGE: return LT;
361 default:
362 LOG(FATAL) << "Unknown if condition";
363 }
364 return EQ; // Unreachable.
365}
366
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100367void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100368 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100369}
370
371void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100372 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100373}
374
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100375size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
376 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
377 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100378}
379
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100380size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
381 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
382 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100383}
384
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000385size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
386 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
387 return kArmWordSize;
388}
389
390size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
391 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
392 return kArmWordSize;
393}
394
Calin Juravle34166012014-12-19 17:22:29 +0000395CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000396 const ArmInstructionSetFeatures& isa_features,
397 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000398 : CodeGenerator(graph,
399 kNumberOfCoreRegisters,
400 kNumberOfSRegisters,
401 kNumberOfRegisterPairs,
402 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
403 arraysize(kCoreCalleeSaves)),
404 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
405 arraysize(kFpuCalleeSaves)),
406 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100407 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100408 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100409 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100410 move_resolver_(graph->GetArena(), this),
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000411 assembler_(),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000412 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000413 // Save the PC register to mimic Quick.
414 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100415}
416
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000417void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
418 // Ensure that we fix up branches and literal loads and emit the literal pool.
419 __ FinalizeCode();
420
421 // Adjust native pc offsets in stack maps.
422 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
423 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
424 uint32_t new_position = __ GetAdjustedPosition(old_position);
425 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
426 }
427 // Adjust native pc offsets of block labels.
428 for (size_t block_idx = 0u, end = block_order_->Size(); block_idx != end; ++block_idx) {
429 HBasicBlock* block = block_order_->Get(block_idx);
430 // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid
431 // FirstNonEmptyBlock() which could lead to adjusting a label more than once.
432 DCHECK_LT(static_cast<size_t>(block->GetBlockId()), block_labels_.Size());
433 Label* block_label = &block_labels_.GetRawStorage()[block->GetBlockId()];
434 DCHECK_EQ(block_label->IsBound(), !block->IsSingleGoto());
435 if (block_label->IsBound()) {
436 __ AdjustLabelPosition(block_label);
437 }
438 }
439
440 CodeGenerator::Finalize(allocator);
441}
442
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100443Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100444 switch (type) {
445 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100446 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100447 ArmManagedRegister pair =
448 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100449 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
450 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
451
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100452 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
453 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100454 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100455 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100456 }
457
458 case Primitive::kPrimByte:
459 case Primitive::kPrimBoolean:
460 case Primitive::kPrimChar:
461 case Primitive::kPrimShort:
462 case Primitive::kPrimInt:
463 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100464 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100465 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100466 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
467 ArmManagedRegister current =
468 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
469 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100470 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100471 }
472 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100473 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100474 }
475
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000476 case Primitive::kPrimFloat: {
477 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100478 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100479 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100480
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000481 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000482 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
483 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000484 return Location::FpuRegisterPairLocation(reg, reg + 1);
485 }
486
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100487 case Primitive::kPrimVoid:
488 LOG(FATAL) << "Unreachable type " << type;
489 }
490
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100491 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100492}
493
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000494void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100495 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100496 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100497
498 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100499 blocked_core_registers_[SP] = true;
500 blocked_core_registers_[LR] = true;
501 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100502
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100503 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100504 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100505
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100506 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100507 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100508
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000509 if (is_baseline) {
510 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
511 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
512 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000513
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000514 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
515
516 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
517 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
518 }
519 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100520
521 UpdateBlockedPairRegisters();
522}
523
524void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
525 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
526 ArmManagedRegister current =
527 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
528 if (blocked_core_registers_[current.AsRegisterPairLow()]
529 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
530 blocked_register_pairs_[i] = true;
531 }
532 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100533}
534
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100535InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
536 : HGraphVisitor(graph),
537 assembler_(codegen->GetAssembler()),
538 codegen_(codegen) {}
539
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000540void CodeGeneratorARM::ComputeSpillMask() {
541 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000542 // Save one extra register for baseline. Note that on thumb2, there is no easy
543 // instruction to restore just the PC, so this actually helps both baseline
544 // and non-baseline to save and restore at least two registers at entry and exit.
545 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000546 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
547 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
548 // We use vpush and vpop for saving and restoring floating point registers, which take
549 // a SRegister and the number of registers to save/restore after that SRegister. We
550 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
551 // but in the range.
552 if (fpu_spill_mask_ != 0) {
553 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
554 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
555 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
556 fpu_spill_mask_ |= (1 << i);
557 }
558 }
559}
560
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100561static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100562 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100563}
564
565static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100566 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100567}
568
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000569void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000570 bool skip_overflow_check =
571 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000572 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000573 __ Bind(&frame_entry_label_);
574
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000575 if (HasEmptyFrame()) {
576 return;
577 }
578
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100579 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000580 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
581 __ LoadFromOffset(kLoadWord, IP, IP, 0);
582 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100583 }
584
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000585 // PC is in the list of callee-save to mimic Quick, but we need to push
586 // LR at entry instead.
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100587 uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR;
588 __ PushList(push_mask);
589 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100590 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, push_mask, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000591 if (fpu_spill_mask_ != 0) {
592 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
593 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100594 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100595 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000596 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100597 int adjust = GetFrameSize() - FrameEntrySpillSize();
598 __ AddConstant(SP, -adjust);
599 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100600 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000601}
602
603void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000604 if (HasEmptyFrame()) {
605 __ bx(LR);
606 return;
607 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100608 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100609 int adjust = GetFrameSize() - FrameEntrySpillSize();
610 __ AddConstant(SP, adjust);
611 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000612 if (fpu_spill_mask_ != 0) {
613 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
614 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100615 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
616 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000617 }
618 __ PopList(core_spill_mask_);
David Srbeckyc34dc932015-04-12 09:27:43 +0100619 __ cfi().RestoreState();
620 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000621}
622
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100623void CodeGeneratorARM::Bind(HBasicBlock* block) {
624 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000625}
626
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100627Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
628 switch (load->GetType()) {
629 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100630 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100631 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100632
633 case Primitive::kPrimInt:
634 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100635 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100636 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100637
638 case Primitive::kPrimBoolean:
639 case Primitive::kPrimByte:
640 case Primitive::kPrimChar:
641 case Primitive::kPrimShort:
642 case Primitive::kPrimVoid:
643 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700644 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100645 }
646
647 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700648 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100649}
650
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100651Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100652 switch (type) {
653 case Primitive::kPrimBoolean:
654 case Primitive::kPrimByte:
655 case Primitive::kPrimChar:
656 case Primitive::kPrimShort:
657 case Primitive::kPrimInt:
658 case Primitive::kPrimNot: {
659 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000660 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100661 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100662 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100663 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000664 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100665 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100666 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100667
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000668 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100669 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000670 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100671 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000672 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100673 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000674 if (calling_convention.GetRegisterAt(index) == R1) {
675 // Skip R1, and use R2_R3 instead.
676 gp_index_++;
677 index++;
678 }
679 }
680 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
681 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000682 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000683 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000684 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100685 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000686 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
687 }
688 }
689
690 case Primitive::kPrimFloat: {
691 uint32_t stack_index = stack_index_++;
692 if (float_index_ % 2 == 0) {
693 float_index_ = std::max(double_index_, float_index_);
694 }
695 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
696 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
697 } else {
698 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
699 }
700 }
701
702 case Primitive::kPrimDouble: {
703 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
704 uint32_t stack_index = stack_index_;
705 stack_index_ += 2;
706 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
707 uint32_t index = double_index_;
708 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000709 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000710 calling_convention.GetFpuRegisterAt(index),
711 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000712 DCHECK(ExpectedPairLayout(result));
713 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000714 } else {
715 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100716 }
717 }
718
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100719 case Primitive::kPrimVoid:
720 LOG(FATAL) << "Unexpected parameter type " << type;
721 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100722 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100723 return Location();
724}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100725
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100726Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000727 switch (type) {
728 case Primitive::kPrimBoolean:
729 case Primitive::kPrimByte:
730 case Primitive::kPrimChar:
731 case Primitive::kPrimShort:
732 case Primitive::kPrimInt:
733 case Primitive::kPrimNot: {
734 return Location::RegisterLocation(R0);
735 }
736
737 case Primitive::kPrimFloat: {
738 return Location::FpuRegisterLocation(S0);
739 }
740
741 case Primitive::kPrimLong: {
742 return Location::RegisterPairLocation(R0, R1);
743 }
744
745 case Primitive::kPrimDouble: {
746 return Location::FpuRegisterPairLocation(S0, S1);
747 }
748
749 case Primitive::kPrimVoid:
750 return Location();
751 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100752
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000753 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000754}
755
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100756Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
757 return Location::RegisterLocation(kMethodRegisterArgument);
758}
759
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100760void CodeGeneratorARM::Move32(Location destination, Location source) {
761 if (source.Equals(destination)) {
762 return;
763 }
764 if (destination.IsRegister()) {
765 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000766 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100767 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000768 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100769 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000770 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100771 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100772 } else if (destination.IsFpuRegister()) {
773 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000774 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100775 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000776 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100777 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000778 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100779 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100780 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000781 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100782 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000783 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100784 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000785 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100786 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000787 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100788 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
789 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100790 }
791 }
792}
793
794void CodeGeneratorARM::Move64(Location destination, Location source) {
795 if (source.Equals(destination)) {
796 return;
797 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100798 if (destination.IsRegisterPair()) {
799 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000800 EmitParallelMoves(
801 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
802 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100803 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000804 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100805 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
806 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100807 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000808 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100809 } else {
810 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000811 DCHECK(ExpectedPairLayout(destination));
812 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
813 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100814 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000815 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100816 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000817 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
818 SP,
819 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100820 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000821 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100822 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100823 } else {
824 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100825 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000826 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100827 if (source.AsRegisterPairLow<Register>() == R1) {
828 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100829 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
830 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100831 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100832 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100833 SP, destination.GetStackIndex());
834 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000835 } else if (source.IsFpuRegisterPair()) {
836 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
837 SP,
838 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100839 } else {
840 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000841 EmitParallelMoves(
842 Location::StackSlot(source.GetStackIndex()),
843 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100844 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000845 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100846 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
847 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100848 }
849 }
850}
851
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100852void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100853 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100854 if (instruction->IsCurrentMethod()) {
855 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
856 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100857 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100858 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000859 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000860 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
861 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000862 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000863 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000864 } else {
865 DCHECK(location.IsStackSlot());
866 __ LoadImmediate(IP, value);
867 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
868 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000869 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000870 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000871 int64_t value = const_to_move->AsLongConstant()->GetValue();
872 if (location.IsRegisterPair()) {
873 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
874 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
875 } else {
876 DCHECK(location.IsDoubleStackSlot());
877 __ LoadImmediate(IP, Low32Bits(value));
878 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
879 __ LoadImmediate(IP, High32Bits(value));
880 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
881 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100882 }
Roland Levillain476df552014-10-09 17:51:36 +0100883 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100884 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
885 switch (instruction->GetType()) {
886 case Primitive::kPrimBoolean:
887 case Primitive::kPrimByte:
888 case Primitive::kPrimChar:
889 case Primitive::kPrimShort:
890 case Primitive::kPrimInt:
891 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100892 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100893 Move32(location, Location::StackSlot(stack_slot));
894 break;
895
896 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100897 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100898 Move64(location, Location::DoubleStackSlot(stack_slot));
899 break;
900
901 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100902 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100903 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000904 } else if (instruction->IsTemporary()) {
905 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000906 if (temp_location.IsStackSlot()) {
907 Move32(location, temp_location);
908 } else {
909 DCHECK(temp_location.IsDoubleStackSlot());
910 Move64(location, temp_location);
911 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000912 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100913 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100914 switch (instruction->GetType()) {
915 case Primitive::kPrimBoolean:
916 case Primitive::kPrimByte:
917 case Primitive::kPrimChar:
918 case Primitive::kPrimShort:
919 case Primitive::kPrimNot:
920 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100921 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100922 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100923 break;
924
925 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100926 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100927 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100928 break;
929
930 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100931 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100932 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000933 }
934}
935
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100936void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
937 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000938 uint32_t dex_pc,
939 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100940 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
941 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000942 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100943 DCHECK(instruction->IsSuspendCheck()
944 || instruction->IsBoundsCheck()
945 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000946 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000947 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100948 || !IsLeafMethod());
949}
950
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000951void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000952 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000953}
954
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000955void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000956 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100957 DCHECK(!successor->IsExitBlock());
958
959 HBasicBlock* block = got->GetBlock();
960 HInstruction* previous = got->GetPrevious();
961
962 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000963 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100964 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
965 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
966 return;
967 }
968
969 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
970 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
971 }
972 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000973 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000974 }
975}
976
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000977void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000978 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000979}
980
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000981void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700982 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000983}
984
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700985void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
986 Label* true_target,
987 Label* false_target,
988 Label* always_true_target) {
989 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100990 if (cond->IsIntConstant()) {
991 // Constant condition, statically compared against 1.
992 int32_t cond_value = cond->AsIntConstant()->GetValue();
993 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700994 if (always_true_target != nullptr) {
995 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100996 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100997 return;
998 } else {
999 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001000 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001001 } else {
1002 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1003 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001004 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
1005 __ cmp(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001006 ShifterOperand(0));
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001007 __ b(true_target, NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001008 } else {
1009 // Condition has not been materialized, use its inputs as the
1010 // comparison and its condition as the branch condition.
1011 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001012 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001013 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001014 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001015 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001016 } else {
1017 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001018 HConstant* constant = locations->InAt(1).GetConstant();
1019 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001020 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001021 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1022 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001023 } else {
1024 Register temp = IP;
1025 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001026 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001027 }
1028 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001029 __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001030 }
Dave Allison20dfc792014-06-16 20:44:29 -07001031 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001032 if (false_target != nullptr) {
1033 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001034 }
1035}
1036
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001037void LocationsBuilderARM::VisitIf(HIf* if_instr) {
1038 LocationSummary* locations =
1039 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
1040 HInstruction* cond = if_instr->InputAt(0);
1041 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1042 locations->SetInAt(0, Location::RequiresRegister());
1043 }
1044}
1045
1046void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1047 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1048 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1049 Label* always_true_target = true_target;
1050 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1051 if_instr->IfTrueSuccessor())) {
1052 always_true_target = nullptr;
1053 }
1054 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1055 if_instr->IfFalseSuccessor())) {
1056 false_target = nullptr;
1057 }
1058 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1059}
1060
1061void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1062 LocationSummary* locations = new (GetGraph()->GetArena())
1063 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1064 HInstruction* cond = deoptimize->InputAt(0);
1065 DCHECK(cond->IsCondition());
1066 if (cond->AsCondition()->NeedsMaterialization()) {
1067 locations->SetInAt(0, Location::RequiresRegister());
1068 }
1069}
1070
1071void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1072 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1073 DeoptimizationSlowPathARM(deoptimize);
1074 codegen_->AddSlowPath(slow_path);
1075 Label* slow_path_entry = slow_path->GetEntryLabel();
1076 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1077}
Dave Allison20dfc792014-06-16 20:44:29 -07001078
Roland Levillain0d37cd02015-05-27 16:39:19 +01001079void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001080 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001081 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001082 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain0d37cd02015-05-27 16:39:19 +01001083 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1084 if (cond->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001085 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001086 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001087}
1088
Roland Levillain0d37cd02015-05-27 16:39:19 +01001089void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
1090 if (!cond->NeedsMaterialization()) return;
1091 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001092 Register left = locations->InAt(0).AsRegister<Register>();
1093
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001094 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001095 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001096 } else {
1097 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -08001098 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001099 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001100 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1101 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001102 } else {
1103 Register temp = IP;
1104 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001105 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001106 }
Dave Allison20dfc792014-06-16 20:44:29 -07001107 }
Roland Levillain0d37cd02015-05-27 16:39:19 +01001108 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001109 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001110 ARMCondition(cond->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001111 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001112 ARMOppositeCondition(cond->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001113}
1114
1115void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1116 VisitCondition(comp);
1117}
1118
1119void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1120 VisitCondition(comp);
1121}
1122
1123void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1124 VisitCondition(comp);
1125}
1126
1127void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1128 VisitCondition(comp);
1129}
1130
1131void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1132 VisitCondition(comp);
1133}
1134
1135void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1136 VisitCondition(comp);
1137}
1138
1139void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1140 VisitCondition(comp);
1141}
1142
1143void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1144 VisitCondition(comp);
1145}
1146
1147void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1148 VisitCondition(comp);
1149}
1150
1151void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1152 VisitCondition(comp);
1153}
1154
1155void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1156 VisitCondition(comp);
1157}
1158
1159void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1160 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001161}
1162
1163void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001164 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001165}
1166
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001167void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1168 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001169}
1170
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001171void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001172 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001173}
1174
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001175void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001176 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001177 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001178}
1179
1180void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001181 LocationSummary* locations =
1182 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001183 switch (store->InputAt(1)->GetType()) {
1184 case Primitive::kPrimBoolean:
1185 case Primitive::kPrimByte:
1186 case Primitive::kPrimChar:
1187 case Primitive::kPrimShort:
1188 case Primitive::kPrimInt:
1189 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001190 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001191 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1192 break;
1193
1194 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001195 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001196 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1197 break;
1198
1199 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001200 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001201 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001202}
1203
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001204void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001205 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001206}
1207
1208void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001209 LocationSummary* locations =
1210 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001211 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001212}
1213
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001214void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001215 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001216 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001217}
1218
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001219void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1220 LocationSummary* locations =
1221 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1222 locations->SetOut(Location::ConstantLocation(constant));
1223}
1224
1225void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1226 // Will be generated at use site.
1227 UNUSED(constant);
1228}
1229
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001230void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001231 LocationSummary* locations =
1232 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001233 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001234}
1235
1236void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1237 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001238 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001239}
1240
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001241void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1242 LocationSummary* locations =
1243 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1244 locations->SetOut(Location::ConstantLocation(constant));
1245}
1246
1247void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1248 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001249 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001250}
1251
1252void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1253 LocationSummary* locations =
1254 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1255 locations->SetOut(Location::ConstantLocation(constant));
1256}
1257
1258void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1259 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001260 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001261}
1262
Calin Juravle27df7582015-04-17 19:12:31 +01001263void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1264 memory_barrier->SetLocations(nullptr);
1265}
1266
1267void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1268 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1269}
1270
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001271void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001272 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001273}
1274
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001275void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001276 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001277 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001278}
1279
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001280void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001281 LocationSummary* locations =
1282 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001283 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001284}
1285
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001286void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001287 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001288 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001289}
1290
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001291void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001292 // When we do not run baseline, explicit clinit checks triggered by static
1293 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1294 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001295
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001296 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1297 codegen_->GetInstructionSetFeatures());
1298 if (intrinsic.TryDispatch(invoke)) {
1299 return;
1300 }
1301
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001302 HandleInvoke(invoke);
1303}
1304
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001305static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1306 if (invoke->GetLocations()->Intrinsified()) {
1307 IntrinsicCodeGeneratorARM intrinsic(codegen);
1308 intrinsic.Dispatch(invoke);
1309 return true;
1310 }
1311 return false;
1312}
1313
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001314void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001315 // When we do not run baseline, explicit clinit checks triggered by static
1316 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1317 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001318
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001319 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1320 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001321 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001322
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001323 LocationSummary* locations = invoke->GetLocations();
1324 codegen_->GenerateStaticOrDirectCall(
1325 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001326 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001327}
1328
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001329void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001330 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001331 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001332}
1333
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001334void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001335 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1336 codegen_->GetInstructionSetFeatures());
1337 if (intrinsic.TryDispatch(invoke)) {
1338 return;
1339 }
1340
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001341 HandleInvoke(invoke);
1342}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001343
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001344void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001345 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1346 return;
1347 }
1348
Roland Levillain271ab9c2014-11-27 15:23:57 +00001349 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001350 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1351 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001352 LocationSummary* locations = invoke->GetLocations();
1353 Location receiver = locations->InAt(0);
1354 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1355 // temp = object->GetClass();
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001356 DCHECK(receiver.IsRegister());
1357 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00001358 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001359 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001360 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001361 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001362 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001363 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001364 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001365 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001366 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001367 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001368 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001369}
1370
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001371void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1372 HandleInvoke(invoke);
1373 // Add the hidden argument.
1374 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1375}
1376
1377void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1378 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001379 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001380 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1381 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001382 LocationSummary* locations = invoke->GetLocations();
1383 Location receiver = locations->InAt(0);
1384 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1385
1386 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001387 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1388 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001389
1390 // temp = object->GetClass();
1391 if (receiver.IsStackSlot()) {
1392 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1393 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1394 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001395 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001396 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001397 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001398 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001399 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001400 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001401 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1402 // LR = temp->GetEntryPoint();
1403 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1404 // LR();
1405 __ blx(LR);
1406 DCHECK(!codegen_->IsLeafMethod());
1407 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1408}
1409
Roland Levillain88cb1752014-10-20 16:36:47 +01001410void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1411 LocationSummary* locations =
1412 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1413 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001414 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001415 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001416 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1417 break;
1418 }
1419 case Primitive::kPrimLong: {
1420 locations->SetInAt(0, Location::RequiresRegister());
1421 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001422 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001423 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001424
Roland Levillain88cb1752014-10-20 16:36:47 +01001425 case Primitive::kPrimFloat:
1426 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001427 locations->SetInAt(0, Location::RequiresFpuRegister());
1428 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001429 break;
1430
1431 default:
1432 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1433 }
1434}
1435
1436void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1437 LocationSummary* locations = neg->GetLocations();
1438 Location out = locations->Out();
1439 Location in = locations->InAt(0);
1440 switch (neg->GetResultType()) {
1441 case Primitive::kPrimInt:
1442 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001443 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001444 break;
1445
1446 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001447 DCHECK(in.IsRegisterPair());
1448 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1449 __ rsbs(out.AsRegisterPairLow<Register>(),
1450 in.AsRegisterPairLow<Register>(),
1451 ShifterOperand(0));
1452 // We cannot emit an RSC (Reverse Subtract with Carry)
1453 // instruction here, as it does not exist in the Thumb-2
1454 // instruction set. We use the following approach
1455 // using SBC and SUB instead.
1456 //
1457 // out.hi = -C
1458 __ sbc(out.AsRegisterPairHigh<Register>(),
1459 out.AsRegisterPairHigh<Register>(),
1460 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1461 // out.hi = out.hi - in.hi
1462 __ sub(out.AsRegisterPairHigh<Register>(),
1463 out.AsRegisterPairHigh<Register>(),
1464 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1465 break;
1466
Roland Levillain88cb1752014-10-20 16:36:47 +01001467 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001468 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001469 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001470 break;
1471
Roland Levillain88cb1752014-10-20 16:36:47 +01001472 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001473 DCHECK(in.IsFpuRegisterPair());
1474 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1475 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001476 break;
1477
1478 default:
1479 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1480 }
1481}
1482
Roland Levillaindff1f282014-11-05 14:15:05 +00001483void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001484 Primitive::Type result_type = conversion->GetResultType();
1485 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001486 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001487
Roland Levillain5b3ee562015-04-14 16:02:41 +01001488 // The float-to-long, double-to-long and long-to-float type conversions
1489 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001490 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001491 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1492 && result_type == Primitive::kPrimLong)
1493 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001494 ? LocationSummary::kCall
1495 : LocationSummary::kNoCall;
1496 LocationSummary* locations =
1497 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1498
David Brazdilb2bd1c52015-03-25 11:17:37 +00001499 // The Java language does not allow treating boolean as an integral type but
1500 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001501
Roland Levillaindff1f282014-11-05 14:15:05 +00001502 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001503 case Primitive::kPrimByte:
1504 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001505 case Primitive::kPrimBoolean:
1506 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001507 case Primitive::kPrimShort:
1508 case Primitive::kPrimInt:
1509 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001510 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001511 locations->SetInAt(0, Location::RequiresRegister());
1512 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1513 break;
1514
1515 default:
1516 LOG(FATAL) << "Unexpected type conversion from " << input_type
1517 << " to " << result_type;
1518 }
1519 break;
1520
Roland Levillain01a8d712014-11-14 16:27:39 +00001521 case Primitive::kPrimShort:
1522 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001523 case Primitive::kPrimBoolean:
1524 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001525 case Primitive::kPrimByte:
1526 case Primitive::kPrimInt:
1527 case Primitive::kPrimChar:
1528 // Processing a Dex `int-to-short' instruction.
1529 locations->SetInAt(0, Location::RequiresRegister());
1530 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1531 break;
1532
1533 default:
1534 LOG(FATAL) << "Unexpected type conversion from " << input_type
1535 << " to " << result_type;
1536 }
1537 break;
1538
Roland Levillain946e1432014-11-11 17:35:19 +00001539 case Primitive::kPrimInt:
1540 switch (input_type) {
1541 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001542 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001543 locations->SetInAt(0, Location::Any());
1544 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1545 break;
1546
1547 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001548 // Processing a Dex `float-to-int' instruction.
1549 locations->SetInAt(0, Location::RequiresFpuRegister());
1550 locations->SetOut(Location::RequiresRegister());
1551 locations->AddTemp(Location::RequiresFpuRegister());
1552 break;
1553
Roland Levillain946e1432014-11-11 17:35:19 +00001554 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001555 // Processing a Dex `double-to-int' instruction.
1556 locations->SetInAt(0, Location::RequiresFpuRegister());
1557 locations->SetOut(Location::RequiresRegister());
1558 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001559 break;
1560
1561 default:
1562 LOG(FATAL) << "Unexpected type conversion from " << input_type
1563 << " to " << result_type;
1564 }
1565 break;
1566
Roland Levillaindff1f282014-11-05 14:15:05 +00001567 case Primitive::kPrimLong:
1568 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001569 case Primitive::kPrimBoolean:
1570 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001571 case Primitive::kPrimByte:
1572 case Primitive::kPrimShort:
1573 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001574 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001575 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001576 locations->SetInAt(0, Location::RequiresRegister());
1577 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1578 break;
1579
Roland Levillain624279f2014-12-04 11:54:28 +00001580 case Primitive::kPrimFloat: {
1581 // Processing a Dex `float-to-long' instruction.
1582 InvokeRuntimeCallingConvention calling_convention;
1583 locations->SetInAt(0, Location::FpuRegisterLocation(
1584 calling_convention.GetFpuRegisterAt(0)));
1585 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1586 break;
1587 }
1588
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001589 case Primitive::kPrimDouble: {
1590 // Processing a Dex `double-to-long' instruction.
1591 InvokeRuntimeCallingConvention calling_convention;
1592 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1593 calling_convention.GetFpuRegisterAt(0),
1594 calling_convention.GetFpuRegisterAt(1)));
1595 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001596 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001597 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001598
1599 default:
1600 LOG(FATAL) << "Unexpected type conversion from " << input_type
1601 << " to " << result_type;
1602 }
1603 break;
1604
Roland Levillain981e4542014-11-14 11:47:14 +00001605 case Primitive::kPrimChar:
1606 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001607 case Primitive::kPrimBoolean:
1608 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001609 case Primitive::kPrimByte:
1610 case Primitive::kPrimShort:
1611 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001612 // Processing a Dex `int-to-char' instruction.
1613 locations->SetInAt(0, Location::RequiresRegister());
1614 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1615 break;
1616
1617 default:
1618 LOG(FATAL) << "Unexpected type conversion from " << input_type
1619 << " to " << result_type;
1620 }
1621 break;
1622
Roland Levillaindff1f282014-11-05 14:15:05 +00001623 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001624 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001625 case Primitive::kPrimBoolean:
1626 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001627 case Primitive::kPrimByte:
1628 case Primitive::kPrimShort:
1629 case Primitive::kPrimInt:
1630 case Primitive::kPrimChar:
1631 // Processing a Dex `int-to-float' instruction.
1632 locations->SetInAt(0, Location::RequiresRegister());
1633 locations->SetOut(Location::RequiresFpuRegister());
1634 break;
1635
Roland Levillain5b3ee562015-04-14 16:02:41 +01001636 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001637 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001638 InvokeRuntimeCallingConvention calling_convention;
1639 locations->SetInAt(0, Location::RegisterPairLocation(
1640 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1641 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001642 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001643 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001644
Roland Levillaincff13742014-11-17 14:32:17 +00001645 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001646 // Processing a Dex `double-to-float' instruction.
1647 locations->SetInAt(0, Location::RequiresFpuRegister());
1648 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001649 break;
1650
1651 default:
1652 LOG(FATAL) << "Unexpected type conversion from " << input_type
1653 << " to " << result_type;
1654 };
1655 break;
1656
Roland Levillaindff1f282014-11-05 14:15:05 +00001657 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001658 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001659 case Primitive::kPrimBoolean:
1660 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001661 case Primitive::kPrimByte:
1662 case Primitive::kPrimShort:
1663 case Primitive::kPrimInt:
1664 case Primitive::kPrimChar:
1665 // Processing a Dex `int-to-double' instruction.
1666 locations->SetInAt(0, Location::RequiresRegister());
1667 locations->SetOut(Location::RequiresFpuRegister());
1668 break;
1669
1670 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001671 // Processing a Dex `long-to-double' instruction.
1672 locations->SetInAt(0, Location::RequiresRegister());
1673 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001674 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001675 locations->AddTemp(Location::RequiresFpuRegister());
1676 break;
1677
Roland Levillaincff13742014-11-17 14:32:17 +00001678 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001679 // Processing a Dex `float-to-double' instruction.
1680 locations->SetInAt(0, Location::RequiresFpuRegister());
1681 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001682 break;
1683
1684 default:
1685 LOG(FATAL) << "Unexpected type conversion from " << input_type
1686 << " to " << result_type;
1687 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001688 break;
1689
1690 default:
1691 LOG(FATAL) << "Unexpected type conversion from " << input_type
1692 << " to " << result_type;
1693 }
1694}
1695
1696void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1697 LocationSummary* locations = conversion->GetLocations();
1698 Location out = locations->Out();
1699 Location in = locations->InAt(0);
1700 Primitive::Type result_type = conversion->GetResultType();
1701 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001702 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001703 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001704 case Primitive::kPrimByte:
1705 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001706 case Primitive::kPrimBoolean:
1707 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001708 case Primitive::kPrimShort:
1709 case Primitive::kPrimInt:
1710 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001711 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001712 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001713 break;
1714
1715 default:
1716 LOG(FATAL) << "Unexpected type conversion from " << input_type
1717 << " to " << result_type;
1718 }
1719 break;
1720
Roland Levillain01a8d712014-11-14 16:27:39 +00001721 case Primitive::kPrimShort:
1722 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001723 case Primitive::kPrimBoolean:
1724 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001725 case Primitive::kPrimByte:
1726 case Primitive::kPrimInt:
1727 case Primitive::kPrimChar:
1728 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001729 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001730 break;
1731
1732 default:
1733 LOG(FATAL) << "Unexpected type conversion from " << input_type
1734 << " to " << result_type;
1735 }
1736 break;
1737
Roland Levillain946e1432014-11-11 17:35:19 +00001738 case Primitive::kPrimInt:
1739 switch (input_type) {
1740 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001741 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001742 DCHECK(out.IsRegister());
1743 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001744 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001745 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001746 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001747 } else {
1748 DCHECK(in.IsConstant());
1749 DCHECK(in.GetConstant()->IsLongConstant());
1750 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001751 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001752 }
1753 break;
1754
Roland Levillain3f8f9362014-12-02 17:45:01 +00001755 case Primitive::kPrimFloat: {
1756 // Processing a Dex `float-to-int' instruction.
1757 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1758 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1759 __ vcvtis(temp, temp);
1760 __ vmovrs(out.AsRegister<Register>(), temp);
1761 break;
1762 }
1763
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001764 case Primitive::kPrimDouble: {
1765 // Processing a Dex `double-to-int' instruction.
1766 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1767 DRegister temp_d = FromLowSToD(temp_s);
1768 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1769 __ vcvtid(temp_s, temp_d);
1770 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001771 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001772 }
Roland Levillain946e1432014-11-11 17:35:19 +00001773
1774 default:
1775 LOG(FATAL) << "Unexpected type conversion from " << input_type
1776 << " to " << result_type;
1777 }
1778 break;
1779
Roland Levillaindff1f282014-11-05 14:15:05 +00001780 case Primitive::kPrimLong:
1781 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001782 case Primitive::kPrimBoolean:
1783 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001784 case Primitive::kPrimByte:
1785 case Primitive::kPrimShort:
1786 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001787 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001788 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001789 DCHECK(out.IsRegisterPair());
1790 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001791 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001792 // Sign extension.
1793 __ Asr(out.AsRegisterPairHigh<Register>(),
1794 out.AsRegisterPairLow<Register>(),
1795 31);
1796 break;
1797
1798 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001799 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001800 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1801 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001802 conversion->GetDexPc(),
1803 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001804 break;
1805
Roland Levillaindff1f282014-11-05 14:15:05 +00001806 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001807 // Processing a Dex `double-to-long' instruction.
1808 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1809 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001810 conversion->GetDexPc(),
1811 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001812 break;
1813
1814 default:
1815 LOG(FATAL) << "Unexpected type conversion from " << input_type
1816 << " to " << result_type;
1817 }
1818 break;
1819
Roland Levillain981e4542014-11-14 11:47:14 +00001820 case Primitive::kPrimChar:
1821 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001822 case Primitive::kPrimBoolean:
1823 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001824 case Primitive::kPrimByte:
1825 case Primitive::kPrimShort:
1826 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001827 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001828 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001829 break;
1830
1831 default:
1832 LOG(FATAL) << "Unexpected type conversion from " << input_type
1833 << " to " << result_type;
1834 }
1835 break;
1836
Roland Levillaindff1f282014-11-05 14:15:05 +00001837 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001838 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001839 case Primitive::kPrimBoolean:
1840 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001841 case Primitive::kPrimByte:
1842 case Primitive::kPrimShort:
1843 case Primitive::kPrimInt:
1844 case Primitive::kPrimChar: {
1845 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001846 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1847 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001848 break;
1849 }
1850
Roland Levillain5b3ee562015-04-14 16:02:41 +01001851 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001852 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001853 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
1854 conversion,
1855 conversion->GetDexPc(),
1856 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001857 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00001858
Roland Levillaincff13742014-11-17 14:32:17 +00001859 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001860 // Processing a Dex `double-to-float' instruction.
1861 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1862 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001863 break;
1864
1865 default:
1866 LOG(FATAL) << "Unexpected type conversion from " << input_type
1867 << " to " << result_type;
1868 };
1869 break;
1870
Roland Levillaindff1f282014-11-05 14:15:05 +00001871 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001872 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001873 case Primitive::kPrimBoolean:
1874 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001875 case Primitive::kPrimByte:
1876 case Primitive::kPrimShort:
1877 case Primitive::kPrimInt:
1878 case Primitive::kPrimChar: {
1879 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001880 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001881 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1882 out.AsFpuRegisterPairLow<SRegister>());
1883 break;
1884 }
1885
Roland Levillain647b9ed2014-11-27 12:06:00 +00001886 case Primitive::kPrimLong: {
1887 // Processing a Dex `long-to-double' instruction.
1888 Register low = in.AsRegisterPairLow<Register>();
1889 Register high = in.AsRegisterPairHigh<Register>();
1890 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1891 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001892 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001893 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001894 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
1895 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001896
Roland Levillain682393c2015-04-14 15:57:52 +01001897 // temp_d = int-to-double(high)
1898 __ vmovsr(temp_s, high);
1899 __ vcvtdi(temp_d, temp_s);
1900 // constant_d = k2Pow32EncodingForDouble
1901 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
1902 // out_d = unsigned-to-double(low)
1903 __ vmovsr(out_s, low);
1904 __ vcvtdu(out_d, out_s);
1905 // out_d += temp_d * constant_d
1906 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001907 break;
1908 }
1909
Roland Levillaincff13742014-11-17 14:32:17 +00001910 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001911 // Processing a Dex `float-to-double' instruction.
1912 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1913 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001914 break;
1915
1916 default:
1917 LOG(FATAL) << "Unexpected type conversion from " << input_type
1918 << " to " << result_type;
1919 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001920 break;
1921
1922 default:
1923 LOG(FATAL) << "Unexpected type conversion from " << input_type
1924 << " to " << result_type;
1925 }
1926}
1927
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001928void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001929 LocationSummary* locations =
1930 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001931 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001932 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001933 locations->SetInAt(0, Location::RequiresRegister());
1934 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001935 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1936 break;
1937 }
1938
1939 case Primitive::kPrimLong: {
1940 locations->SetInAt(0, Location::RequiresRegister());
1941 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001942 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001943 break;
1944 }
1945
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001946 case Primitive::kPrimFloat:
1947 case Primitive::kPrimDouble: {
1948 locations->SetInAt(0, Location::RequiresFpuRegister());
1949 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001950 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001951 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001952 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001953
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001954 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001955 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001956 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001957}
1958
1959void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1960 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001961 Location out = locations->Out();
1962 Location first = locations->InAt(0);
1963 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001964 switch (add->GetResultType()) {
1965 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001966 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001967 __ add(out.AsRegister<Register>(),
1968 first.AsRegister<Register>(),
1969 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001970 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001971 __ AddConstant(out.AsRegister<Register>(),
1972 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001973 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001974 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001975 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001976
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001977 case Primitive::kPrimLong: {
1978 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001979 __ adds(out.AsRegisterPairLow<Register>(),
1980 first.AsRegisterPairLow<Register>(),
1981 ShifterOperand(second.AsRegisterPairLow<Register>()));
1982 __ adc(out.AsRegisterPairHigh<Register>(),
1983 first.AsRegisterPairHigh<Register>(),
1984 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001985 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001986 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001987
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001988 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001989 __ vadds(out.AsFpuRegister<SRegister>(),
1990 first.AsFpuRegister<SRegister>(),
1991 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001992 break;
1993
1994 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001995 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1996 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1997 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001998 break;
1999
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002000 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002001 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002002 }
2003}
2004
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002005void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002006 LocationSummary* locations =
2007 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002008 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002009 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002010 locations->SetInAt(0, Location::RequiresRegister());
2011 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002012 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2013 break;
2014 }
2015
2016 case Primitive::kPrimLong: {
2017 locations->SetInAt(0, Location::RequiresRegister());
2018 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002019 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002020 break;
2021 }
Calin Juravle11351682014-10-23 15:38:15 +01002022 case Primitive::kPrimFloat:
2023 case Primitive::kPrimDouble: {
2024 locations->SetInAt(0, Location::RequiresFpuRegister());
2025 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002026 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002027 break;
Calin Juravle11351682014-10-23 15:38:15 +01002028 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002029 default:
Calin Juravle11351682014-10-23 15:38:15 +01002030 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002031 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002032}
2033
2034void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2035 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002036 Location out = locations->Out();
2037 Location first = locations->InAt(0);
2038 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002039 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002040 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002041 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002042 __ sub(out.AsRegister<Register>(),
2043 first.AsRegister<Register>(),
2044 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002045 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002046 __ AddConstant(out.AsRegister<Register>(),
2047 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002048 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002049 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002050 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002051 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002052
Calin Juravle11351682014-10-23 15:38:15 +01002053 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002054 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002055 __ subs(out.AsRegisterPairLow<Register>(),
2056 first.AsRegisterPairLow<Register>(),
2057 ShifterOperand(second.AsRegisterPairLow<Register>()));
2058 __ sbc(out.AsRegisterPairHigh<Register>(),
2059 first.AsRegisterPairHigh<Register>(),
2060 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002061 break;
Calin Juravle11351682014-10-23 15:38:15 +01002062 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002063
Calin Juravle11351682014-10-23 15:38:15 +01002064 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002065 __ vsubs(out.AsFpuRegister<SRegister>(),
2066 first.AsFpuRegister<SRegister>(),
2067 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002068 break;
Calin Juravle11351682014-10-23 15:38:15 +01002069 }
2070
2071 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002072 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2073 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2074 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002075 break;
2076 }
2077
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002078
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002079 default:
Calin Juravle11351682014-10-23 15:38:15 +01002080 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002081 }
2082}
2083
Calin Juravle34bacdf2014-10-07 20:23:36 +01002084void LocationsBuilderARM::VisitMul(HMul* mul) {
2085 LocationSummary* locations =
2086 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2087 switch (mul->GetResultType()) {
2088 case Primitive::kPrimInt:
2089 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002090 locations->SetInAt(0, Location::RequiresRegister());
2091 locations->SetInAt(1, Location::RequiresRegister());
2092 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002093 break;
2094 }
2095
Calin Juravleb5bfa962014-10-21 18:02:24 +01002096 case Primitive::kPrimFloat:
2097 case Primitive::kPrimDouble: {
2098 locations->SetInAt(0, Location::RequiresFpuRegister());
2099 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002100 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002101 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002102 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002103
2104 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002105 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002106 }
2107}
2108
2109void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2110 LocationSummary* locations = mul->GetLocations();
2111 Location out = locations->Out();
2112 Location first = locations->InAt(0);
2113 Location second = locations->InAt(1);
2114 switch (mul->GetResultType()) {
2115 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002116 __ mul(out.AsRegister<Register>(),
2117 first.AsRegister<Register>(),
2118 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002119 break;
2120 }
2121 case Primitive::kPrimLong: {
2122 Register out_hi = out.AsRegisterPairHigh<Register>();
2123 Register out_lo = out.AsRegisterPairLow<Register>();
2124 Register in1_hi = first.AsRegisterPairHigh<Register>();
2125 Register in1_lo = first.AsRegisterPairLow<Register>();
2126 Register in2_hi = second.AsRegisterPairHigh<Register>();
2127 Register in2_lo = second.AsRegisterPairLow<Register>();
2128
2129 // Extra checks to protect caused by the existence of R1_R2.
2130 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2131 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2132 DCHECK_NE(out_hi, in1_lo);
2133 DCHECK_NE(out_hi, in2_lo);
2134
2135 // input: in1 - 64 bits, in2 - 64 bits
2136 // output: out
2137 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2138 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2139 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2140
2141 // IP <- in1.lo * in2.hi
2142 __ mul(IP, in1_lo, in2_hi);
2143 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2144 __ mla(out_hi, in1_hi, in2_lo, IP);
2145 // out.lo <- (in1.lo * in2.lo)[31:0];
2146 __ umull(out_lo, IP, in1_lo, in2_lo);
2147 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2148 __ add(out_hi, out_hi, ShifterOperand(IP));
2149 break;
2150 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002151
2152 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002153 __ vmuls(out.AsFpuRegister<SRegister>(),
2154 first.AsFpuRegister<SRegister>(),
2155 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002156 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002157 }
2158
2159 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002160 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2161 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2162 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002163 break;
2164 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002165
2166 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002167 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002168 }
2169}
2170
Zheng Xuc6667102015-05-15 16:08:45 +08002171void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2172 DCHECK(instruction->IsDiv() || instruction->IsRem());
2173 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2174
2175 LocationSummary* locations = instruction->GetLocations();
2176 Location second = locations->InAt(1);
2177 DCHECK(second.IsConstant());
2178
2179 Register out = locations->Out().AsRegister<Register>();
2180 Register dividend = locations->InAt(0).AsRegister<Register>();
2181 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2182 DCHECK(imm == 1 || imm == -1);
2183
2184 if (instruction->IsRem()) {
2185 __ LoadImmediate(out, 0);
2186 } else {
2187 if (imm == 1) {
2188 __ Mov(out, dividend);
2189 } else {
2190 __ rsb(out, dividend, ShifterOperand(0));
2191 }
2192 }
2193}
2194
2195void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2196 DCHECK(instruction->IsDiv() || instruction->IsRem());
2197 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2198
2199 LocationSummary* locations = instruction->GetLocations();
2200 Location second = locations->InAt(1);
2201 DCHECK(second.IsConstant());
2202
2203 Register out = locations->Out().AsRegister<Register>();
2204 Register dividend = locations->InAt(0).AsRegister<Register>();
2205 Register temp = locations->GetTemp(0).AsRegister<Register>();
2206 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002207 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002208 DCHECK(IsPowerOfTwo(abs_imm));
2209 int ctz_imm = CTZ(abs_imm);
2210
2211 if (ctz_imm == 1) {
2212 __ Lsr(temp, dividend, 32 - ctz_imm);
2213 } else {
2214 __ Asr(temp, dividend, 31);
2215 __ Lsr(temp, temp, 32 - ctz_imm);
2216 }
2217 __ add(out, temp, ShifterOperand(dividend));
2218
2219 if (instruction->IsDiv()) {
2220 __ Asr(out, out, ctz_imm);
2221 if (imm < 0) {
2222 __ rsb(out, out, ShifterOperand(0));
2223 }
2224 } else {
2225 __ ubfx(out, out, 0, ctz_imm);
2226 __ sub(out, out, ShifterOperand(temp));
2227 }
2228}
2229
2230void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2231 DCHECK(instruction->IsDiv() || instruction->IsRem());
2232 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2233
2234 LocationSummary* locations = instruction->GetLocations();
2235 Location second = locations->InAt(1);
2236 DCHECK(second.IsConstant());
2237
2238 Register out = locations->Out().AsRegister<Register>();
2239 Register dividend = locations->InAt(0).AsRegister<Register>();
2240 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2241 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2242 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2243
2244 int64_t magic;
2245 int shift;
2246 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2247
2248 __ LoadImmediate(temp1, magic);
2249 __ smull(temp2, temp1, dividend, temp1);
2250
2251 if (imm > 0 && magic < 0) {
2252 __ add(temp1, temp1, ShifterOperand(dividend));
2253 } else if (imm < 0 && magic > 0) {
2254 __ sub(temp1, temp1, ShifterOperand(dividend));
2255 }
2256
2257 if (shift != 0) {
2258 __ Asr(temp1, temp1, shift);
2259 }
2260
2261 if (instruction->IsDiv()) {
2262 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2263 } else {
2264 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2265 // TODO: Strength reduction for mls.
2266 __ LoadImmediate(temp2, imm);
2267 __ mls(out, temp1, temp2, dividend);
2268 }
2269}
2270
2271void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2272 DCHECK(instruction->IsDiv() || instruction->IsRem());
2273 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2274
2275 LocationSummary* locations = instruction->GetLocations();
2276 Location second = locations->InAt(1);
2277 DCHECK(second.IsConstant());
2278
2279 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2280 if (imm == 0) {
2281 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2282 } else if (imm == 1 || imm == -1) {
2283 DivRemOneOrMinusOne(instruction);
2284 } else if (IsPowerOfTwo(std::abs(imm))) {
2285 DivRemByPowerOfTwo(instruction);
2286 } else {
2287 DCHECK(imm <= -2 || imm >= 2);
2288 GenerateDivRemWithAnyConstant(instruction);
2289 }
2290}
2291
Calin Juravle7c4954d2014-10-28 16:57:40 +00002292void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002293 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2294 if (div->GetResultType() == Primitive::kPrimLong) {
2295 // pLdiv runtime call.
2296 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002297 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2298 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002299 } else if (div->GetResultType() == Primitive::kPrimInt &&
2300 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2301 // pIdivmod runtime call.
2302 call_kind = LocationSummary::kCall;
2303 }
2304
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002305 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2306
Calin Juravle7c4954d2014-10-28 16:57:40 +00002307 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002308 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002309 if (div->InputAt(1)->IsConstant()) {
2310 locations->SetInAt(0, Location::RequiresRegister());
2311 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2312 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2313 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2314 if (abs_imm <= 1) {
2315 // No temp register required.
2316 } else {
2317 locations->AddTemp(Location::RequiresRegister());
2318 if (!IsPowerOfTwo(abs_imm)) {
2319 locations->AddTemp(Location::RequiresRegister());
2320 }
2321 }
2322 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002323 locations->SetInAt(0, Location::RequiresRegister());
2324 locations->SetInAt(1, Location::RequiresRegister());
2325 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2326 } else {
2327 InvokeRuntimeCallingConvention calling_convention;
2328 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2329 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2330 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2331 // we only need the former.
2332 locations->SetOut(Location::RegisterLocation(R0));
2333 }
Calin Juravled0d48522014-11-04 16:40:20 +00002334 break;
2335 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002336 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002337 InvokeRuntimeCallingConvention calling_convention;
2338 locations->SetInAt(0, Location::RegisterPairLocation(
2339 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2340 locations->SetInAt(1, Location::RegisterPairLocation(
2341 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002342 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002343 break;
2344 }
2345 case Primitive::kPrimFloat:
2346 case Primitive::kPrimDouble: {
2347 locations->SetInAt(0, Location::RequiresFpuRegister());
2348 locations->SetInAt(1, Location::RequiresFpuRegister());
2349 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2350 break;
2351 }
2352
2353 default:
2354 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2355 }
2356}
2357
2358void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2359 LocationSummary* locations = div->GetLocations();
2360 Location out = locations->Out();
2361 Location first = locations->InAt(0);
2362 Location second = locations->InAt(1);
2363
2364 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002365 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002366 if (second.IsConstant()) {
2367 GenerateDivRemConstantIntegral(div);
2368 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002369 __ sdiv(out.AsRegister<Register>(),
2370 first.AsRegister<Register>(),
2371 second.AsRegister<Register>());
2372 } else {
2373 InvokeRuntimeCallingConvention calling_convention;
2374 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2375 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2376 DCHECK_EQ(R0, out.AsRegister<Register>());
2377
2378 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2379 }
Calin Juravled0d48522014-11-04 16:40:20 +00002380 break;
2381 }
2382
Calin Juravle7c4954d2014-10-28 16:57:40 +00002383 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002384 InvokeRuntimeCallingConvention calling_convention;
2385 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2386 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2387 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2388 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2389 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002390 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002391
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002392 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002393 break;
2394 }
2395
2396 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002397 __ vdivs(out.AsFpuRegister<SRegister>(),
2398 first.AsFpuRegister<SRegister>(),
2399 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002400 break;
2401 }
2402
2403 case Primitive::kPrimDouble: {
2404 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2405 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2406 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2407 break;
2408 }
2409
2410 default:
2411 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2412 }
2413}
2414
Calin Juravlebacfec32014-11-14 15:54:36 +00002415void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002416 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002417
2418 // Most remainders are implemented in the runtime.
2419 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002420 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2421 // sdiv will be replaced by other instruction sequence.
2422 call_kind = LocationSummary::kNoCall;
2423 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2424 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002425 // Have hardware divide instruction for int, do it with three instructions.
2426 call_kind = LocationSummary::kNoCall;
2427 }
2428
Calin Juravlebacfec32014-11-14 15:54:36 +00002429 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2430
Calin Juravled2ec87d2014-12-08 14:24:46 +00002431 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002432 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002433 if (rem->InputAt(1)->IsConstant()) {
2434 locations->SetInAt(0, Location::RequiresRegister());
2435 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2436 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2437 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2438 if (abs_imm <= 1) {
2439 // No temp register required.
2440 } else {
2441 locations->AddTemp(Location::RequiresRegister());
2442 if (!IsPowerOfTwo(abs_imm)) {
2443 locations->AddTemp(Location::RequiresRegister());
2444 }
2445 }
2446 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002447 locations->SetInAt(0, Location::RequiresRegister());
2448 locations->SetInAt(1, Location::RequiresRegister());
2449 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2450 locations->AddTemp(Location::RequiresRegister());
2451 } else {
2452 InvokeRuntimeCallingConvention calling_convention;
2453 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2454 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2455 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2456 // we only need the latter.
2457 locations->SetOut(Location::RegisterLocation(R1));
2458 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002459 break;
2460 }
2461 case Primitive::kPrimLong: {
2462 InvokeRuntimeCallingConvention calling_convention;
2463 locations->SetInAt(0, Location::RegisterPairLocation(
2464 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2465 locations->SetInAt(1, Location::RegisterPairLocation(
2466 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2467 // The runtime helper puts the output in R2,R3.
2468 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2469 break;
2470 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002471 case Primitive::kPrimFloat: {
2472 InvokeRuntimeCallingConvention calling_convention;
2473 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2474 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2475 locations->SetOut(Location::FpuRegisterLocation(S0));
2476 break;
2477 }
2478
Calin Juravlebacfec32014-11-14 15:54:36 +00002479 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002480 InvokeRuntimeCallingConvention calling_convention;
2481 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2482 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2483 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2484 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2485 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002486 break;
2487 }
2488
2489 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002490 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002491 }
2492}
2493
2494void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2495 LocationSummary* locations = rem->GetLocations();
2496 Location out = locations->Out();
2497 Location first = locations->InAt(0);
2498 Location second = locations->InAt(1);
2499
Calin Juravled2ec87d2014-12-08 14:24:46 +00002500 Primitive::Type type = rem->GetResultType();
2501 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002502 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002503 if (second.IsConstant()) {
2504 GenerateDivRemConstantIntegral(rem);
2505 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002506 Register reg1 = first.AsRegister<Register>();
2507 Register reg2 = second.AsRegister<Register>();
2508 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002509
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002510 // temp = reg1 / reg2 (integer division)
2511 // temp = temp * reg2
2512 // dest = reg1 - temp
2513 __ sdiv(temp, reg1, reg2);
2514 __ mul(temp, temp, reg2);
2515 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2516 } else {
2517 InvokeRuntimeCallingConvention calling_convention;
2518 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2519 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2520 DCHECK_EQ(R1, out.AsRegister<Register>());
2521
2522 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2523 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002524 break;
2525 }
2526
2527 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002528 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002529 break;
2530 }
2531
Calin Juravled2ec87d2014-12-08 14:24:46 +00002532 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002533 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002534 break;
2535 }
2536
Calin Juravlebacfec32014-11-14 15:54:36 +00002537 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002538 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002539 break;
2540 }
2541
2542 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002543 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002544 }
2545}
2546
Calin Juravled0d48522014-11-04 16:40:20 +00002547void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2548 LocationSummary* locations =
2549 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002550 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002551 if (instruction->HasUses()) {
2552 locations->SetOut(Location::SameAsFirstInput());
2553 }
2554}
2555
2556void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2557 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2558 codegen_->AddSlowPath(slow_path);
2559
2560 LocationSummary* locations = instruction->GetLocations();
2561 Location value = locations->InAt(0);
2562
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002563 switch (instruction->GetType()) {
2564 case Primitive::kPrimInt: {
2565 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002566 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002567 __ b(slow_path->GetEntryLabel(), EQ);
2568 } else {
2569 DCHECK(value.IsConstant()) << value;
2570 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2571 __ b(slow_path->GetEntryLabel());
2572 }
2573 }
2574 break;
2575 }
2576 case Primitive::kPrimLong: {
2577 if (value.IsRegisterPair()) {
2578 __ orrs(IP,
2579 value.AsRegisterPairLow<Register>(),
2580 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2581 __ b(slow_path->GetEntryLabel(), EQ);
2582 } else {
2583 DCHECK(value.IsConstant()) << value;
2584 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2585 __ b(slow_path->GetEntryLabel());
2586 }
2587 }
2588 break;
2589 default:
2590 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2591 }
2592 }
Calin Juravled0d48522014-11-04 16:40:20 +00002593}
2594
Calin Juravle9aec02f2014-11-18 23:06:35 +00002595void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2596 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2597
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002598 LocationSummary* locations =
2599 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002600
2601 switch (op->GetResultType()) {
2602 case Primitive::kPrimInt: {
2603 locations->SetInAt(0, Location::RequiresRegister());
2604 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002605 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002606 break;
2607 }
2608 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002609 locations->SetInAt(0, Location::RequiresRegister());
2610 locations->SetInAt(1, Location::RequiresRegister());
2611 locations->AddTemp(Location::RequiresRegister());
2612 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002613 break;
2614 }
2615 default:
2616 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2617 }
2618}
2619
2620void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2621 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2622
2623 LocationSummary* locations = op->GetLocations();
2624 Location out = locations->Out();
2625 Location first = locations->InAt(0);
2626 Location second = locations->InAt(1);
2627
2628 Primitive::Type type = op->GetResultType();
2629 switch (type) {
2630 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002631 Register out_reg = out.AsRegister<Register>();
2632 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002633 // Arm doesn't mask the shift count so we need to do it ourselves.
2634 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002635 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002636 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2637 if (op->IsShl()) {
2638 __ Lsl(out_reg, first_reg, second_reg);
2639 } else if (op->IsShr()) {
2640 __ Asr(out_reg, first_reg, second_reg);
2641 } else {
2642 __ Lsr(out_reg, first_reg, second_reg);
2643 }
2644 } else {
2645 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2646 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2647 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2648 __ Mov(out_reg, first_reg);
2649 } else if (op->IsShl()) {
2650 __ Lsl(out_reg, first_reg, shift_value);
2651 } else if (op->IsShr()) {
2652 __ Asr(out_reg, first_reg, shift_value);
2653 } else {
2654 __ Lsr(out_reg, first_reg, shift_value);
2655 }
2656 }
2657 break;
2658 }
2659 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002660 Register o_h = out.AsRegisterPairHigh<Register>();
2661 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002662
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002663 Register temp = locations->GetTemp(0).AsRegister<Register>();
2664
2665 Register high = first.AsRegisterPairHigh<Register>();
2666 Register low = first.AsRegisterPairLow<Register>();
2667
2668 Register second_reg = second.AsRegister<Register>();
2669
Calin Juravle9aec02f2014-11-18 23:06:35 +00002670 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002671 // Shift the high part
2672 __ and_(second_reg, second_reg, ShifterOperand(63));
2673 __ Lsl(o_h, high, second_reg);
2674 // Shift the low part and `or` what overflew on the high part
2675 __ rsb(temp, second_reg, ShifterOperand(32));
2676 __ Lsr(temp, low, temp);
2677 __ orr(o_h, o_h, ShifterOperand(temp));
2678 // If the shift is > 32 bits, override the high part
2679 __ subs(temp, second_reg, ShifterOperand(32));
2680 __ it(PL);
2681 __ Lsl(o_h, low, temp, false, PL);
2682 // Shift the low part
2683 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002684 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002685 // Shift the low part
2686 __ and_(second_reg, second_reg, ShifterOperand(63));
2687 __ Lsr(o_l, low, second_reg);
2688 // Shift the high part and `or` what underflew on the low part
2689 __ rsb(temp, second_reg, ShifterOperand(32));
2690 __ Lsl(temp, high, temp);
2691 __ orr(o_l, o_l, ShifterOperand(temp));
2692 // If the shift is > 32 bits, override the low part
2693 __ subs(temp, second_reg, ShifterOperand(32));
2694 __ it(PL);
2695 __ Asr(o_l, high, temp, false, PL);
2696 // Shift the high part
2697 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002698 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002699 // same as Shr except we use `Lsr`s and not `Asr`s
2700 __ and_(second_reg, second_reg, ShifterOperand(63));
2701 __ Lsr(o_l, low, second_reg);
2702 __ rsb(temp, second_reg, ShifterOperand(32));
2703 __ Lsl(temp, high, temp);
2704 __ orr(o_l, o_l, ShifterOperand(temp));
2705 __ subs(temp, second_reg, ShifterOperand(32));
2706 __ it(PL);
2707 __ Lsr(o_l, high, temp, false, PL);
2708 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002709 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002710 break;
2711 }
2712 default:
2713 LOG(FATAL) << "Unexpected operation type " << type;
2714 }
2715}
2716
2717void LocationsBuilderARM::VisitShl(HShl* shl) {
2718 HandleShift(shl);
2719}
2720
2721void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2722 HandleShift(shl);
2723}
2724
2725void LocationsBuilderARM::VisitShr(HShr* shr) {
2726 HandleShift(shr);
2727}
2728
2729void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2730 HandleShift(shr);
2731}
2732
2733void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2734 HandleShift(ushr);
2735}
2736
2737void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2738 HandleShift(ushr);
2739}
2740
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002741void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002742 LocationSummary* locations =
2743 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002744 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002745 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002746 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002747 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002748}
2749
2750void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2751 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002752 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002753 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2754 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002755 instruction->GetDexPc(),
2756 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002757}
2758
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002759void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2760 LocationSummary* locations =
2761 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2762 InvokeRuntimeCallingConvention calling_convention;
2763 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002764 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002765 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002766 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002767}
2768
2769void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2770 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002771 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002772 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2773 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002774 instruction->GetDexPc(),
2775 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002776}
2777
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002778void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002779 LocationSummary* locations =
2780 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002781 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2782 if (location.IsStackSlot()) {
2783 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2784 } else if (location.IsDoubleStackSlot()) {
2785 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002786 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002787 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002788}
2789
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002790void InstructionCodeGeneratorARM::VisitParameterValue(
2791 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002792 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002793}
2794
2795void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
2796 LocationSummary* locations =
2797 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2798 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2799}
2800
2801void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2802 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002803}
2804
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002805void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002806 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002807 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002808 locations->SetInAt(0, Location::RequiresRegister());
2809 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002810}
2811
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002812void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2813 LocationSummary* locations = not_->GetLocations();
2814 Location out = locations->Out();
2815 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002816 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002817 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002818 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002819 break;
2820
2821 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002822 __ mvn(out.AsRegisterPairLow<Register>(),
2823 ShifterOperand(in.AsRegisterPairLow<Register>()));
2824 __ mvn(out.AsRegisterPairHigh<Register>(),
2825 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002826 break;
2827
2828 default:
2829 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2830 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002831}
2832
David Brazdil66d126e2015-04-03 16:02:44 +01002833void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2834 LocationSummary* locations =
2835 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2836 locations->SetInAt(0, Location::RequiresRegister());
2837 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2838}
2839
2840void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002841 LocationSummary* locations = bool_not->GetLocations();
2842 Location out = locations->Out();
2843 Location in = locations->InAt(0);
2844 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2845}
2846
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002847void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002848 LocationSummary* locations =
2849 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002850 switch (compare->InputAt(0)->GetType()) {
2851 case Primitive::kPrimLong: {
2852 locations->SetInAt(0, Location::RequiresRegister());
2853 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002854 // Output overlaps because it is written before doing the low comparison.
2855 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002856 break;
2857 }
2858 case Primitive::kPrimFloat:
2859 case Primitive::kPrimDouble: {
2860 locations->SetInAt(0, Location::RequiresFpuRegister());
2861 locations->SetInAt(1, Location::RequiresFpuRegister());
2862 locations->SetOut(Location::RequiresRegister());
2863 break;
2864 }
2865 default:
2866 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2867 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002868}
2869
2870void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002871 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002872 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002873 Location left = locations->InAt(0);
2874 Location right = locations->InAt(1);
2875
Vladimir Markocf93a5c2015-06-16 11:33:24 +00002876 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00002877 Primitive::Type type = compare->InputAt(0)->GetType();
2878 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002879 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002880 __ cmp(left.AsRegisterPairHigh<Register>(),
2881 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002882 __ b(&less, LT);
2883 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002884 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2885 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002886 __ cmp(left.AsRegisterPairLow<Register>(),
2887 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002888 break;
2889 }
2890 case Primitive::kPrimFloat:
2891 case Primitive::kPrimDouble: {
2892 __ LoadImmediate(out, 0);
2893 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002894 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002895 } else {
2896 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2897 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2898 }
2899 __ vmstat(); // transfer FP status register to ARM APSR.
2900 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002901 break;
2902 }
2903 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002904 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002905 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002906 __ b(&done, EQ);
2907 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2908
2909 __ Bind(&greater);
2910 __ LoadImmediate(out, 1);
2911 __ b(&done);
2912
2913 __ Bind(&less);
2914 __ LoadImmediate(out, -1);
2915
2916 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002917}
2918
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002919void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002920 LocationSummary* locations =
2921 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002922 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2923 locations->SetInAt(i, Location::Any());
2924 }
2925 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002926}
2927
2928void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002929 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002930 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002931}
2932
Calin Juravle52c48962014-12-16 17:02:57 +00002933void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2934 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07002935 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00002936 switch (kind) {
2937 case MemBarrierKind::kAnyStore:
2938 case MemBarrierKind::kLoadAny:
2939 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002940 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00002941 break;
2942 }
2943 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002944 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00002945 break;
2946 }
2947 default:
2948 LOG(FATAL) << "Unexpected memory barrier " << kind;
2949 }
Kenny Root1d8199d2015-06-02 11:01:10 -07002950 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00002951}
2952
2953void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2954 uint32_t offset,
2955 Register out_lo,
2956 Register out_hi) {
2957 if (offset != 0) {
2958 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002959 __ add(IP, addr, ShifterOperand(out_lo));
2960 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002961 }
2962 __ ldrexd(out_lo, out_hi, addr);
2963}
2964
2965void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2966 uint32_t offset,
2967 Register value_lo,
2968 Register value_hi,
2969 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002970 Register temp2,
2971 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00002972 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00002973 if (offset != 0) {
2974 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002975 __ add(IP, addr, ShifterOperand(temp1));
2976 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002977 }
2978 __ Bind(&fail);
2979 // We need a load followed by store. (The address used in a STREX instruction must
2980 // be the same as the address in the most recently executed LDREX instruction.)
2981 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002982 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002983 __ strexd(temp1, value_lo, value_hi, addr);
2984 __ cmp(temp1, ShifterOperand(0));
2985 __ b(&fail, NE);
2986}
2987
2988void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2989 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2990
Nicolas Geoffray39468442014-09-02 15:17:15 +01002991 LocationSummary* locations =
2992 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002993 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002994
Calin Juravle52c48962014-12-16 17:02:57 +00002995 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01002996 if (Primitive::IsFloatingPointType(field_type)) {
2997 locations->SetInAt(1, Location::RequiresFpuRegister());
2998 } else {
2999 locations->SetInAt(1, Location::RequiresRegister());
3000 }
3001
Calin Juravle52c48962014-12-16 17:02:57 +00003002 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003003 bool generate_volatile = field_info.IsVolatile()
3004 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003005 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003006 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003007 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
3008 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003009 locations->AddTemp(Location::RequiresRegister());
3010 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003011 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003012 // Arm encoding have some additional constraints for ldrexd/strexd:
3013 // - registers need to be consecutive
3014 // - the first register should be even but not R14.
3015 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3016 // enable Arm encoding.
3017 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3018
3019 locations->AddTemp(Location::RequiresRegister());
3020 locations->AddTemp(Location::RequiresRegister());
3021 if (field_type == Primitive::kPrimDouble) {
3022 // For doubles we need two more registers to copy the value.
3023 locations->AddTemp(Location::RegisterLocation(R2));
3024 locations->AddTemp(Location::RegisterLocation(R3));
3025 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003026 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003027}
3028
Calin Juravle52c48962014-12-16 17:02:57 +00003029void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003030 const FieldInfo& field_info,
3031 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003032 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3033
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003034 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003035 Register base = locations->InAt(0).AsRegister<Register>();
3036 Location value = locations->InAt(1);
3037
3038 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003039 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003040 Primitive::Type field_type = field_info.GetFieldType();
3041 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3042
3043 if (is_volatile) {
3044 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3045 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003046
3047 switch (field_type) {
3048 case Primitive::kPrimBoolean:
3049 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003050 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003051 break;
3052 }
3053
3054 case Primitive::kPrimShort:
3055 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003056 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003057 break;
3058 }
3059
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003060 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003061 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00003062 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003063 break;
3064 }
3065
3066 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003067 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003068 GenerateWideAtomicStore(base, offset,
3069 value.AsRegisterPairLow<Register>(),
3070 value.AsRegisterPairHigh<Register>(),
3071 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003072 locations->GetTemp(1).AsRegister<Register>(),
3073 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003074 } else {
3075 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003076 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003077 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003078 break;
3079 }
3080
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003081 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003082 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003083 break;
3084 }
3085
3086 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003087 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003088 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003089 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3090 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3091
3092 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3093
3094 GenerateWideAtomicStore(base, offset,
3095 value_reg_lo,
3096 value_reg_hi,
3097 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003098 locations->GetTemp(3).AsRegister<Register>(),
3099 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003100 } else {
3101 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003102 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003103 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003104 break;
3105 }
3106
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003107 case Primitive::kPrimVoid:
3108 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003109 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003110 }
Calin Juravle52c48962014-12-16 17:02:57 +00003111
Calin Juravle77520bc2015-01-12 18:45:46 +00003112 // Longs and doubles are handled in the switch.
3113 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3114 codegen_->MaybeRecordImplicitNullCheck(instruction);
3115 }
3116
3117 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3118 Register temp = locations->GetTemp(0).AsRegister<Register>();
3119 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003120 codegen_->MarkGCCard(
3121 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003122 }
3123
Calin Juravle52c48962014-12-16 17:02:57 +00003124 if (is_volatile) {
3125 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3126 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003127}
3128
Calin Juravle52c48962014-12-16 17:02:57 +00003129void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3130 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003131 LocationSummary* locations =
3132 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003133 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003134
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003135 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003136 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003137 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003138 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003139
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003140 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3141 locations->SetOut(Location::RequiresFpuRegister());
3142 } else {
3143 locations->SetOut(Location::RequiresRegister(),
3144 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3145 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003146 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003147 // Arm encoding have some additional constraints for ldrexd/strexd:
3148 // - registers need to be consecutive
3149 // - the first register should be even but not R14.
3150 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3151 // enable Arm encoding.
3152 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3153 locations->AddTemp(Location::RequiresRegister());
3154 locations->AddTemp(Location::RequiresRegister());
3155 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003156}
3157
Calin Juravle52c48962014-12-16 17:02:57 +00003158void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3159 const FieldInfo& field_info) {
3160 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003161
Calin Juravle52c48962014-12-16 17:02:57 +00003162 LocationSummary* locations = instruction->GetLocations();
3163 Register base = locations->InAt(0).AsRegister<Register>();
3164 Location out = locations->Out();
3165 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003166 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003167 Primitive::Type field_type = field_info.GetFieldType();
3168 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3169
3170 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003171 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003172 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003173 break;
3174 }
3175
3176 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003177 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003178 break;
3179 }
3180
3181 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003182 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003183 break;
3184 }
3185
3186 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003187 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003188 break;
3189 }
3190
3191 case Primitive::kPrimInt:
3192 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003193 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003194 break;
3195 }
3196
3197 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003198 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003199 GenerateWideAtomicLoad(base, offset,
3200 out.AsRegisterPairLow<Register>(),
3201 out.AsRegisterPairHigh<Register>());
3202 } else {
3203 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3204 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003205 break;
3206 }
3207
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003208 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003209 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003210 break;
3211 }
3212
3213 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003214 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003215 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003216 Register lo = locations->GetTemp(0).AsRegister<Register>();
3217 Register hi = locations->GetTemp(1).AsRegister<Register>();
3218 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003219 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003220 __ vmovdrr(out_reg, lo, hi);
3221 } else {
3222 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003223 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003224 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003225 break;
3226 }
3227
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003228 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003229 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003230 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003231 }
Calin Juravle52c48962014-12-16 17:02:57 +00003232
Calin Juravle77520bc2015-01-12 18:45:46 +00003233 // Doubles are handled in the switch.
3234 if (field_type != Primitive::kPrimDouble) {
3235 codegen_->MaybeRecordImplicitNullCheck(instruction);
3236 }
3237
Calin Juravle52c48962014-12-16 17:02:57 +00003238 if (is_volatile) {
3239 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3240 }
3241}
3242
3243void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3244 HandleFieldSet(instruction, instruction->GetFieldInfo());
3245}
3246
3247void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003248 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003249}
3250
3251void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3252 HandleFieldGet(instruction, instruction->GetFieldInfo());
3253}
3254
3255void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3256 HandleFieldGet(instruction, instruction->GetFieldInfo());
3257}
3258
3259void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3260 HandleFieldGet(instruction, instruction->GetFieldInfo());
3261}
3262
3263void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3264 HandleFieldGet(instruction, instruction->GetFieldInfo());
3265}
3266
3267void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3268 HandleFieldSet(instruction, instruction->GetFieldInfo());
3269}
3270
3271void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003272 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003273}
3274
3275void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003276 LocationSummary* locations =
3277 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003278 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003279 if (instruction->HasUses()) {
3280 locations->SetOut(Location::SameAsFirstInput());
3281 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003282}
3283
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003284void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003285 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3286 return;
3287 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003288 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003289
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003290 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3291 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3292}
3293
3294void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003295 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003296 codegen_->AddSlowPath(slow_path);
3297
3298 LocationSummary* locations = instruction->GetLocations();
3299 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003300
Calin Juravle77520bc2015-01-12 18:45:46 +00003301 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3302 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003303}
3304
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003305void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3306 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3307 GenerateImplicitNullCheck(instruction);
3308 } else {
3309 GenerateExplicitNullCheck(instruction);
3310 }
3311}
3312
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003313void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003314 LocationSummary* locations =
3315 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003316 locations->SetInAt(0, Location::RequiresRegister());
3317 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003318 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3319 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3320 } else {
3321 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3322 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003323}
3324
3325void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3326 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003327 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003328 Location index = locations->InAt(1);
3329
3330 switch (instruction->GetType()) {
3331 case Primitive::kPrimBoolean: {
3332 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003333 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003334 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003335 size_t offset =
3336 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003337 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3338 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003339 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003340 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3341 }
3342 break;
3343 }
3344
3345 case Primitive::kPrimByte: {
3346 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003347 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003348 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003349 size_t offset =
3350 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003351 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3352 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003353 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003354 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3355 }
3356 break;
3357 }
3358
3359 case Primitive::kPrimShort: {
3360 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003361 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003362 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003363 size_t offset =
3364 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003365 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3366 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003367 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003368 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3369 }
3370 break;
3371 }
3372
3373 case Primitive::kPrimChar: {
3374 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003375 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003376 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003377 size_t offset =
3378 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003379 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3380 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003381 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003382 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3383 }
3384 break;
3385 }
3386
3387 case Primitive::kPrimInt:
3388 case Primitive::kPrimNot: {
3389 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3390 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003391 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003392 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003393 size_t offset =
3394 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003395 __ LoadFromOffset(kLoadWord, out, obj, offset);
3396 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003397 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003398 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3399 }
3400 break;
3401 }
3402
3403 case Primitive::kPrimLong: {
3404 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003405 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003406 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003407 size_t offset =
3408 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003409 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003410 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003411 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003412 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003413 }
3414 break;
3415 }
3416
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003417 case Primitive::kPrimFloat: {
3418 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3419 Location out = locations->Out();
3420 DCHECK(out.IsFpuRegister());
3421 if (index.IsConstant()) {
3422 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3423 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3424 } else {
3425 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3426 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3427 }
3428 break;
3429 }
3430
3431 case Primitive::kPrimDouble: {
3432 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3433 Location out = locations->Out();
3434 DCHECK(out.IsFpuRegisterPair());
3435 if (index.IsConstant()) {
3436 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3437 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3438 } else {
3439 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3440 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3441 }
3442 break;
3443 }
3444
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003445 case Primitive::kPrimVoid:
3446 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003447 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003448 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003449 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003450}
3451
3452void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003453 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003454
3455 bool needs_write_barrier =
3456 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3457 bool needs_runtime_call = instruction->NeedsTypeCheck();
3458
Nicolas Geoffray39468442014-09-02 15:17:15 +01003459 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003460 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3461 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003462 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003463 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3464 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3465 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003466 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003467 locations->SetInAt(0, Location::RequiresRegister());
3468 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003469 if (Primitive::IsFloatingPointType(value_type)) {
3470 locations->SetInAt(2, Location::RequiresFpuRegister());
3471 } else {
3472 locations->SetInAt(2, Location::RequiresRegister());
3473 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003474
3475 if (needs_write_barrier) {
3476 // Temporary registers for the write barrier.
3477 locations->AddTemp(Location::RequiresRegister());
3478 locations->AddTemp(Location::RequiresRegister());
3479 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003480 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003481}
3482
3483void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3484 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003485 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003486 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003487 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003488 bool needs_runtime_call = locations->WillCall();
3489 bool needs_write_barrier =
3490 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003491
3492 switch (value_type) {
3493 case Primitive::kPrimBoolean:
3494 case Primitive::kPrimByte: {
3495 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003496 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003497 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003498 size_t offset =
3499 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003500 __ StoreToOffset(kStoreByte, value, obj, offset);
3501 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003502 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003503 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3504 }
3505 break;
3506 }
3507
3508 case Primitive::kPrimShort:
3509 case Primitive::kPrimChar: {
3510 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003511 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003512 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003513 size_t offset =
3514 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003515 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3516 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003517 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003518 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3519 }
3520 break;
3521 }
3522
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003523 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003524 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003525 if (!needs_runtime_call) {
3526 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003527 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003528 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003529 size_t offset =
3530 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003531 __ StoreToOffset(kStoreWord, value, obj, offset);
3532 } else {
3533 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003534 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003535 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3536 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003537 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003538 if (needs_write_barrier) {
3539 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003540 Register temp = locations->GetTemp(0).AsRegister<Register>();
3541 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003542 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003543 }
3544 } else {
3545 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003546 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3547 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003548 instruction->GetDexPc(),
3549 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003550 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003551 break;
3552 }
3553
3554 case Primitive::kPrimLong: {
3555 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003556 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003557 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003558 size_t offset =
3559 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003560 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003561 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003562 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003563 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003564 }
3565 break;
3566 }
3567
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003568 case Primitive::kPrimFloat: {
3569 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3570 Location value = locations->InAt(2);
3571 DCHECK(value.IsFpuRegister());
3572 if (index.IsConstant()) {
3573 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3574 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3575 } else {
3576 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3577 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3578 }
3579 break;
3580 }
3581
3582 case Primitive::kPrimDouble: {
3583 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3584 Location value = locations->InAt(2);
3585 DCHECK(value.IsFpuRegisterPair());
3586 if (index.IsConstant()) {
3587 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3588 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3589 } else {
3590 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3591 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3592 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003593
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003594 break;
3595 }
3596
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003597 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003598 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003599 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003600 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003601
3602 // Ints and objects are handled in the switch.
3603 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3604 codegen_->MaybeRecordImplicitNullCheck(instruction);
3605 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003606}
3607
3608void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003609 LocationSummary* locations =
3610 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003611 locations->SetInAt(0, Location::RequiresRegister());
3612 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003613}
3614
3615void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3616 LocationSummary* locations = instruction->GetLocations();
3617 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003618 Register obj = locations->InAt(0).AsRegister<Register>();
3619 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003620 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003621 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003622}
3623
3624void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003625 LocationSummary* locations =
3626 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003627 locations->SetInAt(0, Location::RequiresRegister());
3628 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003629 if (instruction->HasUses()) {
3630 locations->SetOut(Location::SameAsFirstInput());
3631 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003632}
3633
3634void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3635 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003636 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003637 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003638 codegen_->AddSlowPath(slow_path);
3639
Roland Levillain271ab9c2014-11-27 15:23:57 +00003640 Register index = locations->InAt(0).AsRegister<Register>();
3641 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003642
3643 __ cmp(index, ShifterOperand(length));
3644 __ b(slow_path->GetEntryLabel(), CS);
3645}
3646
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003647void CodeGeneratorARM::MarkGCCard(Register temp,
3648 Register card,
3649 Register object,
3650 Register value,
3651 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003652 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003653 if (can_be_null) {
3654 __ CompareAndBranchIfZero(value, &is_null);
3655 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003656 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3657 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3658 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003659 if (can_be_null) {
3660 __ Bind(&is_null);
3661 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003662}
3663
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003664void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3665 temp->SetLocations(nullptr);
3666}
3667
3668void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3669 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003670 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003671}
3672
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003673void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003674 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003675 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003676}
3677
3678void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003679 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3680}
3681
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003682void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3683 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3684}
3685
3686void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003687 HBasicBlock* block = instruction->GetBlock();
3688 if (block->GetLoopInformation() != nullptr) {
3689 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3690 // The back edge will generate the suspend check.
3691 return;
3692 }
3693 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3694 // The goto will generate the suspend check.
3695 return;
3696 }
3697 GenerateSuspendCheck(instruction, nullptr);
3698}
3699
3700void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3701 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003702 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003703 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3704 if (slow_path == nullptr) {
3705 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3706 instruction->SetSlowPath(slow_path);
3707 codegen_->AddSlowPath(slow_path);
3708 if (successor != nullptr) {
3709 DCHECK(successor->IsLoopHeader());
3710 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3711 }
3712 } else {
3713 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3714 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003715
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003716 __ LoadFromOffset(
3717 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3718 __ cmp(IP, ShifterOperand(0));
3719 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003720 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003721 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003722 __ Bind(slow_path->GetReturnLabel());
3723 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003724 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003725 __ b(slow_path->GetEntryLabel());
3726 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003727}
3728
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003729ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3730 return codegen_->GetAssembler();
3731}
3732
3733void ParallelMoveResolverARM::EmitMove(size_t index) {
3734 MoveOperands* move = moves_.Get(index);
3735 Location source = move->GetSource();
3736 Location destination = move->GetDestination();
3737
3738 if (source.IsRegister()) {
3739 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003740 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003741 } else {
3742 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003743 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003744 SP, destination.GetStackIndex());
3745 }
3746 } else if (source.IsStackSlot()) {
3747 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003748 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003749 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003750 } else if (destination.IsFpuRegister()) {
3751 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003752 } else {
3753 DCHECK(destination.IsStackSlot());
3754 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3755 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3756 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003757 } else if (source.IsFpuRegister()) {
3758 if (destination.IsFpuRegister()) {
3759 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003760 } else {
3761 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003762 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3763 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003764 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003765 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003766 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3767 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003768 } else if (destination.IsRegisterPair()) {
3769 DCHECK(ExpectedPairLayout(destination));
3770 __ LoadFromOffset(
3771 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3772 } else {
3773 DCHECK(destination.IsFpuRegisterPair()) << destination;
3774 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3775 SP,
3776 source.GetStackIndex());
3777 }
3778 } else if (source.IsRegisterPair()) {
3779 if (destination.IsRegisterPair()) {
3780 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3781 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3782 } else {
3783 DCHECK(destination.IsDoubleStackSlot()) << destination;
3784 DCHECK(ExpectedPairLayout(source));
3785 __ StoreToOffset(
3786 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3787 }
3788 } else if (source.IsFpuRegisterPair()) {
3789 if (destination.IsFpuRegisterPair()) {
3790 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3791 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3792 } else {
3793 DCHECK(destination.IsDoubleStackSlot()) << destination;
3794 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3795 SP,
3796 destination.GetStackIndex());
3797 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003798 } else {
3799 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003800 HConstant* constant = source.GetConstant();
3801 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3802 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003803 if (destination.IsRegister()) {
3804 __ LoadImmediate(destination.AsRegister<Register>(), value);
3805 } else {
3806 DCHECK(destination.IsStackSlot());
3807 __ LoadImmediate(IP, value);
3808 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3809 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003810 } else if (constant->IsLongConstant()) {
3811 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003812 if (destination.IsRegisterPair()) {
3813 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3814 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003815 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003816 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003817 __ LoadImmediate(IP, Low32Bits(value));
3818 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3819 __ LoadImmediate(IP, High32Bits(value));
3820 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3821 }
3822 } else if (constant->IsDoubleConstant()) {
3823 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003824 if (destination.IsFpuRegisterPair()) {
3825 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003826 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003827 DCHECK(destination.IsDoubleStackSlot()) << destination;
3828 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003829 __ LoadImmediate(IP, Low32Bits(int_value));
3830 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3831 __ LoadImmediate(IP, High32Bits(int_value));
3832 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3833 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003834 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003835 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003836 float value = constant->AsFloatConstant()->GetValue();
3837 if (destination.IsFpuRegister()) {
3838 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3839 } else {
3840 DCHECK(destination.IsStackSlot());
3841 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3842 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3843 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003844 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003845 }
3846}
3847
3848void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3849 __ Mov(IP, reg);
3850 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3851 __ StoreToOffset(kStoreWord, IP, SP, mem);
3852}
3853
3854void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3855 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3856 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3857 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3858 SP, mem1 + stack_offset);
3859 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3860 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3861 SP, mem2 + stack_offset);
3862 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3863}
3864
3865void ParallelMoveResolverARM::EmitSwap(size_t index) {
3866 MoveOperands* move = moves_.Get(index);
3867 Location source = move->GetSource();
3868 Location destination = move->GetDestination();
3869
3870 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003871 DCHECK_NE(source.AsRegister<Register>(), IP);
3872 DCHECK_NE(destination.AsRegister<Register>(), IP);
3873 __ Mov(IP, source.AsRegister<Register>());
3874 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3875 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003876 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003877 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003878 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003879 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003880 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3881 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003882 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003883 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003884 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003885 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003886 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003887 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003888 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003889 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003890 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3891 destination.AsRegisterPairHigh<Register>(),
3892 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003893 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003894 Register low_reg = source.IsRegisterPair()
3895 ? source.AsRegisterPairLow<Register>()
3896 : destination.AsRegisterPairLow<Register>();
3897 int mem = source.IsRegisterPair()
3898 ? destination.GetStackIndex()
3899 : source.GetStackIndex();
3900 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003901 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003902 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003903 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003904 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003905 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3906 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003907 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003908 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003909 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003910 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3911 DRegister reg = source.IsFpuRegisterPair()
3912 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3913 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3914 int mem = source.IsFpuRegisterPair()
3915 ? destination.GetStackIndex()
3916 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003917 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003918 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003919 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003920 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3921 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3922 : destination.AsFpuRegister<SRegister>();
3923 int mem = source.IsFpuRegister()
3924 ? destination.GetStackIndex()
3925 : source.GetStackIndex();
3926
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003927 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003928 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003929 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003930 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003931 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3932 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003933 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003934 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003935 }
3936}
3937
3938void ParallelMoveResolverARM::SpillScratch(int reg) {
3939 __ Push(static_cast<Register>(reg));
3940}
3941
3942void ParallelMoveResolverARM::RestoreScratch(int reg) {
3943 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003944}
3945
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003946void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003947 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3948 ? LocationSummary::kCallOnSlowPath
3949 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003950 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003951 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003952 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003953 locations->SetOut(Location::RequiresRegister());
3954}
3955
3956void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003957 LocationSummary* locations = cls->GetLocations();
3958 Register out = locations->Out().AsRegister<Register>();
3959 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003960 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003961 DCHECK(!cls->CanCallRuntime());
3962 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003963 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003964 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003965 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003966 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003967 __ LoadFromOffset(kLoadWord,
3968 out,
3969 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07003970 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003971 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003972
3973 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3974 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3975 codegen_->AddSlowPath(slow_path);
3976 __ cmp(out, ShifterOperand(0));
3977 __ b(slow_path->GetEntryLabel(), EQ);
3978 if (cls->MustGenerateClinitCheck()) {
3979 GenerateClassInitializationCheck(slow_path, out);
3980 } else {
3981 __ Bind(slow_path->GetExitLabel());
3982 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003983 }
3984}
3985
3986void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3987 LocationSummary* locations =
3988 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3989 locations->SetInAt(0, Location::RequiresRegister());
3990 if (check->HasUses()) {
3991 locations->SetOut(Location::SameAsFirstInput());
3992 }
3993}
3994
3995void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003996 // We assume the class is not null.
3997 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3998 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003999 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004000 GenerateClassInitializationCheck(slow_path,
4001 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004002}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004003
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004004void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
4005 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004006 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4007 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4008 __ b(slow_path->GetEntryLabel(), LT);
4009 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4010 // properly. Therefore, we do a memory fence.
4011 __ dmb(ISH);
4012 __ Bind(slow_path->GetExitLabel());
4013}
4014
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004015void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4016 LocationSummary* locations =
4017 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004018 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004019 locations->SetOut(Location::RequiresRegister());
4020}
4021
4022void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4023 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4024 codegen_->AddSlowPath(slow_path);
4025
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004026 LocationSummary* locations = load->GetLocations();
4027 Register out = locations->Out().AsRegister<Register>();
4028 Register current_method = locations->InAt(0).AsRegister<Register>();
4029 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004030 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004031 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004032 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
4033 __ cmp(out, ShifterOperand(0));
4034 __ b(slow_path->GetEntryLabel(), EQ);
4035 __ Bind(slow_path->GetExitLabel());
4036}
4037
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004038void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4039 LocationSummary* locations =
4040 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4041 locations->SetOut(Location::RequiresRegister());
4042}
4043
4044void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004045 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004046 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4047 __ LoadFromOffset(kLoadWord, out, TR, offset);
4048 __ LoadImmediate(IP, 0);
4049 __ StoreToOffset(kStoreWord, IP, TR, offset);
4050}
4051
4052void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4053 LocationSummary* locations =
4054 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4055 InvokeRuntimeCallingConvention calling_convention;
4056 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4057}
4058
4059void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4060 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004061 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004062}
4063
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004064void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004065 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4066 ? LocationSummary::kNoCall
4067 : LocationSummary::kCallOnSlowPath;
4068 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4069 locations->SetInAt(0, Location::RequiresRegister());
4070 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004071 // The out register is used as a temporary, so it overlaps with the inputs.
4072 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004073}
4074
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004075void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004076 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004077 Register obj = locations->InAt(0).AsRegister<Register>();
4078 Register cls = locations->InAt(1).AsRegister<Register>();
4079 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004080 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004081 Label done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004082 SlowPathCodeARM* slow_path = nullptr;
4083
4084 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004085 // avoid null check if we know obj is not null.
4086 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004087 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004088 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004089 // Compare the class of `obj` with `cls`.
4090 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
4091 __ cmp(out, ShifterOperand(cls));
4092 if (instruction->IsClassFinal()) {
4093 // Classes must be equal for the instanceof to succeed.
4094 __ b(&zero, NE);
4095 __ LoadImmediate(out, 1);
4096 __ b(&done);
4097 } else {
4098 // If the classes are not equal, we go into a slow path.
4099 DCHECK(locations->OnlyCallsOnSlowPath());
4100 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004101 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004102 codegen_->AddSlowPath(slow_path);
4103 __ b(slow_path->GetEntryLabel(), NE);
4104 __ LoadImmediate(out, 1);
4105 __ b(&done);
4106 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004107
4108 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4109 __ Bind(&zero);
4110 __ LoadImmediate(out, 0);
4111 }
4112
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004113 if (slow_path != nullptr) {
4114 __ Bind(slow_path->GetExitLabel());
4115 }
4116 __ Bind(&done);
4117}
4118
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004119void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4120 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4121 instruction, LocationSummary::kCallOnSlowPath);
4122 locations->SetInAt(0, Location::RequiresRegister());
4123 locations->SetInAt(1, Location::RequiresRegister());
4124 locations->AddTemp(Location::RequiresRegister());
4125}
4126
4127void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4128 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004129 Register obj = locations->InAt(0).AsRegister<Register>();
4130 Register cls = locations->InAt(1).AsRegister<Register>();
4131 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004132 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4133
4134 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4135 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4136 codegen_->AddSlowPath(slow_path);
4137
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004138 // avoid null check if we know obj is not null.
4139 if (instruction->MustDoNullCheck()) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004140 __ CompareAndBranchIfZero(obj, slow_path->GetExitLabel());
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004141 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004142 // Compare the class of `obj` with `cls`.
4143 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4144 __ cmp(temp, ShifterOperand(cls));
4145 __ b(slow_path->GetEntryLabel(), NE);
4146 __ Bind(slow_path->GetExitLabel());
4147}
4148
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004149void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4150 LocationSummary* locations =
4151 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4152 InvokeRuntimeCallingConvention calling_convention;
4153 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4154}
4155
4156void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4157 codegen_->InvokeRuntime(instruction->IsEnter()
4158 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4159 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004160 instruction->GetDexPc(),
4161 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004162}
4163
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004164void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4165void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4166void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4167
4168void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4169 LocationSummary* locations =
4170 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4171 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4172 || instruction->GetResultType() == Primitive::kPrimLong);
4173 locations->SetInAt(0, Location::RequiresRegister());
4174 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004175 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004176}
4177
4178void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4179 HandleBitwiseOperation(instruction);
4180}
4181
4182void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4183 HandleBitwiseOperation(instruction);
4184}
4185
4186void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4187 HandleBitwiseOperation(instruction);
4188}
4189
4190void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4191 LocationSummary* locations = instruction->GetLocations();
4192
4193 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004194 Register first = locations->InAt(0).AsRegister<Register>();
4195 Register second = locations->InAt(1).AsRegister<Register>();
4196 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004197 if (instruction->IsAnd()) {
4198 __ and_(out, first, ShifterOperand(second));
4199 } else if (instruction->IsOr()) {
4200 __ orr(out, first, ShifterOperand(second));
4201 } else {
4202 DCHECK(instruction->IsXor());
4203 __ eor(out, first, ShifterOperand(second));
4204 }
4205 } else {
4206 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4207 Location first = locations->InAt(0);
4208 Location second = locations->InAt(1);
4209 Location out = locations->Out();
4210 if (instruction->IsAnd()) {
4211 __ and_(out.AsRegisterPairLow<Register>(),
4212 first.AsRegisterPairLow<Register>(),
4213 ShifterOperand(second.AsRegisterPairLow<Register>()));
4214 __ and_(out.AsRegisterPairHigh<Register>(),
4215 first.AsRegisterPairHigh<Register>(),
4216 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4217 } else if (instruction->IsOr()) {
4218 __ orr(out.AsRegisterPairLow<Register>(),
4219 first.AsRegisterPairLow<Register>(),
4220 ShifterOperand(second.AsRegisterPairLow<Register>()));
4221 __ orr(out.AsRegisterPairHigh<Register>(),
4222 first.AsRegisterPairHigh<Register>(),
4223 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4224 } else {
4225 DCHECK(instruction->IsXor());
4226 __ eor(out.AsRegisterPairLow<Register>(),
4227 first.AsRegisterPairLow<Register>(),
4228 ShifterOperand(second.AsRegisterPairLow<Register>()));
4229 __ eor(out.AsRegisterPairHigh<Register>(),
4230 first.AsRegisterPairHigh<Register>(),
4231 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4232 }
4233 }
4234}
4235
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004236void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004237 // TODO: Implement all kinds of calls:
4238 // 1) boot -> boot
4239 // 2) app -> boot
4240 // 3) app -> app
4241 //
4242 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4243
Jeff Hao848f70a2014-01-15 13:49:50 -08004244 if (invoke->IsStringInit()) {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004245 Register reg = temp.AsRegister<Register>();
Jeff Hao848f70a2014-01-15 13:49:50 -08004246 // temp = thread->string_init_entrypoint
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004247 __ LoadFromOffset(kLoadWord, reg, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004248 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004249 __ LoadFromOffset(kLoadWord, LR, reg,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004250 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004251 kArmWordSize).Int32Value());
4252 // LR()
4253 __ blx(LR);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004254 } else if (invoke->IsRecursive()) {
4255 __ bl(GetFrameEntryLabel());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004256 } else {
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004257 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4258 Register method_reg;
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004259 Register reg = temp.AsRegister<Register>();
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004260 if (current_method.IsRegister()) {
4261 method_reg = current_method.AsRegister<Register>();
4262 } else {
4263 DCHECK(invoke->GetLocations()->Intrinsified());
4264 DCHECK(!current_method.IsValid());
4265 method_reg = reg;
4266 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4267 }
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004268 // reg = current_method->dex_cache_resolved_methods_;
4269 __ LoadFromOffset(
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004270 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004271 // reg = reg[index_in_cache]
4272 __ LoadFromOffset(
4273 kLoadWord, reg, reg, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4274 // LR = reg[offset_of_quick_compiled_code]
4275 __ LoadFromOffset(kLoadWord, LR, reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4276 kArmWordSize).Int32Value());
4277 // LR()
4278 __ blx(LR);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004279 }
4280
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004281 DCHECK(!IsLeafMethod());
4282}
4283
Calin Juravleb1498f62015-02-16 13:13:29 +00004284void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4285 // Nothing to do, this should be removed during prepare for register allocator.
4286 UNUSED(instruction);
4287 LOG(FATAL) << "Unreachable";
4288}
4289
4290void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4291 // Nothing to do, this should be removed during prepare for register allocator.
4292 UNUSED(instruction);
4293 LOG(FATAL) << "Unreachable";
4294}
4295
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004296} // namespace arm
4297} // namespace art