blob: 0e099a83ebf8d2843dd0e0a61462e008a952cfa2 [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 __
Roland Levillain62a46b22015-06-01 18:24:13 +0100335#define __ down_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700336
337inline Condition ARMCondition(IfCondition cond) {
338 switch (cond) {
339 case kCondEQ: return EQ;
340 case kCondNE: return NE;
341 case kCondLT: return LT;
342 case kCondLE: return LE;
343 case kCondGT: return GT;
344 case kCondGE: return GE;
345 default:
346 LOG(FATAL) << "Unknown if condition";
347 }
348 return EQ; // Unreachable.
349}
350
351inline Condition ARMOppositeCondition(IfCondition cond) {
352 switch (cond) {
353 case kCondEQ: return NE;
354 case kCondNE: return EQ;
355 case kCondLT: return GE;
356 case kCondLE: return GT;
357 case kCondGT: return LE;
358 case kCondGE: return LT;
359 default:
360 LOG(FATAL) << "Unknown if condition";
361 }
362 return EQ; // Unreachable.
363}
364
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100365void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100366 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100367}
368
369void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100370 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100371}
372
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100373size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
374 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
375 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100376}
377
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100378size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
379 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
380 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100381}
382
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000383size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
384 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
385 return kArmWordSize;
386}
387
388size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
389 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
390 return kArmWordSize;
391}
392
Calin Juravle34166012014-12-19 17:22:29 +0000393CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000394 const ArmInstructionSetFeatures& isa_features,
395 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000396 : CodeGenerator(graph,
397 kNumberOfCoreRegisters,
398 kNumberOfSRegisters,
399 kNumberOfRegisterPairs,
400 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
401 arraysize(kCoreCalleeSaves)),
402 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
403 arraysize(kFpuCalleeSaves)),
404 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100405 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100406 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100407 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100408 move_resolver_(graph->GetArena(), this),
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000409 assembler_(),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000410 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000411 // Save the PC register to mimic Quick.
412 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100413}
414
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000415void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
416 // Ensure that we fix up branches and literal loads and emit the literal pool.
417 __ FinalizeCode();
418
419 // Adjust native pc offsets in stack maps.
420 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
421 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
422 uint32_t new_position = __ GetAdjustedPosition(old_position);
423 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
424 }
425 // Adjust native pc offsets of block labels.
426 for (size_t block_idx = 0u, end = block_order_->Size(); block_idx != end; ++block_idx) {
427 HBasicBlock* block = block_order_->Get(block_idx);
428 // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid
429 // FirstNonEmptyBlock() which could lead to adjusting a label more than once.
430 DCHECK_LT(static_cast<size_t>(block->GetBlockId()), block_labels_.Size());
431 Label* block_label = &block_labels_.GetRawStorage()[block->GetBlockId()];
David Brazdilfc6a86a2015-06-26 10:33:45 +0000432 DCHECK_EQ(block_label->IsBound(), !block->IsSingleJump());
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000433 if (block_label->IsBound()) {
434 __ AdjustLabelPosition(block_label);
435 }
436 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100437 // Adjust pc offsets for the disassembly information.
438 if (disasm_info_ != nullptr) {
439 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
440 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
441 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
442 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
443 it.second.start = __ GetAdjustedPosition(it.second.start);
444 it.second.end = __ GetAdjustedPosition(it.second.end);
445 }
446 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
447 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
448 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
449 }
450 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000451
452 CodeGenerator::Finalize(allocator);
453}
454
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100455Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100456 switch (type) {
457 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100458 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100459 ArmManagedRegister pair =
460 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100461 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
462 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
463
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100464 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
465 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100466 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100467 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100468 }
469
470 case Primitive::kPrimByte:
471 case Primitive::kPrimBoolean:
472 case Primitive::kPrimChar:
473 case Primitive::kPrimShort:
474 case Primitive::kPrimInt:
475 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100476 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100477 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100478 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
479 ArmManagedRegister current =
480 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
481 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100482 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100483 }
484 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100485 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100486 }
487
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000488 case Primitive::kPrimFloat: {
489 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100490 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100491 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100492
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000493 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000494 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
495 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000496 return Location::FpuRegisterPairLocation(reg, reg + 1);
497 }
498
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100499 case Primitive::kPrimVoid:
500 LOG(FATAL) << "Unreachable type " << type;
501 }
502
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100503 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100504}
505
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000506void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100507 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100508 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100509
510 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100511 blocked_core_registers_[SP] = true;
512 blocked_core_registers_[LR] = true;
513 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100514
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100515 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100516 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100517
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100518 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100519 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100520
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000521 if (is_baseline) {
522 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
523 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
524 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000525
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000526 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
527
528 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
529 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
530 }
531 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100532
533 UpdateBlockedPairRegisters();
534}
535
536void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
537 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
538 ArmManagedRegister current =
539 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
540 if (blocked_core_registers_[current.AsRegisterPairLow()]
541 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
542 blocked_register_pairs_[i] = true;
543 }
544 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100545}
546
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100547InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
548 : HGraphVisitor(graph),
549 assembler_(codegen->GetAssembler()),
550 codegen_(codegen) {}
551
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000552void CodeGeneratorARM::ComputeSpillMask() {
553 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000554 // Save one extra register for baseline. Note that on thumb2, there is no easy
555 // instruction to restore just the PC, so this actually helps both baseline
556 // and non-baseline to save and restore at least two registers at entry and exit.
557 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000558 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
559 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
560 // We use vpush and vpop for saving and restoring floating point registers, which take
561 // a SRegister and the number of registers to save/restore after that SRegister. We
562 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
563 // but in the range.
564 if (fpu_spill_mask_ != 0) {
565 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
566 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
567 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
568 fpu_spill_mask_ |= (1 << i);
569 }
570 }
571}
572
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100573static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100574 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100575}
576
577static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100578 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100579}
580
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000581void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000582 bool skip_overflow_check =
583 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000584 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000585 __ Bind(&frame_entry_label_);
586
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000587 if (HasEmptyFrame()) {
588 return;
589 }
590
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100591 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000592 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
593 __ LoadFromOffset(kLoadWord, IP, IP, 0);
594 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100595 }
596
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000597 // PC is in the list of callee-save to mimic Quick, but we need to push
598 // LR at entry instead.
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100599 uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR;
600 __ PushList(push_mask);
601 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100602 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, push_mask, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000603 if (fpu_spill_mask_ != 0) {
604 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
605 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100606 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100607 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000608 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100609 int adjust = GetFrameSize() - FrameEntrySpillSize();
610 __ AddConstant(SP, -adjust);
611 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100612 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000613}
614
615void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000616 if (HasEmptyFrame()) {
617 __ bx(LR);
618 return;
619 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100620 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100621 int adjust = GetFrameSize() - FrameEntrySpillSize();
622 __ AddConstant(SP, adjust);
623 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000624 if (fpu_spill_mask_ != 0) {
625 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
626 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100627 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
628 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000629 }
630 __ PopList(core_spill_mask_);
David Srbeckyc34dc932015-04-12 09:27:43 +0100631 __ cfi().RestoreState();
632 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000633}
634
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100635void CodeGeneratorARM::Bind(HBasicBlock* block) {
636 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000637}
638
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100639Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
640 switch (load->GetType()) {
641 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100642 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100643 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100644
645 case Primitive::kPrimInt:
646 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100647 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100648 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100649
650 case Primitive::kPrimBoolean:
651 case Primitive::kPrimByte:
652 case Primitive::kPrimChar:
653 case Primitive::kPrimShort:
654 case Primitive::kPrimVoid:
655 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700656 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100657 }
658
659 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700660 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100661}
662
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100663Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100664 switch (type) {
665 case Primitive::kPrimBoolean:
666 case Primitive::kPrimByte:
667 case Primitive::kPrimChar:
668 case Primitive::kPrimShort:
669 case Primitive::kPrimInt:
670 case Primitive::kPrimNot: {
671 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000672 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100673 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100674 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100675 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000676 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100677 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100678 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100679
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000680 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100681 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000682 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100683 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000684 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100685 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000686 if (calling_convention.GetRegisterAt(index) == R1) {
687 // Skip R1, and use R2_R3 instead.
688 gp_index_++;
689 index++;
690 }
691 }
692 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
693 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000694 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000695 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000696 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100697 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000698 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
699 }
700 }
701
702 case Primitive::kPrimFloat: {
703 uint32_t stack_index = stack_index_++;
704 if (float_index_ % 2 == 0) {
705 float_index_ = std::max(double_index_, float_index_);
706 }
707 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
708 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
709 } else {
710 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
711 }
712 }
713
714 case Primitive::kPrimDouble: {
715 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
716 uint32_t stack_index = stack_index_;
717 stack_index_ += 2;
718 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
719 uint32_t index = double_index_;
720 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000721 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000722 calling_convention.GetFpuRegisterAt(index),
723 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000724 DCHECK(ExpectedPairLayout(result));
725 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000726 } else {
727 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100728 }
729 }
730
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100731 case Primitive::kPrimVoid:
732 LOG(FATAL) << "Unexpected parameter type " << type;
733 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100734 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100735 return Location();
736}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100737
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100738Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000739 switch (type) {
740 case Primitive::kPrimBoolean:
741 case Primitive::kPrimByte:
742 case Primitive::kPrimChar:
743 case Primitive::kPrimShort:
744 case Primitive::kPrimInt:
745 case Primitive::kPrimNot: {
746 return Location::RegisterLocation(R0);
747 }
748
749 case Primitive::kPrimFloat: {
750 return Location::FpuRegisterLocation(S0);
751 }
752
753 case Primitive::kPrimLong: {
754 return Location::RegisterPairLocation(R0, R1);
755 }
756
757 case Primitive::kPrimDouble: {
758 return Location::FpuRegisterPairLocation(S0, S1);
759 }
760
761 case Primitive::kPrimVoid:
762 return Location();
763 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100764
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000765 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000766}
767
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100768Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
769 return Location::RegisterLocation(kMethodRegisterArgument);
770}
771
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100772void CodeGeneratorARM::Move32(Location destination, Location source) {
773 if (source.Equals(destination)) {
774 return;
775 }
776 if (destination.IsRegister()) {
777 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000778 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100779 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000780 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100781 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000782 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100783 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100784 } else if (destination.IsFpuRegister()) {
785 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000786 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100787 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000788 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100789 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000790 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100791 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100792 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000793 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100794 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000795 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100796 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000797 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100798 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000799 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100800 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
801 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100802 }
803 }
804}
805
806void CodeGeneratorARM::Move64(Location destination, Location source) {
807 if (source.Equals(destination)) {
808 return;
809 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100810 if (destination.IsRegisterPair()) {
811 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000812 EmitParallelMoves(
813 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
814 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100815 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000816 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100817 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
818 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100819 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000820 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100821 } else {
822 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000823 DCHECK(ExpectedPairLayout(destination));
824 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
825 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100826 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000827 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100828 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000829 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
830 SP,
831 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100832 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000833 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100834 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100835 } else {
836 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100837 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000838 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100839 if (source.AsRegisterPairLow<Register>() == R1) {
840 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100841 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
842 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100843 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100844 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100845 SP, destination.GetStackIndex());
846 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000847 } else if (source.IsFpuRegisterPair()) {
848 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
849 SP,
850 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100851 } else {
852 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000853 EmitParallelMoves(
854 Location::StackSlot(source.GetStackIndex()),
855 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100856 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000857 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100858 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
859 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100860 }
861 }
862}
863
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100864void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100865 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100866 if (instruction->IsCurrentMethod()) {
867 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
868 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100869 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100870 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000871 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000872 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
873 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000874 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000875 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000876 } else {
877 DCHECK(location.IsStackSlot());
878 __ LoadImmediate(IP, value);
879 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
880 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000881 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000882 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000883 int64_t value = const_to_move->AsLongConstant()->GetValue();
884 if (location.IsRegisterPair()) {
885 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
886 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
887 } else {
888 DCHECK(location.IsDoubleStackSlot());
889 __ LoadImmediate(IP, Low32Bits(value));
890 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
891 __ LoadImmediate(IP, High32Bits(value));
892 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
893 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100894 }
Roland Levillain476df552014-10-09 17:51:36 +0100895 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100896 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
897 switch (instruction->GetType()) {
898 case Primitive::kPrimBoolean:
899 case Primitive::kPrimByte:
900 case Primitive::kPrimChar:
901 case Primitive::kPrimShort:
902 case Primitive::kPrimInt:
903 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100904 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100905 Move32(location, Location::StackSlot(stack_slot));
906 break;
907
908 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100909 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100910 Move64(location, Location::DoubleStackSlot(stack_slot));
911 break;
912
913 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100914 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100915 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000916 } else if (instruction->IsTemporary()) {
917 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000918 if (temp_location.IsStackSlot()) {
919 Move32(location, temp_location);
920 } else {
921 DCHECK(temp_location.IsDoubleStackSlot());
922 Move64(location, temp_location);
923 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000924 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100925 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100926 switch (instruction->GetType()) {
927 case Primitive::kPrimBoolean:
928 case Primitive::kPrimByte:
929 case Primitive::kPrimChar:
930 case Primitive::kPrimShort:
931 case Primitive::kPrimNot:
932 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100933 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100934 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100935 break;
936
937 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100938 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100939 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100940 break;
941
942 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100943 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100944 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000945 }
946}
947
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100948void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
949 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000950 uint32_t dex_pc,
951 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100952 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
953 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000954 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100955 DCHECK(instruction->IsSuspendCheck()
956 || instruction->IsBoundsCheck()
957 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000958 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000959 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100960 || !IsLeafMethod());
961}
962
David Brazdilfc6a86a2015-06-26 10:33:45 +0000963void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100964 DCHECK(!successor->IsExitBlock());
965
966 HBasicBlock* block = got->GetBlock();
967 HInstruction* previous = got->GetPrevious();
968
969 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000970 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100971 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
972 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
973 return;
974 }
975
976 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
977 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
978 }
979 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000980 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000981 }
982}
983
David Brazdilfc6a86a2015-06-26 10:33:45 +0000984void LocationsBuilderARM::VisitGoto(HGoto* got) {
985 got->SetLocations(nullptr);
986}
987
988void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
989 HandleGoto(got, got->GetSuccessor());
990}
991
992void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
993 try_boundary->SetLocations(nullptr);
994}
995
996void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
997 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
998 if (!successor->IsExitBlock()) {
999 HandleGoto(try_boundary, successor);
1000 }
1001}
1002
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001003void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001004 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001005}
1006
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001007void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001008 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001009}
1010
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001011void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
1012 Label* true_target,
1013 Label* false_target,
1014 Label* always_true_target) {
1015 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001016 if (cond->IsIntConstant()) {
1017 // Constant condition, statically compared against 1.
1018 int32_t cond_value = cond->AsIntConstant()->GetValue();
1019 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001020 if (always_true_target != nullptr) {
1021 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001022 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001023 return;
1024 } else {
1025 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001026 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001027 } else {
1028 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1029 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001030 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01001031 __ CompareAndBranchIfNonZero(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
1032 true_target);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001033 } else {
1034 // Condition has not been materialized, use its inputs as the
1035 // comparison and its condition as the branch condition.
1036 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001037 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001038 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001039 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001040 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001041 } else {
1042 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001043 HConstant* constant = locations->InAt(1).GetConstant();
1044 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001045 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001046 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1047 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001048 } else {
1049 Register temp = IP;
1050 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001051 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001052 }
1053 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001054 __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001055 }
Dave Allison20dfc792014-06-16 20:44:29 -07001056 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001057 if (false_target != nullptr) {
1058 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001059 }
1060}
1061
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001062void LocationsBuilderARM::VisitIf(HIf* if_instr) {
1063 LocationSummary* locations =
1064 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
1065 HInstruction* cond = if_instr->InputAt(0);
1066 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1067 locations->SetInAt(0, Location::RequiresRegister());
1068 }
1069}
1070
1071void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1072 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1073 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1074 Label* always_true_target = true_target;
1075 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1076 if_instr->IfTrueSuccessor())) {
1077 always_true_target = nullptr;
1078 }
1079 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1080 if_instr->IfFalseSuccessor())) {
1081 false_target = nullptr;
1082 }
1083 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1084}
1085
1086void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1087 LocationSummary* locations = new (GetGraph()->GetArena())
1088 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1089 HInstruction* cond = deoptimize->InputAt(0);
1090 DCHECK(cond->IsCondition());
1091 if (cond->AsCondition()->NeedsMaterialization()) {
1092 locations->SetInAt(0, Location::RequiresRegister());
1093 }
1094}
1095
1096void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1097 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1098 DeoptimizationSlowPathARM(deoptimize);
1099 codegen_->AddSlowPath(slow_path);
1100 Label* slow_path_entry = slow_path->GetEntryLabel();
1101 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1102}
Dave Allison20dfc792014-06-16 20:44:29 -07001103
Roland Levillain0d37cd02015-05-27 16:39:19 +01001104void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001105 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001106 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001107 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain0d37cd02015-05-27 16:39:19 +01001108 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1109 if (cond->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001110 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001111 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001112}
1113
Roland Levillain0d37cd02015-05-27 16:39:19 +01001114void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
1115 if (!cond->NeedsMaterialization()) return;
1116 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001117 Register left = locations->InAt(0).AsRegister<Register>();
1118
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001119 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001120 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001121 } else {
1122 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -08001123 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001124 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001125 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1126 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001127 } else {
1128 Register temp = IP;
1129 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001130 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001131 }
Dave Allison20dfc792014-06-16 20:44:29 -07001132 }
Roland Levillain0d37cd02015-05-27 16:39:19 +01001133 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001134 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001135 ARMCondition(cond->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001136 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001137 ARMOppositeCondition(cond->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001138}
1139
1140void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1141 VisitCondition(comp);
1142}
1143
1144void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1145 VisitCondition(comp);
1146}
1147
1148void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1149 VisitCondition(comp);
1150}
1151
1152void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1153 VisitCondition(comp);
1154}
1155
1156void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1157 VisitCondition(comp);
1158}
1159
1160void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1161 VisitCondition(comp);
1162}
1163
1164void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1165 VisitCondition(comp);
1166}
1167
1168void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1169 VisitCondition(comp);
1170}
1171
1172void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1173 VisitCondition(comp);
1174}
1175
1176void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1177 VisitCondition(comp);
1178}
1179
1180void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1181 VisitCondition(comp);
1182}
1183
1184void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1185 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001186}
1187
1188void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001189 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001190}
1191
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001192void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1193 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001194}
1195
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001196void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001197 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001198}
1199
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001200void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001201 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001202 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001203}
1204
1205void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001206 LocationSummary* locations =
1207 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001208 switch (store->InputAt(1)->GetType()) {
1209 case Primitive::kPrimBoolean:
1210 case Primitive::kPrimByte:
1211 case Primitive::kPrimChar:
1212 case Primitive::kPrimShort:
1213 case Primitive::kPrimInt:
1214 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001215 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001216 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1217 break;
1218
1219 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001220 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001221 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1222 break;
1223
1224 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001225 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001226 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001227}
1228
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001229void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001230 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001231}
1232
1233void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001234 LocationSummary* locations =
1235 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001236 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001237}
1238
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001239void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001240 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001241 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001242}
1243
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001244void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1245 LocationSummary* locations =
1246 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1247 locations->SetOut(Location::ConstantLocation(constant));
1248}
1249
1250void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1251 // Will be generated at use site.
1252 UNUSED(constant);
1253}
1254
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001255void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001256 LocationSummary* locations =
1257 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001258 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001259}
1260
1261void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1262 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001263 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001264}
1265
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001266void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1267 LocationSummary* locations =
1268 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1269 locations->SetOut(Location::ConstantLocation(constant));
1270}
1271
1272void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1273 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001274 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001275}
1276
1277void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1278 LocationSummary* locations =
1279 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1280 locations->SetOut(Location::ConstantLocation(constant));
1281}
1282
1283void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1284 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001285 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001286}
1287
Calin Juravle27df7582015-04-17 19:12:31 +01001288void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1289 memory_barrier->SetLocations(nullptr);
1290}
1291
1292void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1293 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1294}
1295
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001296void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001297 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001298}
1299
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001300void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001301 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001302 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001303}
1304
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001305void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001306 LocationSummary* locations =
1307 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001308 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001309}
1310
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001311void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001312 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001313 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001314}
1315
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001316void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001317 // When we do not run baseline, explicit clinit checks triggered by static
1318 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1319 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001320
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001321 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1322 codegen_->GetInstructionSetFeatures());
1323 if (intrinsic.TryDispatch(invoke)) {
1324 return;
1325 }
1326
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001327 HandleInvoke(invoke);
1328}
1329
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001330static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1331 if (invoke->GetLocations()->Intrinsified()) {
1332 IntrinsicCodeGeneratorARM intrinsic(codegen);
1333 intrinsic.Dispatch(invoke);
1334 return true;
1335 }
1336 return false;
1337}
1338
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001339void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001340 // When we do not run baseline, explicit clinit checks triggered by static
1341 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1342 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001343
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001344 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1345 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001346 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001347
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001348 LocationSummary* locations = invoke->GetLocations();
1349 codegen_->GenerateStaticOrDirectCall(
1350 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001351 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001352}
1353
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001354void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001355 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001356 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001357}
1358
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001359void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001360 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1361 codegen_->GetInstructionSetFeatures());
1362 if (intrinsic.TryDispatch(invoke)) {
1363 return;
1364 }
1365
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001366 HandleInvoke(invoke);
1367}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001368
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001369void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001370 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1371 return;
1372 }
1373
Roland Levillain271ab9c2014-11-27 15:23:57 +00001374 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001375 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1376 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001377 LocationSummary* locations = invoke->GetLocations();
1378 Location receiver = locations->InAt(0);
1379 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1380 // temp = object->GetClass();
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001381 DCHECK(receiver.IsRegister());
1382 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00001383 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001384 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001385 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001386 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001387 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001388 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001389 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001390 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001391 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001392 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001393 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001394 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001395}
1396
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001397void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1398 HandleInvoke(invoke);
1399 // Add the hidden argument.
1400 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1401}
1402
1403void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1404 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001405 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001406 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1407 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001408 LocationSummary* locations = invoke->GetLocations();
1409 Location receiver = locations->InAt(0);
1410 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1411
1412 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001413 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1414 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001415
1416 // temp = object->GetClass();
1417 if (receiver.IsStackSlot()) {
1418 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1419 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1420 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001421 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001422 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001423 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001424 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001425 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001426 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001427 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001428 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1429 // LR = temp->GetEntryPoint();
1430 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1431 // LR();
1432 __ blx(LR);
1433 DCHECK(!codegen_->IsLeafMethod());
1434 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1435}
1436
Roland Levillain88cb1752014-10-20 16:36:47 +01001437void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1438 LocationSummary* locations =
1439 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1440 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001441 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001442 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001443 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1444 break;
1445 }
1446 case Primitive::kPrimLong: {
1447 locations->SetInAt(0, Location::RequiresRegister());
1448 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001449 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001450 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001451
Roland Levillain88cb1752014-10-20 16:36:47 +01001452 case Primitive::kPrimFloat:
1453 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001454 locations->SetInAt(0, Location::RequiresFpuRegister());
1455 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001456 break;
1457
1458 default:
1459 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1460 }
1461}
1462
1463void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1464 LocationSummary* locations = neg->GetLocations();
1465 Location out = locations->Out();
1466 Location in = locations->InAt(0);
1467 switch (neg->GetResultType()) {
1468 case Primitive::kPrimInt:
1469 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001470 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001471 break;
1472
1473 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001474 DCHECK(in.IsRegisterPair());
1475 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1476 __ rsbs(out.AsRegisterPairLow<Register>(),
1477 in.AsRegisterPairLow<Register>(),
1478 ShifterOperand(0));
1479 // We cannot emit an RSC (Reverse Subtract with Carry)
1480 // instruction here, as it does not exist in the Thumb-2
1481 // instruction set. We use the following approach
1482 // using SBC and SUB instead.
1483 //
1484 // out.hi = -C
1485 __ sbc(out.AsRegisterPairHigh<Register>(),
1486 out.AsRegisterPairHigh<Register>(),
1487 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1488 // out.hi = out.hi - in.hi
1489 __ sub(out.AsRegisterPairHigh<Register>(),
1490 out.AsRegisterPairHigh<Register>(),
1491 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1492 break;
1493
Roland Levillain88cb1752014-10-20 16:36:47 +01001494 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001495 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001496 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001497 break;
1498
Roland Levillain88cb1752014-10-20 16:36:47 +01001499 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001500 DCHECK(in.IsFpuRegisterPair());
1501 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1502 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001503 break;
1504
1505 default:
1506 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1507 }
1508}
1509
Roland Levillaindff1f282014-11-05 14:15:05 +00001510void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001511 Primitive::Type result_type = conversion->GetResultType();
1512 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001513 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001514
Roland Levillain5b3ee562015-04-14 16:02:41 +01001515 // The float-to-long, double-to-long and long-to-float type conversions
1516 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001517 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001518 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1519 && result_type == Primitive::kPrimLong)
1520 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001521 ? LocationSummary::kCall
1522 : LocationSummary::kNoCall;
1523 LocationSummary* locations =
1524 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1525
David Brazdilb2bd1c52015-03-25 11:17:37 +00001526 // The Java language does not allow treating boolean as an integral type but
1527 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001528
Roland Levillaindff1f282014-11-05 14:15:05 +00001529 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001530 case Primitive::kPrimByte:
1531 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001532 case Primitive::kPrimBoolean:
1533 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001534 case Primitive::kPrimShort:
1535 case Primitive::kPrimInt:
1536 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001537 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001538 locations->SetInAt(0, Location::RequiresRegister());
1539 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1540 break;
1541
1542 default:
1543 LOG(FATAL) << "Unexpected type conversion from " << input_type
1544 << " to " << result_type;
1545 }
1546 break;
1547
Roland Levillain01a8d712014-11-14 16:27:39 +00001548 case Primitive::kPrimShort:
1549 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001550 case Primitive::kPrimBoolean:
1551 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001552 case Primitive::kPrimByte:
1553 case Primitive::kPrimInt:
1554 case Primitive::kPrimChar:
1555 // Processing a Dex `int-to-short' instruction.
1556 locations->SetInAt(0, Location::RequiresRegister());
1557 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1558 break;
1559
1560 default:
1561 LOG(FATAL) << "Unexpected type conversion from " << input_type
1562 << " to " << result_type;
1563 }
1564 break;
1565
Roland Levillain946e1432014-11-11 17:35:19 +00001566 case Primitive::kPrimInt:
1567 switch (input_type) {
1568 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001569 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001570 locations->SetInAt(0, Location::Any());
1571 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1572 break;
1573
1574 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001575 // Processing a Dex `float-to-int' instruction.
1576 locations->SetInAt(0, Location::RequiresFpuRegister());
1577 locations->SetOut(Location::RequiresRegister());
1578 locations->AddTemp(Location::RequiresFpuRegister());
1579 break;
1580
Roland Levillain946e1432014-11-11 17:35:19 +00001581 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001582 // Processing a Dex `double-to-int' instruction.
1583 locations->SetInAt(0, Location::RequiresFpuRegister());
1584 locations->SetOut(Location::RequiresRegister());
1585 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001586 break;
1587
1588 default:
1589 LOG(FATAL) << "Unexpected type conversion from " << input_type
1590 << " to " << result_type;
1591 }
1592 break;
1593
Roland Levillaindff1f282014-11-05 14:15:05 +00001594 case Primitive::kPrimLong:
1595 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001596 case Primitive::kPrimBoolean:
1597 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001598 case Primitive::kPrimByte:
1599 case Primitive::kPrimShort:
1600 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001601 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001602 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001603 locations->SetInAt(0, Location::RequiresRegister());
1604 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1605 break;
1606
Roland Levillain624279f2014-12-04 11:54:28 +00001607 case Primitive::kPrimFloat: {
1608 // Processing a Dex `float-to-long' instruction.
1609 InvokeRuntimeCallingConvention calling_convention;
1610 locations->SetInAt(0, Location::FpuRegisterLocation(
1611 calling_convention.GetFpuRegisterAt(0)));
1612 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1613 break;
1614 }
1615
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001616 case Primitive::kPrimDouble: {
1617 // Processing a Dex `double-to-long' instruction.
1618 InvokeRuntimeCallingConvention calling_convention;
1619 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1620 calling_convention.GetFpuRegisterAt(0),
1621 calling_convention.GetFpuRegisterAt(1)));
1622 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001623 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001624 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001625
1626 default:
1627 LOG(FATAL) << "Unexpected type conversion from " << input_type
1628 << " to " << result_type;
1629 }
1630 break;
1631
Roland Levillain981e4542014-11-14 11:47:14 +00001632 case Primitive::kPrimChar:
1633 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001634 case Primitive::kPrimBoolean:
1635 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001636 case Primitive::kPrimByte:
1637 case Primitive::kPrimShort:
1638 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001639 // Processing a Dex `int-to-char' instruction.
1640 locations->SetInAt(0, Location::RequiresRegister());
1641 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1642 break;
1643
1644 default:
1645 LOG(FATAL) << "Unexpected type conversion from " << input_type
1646 << " to " << result_type;
1647 }
1648 break;
1649
Roland Levillaindff1f282014-11-05 14:15:05 +00001650 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001651 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001652 case Primitive::kPrimBoolean:
1653 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001654 case Primitive::kPrimByte:
1655 case Primitive::kPrimShort:
1656 case Primitive::kPrimInt:
1657 case Primitive::kPrimChar:
1658 // Processing a Dex `int-to-float' instruction.
1659 locations->SetInAt(0, Location::RequiresRegister());
1660 locations->SetOut(Location::RequiresFpuRegister());
1661 break;
1662
Roland Levillain5b3ee562015-04-14 16:02:41 +01001663 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001664 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001665 InvokeRuntimeCallingConvention calling_convention;
1666 locations->SetInAt(0, Location::RegisterPairLocation(
1667 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1668 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001669 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001670 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001671
Roland Levillaincff13742014-11-17 14:32:17 +00001672 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001673 // Processing a Dex `double-to-float' instruction.
1674 locations->SetInAt(0, Location::RequiresFpuRegister());
1675 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001676 break;
1677
1678 default:
1679 LOG(FATAL) << "Unexpected type conversion from " << input_type
1680 << " to " << result_type;
1681 };
1682 break;
1683
Roland Levillaindff1f282014-11-05 14:15:05 +00001684 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001685 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001686 case Primitive::kPrimBoolean:
1687 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001688 case Primitive::kPrimByte:
1689 case Primitive::kPrimShort:
1690 case Primitive::kPrimInt:
1691 case Primitive::kPrimChar:
1692 // Processing a Dex `int-to-double' instruction.
1693 locations->SetInAt(0, Location::RequiresRegister());
1694 locations->SetOut(Location::RequiresFpuRegister());
1695 break;
1696
1697 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001698 // Processing a Dex `long-to-double' instruction.
1699 locations->SetInAt(0, Location::RequiresRegister());
1700 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001701 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001702 locations->AddTemp(Location::RequiresFpuRegister());
1703 break;
1704
Roland Levillaincff13742014-11-17 14:32:17 +00001705 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001706 // Processing a Dex `float-to-double' instruction.
1707 locations->SetInAt(0, Location::RequiresFpuRegister());
1708 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001709 break;
1710
1711 default:
1712 LOG(FATAL) << "Unexpected type conversion from " << input_type
1713 << " to " << result_type;
1714 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001715 break;
1716
1717 default:
1718 LOG(FATAL) << "Unexpected type conversion from " << input_type
1719 << " to " << result_type;
1720 }
1721}
1722
1723void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1724 LocationSummary* locations = conversion->GetLocations();
1725 Location out = locations->Out();
1726 Location in = locations->InAt(0);
1727 Primitive::Type result_type = conversion->GetResultType();
1728 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001729 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001730 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001731 case Primitive::kPrimByte:
1732 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001733 case Primitive::kPrimBoolean:
1734 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001735 case Primitive::kPrimShort:
1736 case Primitive::kPrimInt:
1737 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001738 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001739 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001740 break;
1741
1742 default:
1743 LOG(FATAL) << "Unexpected type conversion from " << input_type
1744 << " to " << result_type;
1745 }
1746 break;
1747
Roland Levillain01a8d712014-11-14 16:27:39 +00001748 case Primitive::kPrimShort:
1749 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001750 case Primitive::kPrimBoolean:
1751 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001752 case Primitive::kPrimByte:
1753 case Primitive::kPrimInt:
1754 case Primitive::kPrimChar:
1755 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001756 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001757 break;
1758
1759 default:
1760 LOG(FATAL) << "Unexpected type conversion from " << input_type
1761 << " to " << result_type;
1762 }
1763 break;
1764
Roland Levillain946e1432014-11-11 17:35:19 +00001765 case Primitive::kPrimInt:
1766 switch (input_type) {
1767 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001768 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001769 DCHECK(out.IsRegister());
1770 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001771 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001772 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001773 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001774 } else {
1775 DCHECK(in.IsConstant());
1776 DCHECK(in.GetConstant()->IsLongConstant());
1777 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001778 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001779 }
1780 break;
1781
Roland Levillain3f8f9362014-12-02 17:45:01 +00001782 case Primitive::kPrimFloat: {
1783 // Processing a Dex `float-to-int' instruction.
1784 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1785 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1786 __ vcvtis(temp, temp);
1787 __ vmovrs(out.AsRegister<Register>(), temp);
1788 break;
1789 }
1790
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001791 case Primitive::kPrimDouble: {
1792 // Processing a Dex `double-to-int' instruction.
1793 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1794 DRegister temp_d = FromLowSToD(temp_s);
1795 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1796 __ vcvtid(temp_s, temp_d);
1797 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001798 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001799 }
Roland Levillain946e1432014-11-11 17:35:19 +00001800
1801 default:
1802 LOG(FATAL) << "Unexpected type conversion from " << input_type
1803 << " to " << result_type;
1804 }
1805 break;
1806
Roland Levillaindff1f282014-11-05 14:15:05 +00001807 case Primitive::kPrimLong:
1808 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001809 case Primitive::kPrimBoolean:
1810 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001811 case Primitive::kPrimByte:
1812 case Primitive::kPrimShort:
1813 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001814 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001815 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001816 DCHECK(out.IsRegisterPair());
1817 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001818 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001819 // Sign extension.
1820 __ Asr(out.AsRegisterPairHigh<Register>(),
1821 out.AsRegisterPairLow<Register>(),
1822 31);
1823 break;
1824
1825 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001826 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001827 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1828 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001829 conversion->GetDexPc(),
1830 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001831 break;
1832
Roland Levillaindff1f282014-11-05 14:15:05 +00001833 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001834 // Processing a Dex `double-to-long' instruction.
1835 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1836 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001837 conversion->GetDexPc(),
1838 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001839 break;
1840
1841 default:
1842 LOG(FATAL) << "Unexpected type conversion from " << input_type
1843 << " to " << result_type;
1844 }
1845 break;
1846
Roland Levillain981e4542014-11-14 11:47:14 +00001847 case Primitive::kPrimChar:
1848 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001849 case Primitive::kPrimBoolean:
1850 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001851 case Primitive::kPrimByte:
1852 case Primitive::kPrimShort:
1853 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001854 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001855 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001856 break;
1857
1858 default:
1859 LOG(FATAL) << "Unexpected type conversion from " << input_type
1860 << " to " << result_type;
1861 }
1862 break;
1863
Roland Levillaindff1f282014-11-05 14:15:05 +00001864 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001865 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001866 case Primitive::kPrimBoolean:
1867 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001868 case Primitive::kPrimByte:
1869 case Primitive::kPrimShort:
1870 case Primitive::kPrimInt:
1871 case Primitive::kPrimChar: {
1872 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001873 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1874 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001875 break;
1876 }
1877
Roland Levillain5b3ee562015-04-14 16:02:41 +01001878 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001879 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001880 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
1881 conversion,
1882 conversion->GetDexPc(),
1883 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001884 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00001885
Roland Levillaincff13742014-11-17 14:32:17 +00001886 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001887 // Processing a Dex `double-to-float' instruction.
1888 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1889 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001890 break;
1891
1892 default:
1893 LOG(FATAL) << "Unexpected type conversion from " << input_type
1894 << " to " << result_type;
1895 };
1896 break;
1897
Roland Levillaindff1f282014-11-05 14:15:05 +00001898 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001899 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001900 case Primitive::kPrimBoolean:
1901 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001902 case Primitive::kPrimByte:
1903 case Primitive::kPrimShort:
1904 case Primitive::kPrimInt:
1905 case Primitive::kPrimChar: {
1906 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001907 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001908 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1909 out.AsFpuRegisterPairLow<SRegister>());
1910 break;
1911 }
1912
Roland Levillain647b9ed2014-11-27 12:06:00 +00001913 case Primitive::kPrimLong: {
1914 // Processing a Dex `long-to-double' instruction.
1915 Register low = in.AsRegisterPairLow<Register>();
1916 Register high = in.AsRegisterPairHigh<Register>();
1917 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1918 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001919 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001920 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001921 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
1922 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001923
Roland Levillain682393c2015-04-14 15:57:52 +01001924 // temp_d = int-to-double(high)
1925 __ vmovsr(temp_s, high);
1926 __ vcvtdi(temp_d, temp_s);
1927 // constant_d = k2Pow32EncodingForDouble
1928 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
1929 // out_d = unsigned-to-double(low)
1930 __ vmovsr(out_s, low);
1931 __ vcvtdu(out_d, out_s);
1932 // out_d += temp_d * constant_d
1933 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001934 break;
1935 }
1936
Roland Levillaincff13742014-11-17 14:32:17 +00001937 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001938 // Processing a Dex `float-to-double' instruction.
1939 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1940 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001941 break;
1942
1943 default:
1944 LOG(FATAL) << "Unexpected type conversion from " << input_type
1945 << " to " << result_type;
1946 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001947 break;
1948
1949 default:
1950 LOG(FATAL) << "Unexpected type conversion from " << input_type
1951 << " to " << result_type;
1952 }
1953}
1954
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001955void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001956 LocationSummary* locations =
1957 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001958 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001959 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001960 locations->SetInAt(0, Location::RequiresRegister());
1961 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001962 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1963 break;
1964 }
1965
1966 case Primitive::kPrimLong: {
1967 locations->SetInAt(0, Location::RequiresRegister());
1968 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001969 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001970 break;
1971 }
1972
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001973 case Primitive::kPrimFloat:
1974 case Primitive::kPrimDouble: {
1975 locations->SetInAt(0, Location::RequiresFpuRegister());
1976 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001977 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001978 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001979 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001980
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001981 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001982 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001983 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001984}
1985
1986void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1987 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001988 Location out = locations->Out();
1989 Location first = locations->InAt(0);
1990 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001991 switch (add->GetResultType()) {
1992 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001993 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001994 __ add(out.AsRegister<Register>(),
1995 first.AsRegister<Register>(),
1996 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001997 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001998 __ AddConstant(out.AsRegister<Register>(),
1999 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002000 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002001 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002002 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002003
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002004 case Primitive::kPrimLong: {
2005 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002006 __ adds(out.AsRegisterPairLow<Register>(),
2007 first.AsRegisterPairLow<Register>(),
2008 ShifterOperand(second.AsRegisterPairLow<Register>()));
2009 __ adc(out.AsRegisterPairHigh<Register>(),
2010 first.AsRegisterPairHigh<Register>(),
2011 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002012 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002013 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002014
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002015 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002016 __ vadds(out.AsFpuRegister<SRegister>(),
2017 first.AsFpuRegister<SRegister>(),
2018 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002019 break;
2020
2021 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002022 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2023 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2024 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002025 break;
2026
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002027 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002028 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002029 }
2030}
2031
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002032void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002033 LocationSummary* locations =
2034 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002035 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002036 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002037 locations->SetInAt(0, Location::RequiresRegister());
2038 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002039 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2040 break;
2041 }
2042
2043 case Primitive::kPrimLong: {
2044 locations->SetInAt(0, Location::RequiresRegister());
2045 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002046 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002047 break;
2048 }
Calin Juravle11351682014-10-23 15:38:15 +01002049 case Primitive::kPrimFloat:
2050 case Primitive::kPrimDouble: {
2051 locations->SetInAt(0, Location::RequiresFpuRegister());
2052 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002053 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002054 break;
Calin Juravle11351682014-10-23 15:38:15 +01002055 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002056 default:
Calin Juravle11351682014-10-23 15:38:15 +01002057 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002058 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002059}
2060
2061void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2062 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002063 Location out = locations->Out();
2064 Location first = locations->InAt(0);
2065 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002066 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002067 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002068 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002069 __ sub(out.AsRegister<Register>(),
2070 first.AsRegister<Register>(),
2071 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002072 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002073 __ AddConstant(out.AsRegister<Register>(),
2074 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002075 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002076 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002077 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002078 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002079
Calin Juravle11351682014-10-23 15:38:15 +01002080 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002081 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002082 __ subs(out.AsRegisterPairLow<Register>(),
2083 first.AsRegisterPairLow<Register>(),
2084 ShifterOperand(second.AsRegisterPairLow<Register>()));
2085 __ sbc(out.AsRegisterPairHigh<Register>(),
2086 first.AsRegisterPairHigh<Register>(),
2087 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002088 break;
Calin Juravle11351682014-10-23 15:38:15 +01002089 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002090
Calin Juravle11351682014-10-23 15:38:15 +01002091 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002092 __ vsubs(out.AsFpuRegister<SRegister>(),
2093 first.AsFpuRegister<SRegister>(),
2094 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002095 break;
Calin Juravle11351682014-10-23 15:38:15 +01002096 }
2097
2098 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002099 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2100 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2101 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002102 break;
2103 }
2104
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002105
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002106 default:
Calin Juravle11351682014-10-23 15:38:15 +01002107 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002108 }
2109}
2110
Calin Juravle34bacdf2014-10-07 20:23:36 +01002111void LocationsBuilderARM::VisitMul(HMul* mul) {
2112 LocationSummary* locations =
2113 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2114 switch (mul->GetResultType()) {
2115 case Primitive::kPrimInt:
2116 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002117 locations->SetInAt(0, Location::RequiresRegister());
2118 locations->SetInAt(1, Location::RequiresRegister());
2119 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002120 break;
2121 }
2122
Calin Juravleb5bfa962014-10-21 18:02:24 +01002123 case Primitive::kPrimFloat:
2124 case Primitive::kPrimDouble: {
2125 locations->SetInAt(0, Location::RequiresFpuRegister());
2126 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002127 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002128 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002129 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002130
2131 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002132 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002133 }
2134}
2135
2136void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2137 LocationSummary* locations = mul->GetLocations();
2138 Location out = locations->Out();
2139 Location first = locations->InAt(0);
2140 Location second = locations->InAt(1);
2141 switch (mul->GetResultType()) {
2142 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002143 __ mul(out.AsRegister<Register>(),
2144 first.AsRegister<Register>(),
2145 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002146 break;
2147 }
2148 case Primitive::kPrimLong: {
2149 Register out_hi = out.AsRegisterPairHigh<Register>();
2150 Register out_lo = out.AsRegisterPairLow<Register>();
2151 Register in1_hi = first.AsRegisterPairHigh<Register>();
2152 Register in1_lo = first.AsRegisterPairLow<Register>();
2153 Register in2_hi = second.AsRegisterPairHigh<Register>();
2154 Register in2_lo = second.AsRegisterPairLow<Register>();
2155
2156 // Extra checks to protect caused by the existence of R1_R2.
2157 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2158 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2159 DCHECK_NE(out_hi, in1_lo);
2160 DCHECK_NE(out_hi, in2_lo);
2161
2162 // input: in1 - 64 bits, in2 - 64 bits
2163 // output: out
2164 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2165 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2166 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2167
2168 // IP <- in1.lo * in2.hi
2169 __ mul(IP, in1_lo, in2_hi);
2170 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2171 __ mla(out_hi, in1_hi, in2_lo, IP);
2172 // out.lo <- (in1.lo * in2.lo)[31:0];
2173 __ umull(out_lo, IP, in1_lo, in2_lo);
2174 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2175 __ add(out_hi, out_hi, ShifterOperand(IP));
2176 break;
2177 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002178
2179 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002180 __ vmuls(out.AsFpuRegister<SRegister>(),
2181 first.AsFpuRegister<SRegister>(),
2182 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002183 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002184 }
2185
2186 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002187 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2188 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2189 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002190 break;
2191 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002192
2193 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002194 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002195 }
2196}
2197
Zheng Xuc6667102015-05-15 16:08:45 +08002198void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2199 DCHECK(instruction->IsDiv() || instruction->IsRem());
2200 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2201
2202 LocationSummary* locations = instruction->GetLocations();
2203 Location second = locations->InAt(1);
2204 DCHECK(second.IsConstant());
2205
2206 Register out = locations->Out().AsRegister<Register>();
2207 Register dividend = locations->InAt(0).AsRegister<Register>();
2208 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2209 DCHECK(imm == 1 || imm == -1);
2210
2211 if (instruction->IsRem()) {
2212 __ LoadImmediate(out, 0);
2213 } else {
2214 if (imm == 1) {
2215 __ Mov(out, dividend);
2216 } else {
2217 __ rsb(out, dividend, ShifterOperand(0));
2218 }
2219 }
2220}
2221
2222void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2223 DCHECK(instruction->IsDiv() || instruction->IsRem());
2224 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2225
2226 LocationSummary* locations = instruction->GetLocations();
2227 Location second = locations->InAt(1);
2228 DCHECK(second.IsConstant());
2229
2230 Register out = locations->Out().AsRegister<Register>();
2231 Register dividend = locations->InAt(0).AsRegister<Register>();
2232 Register temp = locations->GetTemp(0).AsRegister<Register>();
2233 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002234 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002235 DCHECK(IsPowerOfTwo(abs_imm));
2236 int ctz_imm = CTZ(abs_imm);
2237
2238 if (ctz_imm == 1) {
2239 __ Lsr(temp, dividend, 32 - ctz_imm);
2240 } else {
2241 __ Asr(temp, dividend, 31);
2242 __ Lsr(temp, temp, 32 - ctz_imm);
2243 }
2244 __ add(out, temp, ShifterOperand(dividend));
2245
2246 if (instruction->IsDiv()) {
2247 __ Asr(out, out, ctz_imm);
2248 if (imm < 0) {
2249 __ rsb(out, out, ShifterOperand(0));
2250 }
2251 } else {
2252 __ ubfx(out, out, 0, ctz_imm);
2253 __ sub(out, out, ShifterOperand(temp));
2254 }
2255}
2256
2257void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2258 DCHECK(instruction->IsDiv() || instruction->IsRem());
2259 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2260
2261 LocationSummary* locations = instruction->GetLocations();
2262 Location second = locations->InAt(1);
2263 DCHECK(second.IsConstant());
2264
2265 Register out = locations->Out().AsRegister<Register>();
2266 Register dividend = locations->InAt(0).AsRegister<Register>();
2267 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2268 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2269 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2270
2271 int64_t magic;
2272 int shift;
2273 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2274
2275 __ LoadImmediate(temp1, magic);
2276 __ smull(temp2, temp1, dividend, temp1);
2277
2278 if (imm > 0 && magic < 0) {
2279 __ add(temp1, temp1, ShifterOperand(dividend));
2280 } else if (imm < 0 && magic > 0) {
2281 __ sub(temp1, temp1, ShifterOperand(dividend));
2282 }
2283
2284 if (shift != 0) {
2285 __ Asr(temp1, temp1, shift);
2286 }
2287
2288 if (instruction->IsDiv()) {
2289 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2290 } else {
2291 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2292 // TODO: Strength reduction for mls.
2293 __ LoadImmediate(temp2, imm);
2294 __ mls(out, temp1, temp2, dividend);
2295 }
2296}
2297
2298void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2299 DCHECK(instruction->IsDiv() || instruction->IsRem());
2300 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2301
2302 LocationSummary* locations = instruction->GetLocations();
2303 Location second = locations->InAt(1);
2304 DCHECK(second.IsConstant());
2305
2306 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2307 if (imm == 0) {
2308 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2309 } else if (imm == 1 || imm == -1) {
2310 DivRemOneOrMinusOne(instruction);
2311 } else if (IsPowerOfTwo(std::abs(imm))) {
2312 DivRemByPowerOfTwo(instruction);
2313 } else {
2314 DCHECK(imm <= -2 || imm >= 2);
2315 GenerateDivRemWithAnyConstant(instruction);
2316 }
2317}
2318
Calin Juravle7c4954d2014-10-28 16:57:40 +00002319void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002320 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2321 if (div->GetResultType() == Primitive::kPrimLong) {
2322 // pLdiv runtime call.
2323 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002324 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2325 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002326 } else if (div->GetResultType() == Primitive::kPrimInt &&
2327 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2328 // pIdivmod runtime call.
2329 call_kind = LocationSummary::kCall;
2330 }
2331
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002332 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2333
Calin Juravle7c4954d2014-10-28 16:57:40 +00002334 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002335 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002336 if (div->InputAt(1)->IsConstant()) {
2337 locations->SetInAt(0, Location::RequiresRegister());
2338 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2339 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2340 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2341 if (abs_imm <= 1) {
2342 // No temp register required.
2343 } else {
2344 locations->AddTemp(Location::RequiresRegister());
2345 if (!IsPowerOfTwo(abs_imm)) {
2346 locations->AddTemp(Location::RequiresRegister());
2347 }
2348 }
2349 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002350 locations->SetInAt(0, Location::RequiresRegister());
2351 locations->SetInAt(1, Location::RequiresRegister());
2352 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2353 } else {
2354 InvokeRuntimeCallingConvention calling_convention;
2355 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2356 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2357 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2358 // we only need the former.
2359 locations->SetOut(Location::RegisterLocation(R0));
2360 }
Calin Juravled0d48522014-11-04 16:40:20 +00002361 break;
2362 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002363 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002364 InvokeRuntimeCallingConvention calling_convention;
2365 locations->SetInAt(0, Location::RegisterPairLocation(
2366 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2367 locations->SetInAt(1, Location::RegisterPairLocation(
2368 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002369 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002370 break;
2371 }
2372 case Primitive::kPrimFloat:
2373 case Primitive::kPrimDouble: {
2374 locations->SetInAt(0, Location::RequiresFpuRegister());
2375 locations->SetInAt(1, Location::RequiresFpuRegister());
2376 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2377 break;
2378 }
2379
2380 default:
2381 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2382 }
2383}
2384
2385void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2386 LocationSummary* locations = div->GetLocations();
2387 Location out = locations->Out();
2388 Location first = locations->InAt(0);
2389 Location second = locations->InAt(1);
2390
2391 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002392 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002393 if (second.IsConstant()) {
2394 GenerateDivRemConstantIntegral(div);
2395 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002396 __ sdiv(out.AsRegister<Register>(),
2397 first.AsRegister<Register>(),
2398 second.AsRegister<Register>());
2399 } else {
2400 InvokeRuntimeCallingConvention calling_convention;
2401 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2402 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2403 DCHECK_EQ(R0, out.AsRegister<Register>());
2404
2405 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2406 }
Calin Juravled0d48522014-11-04 16:40:20 +00002407 break;
2408 }
2409
Calin Juravle7c4954d2014-10-28 16:57:40 +00002410 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002411 InvokeRuntimeCallingConvention calling_convention;
2412 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2413 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2414 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2415 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2416 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002417 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002418
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002419 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002420 break;
2421 }
2422
2423 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002424 __ vdivs(out.AsFpuRegister<SRegister>(),
2425 first.AsFpuRegister<SRegister>(),
2426 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002427 break;
2428 }
2429
2430 case Primitive::kPrimDouble: {
2431 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2432 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2433 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2434 break;
2435 }
2436
2437 default:
2438 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2439 }
2440}
2441
Calin Juravlebacfec32014-11-14 15:54:36 +00002442void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002443 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002444
2445 // Most remainders are implemented in the runtime.
2446 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002447 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2448 // sdiv will be replaced by other instruction sequence.
2449 call_kind = LocationSummary::kNoCall;
2450 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2451 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002452 // Have hardware divide instruction for int, do it with three instructions.
2453 call_kind = LocationSummary::kNoCall;
2454 }
2455
Calin Juravlebacfec32014-11-14 15:54:36 +00002456 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2457
Calin Juravled2ec87d2014-12-08 14:24:46 +00002458 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002459 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002460 if (rem->InputAt(1)->IsConstant()) {
2461 locations->SetInAt(0, Location::RequiresRegister());
2462 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2463 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2464 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2465 if (abs_imm <= 1) {
2466 // No temp register required.
2467 } else {
2468 locations->AddTemp(Location::RequiresRegister());
2469 if (!IsPowerOfTwo(abs_imm)) {
2470 locations->AddTemp(Location::RequiresRegister());
2471 }
2472 }
2473 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002474 locations->SetInAt(0, Location::RequiresRegister());
2475 locations->SetInAt(1, Location::RequiresRegister());
2476 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2477 locations->AddTemp(Location::RequiresRegister());
2478 } else {
2479 InvokeRuntimeCallingConvention calling_convention;
2480 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2481 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2482 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2483 // we only need the latter.
2484 locations->SetOut(Location::RegisterLocation(R1));
2485 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002486 break;
2487 }
2488 case Primitive::kPrimLong: {
2489 InvokeRuntimeCallingConvention calling_convention;
2490 locations->SetInAt(0, Location::RegisterPairLocation(
2491 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2492 locations->SetInAt(1, Location::RegisterPairLocation(
2493 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2494 // The runtime helper puts the output in R2,R3.
2495 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2496 break;
2497 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002498 case Primitive::kPrimFloat: {
2499 InvokeRuntimeCallingConvention calling_convention;
2500 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2501 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2502 locations->SetOut(Location::FpuRegisterLocation(S0));
2503 break;
2504 }
2505
Calin Juravlebacfec32014-11-14 15:54:36 +00002506 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002507 InvokeRuntimeCallingConvention calling_convention;
2508 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2509 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2510 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2511 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2512 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002513 break;
2514 }
2515
2516 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002517 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002518 }
2519}
2520
2521void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2522 LocationSummary* locations = rem->GetLocations();
2523 Location out = locations->Out();
2524 Location first = locations->InAt(0);
2525 Location second = locations->InAt(1);
2526
Calin Juravled2ec87d2014-12-08 14:24:46 +00002527 Primitive::Type type = rem->GetResultType();
2528 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002529 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002530 if (second.IsConstant()) {
2531 GenerateDivRemConstantIntegral(rem);
2532 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002533 Register reg1 = first.AsRegister<Register>();
2534 Register reg2 = second.AsRegister<Register>();
2535 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002536
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002537 // temp = reg1 / reg2 (integer division)
2538 // temp = temp * reg2
2539 // dest = reg1 - temp
2540 __ sdiv(temp, reg1, reg2);
2541 __ mul(temp, temp, reg2);
2542 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2543 } else {
2544 InvokeRuntimeCallingConvention calling_convention;
2545 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2546 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2547 DCHECK_EQ(R1, out.AsRegister<Register>());
2548
2549 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2550 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002551 break;
2552 }
2553
2554 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002555 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002556 break;
2557 }
2558
Calin Juravled2ec87d2014-12-08 14:24:46 +00002559 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002560 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002561 break;
2562 }
2563
Calin Juravlebacfec32014-11-14 15:54:36 +00002564 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002565 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002566 break;
2567 }
2568
2569 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002570 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002571 }
2572}
2573
Calin Juravled0d48522014-11-04 16:40:20 +00002574void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2575 LocationSummary* locations =
2576 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002577 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002578 if (instruction->HasUses()) {
2579 locations->SetOut(Location::SameAsFirstInput());
2580 }
2581}
2582
2583void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2584 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2585 codegen_->AddSlowPath(slow_path);
2586
2587 LocationSummary* locations = instruction->GetLocations();
2588 Location value = locations->InAt(0);
2589
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002590 switch (instruction->GetType()) {
2591 case Primitive::kPrimInt: {
2592 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01002593 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002594 } else {
2595 DCHECK(value.IsConstant()) << value;
2596 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2597 __ b(slow_path->GetEntryLabel());
2598 }
2599 }
2600 break;
2601 }
2602 case Primitive::kPrimLong: {
2603 if (value.IsRegisterPair()) {
2604 __ orrs(IP,
2605 value.AsRegisterPairLow<Register>(),
2606 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2607 __ b(slow_path->GetEntryLabel(), EQ);
2608 } else {
2609 DCHECK(value.IsConstant()) << value;
2610 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2611 __ b(slow_path->GetEntryLabel());
2612 }
2613 }
2614 break;
2615 default:
2616 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2617 }
2618 }
Calin Juravled0d48522014-11-04 16:40:20 +00002619}
2620
Calin Juravle9aec02f2014-11-18 23:06:35 +00002621void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2622 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2623
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002624 LocationSummary* locations =
2625 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002626
2627 switch (op->GetResultType()) {
2628 case Primitive::kPrimInt: {
2629 locations->SetInAt(0, Location::RequiresRegister());
2630 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002631 // Make the output overlap, as it will be used to hold the masked
2632 // second input.
2633 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002634 break;
2635 }
2636 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002637 locations->SetInAt(0, Location::RequiresRegister());
2638 locations->SetInAt(1, Location::RequiresRegister());
2639 locations->AddTemp(Location::RequiresRegister());
2640 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002641 break;
2642 }
2643 default:
2644 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2645 }
2646}
2647
2648void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2649 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2650
2651 LocationSummary* locations = op->GetLocations();
2652 Location out = locations->Out();
2653 Location first = locations->InAt(0);
2654 Location second = locations->InAt(1);
2655
2656 Primitive::Type type = op->GetResultType();
2657 switch (type) {
2658 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002659 Register out_reg = out.AsRegister<Register>();
2660 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002661 // Arm doesn't mask the shift count so we need to do it ourselves.
2662 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002663 Register second_reg = second.AsRegister<Register>();
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002664 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002665 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002666 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002667 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002668 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002669 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002670 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002671 }
2672 } else {
2673 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2674 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2675 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2676 __ Mov(out_reg, first_reg);
2677 } else if (op->IsShl()) {
2678 __ Lsl(out_reg, first_reg, shift_value);
2679 } else if (op->IsShr()) {
2680 __ Asr(out_reg, first_reg, shift_value);
2681 } else {
2682 __ Lsr(out_reg, first_reg, shift_value);
2683 }
2684 }
2685 break;
2686 }
2687 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002688 Register o_h = out.AsRegisterPairHigh<Register>();
2689 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002690
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002691 Register temp = locations->GetTemp(0).AsRegister<Register>();
2692
2693 Register high = first.AsRegisterPairHigh<Register>();
2694 Register low = first.AsRegisterPairLow<Register>();
2695
2696 Register second_reg = second.AsRegister<Register>();
2697
Calin Juravle9aec02f2014-11-18 23:06:35 +00002698 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002699 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002700 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002701 __ Lsl(o_h, high, o_l);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002702 // Shift the low part and `or` what overflew on the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002703 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002704 __ Lsr(temp, low, temp);
2705 __ orr(o_h, o_h, ShifterOperand(temp));
2706 // If the shift is > 32 bits, override the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002707 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002708 __ it(PL);
2709 __ Lsl(o_h, low, temp, false, PL);
2710 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002711 __ Lsl(o_l, low, o_l);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002712 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002713 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002714 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002715 __ Lsr(o_l, low, o_h);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002716 // Shift the high part and `or` what underflew on the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002717 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002718 __ Lsl(temp, high, temp);
2719 __ orr(o_l, o_l, ShifterOperand(temp));
2720 // If the shift is > 32 bits, override the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002721 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002722 __ it(PL);
2723 __ Asr(o_l, high, temp, false, PL);
2724 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002725 __ Asr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002726 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002727 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002728 // same as Shr except we use `Lsr`s and not `Asr`s
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002729 __ Lsr(o_l, low, o_h);
2730 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002731 __ Lsl(temp, high, temp);
2732 __ orr(o_l, o_l, ShifterOperand(temp));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002733 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002734 __ it(PL);
2735 __ Lsr(o_l, high, temp, false, PL);
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002736 __ Lsr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002737 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002738 break;
2739 }
2740 default:
2741 LOG(FATAL) << "Unexpected operation type " << type;
2742 }
2743}
2744
2745void LocationsBuilderARM::VisitShl(HShl* shl) {
2746 HandleShift(shl);
2747}
2748
2749void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2750 HandleShift(shl);
2751}
2752
2753void LocationsBuilderARM::VisitShr(HShr* shr) {
2754 HandleShift(shr);
2755}
2756
2757void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2758 HandleShift(shr);
2759}
2760
2761void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2762 HandleShift(ushr);
2763}
2764
2765void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2766 HandleShift(ushr);
2767}
2768
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002769void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002770 LocationSummary* locations =
2771 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002772 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002773 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002774 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002775 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002776}
2777
2778void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2779 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002780 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01002781 // Note: if heap poisoning is enabled, the entry point takes cares
2782 // of poisoning the reference.
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002783 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2784 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002785 instruction->GetDexPc(),
2786 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002787}
2788
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002789void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2790 LocationSummary* locations =
2791 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2792 InvokeRuntimeCallingConvention calling_convention;
2793 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002794 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002795 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002796 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002797}
2798
2799void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2800 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002801 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01002802 // Note: if heap poisoning is enabled, the entry point takes cares
2803 // of poisoning the reference.
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002804 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2805 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002806 instruction->GetDexPc(),
2807 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002808}
2809
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002810void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002811 LocationSummary* locations =
2812 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002813 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2814 if (location.IsStackSlot()) {
2815 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2816 } else if (location.IsDoubleStackSlot()) {
2817 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002818 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002819 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002820}
2821
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002822void InstructionCodeGeneratorARM::VisitParameterValue(
2823 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002824 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002825}
2826
2827void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
2828 LocationSummary* locations =
2829 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2830 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2831}
2832
2833void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2834 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002835}
2836
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002837void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002838 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002839 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002840 locations->SetInAt(0, Location::RequiresRegister());
2841 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002842}
2843
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002844void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2845 LocationSummary* locations = not_->GetLocations();
2846 Location out = locations->Out();
2847 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002848 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002849 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002850 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002851 break;
2852
2853 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002854 __ mvn(out.AsRegisterPairLow<Register>(),
2855 ShifterOperand(in.AsRegisterPairLow<Register>()));
2856 __ mvn(out.AsRegisterPairHigh<Register>(),
2857 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002858 break;
2859
2860 default:
2861 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2862 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002863}
2864
David Brazdil66d126e2015-04-03 16:02:44 +01002865void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2866 LocationSummary* locations =
2867 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2868 locations->SetInAt(0, Location::RequiresRegister());
2869 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2870}
2871
2872void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002873 LocationSummary* locations = bool_not->GetLocations();
2874 Location out = locations->Out();
2875 Location in = locations->InAt(0);
2876 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2877}
2878
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002879void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002880 LocationSummary* locations =
2881 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002882 switch (compare->InputAt(0)->GetType()) {
2883 case Primitive::kPrimLong: {
2884 locations->SetInAt(0, Location::RequiresRegister());
2885 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002886 // Output overlaps because it is written before doing the low comparison.
2887 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002888 break;
2889 }
2890 case Primitive::kPrimFloat:
2891 case Primitive::kPrimDouble: {
2892 locations->SetInAt(0, Location::RequiresFpuRegister());
2893 locations->SetInAt(1, Location::RequiresFpuRegister());
2894 locations->SetOut(Location::RequiresRegister());
2895 break;
2896 }
2897 default:
2898 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2899 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002900}
2901
2902void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002903 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002904 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002905 Location left = locations->InAt(0);
2906 Location right = locations->InAt(1);
2907
Vladimir Markocf93a5c2015-06-16 11:33:24 +00002908 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00002909 Primitive::Type type = compare->InputAt(0)->GetType();
2910 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002911 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002912 __ cmp(left.AsRegisterPairHigh<Register>(),
2913 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002914 __ b(&less, LT);
2915 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002916 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2917 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002918 __ cmp(left.AsRegisterPairLow<Register>(),
2919 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002920 break;
2921 }
2922 case Primitive::kPrimFloat:
2923 case Primitive::kPrimDouble: {
2924 __ LoadImmediate(out, 0);
2925 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002926 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002927 } else {
2928 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2929 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2930 }
2931 __ vmstat(); // transfer FP status register to ARM APSR.
2932 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002933 break;
2934 }
2935 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002936 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002937 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002938 __ b(&done, EQ);
2939 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2940
2941 __ Bind(&greater);
2942 __ LoadImmediate(out, 1);
2943 __ b(&done);
2944
2945 __ Bind(&less);
2946 __ LoadImmediate(out, -1);
2947
2948 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002949}
2950
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002951void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002952 LocationSummary* locations =
2953 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002954 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2955 locations->SetInAt(i, Location::Any());
2956 }
2957 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002958}
2959
2960void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002961 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002962 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002963}
2964
Calin Juravle52c48962014-12-16 17:02:57 +00002965void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2966 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07002967 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00002968 switch (kind) {
2969 case MemBarrierKind::kAnyStore:
2970 case MemBarrierKind::kLoadAny:
2971 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002972 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00002973 break;
2974 }
2975 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002976 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00002977 break;
2978 }
2979 default:
2980 LOG(FATAL) << "Unexpected memory barrier " << kind;
2981 }
Kenny Root1d8199d2015-06-02 11:01:10 -07002982 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00002983}
2984
2985void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2986 uint32_t offset,
2987 Register out_lo,
2988 Register out_hi) {
2989 if (offset != 0) {
2990 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002991 __ add(IP, addr, ShifterOperand(out_lo));
2992 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002993 }
2994 __ ldrexd(out_lo, out_hi, addr);
2995}
2996
2997void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2998 uint32_t offset,
2999 Register value_lo,
3000 Register value_hi,
3001 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003002 Register temp2,
3003 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003004 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003005 if (offset != 0) {
3006 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003007 __ add(IP, addr, ShifterOperand(temp1));
3008 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003009 }
3010 __ Bind(&fail);
3011 // We need a load followed by store. (The address used in a STREX instruction must
3012 // be the same as the address in the most recently executed LDREX instruction.)
3013 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003014 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003015 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003016 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003017}
3018
3019void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3020 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3021
Nicolas Geoffray39468442014-09-02 15:17:15 +01003022 LocationSummary* locations =
3023 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003024 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003025
Calin Juravle52c48962014-12-16 17:02:57 +00003026 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003027 if (Primitive::IsFloatingPointType(field_type)) {
3028 locations->SetInAt(1, Location::RequiresFpuRegister());
3029 } else {
3030 locations->SetInAt(1, Location::RequiresRegister());
3031 }
3032
Calin Juravle52c48962014-12-16 17:02:57 +00003033 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003034 bool generate_volatile = field_info.IsVolatile()
3035 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003036 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003037 bool needs_write_barrier =
3038 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003039 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003040 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003041 if (needs_write_barrier) {
3042 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003043 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003044 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003045 // Arm encoding have some additional constraints for ldrexd/strexd:
3046 // - registers need to be consecutive
3047 // - the first register should be even but not R14.
3048 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3049 // enable Arm encoding.
3050 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3051
3052 locations->AddTemp(Location::RequiresRegister());
3053 locations->AddTemp(Location::RequiresRegister());
3054 if (field_type == Primitive::kPrimDouble) {
3055 // For doubles we need two more registers to copy the value.
3056 locations->AddTemp(Location::RegisterLocation(R2));
3057 locations->AddTemp(Location::RegisterLocation(R3));
3058 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003059 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003060}
3061
Calin Juravle52c48962014-12-16 17:02:57 +00003062void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003063 const FieldInfo& field_info,
3064 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003065 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3066
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003067 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003068 Register base = locations->InAt(0).AsRegister<Register>();
3069 Location value = locations->InAt(1);
3070
3071 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003072 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003073 Primitive::Type field_type = field_info.GetFieldType();
3074 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003075 bool needs_write_barrier =
3076 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003077
3078 if (is_volatile) {
3079 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3080 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003081
3082 switch (field_type) {
3083 case Primitive::kPrimBoolean:
3084 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003085 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003086 break;
3087 }
3088
3089 case Primitive::kPrimShort:
3090 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003091 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003092 break;
3093 }
3094
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003095 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003096 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003097 if (kPoisonHeapReferences && needs_write_barrier) {
3098 // Note that in the case where `value` is a null reference,
3099 // we do not enter this block, as a null reference does not
3100 // need poisoning.
3101 DCHECK_EQ(field_type, Primitive::kPrimNot);
3102 Register temp = locations->GetTemp(0).AsRegister<Register>();
3103 __ Mov(temp, value.AsRegister<Register>());
3104 __ PoisonHeapReference(temp);
3105 __ StoreToOffset(kStoreWord, temp, base, offset);
3106 } else {
3107 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3108 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003109 break;
3110 }
3111
3112 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003113 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003114 GenerateWideAtomicStore(base, offset,
3115 value.AsRegisterPairLow<Register>(),
3116 value.AsRegisterPairHigh<Register>(),
3117 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003118 locations->GetTemp(1).AsRegister<Register>(),
3119 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003120 } else {
3121 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003122 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003123 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003124 break;
3125 }
3126
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003127 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003128 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003129 break;
3130 }
3131
3132 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003133 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003134 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003135 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3136 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3137
3138 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3139
3140 GenerateWideAtomicStore(base, offset,
3141 value_reg_lo,
3142 value_reg_hi,
3143 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003144 locations->GetTemp(3).AsRegister<Register>(),
3145 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003146 } else {
3147 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003148 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003149 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003150 break;
3151 }
3152
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003153 case Primitive::kPrimVoid:
3154 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003155 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003156 }
Calin Juravle52c48962014-12-16 17:02:57 +00003157
Calin Juravle77520bc2015-01-12 18:45:46 +00003158 // Longs and doubles are handled in the switch.
3159 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3160 codegen_->MaybeRecordImplicitNullCheck(instruction);
3161 }
3162
3163 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3164 Register temp = locations->GetTemp(0).AsRegister<Register>();
3165 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003166 codegen_->MarkGCCard(
3167 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003168 }
3169
Calin Juravle52c48962014-12-16 17:02:57 +00003170 if (is_volatile) {
3171 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3172 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003173}
3174
Calin Juravle52c48962014-12-16 17:02:57 +00003175void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3176 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003177 LocationSummary* locations =
3178 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003179 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003180
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003181 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003182 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003183 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003184 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003185
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003186 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3187 locations->SetOut(Location::RequiresFpuRegister());
3188 } else {
3189 locations->SetOut(Location::RequiresRegister(),
3190 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3191 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003192 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003193 // Arm encoding have some additional constraints for ldrexd/strexd:
3194 // - registers need to be consecutive
3195 // - the first register should be even but not R14.
3196 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3197 // enable Arm encoding.
3198 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3199 locations->AddTemp(Location::RequiresRegister());
3200 locations->AddTemp(Location::RequiresRegister());
3201 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003202}
3203
Calin Juravle52c48962014-12-16 17:02:57 +00003204void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3205 const FieldInfo& field_info) {
3206 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003207
Calin Juravle52c48962014-12-16 17:02:57 +00003208 LocationSummary* locations = instruction->GetLocations();
3209 Register base = locations->InAt(0).AsRegister<Register>();
3210 Location out = locations->Out();
3211 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003212 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003213 Primitive::Type field_type = field_info.GetFieldType();
3214 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3215
3216 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003217 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003218 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003219 break;
3220 }
3221
3222 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003223 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003224 break;
3225 }
3226
3227 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003228 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003229 break;
3230 }
3231
3232 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003233 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003234 break;
3235 }
3236
3237 case Primitive::kPrimInt:
3238 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003239 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003240 break;
3241 }
3242
3243 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003244 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003245 GenerateWideAtomicLoad(base, offset,
3246 out.AsRegisterPairLow<Register>(),
3247 out.AsRegisterPairHigh<Register>());
3248 } else {
3249 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3250 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003251 break;
3252 }
3253
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003254 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003255 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003256 break;
3257 }
3258
3259 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003260 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003261 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003262 Register lo = locations->GetTemp(0).AsRegister<Register>();
3263 Register hi = locations->GetTemp(1).AsRegister<Register>();
3264 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003265 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003266 __ vmovdrr(out_reg, lo, hi);
3267 } else {
3268 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003269 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003270 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003271 break;
3272 }
3273
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003274 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003275 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003276 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003277 }
Calin Juravle52c48962014-12-16 17:02:57 +00003278
Calin Juravle77520bc2015-01-12 18:45:46 +00003279 // Doubles are handled in the switch.
3280 if (field_type != Primitive::kPrimDouble) {
3281 codegen_->MaybeRecordImplicitNullCheck(instruction);
3282 }
3283
Calin Juravle52c48962014-12-16 17:02:57 +00003284 if (is_volatile) {
3285 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3286 }
Roland Levillain4d027112015-07-01 15:41:14 +01003287
3288 if (field_type == Primitive::kPrimNot) {
3289 __ MaybeUnpoisonHeapReference(out.AsRegister<Register>());
3290 }
Calin Juravle52c48962014-12-16 17:02:57 +00003291}
3292
3293void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3294 HandleFieldSet(instruction, instruction->GetFieldInfo());
3295}
3296
3297void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003298 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003299}
3300
3301void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3302 HandleFieldGet(instruction, instruction->GetFieldInfo());
3303}
3304
3305void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3306 HandleFieldGet(instruction, instruction->GetFieldInfo());
3307}
3308
3309void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3310 HandleFieldGet(instruction, instruction->GetFieldInfo());
3311}
3312
3313void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3314 HandleFieldGet(instruction, instruction->GetFieldInfo());
3315}
3316
3317void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3318 HandleFieldSet(instruction, instruction->GetFieldInfo());
3319}
3320
3321void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003322 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003323}
3324
3325void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003326 LocationSummary* locations =
3327 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003328 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003329 if (instruction->HasUses()) {
3330 locations->SetOut(Location::SameAsFirstInput());
3331 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003332}
3333
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003334void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003335 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3336 return;
3337 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003338 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003339
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003340 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3341 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3342}
3343
3344void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003345 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003346 codegen_->AddSlowPath(slow_path);
3347
3348 LocationSummary* locations = instruction->GetLocations();
3349 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003350
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003351 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003352}
3353
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003354void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3355 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3356 GenerateImplicitNullCheck(instruction);
3357 } else {
3358 GenerateExplicitNullCheck(instruction);
3359 }
3360}
3361
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003362void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003363 LocationSummary* locations =
3364 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003365 locations->SetInAt(0, Location::RequiresRegister());
3366 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003367 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3368 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3369 } else {
3370 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3371 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003372}
3373
3374void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3375 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003376 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003377 Location index = locations->InAt(1);
Roland Levillain4d027112015-07-01 15:41:14 +01003378 Primitive::Type type = instruction->GetType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003379
Roland Levillain4d027112015-07-01 15:41:14 +01003380 switch (type) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003381 case Primitive::kPrimBoolean: {
3382 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003383 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003384 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003385 size_t offset =
3386 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003387 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3388 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003389 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003390 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3391 }
3392 break;
3393 }
3394
3395 case Primitive::kPrimByte: {
3396 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003397 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003398 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003399 size_t offset =
3400 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003401 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3402 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003403 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003404 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3405 }
3406 break;
3407 }
3408
3409 case Primitive::kPrimShort: {
3410 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003411 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003412 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003413 size_t offset =
3414 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003415 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3416 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003417 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003418 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3419 }
3420 break;
3421 }
3422
3423 case Primitive::kPrimChar: {
3424 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003425 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003426 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003427 size_t offset =
3428 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003429 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3430 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003431 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003432 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3433 }
3434 break;
3435 }
3436
3437 case Primitive::kPrimInt:
3438 case Primitive::kPrimNot: {
Roland Levillain33d69032015-06-18 18:20:59 +01003439 static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
3440 "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003441 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003442 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003443 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003444 size_t offset =
3445 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003446 __ LoadFromOffset(kLoadWord, out, obj, offset);
3447 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003448 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003449 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3450 }
3451 break;
3452 }
3453
3454 case Primitive::kPrimLong: {
3455 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003456 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003457 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003458 size_t offset =
3459 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003460 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003461 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003462 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003463 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003464 }
3465 break;
3466 }
3467
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003468 case Primitive::kPrimFloat: {
3469 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3470 Location out = locations->Out();
3471 DCHECK(out.IsFpuRegister());
3472 if (index.IsConstant()) {
3473 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3474 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3475 } else {
3476 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3477 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3478 }
3479 break;
3480 }
3481
3482 case Primitive::kPrimDouble: {
3483 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3484 Location out = locations->Out();
3485 DCHECK(out.IsFpuRegisterPair());
3486 if (index.IsConstant()) {
3487 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3488 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3489 } else {
3490 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3491 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3492 }
3493 break;
3494 }
3495
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003496 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01003497 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003498 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003499 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003500 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01003501
3502 if (type == Primitive::kPrimNot) {
3503 Register out = locations->Out().AsRegister<Register>();
3504 __ MaybeUnpoisonHeapReference(out);
3505 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003506}
3507
3508void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003509 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003510
3511 bool needs_write_barrier =
3512 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3513 bool needs_runtime_call = instruction->NeedsTypeCheck();
3514
Nicolas Geoffray39468442014-09-02 15:17:15 +01003515 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003516 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3517 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003518 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003519 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3520 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3521 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003522 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003523 locations->SetInAt(0, Location::RequiresRegister());
3524 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003525 if (Primitive::IsFloatingPointType(value_type)) {
3526 locations->SetInAt(2, Location::RequiresFpuRegister());
3527 } else {
3528 locations->SetInAt(2, Location::RequiresRegister());
3529 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003530
3531 if (needs_write_barrier) {
3532 // Temporary registers for the write barrier.
Roland Levillain4d027112015-07-01 15:41:14 +01003533 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003534 locations->AddTemp(Location::RequiresRegister());
3535 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003536 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003537}
3538
3539void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3540 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003541 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003542 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003543 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003544 bool needs_runtime_call = locations->WillCall();
3545 bool needs_write_barrier =
3546 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003547
3548 switch (value_type) {
3549 case Primitive::kPrimBoolean:
3550 case Primitive::kPrimByte: {
3551 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003552 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003553 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003554 size_t offset =
3555 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003556 __ StoreToOffset(kStoreByte, value, obj, offset);
3557 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003558 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003559 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3560 }
3561 break;
3562 }
3563
3564 case Primitive::kPrimShort:
3565 case Primitive::kPrimChar: {
3566 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003567 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003568 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003569 size_t offset =
3570 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003571 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3572 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003573 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003574 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3575 }
3576 break;
3577 }
3578
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003579 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003580 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003581 if (!needs_runtime_call) {
3582 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003583 Register value = locations->InAt(2).AsRegister<Register>();
Roland Levillain4d027112015-07-01 15:41:14 +01003584 Register source = value;
3585 if (kPoisonHeapReferences && needs_write_barrier) {
3586 // Note that in the case where `value` is a null reference,
3587 // we do not enter this block, as a null reference does not
3588 // need poisoning.
3589 DCHECK_EQ(value_type, Primitive::kPrimNot);
3590 Register temp = locations->GetTemp(0).AsRegister<Register>();
3591 __ Mov(temp, value);
3592 __ PoisonHeapReference(temp);
3593 source = temp;
3594 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003595 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003596 size_t offset =
3597 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillain4d027112015-07-01 15:41:14 +01003598 __ StoreToOffset(kStoreWord, source, obj, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003599 } else {
3600 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003601 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillain4d027112015-07-01 15:41:14 +01003602 __ StoreToOffset(kStoreWord, source, IP, data_offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003603 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003604 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003605 if (needs_write_barrier) {
3606 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003607 Register temp = locations->GetTemp(0).AsRegister<Register>();
3608 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003609 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003610 }
3611 } else {
3612 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain4d027112015-07-01 15:41:14 +01003613 // Note: if heap poisoning is enabled, pAputObject takes cares
3614 // of poisoning the reference.
Roland Levillain199f3362014-11-27 17:15:16 +00003615 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3616 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003617 instruction->GetDexPc(),
3618 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003619 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003620 break;
3621 }
3622
3623 case Primitive::kPrimLong: {
3624 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003625 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003626 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003627 size_t offset =
3628 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003629 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003630 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003631 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003632 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003633 }
3634 break;
3635 }
3636
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003637 case Primitive::kPrimFloat: {
3638 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3639 Location value = locations->InAt(2);
3640 DCHECK(value.IsFpuRegister());
3641 if (index.IsConstant()) {
3642 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3643 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3644 } else {
3645 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3646 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3647 }
3648 break;
3649 }
3650
3651 case Primitive::kPrimDouble: {
3652 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3653 Location value = locations->InAt(2);
3654 DCHECK(value.IsFpuRegisterPair());
3655 if (index.IsConstant()) {
3656 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3657 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3658 } else {
3659 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3660 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3661 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003662
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003663 break;
3664 }
3665
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003666 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003667 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003668 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003669 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003670
3671 // Ints and objects are handled in the switch.
3672 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3673 codegen_->MaybeRecordImplicitNullCheck(instruction);
3674 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003675}
3676
3677void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003678 LocationSummary* locations =
3679 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003680 locations->SetInAt(0, Location::RequiresRegister());
3681 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003682}
3683
3684void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3685 LocationSummary* locations = instruction->GetLocations();
3686 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003687 Register obj = locations->InAt(0).AsRegister<Register>();
3688 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003689 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003690 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003691}
3692
3693void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003694 LocationSummary* locations =
3695 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003696 locations->SetInAt(0, Location::RequiresRegister());
3697 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003698 if (instruction->HasUses()) {
3699 locations->SetOut(Location::SameAsFirstInput());
3700 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003701}
3702
3703void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3704 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003705 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003706 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003707 codegen_->AddSlowPath(slow_path);
3708
Roland Levillain271ab9c2014-11-27 15:23:57 +00003709 Register index = locations->InAt(0).AsRegister<Register>();
3710 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003711
3712 __ cmp(index, ShifterOperand(length));
3713 __ b(slow_path->GetEntryLabel(), CS);
3714}
3715
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003716void CodeGeneratorARM::MarkGCCard(Register temp,
3717 Register card,
3718 Register object,
3719 Register value,
3720 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003721 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003722 if (can_be_null) {
3723 __ CompareAndBranchIfZero(value, &is_null);
3724 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003725 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3726 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3727 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003728 if (can_be_null) {
3729 __ Bind(&is_null);
3730 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003731}
3732
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003733void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3734 temp->SetLocations(nullptr);
3735}
3736
3737void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3738 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003739 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003740}
3741
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003742void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003743 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003744 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003745}
3746
3747void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003748 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3749}
3750
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003751void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3752 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3753}
3754
3755void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003756 HBasicBlock* block = instruction->GetBlock();
3757 if (block->GetLoopInformation() != nullptr) {
3758 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3759 // The back edge will generate the suspend check.
3760 return;
3761 }
3762 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3763 // The goto will generate the suspend check.
3764 return;
3765 }
3766 GenerateSuspendCheck(instruction, nullptr);
3767}
3768
3769void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3770 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003771 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003772 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3773 if (slow_path == nullptr) {
3774 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3775 instruction->SetSlowPath(slow_path);
3776 codegen_->AddSlowPath(slow_path);
3777 if (successor != nullptr) {
3778 DCHECK(successor->IsLoopHeader());
3779 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3780 }
3781 } else {
3782 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3783 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003784
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003785 __ LoadFromOffset(
3786 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003787 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003788 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003789 __ Bind(slow_path->GetReturnLabel());
3790 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003791 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003792 __ b(slow_path->GetEntryLabel());
3793 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003794}
3795
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003796ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3797 return codegen_->GetAssembler();
3798}
3799
3800void ParallelMoveResolverARM::EmitMove(size_t index) {
3801 MoveOperands* move = moves_.Get(index);
3802 Location source = move->GetSource();
3803 Location destination = move->GetDestination();
3804
3805 if (source.IsRegister()) {
3806 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003807 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003808 } else {
3809 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003810 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003811 SP, destination.GetStackIndex());
3812 }
3813 } else if (source.IsStackSlot()) {
3814 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003815 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003816 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003817 } else if (destination.IsFpuRegister()) {
3818 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003819 } else {
3820 DCHECK(destination.IsStackSlot());
3821 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3822 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3823 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003824 } else if (source.IsFpuRegister()) {
3825 if (destination.IsFpuRegister()) {
3826 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003827 } else {
3828 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003829 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3830 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003831 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003832 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003833 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3834 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003835 } else if (destination.IsRegisterPair()) {
3836 DCHECK(ExpectedPairLayout(destination));
3837 __ LoadFromOffset(
3838 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3839 } else {
3840 DCHECK(destination.IsFpuRegisterPair()) << destination;
3841 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3842 SP,
3843 source.GetStackIndex());
3844 }
3845 } else if (source.IsRegisterPair()) {
3846 if (destination.IsRegisterPair()) {
3847 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3848 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3849 } else {
3850 DCHECK(destination.IsDoubleStackSlot()) << destination;
3851 DCHECK(ExpectedPairLayout(source));
3852 __ StoreToOffset(
3853 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3854 }
3855 } else if (source.IsFpuRegisterPair()) {
3856 if (destination.IsFpuRegisterPair()) {
3857 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3858 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3859 } else {
3860 DCHECK(destination.IsDoubleStackSlot()) << destination;
3861 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3862 SP,
3863 destination.GetStackIndex());
3864 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003865 } else {
3866 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003867 HConstant* constant = source.GetConstant();
3868 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3869 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003870 if (destination.IsRegister()) {
3871 __ LoadImmediate(destination.AsRegister<Register>(), value);
3872 } else {
3873 DCHECK(destination.IsStackSlot());
3874 __ LoadImmediate(IP, value);
3875 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3876 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003877 } else if (constant->IsLongConstant()) {
3878 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003879 if (destination.IsRegisterPair()) {
3880 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3881 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003882 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003883 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003884 __ LoadImmediate(IP, Low32Bits(value));
3885 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3886 __ LoadImmediate(IP, High32Bits(value));
3887 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3888 }
3889 } else if (constant->IsDoubleConstant()) {
3890 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003891 if (destination.IsFpuRegisterPair()) {
3892 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003893 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003894 DCHECK(destination.IsDoubleStackSlot()) << destination;
3895 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003896 __ LoadImmediate(IP, Low32Bits(int_value));
3897 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3898 __ LoadImmediate(IP, High32Bits(int_value));
3899 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3900 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003901 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003902 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003903 float value = constant->AsFloatConstant()->GetValue();
3904 if (destination.IsFpuRegister()) {
3905 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3906 } else {
3907 DCHECK(destination.IsStackSlot());
3908 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3909 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3910 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003911 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003912 }
3913}
3914
3915void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3916 __ Mov(IP, reg);
3917 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3918 __ StoreToOffset(kStoreWord, IP, SP, mem);
3919}
3920
3921void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3922 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3923 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3924 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3925 SP, mem1 + stack_offset);
3926 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3927 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3928 SP, mem2 + stack_offset);
3929 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3930}
3931
3932void ParallelMoveResolverARM::EmitSwap(size_t index) {
3933 MoveOperands* move = moves_.Get(index);
3934 Location source = move->GetSource();
3935 Location destination = move->GetDestination();
3936
3937 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003938 DCHECK_NE(source.AsRegister<Register>(), IP);
3939 DCHECK_NE(destination.AsRegister<Register>(), IP);
3940 __ Mov(IP, source.AsRegister<Register>());
3941 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3942 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003943 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003944 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003945 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003946 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003947 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3948 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003949 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003950 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003951 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003952 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003953 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003954 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003955 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003956 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003957 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3958 destination.AsRegisterPairHigh<Register>(),
3959 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003960 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003961 Register low_reg = source.IsRegisterPair()
3962 ? source.AsRegisterPairLow<Register>()
3963 : destination.AsRegisterPairLow<Register>();
3964 int mem = source.IsRegisterPair()
3965 ? destination.GetStackIndex()
3966 : source.GetStackIndex();
3967 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003968 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003969 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003970 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003971 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003972 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3973 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003974 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003975 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003976 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003977 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3978 DRegister reg = source.IsFpuRegisterPair()
3979 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3980 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3981 int mem = source.IsFpuRegisterPair()
3982 ? destination.GetStackIndex()
3983 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003984 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003985 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003986 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003987 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3988 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3989 : destination.AsFpuRegister<SRegister>();
3990 int mem = source.IsFpuRegister()
3991 ? destination.GetStackIndex()
3992 : source.GetStackIndex();
3993
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003994 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003995 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003996 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003997 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003998 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3999 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004000 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004001 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004002 }
4003}
4004
4005void ParallelMoveResolverARM::SpillScratch(int reg) {
4006 __ Push(static_cast<Register>(reg));
4007}
4008
4009void ParallelMoveResolverARM::RestoreScratch(int reg) {
4010 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004011}
4012
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004013void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004014 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
4015 ? LocationSummary::kCallOnSlowPath
4016 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004017 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004018 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004019 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004020 locations->SetOut(Location::RequiresRegister());
4021}
4022
4023void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004024 LocationSummary* locations = cls->GetLocations();
4025 Register out = locations->Out().AsRegister<Register>();
4026 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004027 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004028 DCHECK(!cls->CanCallRuntime());
4029 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004030 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004031 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004032 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004033 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004034 __ LoadFromOffset(kLoadWord,
4035 out,
4036 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004037 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004038 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Roland Levillain4d027112015-07-01 15:41:14 +01004039 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004040
4041 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4042 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4043 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004044 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004045 if (cls->MustGenerateClinitCheck()) {
4046 GenerateClassInitializationCheck(slow_path, out);
4047 } else {
4048 __ Bind(slow_path->GetExitLabel());
4049 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004050 }
4051}
4052
4053void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
4054 LocationSummary* locations =
4055 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
4056 locations->SetInAt(0, Location::RequiresRegister());
4057 if (check->HasUses()) {
4058 locations->SetOut(Location::SameAsFirstInput());
4059 }
4060}
4061
4062void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004063 // We assume the class is not null.
4064 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4065 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004066 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004067 GenerateClassInitializationCheck(slow_path,
4068 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004069}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004070
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004071void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
4072 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004073 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4074 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4075 __ b(slow_path->GetEntryLabel(), LT);
4076 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4077 // properly. Therefore, we do a memory fence.
4078 __ dmb(ISH);
4079 __ Bind(slow_path->GetExitLabel());
4080}
4081
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004082void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4083 LocationSummary* locations =
4084 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004085 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004086 locations->SetOut(Location::RequiresRegister());
4087}
4088
4089void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4090 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4091 codegen_->AddSlowPath(slow_path);
4092
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004093 LocationSummary* locations = load->GetLocations();
4094 Register out = locations->Out().AsRegister<Register>();
4095 Register current_method = locations->InAt(0).AsRegister<Register>();
4096 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004097 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004098 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Roland Levillain4d027112015-07-01 15:41:14 +01004099 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004100 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Roland Levillain4d027112015-07-01 15:41:14 +01004101 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004102 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004103 __ Bind(slow_path->GetExitLabel());
4104}
4105
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004106void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4107 LocationSummary* locations =
4108 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4109 locations->SetOut(Location::RequiresRegister());
4110}
4111
4112void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004113 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004114 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4115 __ LoadFromOffset(kLoadWord, out, TR, offset);
4116 __ LoadImmediate(IP, 0);
4117 __ StoreToOffset(kStoreWord, IP, TR, offset);
4118}
4119
4120void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4121 LocationSummary* locations =
4122 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4123 InvokeRuntimeCallingConvention calling_convention;
4124 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4125}
4126
4127void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4128 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004129 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004130}
4131
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004132void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004133 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4134 ? LocationSummary::kNoCall
4135 : LocationSummary::kCallOnSlowPath;
4136 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4137 locations->SetInAt(0, Location::RequiresRegister());
4138 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004139 // The out register is used as a temporary, so it overlaps with the inputs.
4140 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004141}
4142
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004143void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004144 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004145 Register obj = locations->InAt(0).AsRegister<Register>();
4146 Register cls = locations->InAt(1).AsRegister<Register>();
4147 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004148 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004149 Label done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004150 SlowPathCodeARM* slow_path = nullptr;
4151
4152 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004153 // avoid null check if we know obj is not null.
4154 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004155 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004156 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004157 // Compare the class of `obj` with `cls`.
4158 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
Roland Levillain4d027112015-07-01 15:41:14 +01004159 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004160 __ cmp(out, ShifterOperand(cls));
4161 if (instruction->IsClassFinal()) {
4162 // Classes must be equal for the instanceof to succeed.
4163 __ b(&zero, NE);
4164 __ LoadImmediate(out, 1);
4165 __ b(&done);
4166 } else {
4167 // If the classes are not equal, we go into a slow path.
4168 DCHECK(locations->OnlyCallsOnSlowPath());
4169 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004170 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004171 codegen_->AddSlowPath(slow_path);
4172 __ b(slow_path->GetEntryLabel(), NE);
4173 __ LoadImmediate(out, 1);
4174 __ b(&done);
4175 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004176
4177 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4178 __ Bind(&zero);
4179 __ LoadImmediate(out, 0);
4180 }
4181
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004182 if (slow_path != nullptr) {
4183 __ Bind(slow_path->GetExitLabel());
4184 }
4185 __ Bind(&done);
4186}
4187
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004188void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4189 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4190 instruction, LocationSummary::kCallOnSlowPath);
4191 locations->SetInAt(0, Location::RequiresRegister());
4192 locations->SetInAt(1, Location::RequiresRegister());
4193 locations->AddTemp(Location::RequiresRegister());
4194}
4195
4196void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4197 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004198 Register obj = locations->InAt(0).AsRegister<Register>();
4199 Register cls = locations->InAt(1).AsRegister<Register>();
4200 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004201 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4202
4203 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4204 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4205 codegen_->AddSlowPath(slow_path);
4206
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004207 // avoid null check if we know obj is not null.
4208 if (instruction->MustDoNullCheck()) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004209 __ CompareAndBranchIfZero(obj, slow_path->GetExitLabel());
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004210 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004211 // Compare the class of `obj` with `cls`.
4212 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
Roland Levillain4d027112015-07-01 15:41:14 +01004213 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004214 __ cmp(temp, ShifterOperand(cls));
Roland Levillain4d027112015-07-01 15:41:14 +01004215 // The checkcast succeeds if the classes are equal (fast path).
4216 // Otherwise, we need to go into the slow path to check the types.
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004217 __ b(slow_path->GetEntryLabel(), NE);
4218 __ Bind(slow_path->GetExitLabel());
4219}
4220
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004221void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4222 LocationSummary* locations =
4223 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4224 InvokeRuntimeCallingConvention calling_convention;
4225 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4226}
4227
4228void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4229 codegen_->InvokeRuntime(instruction->IsEnter()
4230 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4231 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004232 instruction->GetDexPc(),
4233 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004234}
4235
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004236void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4237void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4238void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4239
4240void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4241 LocationSummary* locations =
4242 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4243 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4244 || instruction->GetResultType() == Primitive::kPrimLong);
4245 locations->SetInAt(0, Location::RequiresRegister());
4246 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004247 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004248}
4249
4250void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4251 HandleBitwiseOperation(instruction);
4252}
4253
4254void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4255 HandleBitwiseOperation(instruction);
4256}
4257
4258void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4259 HandleBitwiseOperation(instruction);
4260}
4261
4262void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4263 LocationSummary* locations = instruction->GetLocations();
4264
4265 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004266 Register first = locations->InAt(0).AsRegister<Register>();
4267 Register second = locations->InAt(1).AsRegister<Register>();
4268 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004269 if (instruction->IsAnd()) {
4270 __ and_(out, first, ShifterOperand(second));
4271 } else if (instruction->IsOr()) {
4272 __ orr(out, first, ShifterOperand(second));
4273 } else {
4274 DCHECK(instruction->IsXor());
4275 __ eor(out, first, ShifterOperand(second));
4276 }
4277 } else {
4278 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4279 Location first = locations->InAt(0);
4280 Location second = locations->InAt(1);
4281 Location out = locations->Out();
4282 if (instruction->IsAnd()) {
4283 __ and_(out.AsRegisterPairLow<Register>(),
4284 first.AsRegisterPairLow<Register>(),
4285 ShifterOperand(second.AsRegisterPairLow<Register>()));
4286 __ and_(out.AsRegisterPairHigh<Register>(),
4287 first.AsRegisterPairHigh<Register>(),
4288 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4289 } else if (instruction->IsOr()) {
4290 __ orr(out.AsRegisterPairLow<Register>(),
4291 first.AsRegisterPairLow<Register>(),
4292 ShifterOperand(second.AsRegisterPairLow<Register>()));
4293 __ orr(out.AsRegisterPairHigh<Register>(),
4294 first.AsRegisterPairHigh<Register>(),
4295 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4296 } else {
4297 DCHECK(instruction->IsXor());
4298 __ eor(out.AsRegisterPairLow<Register>(),
4299 first.AsRegisterPairLow<Register>(),
4300 ShifterOperand(second.AsRegisterPairLow<Register>()));
4301 __ eor(out.AsRegisterPairHigh<Register>(),
4302 first.AsRegisterPairHigh<Register>(),
4303 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4304 }
4305 }
4306}
4307
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004308void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004309 // TODO: Implement all kinds of calls:
4310 // 1) boot -> boot
4311 // 2) app -> boot
4312 // 3) app -> app
4313 //
4314 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4315
Jeff Hao848f70a2014-01-15 13:49:50 -08004316 if (invoke->IsStringInit()) {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004317 Register reg = temp.AsRegister<Register>();
Jeff Hao848f70a2014-01-15 13:49:50 -08004318 // temp = thread->string_init_entrypoint
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004319 __ LoadFromOffset(kLoadWord, reg, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004320 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004321 __ LoadFromOffset(kLoadWord, LR, reg,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004322 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004323 kArmWordSize).Int32Value());
4324 // LR()
4325 __ blx(LR);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004326 } else if (invoke->IsRecursive()) {
4327 __ bl(GetFrameEntryLabel());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004328 } else {
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004329 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4330 Register method_reg;
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004331 Register reg = temp.AsRegister<Register>();
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004332 if (current_method.IsRegister()) {
4333 method_reg = current_method.AsRegister<Register>();
4334 } else {
4335 DCHECK(invoke->GetLocations()->Intrinsified());
4336 DCHECK(!current_method.IsValid());
4337 method_reg = reg;
4338 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4339 }
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004340 // reg = current_method->dex_cache_resolved_methods_;
4341 __ LoadFromOffset(
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004342 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004343 // reg = reg[index_in_cache]
4344 __ LoadFromOffset(
4345 kLoadWord, reg, reg, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4346 // LR = reg[offset_of_quick_compiled_code]
4347 __ LoadFromOffset(kLoadWord, LR, reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4348 kArmWordSize).Int32Value());
4349 // LR()
4350 __ blx(LR);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004351 }
4352
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004353 DCHECK(!IsLeafMethod());
4354}
4355
Calin Juravleb1498f62015-02-16 13:13:29 +00004356void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4357 // Nothing to do, this should be removed during prepare for register allocator.
4358 UNUSED(instruction);
4359 LOG(FATAL) << "Unreachable";
4360}
4361
4362void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4363 // Nothing to do, this should be removed during prepare for register allocator.
4364 UNUSED(instruction);
4365 LOG(FATAL) << "Unreachable";
4366}
4367
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01004368void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) {
4369 DCHECK(codegen_->IsBaseline());
4370 LocationSummary* locations =
4371 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4372 locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
4373}
4374
4375void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
4376 DCHECK(codegen_->IsBaseline());
4377 // Will be generated at use site.
4378}
4379
Roland Levillain4d027112015-07-01 15:41:14 +01004380#undef __
4381#undef QUICK_ENTRY_POINT
4382
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004383} // namespace arm
4384} // namespace art