blob: ff9373ab00ecd9427d4d00f9b56234077ab6c654 [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_arm.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000018
Calin Juravle34166012014-12-19 17:22:29 +000019#include "arch/arm/instruction_set_features_arm.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "art_method.h"
Zheng Xuc6667102015-05-15 16:08:45 +080021#include "code_generator_utils.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070022#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010023#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080024#include "intrinsics.h"
25#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070026#include "mirror/array-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070027#include "mirror/class-inl.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070028#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010029#include "utils/arm/assembler_arm.h"
30#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000031#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010032#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000033
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000034namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010035
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000036namespace arm {
37
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000038static bool ExpectedPairLayout(Location location) {
39 // We expected this for both core and fpu register pairs.
40 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
41}
42
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010043static constexpr int kCurrentMethodStackOffset = 0;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +010044static constexpr Register kMethodRegisterArgument = R0;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010045
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000046// We unconditionally allocate R5 to ensure we can do long operations
47// with baseline.
48static constexpr Register kCoreSavedRegisterForBaseline = R5;
49static constexpr Register kCoreCalleeSaves[] =
50 { R5, R6, R7, R8, R10, R11, PC };
51static constexpr SRegister kFpuCalleeSaves[] =
52 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010053
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000054// D31 cannot be split into two S registers, and the register allocator only works on
55// S registers. Therefore there is no need to block it.
56static constexpr DRegister DTMP = D31;
57
Roland Levillain62a46b22015-06-01 18:24:13 +010058#define __ down_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010059#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010060
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010061class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010063 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064
Alexandre Rames67555f72014-11-18 10:55:16 +000065 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010066 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010067 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010068 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000069 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010070 }
71
Alexandre Rames9931f312015-06-19 14:47:01 +010072 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
73
Nicolas Geoffraye5038322014-07-04 09:41:32 +010074 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010075 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010076 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
77};
78
Calin Juravled0d48522014-11-04 16:40:20 +000079class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
80 public:
81 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
82
Alexandre Rames67555f72014-11-18 10:55:16 +000083 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000084 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
85 __ Bind(GetEntryLabel());
86 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000087 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +000088 }
89
Alexandre Rames9931f312015-06-19 14:47:01 +010090 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
91
Calin Juravled0d48522014-11-04 16:40:20 +000092 private:
93 HDivZeroCheck* const instruction_;
94 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
95};
96
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010097class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000098 public:
Alexandre Rames67555f72014-11-18 10:55:16 +000099 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100100 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000101
Alexandre Rames67555f72014-11-18 10:55:16 +0000102 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100103 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000104 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000105 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100106 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000107 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000108 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100109 if (successor_ == nullptr) {
110 __ b(GetReturnLabel());
111 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100112 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100113 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000114 }
115
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100116 Label* GetReturnLabel() {
117 DCHECK(successor_ == nullptr);
118 return &return_label_;
119 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000120
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100121 HBasicBlock* GetSuccessor() const {
122 return successor_;
123 }
124
Alexandre Rames9931f312015-06-19 14:47:01 +0100125 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; }
126
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000127 private:
128 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100129 // If not null, the block to branch to after the suspend check.
130 HBasicBlock* const successor_;
131
132 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000133 Label return_label_;
134
135 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
136};
137
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100138class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100139 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100140 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
141 Location index_location,
142 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100143 : instruction_(instruction),
144 index_location_(index_location),
145 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100146
Alexandre Rames67555f72014-11-18 10:55:16 +0000147 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100148 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100149 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000150 // We're moving two locations to locations that could overlap, so we need a parallel
151 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000153 codegen->EmitParallelMoves(
154 index_location_,
155 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100156 Primitive::kPrimInt,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000157 length_location_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100158 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
159 Primitive::kPrimInt);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100160 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000161 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100162 }
163
Alexandre Rames9931f312015-06-19 14:47:01 +0100164 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; }
165
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100166 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100167 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100168 const Location index_location_;
169 const Location length_location_;
170
171 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
172};
173
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000174class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100175 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000176 LoadClassSlowPathARM(HLoadClass* cls,
177 HInstruction* at,
178 uint32_t dex_pc,
179 bool do_clinit)
180 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
181 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
182 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100183
Alexandre Rames67555f72014-11-18 10:55:16 +0000184 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000185 LocationSummary* locations = at_->GetLocations();
186
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100187 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
188 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000189 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100191 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000192 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000193 int32_t entry_point_offset = do_clinit_
194 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
195 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000196 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000197
198 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000199 Location out = locations->Out();
200 if (out.IsValid()) {
201 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000202 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
203 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000204 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100205 __ b(GetExitLabel());
206 }
207
Alexandre Rames9931f312015-06-19 14:47:01 +0100208 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
209
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000211 // The class this slow path will load.
212 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100213
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000214 // The instruction where this slow path is happening.
215 // (Might be the load class or an initialization check).
216 HInstruction* const at_;
217
218 // The dex PC of `at_`.
219 const uint32_t dex_pc_;
220
221 // Whether to initialize the class.
222 const bool do_clinit_;
223
224 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100225};
226
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000227class LoadStringSlowPathARM : public SlowPathCodeARM {
228 public:
229 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
230
Alexandre Rames67555f72014-11-18 10:55:16 +0000231 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000232 LocationSummary* locations = instruction_->GetLocations();
233 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
234
235 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
236 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000237 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000238
239 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800240 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000241 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000242 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000243 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
244
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000245 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000246 __ b(GetExitLabel());
247 }
248
Alexandre Rames9931f312015-06-19 14:47:01 +0100249 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
250
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000251 private:
252 HLoadString* const instruction_;
253
254 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
255};
256
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000257class TypeCheckSlowPathARM : public SlowPathCodeARM {
258 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000259 TypeCheckSlowPathARM(HInstruction* instruction,
260 Location class_to_check,
261 Location object_class,
262 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000263 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000264 class_to_check_(class_to_check),
265 object_class_(object_class),
266 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000267
Alexandre Rames67555f72014-11-18 10:55:16 +0000268 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000269 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000270 DCHECK(instruction_->IsCheckCast()
271 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000272
273 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
274 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000275 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000276
277 // We're moving two locations to locations that could overlap, so we need a parallel
278 // move resolver.
279 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000280 codegen->EmitParallelMoves(
281 class_to_check_,
282 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100283 Primitive::kPrimNot,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000284 object_class_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100285 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
286 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000287
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000288 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000289 arm_codegen->InvokeRuntime(
290 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000291 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
292 } else {
293 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000294 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000295 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000296
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000297 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000298 __ b(GetExitLabel());
299 }
300
Alexandre Rames9931f312015-06-19 14:47:01 +0100301 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
302
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000303 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000304 HInstruction* const instruction_;
305 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000306 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000307 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000308
309 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
310};
311
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700312class DeoptimizationSlowPathARM : public SlowPathCodeARM {
313 public:
314 explicit DeoptimizationSlowPathARM(HInstruction* instruction)
315 : instruction_(instruction) {}
316
317 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
318 __ Bind(GetEntryLabel());
319 SaveLiveRegisters(codegen, instruction_->GetLocations());
320 DCHECK(instruction_->IsDeoptimize());
321 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
322 uint32_t dex_pc = deoptimize->GetDexPc();
323 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
324 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
325 }
326
Alexandre Rames9931f312015-06-19 14:47:01 +0100327 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
328
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700329 private:
330 HInstruction* const instruction_;
331 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
332};
333
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000334#undef __
335
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100336#undef __
Roland Levillain62a46b22015-06-01 18:24:13 +0100337#define __ down_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700338
339inline Condition ARMCondition(IfCondition cond) {
340 switch (cond) {
341 case kCondEQ: return EQ;
342 case kCondNE: return NE;
343 case kCondLT: return LT;
344 case kCondLE: return LE;
345 case kCondGT: return GT;
346 case kCondGE: return GE;
347 default:
348 LOG(FATAL) << "Unknown if condition";
349 }
350 return EQ; // Unreachable.
351}
352
353inline Condition ARMOppositeCondition(IfCondition cond) {
354 switch (cond) {
355 case kCondEQ: return NE;
356 case kCondNE: return EQ;
357 case kCondLT: return GE;
358 case kCondLE: return GT;
359 case kCondGT: return LE;
360 case kCondGE: return LT;
361 default:
362 LOG(FATAL) << "Unknown if condition";
363 }
364 return EQ; // Unreachable.
365}
366
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100367void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100368 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100369}
370
371void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100372 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100373}
374
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100375size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
376 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
377 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100378}
379
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100380size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
381 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
382 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100383}
384
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000385size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
386 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
387 return kArmWordSize;
388}
389
390size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
391 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
392 return kArmWordSize;
393}
394
Calin Juravle34166012014-12-19 17:22:29 +0000395CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000396 const ArmInstructionSetFeatures& isa_features,
397 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000398 : CodeGenerator(graph,
399 kNumberOfCoreRegisters,
400 kNumberOfSRegisters,
401 kNumberOfRegisterPairs,
402 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
403 arraysize(kCoreCalleeSaves)),
404 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
405 arraysize(kFpuCalleeSaves)),
406 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100407 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100408 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100409 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100410 move_resolver_(graph->GetArena(), this),
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000411 assembler_(),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000412 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000413 // Save the PC register to mimic Quick.
414 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100415}
416
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000417void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
418 // Ensure that we fix up branches and literal loads and emit the literal pool.
419 __ FinalizeCode();
420
421 // Adjust native pc offsets in stack maps.
422 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
423 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
424 uint32_t new_position = __ GetAdjustedPosition(old_position);
425 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
426 }
427 // Adjust native pc offsets of block labels.
428 for (size_t block_idx = 0u, end = block_order_->Size(); block_idx != end; ++block_idx) {
429 HBasicBlock* block = block_order_->Get(block_idx);
430 // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid
431 // FirstNonEmptyBlock() which could lead to adjusting a label more than once.
432 DCHECK_LT(static_cast<size_t>(block->GetBlockId()), block_labels_.Size());
433 Label* block_label = &block_labels_.GetRawStorage()[block->GetBlockId()];
David Brazdilfc6a86a2015-06-26 10:33:45 +0000434 DCHECK_EQ(block_label->IsBound(), !block->IsSingleJump());
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000435 if (block_label->IsBound()) {
436 __ AdjustLabelPosition(block_label);
437 }
438 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100439 // Adjust pc offsets for the disassembly information.
440 if (disasm_info_ != nullptr) {
441 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
442 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
443 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
444 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
445 it.second.start = __ GetAdjustedPosition(it.second.start);
446 it.second.end = __ GetAdjustedPosition(it.second.end);
447 }
448 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
449 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
450 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
451 }
452 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000453
454 CodeGenerator::Finalize(allocator);
455}
456
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100457Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100458 switch (type) {
459 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100460 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100461 ArmManagedRegister pair =
462 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100463 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
464 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
465
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100466 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
467 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100468 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100469 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100470 }
471
472 case Primitive::kPrimByte:
473 case Primitive::kPrimBoolean:
474 case Primitive::kPrimChar:
475 case Primitive::kPrimShort:
476 case Primitive::kPrimInt:
477 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100478 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100479 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100480 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
481 ArmManagedRegister current =
482 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
483 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100484 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100485 }
486 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100487 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100488 }
489
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000490 case Primitive::kPrimFloat: {
491 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100492 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100493 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100494
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000495 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000496 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
497 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000498 return Location::FpuRegisterPairLocation(reg, reg + 1);
499 }
500
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100501 case Primitive::kPrimVoid:
502 LOG(FATAL) << "Unreachable type " << type;
503 }
504
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100505 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100506}
507
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000508void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100509 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100510 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100511
512 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100513 blocked_core_registers_[SP] = true;
514 blocked_core_registers_[LR] = true;
515 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100516
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100517 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100518 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100519
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100520 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100521 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100522
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000523 if (is_baseline) {
524 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
525 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
526 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000527
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000528 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
529
530 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
531 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
532 }
533 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100534
535 UpdateBlockedPairRegisters();
536}
537
538void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
539 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
540 ArmManagedRegister current =
541 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
542 if (blocked_core_registers_[current.AsRegisterPairLow()]
543 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
544 blocked_register_pairs_[i] = true;
545 }
546 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100547}
548
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100549InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
550 : HGraphVisitor(graph),
551 assembler_(codegen->GetAssembler()),
552 codegen_(codegen) {}
553
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000554void CodeGeneratorARM::ComputeSpillMask() {
555 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000556 // Save one extra register for baseline. Note that on thumb2, there is no easy
557 // instruction to restore just the PC, so this actually helps both baseline
558 // and non-baseline to save and restore at least two registers at entry and exit.
559 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000560 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
561 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
562 // We use vpush and vpop for saving and restoring floating point registers, which take
563 // a SRegister and the number of registers to save/restore after that SRegister. We
564 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
565 // but in the range.
566 if (fpu_spill_mask_ != 0) {
567 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
568 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
569 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
570 fpu_spill_mask_ |= (1 << i);
571 }
572 }
573}
574
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100575static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100576 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100577}
578
579static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100580 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100581}
582
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000583void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000584 bool skip_overflow_check =
585 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000586 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000587 __ Bind(&frame_entry_label_);
588
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000589 if (HasEmptyFrame()) {
590 return;
591 }
592
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100593 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000594 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
595 __ LoadFromOffset(kLoadWord, IP, IP, 0);
596 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100597 }
598
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000599 // PC is in the list of callee-save to mimic Quick, but we need to push
600 // LR at entry instead.
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100601 uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR;
602 __ PushList(push_mask);
603 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100604 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, push_mask, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000605 if (fpu_spill_mask_ != 0) {
606 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
607 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100608 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100609 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000610 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100611 int adjust = GetFrameSize() - FrameEntrySpillSize();
612 __ AddConstant(SP, -adjust);
613 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100614 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000615}
616
617void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000618 if (HasEmptyFrame()) {
619 __ bx(LR);
620 return;
621 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100622 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100623 int adjust = GetFrameSize() - FrameEntrySpillSize();
624 __ AddConstant(SP, adjust);
625 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000626 if (fpu_spill_mask_ != 0) {
627 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
628 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100629 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
630 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000631 }
632 __ PopList(core_spill_mask_);
David Srbeckyc34dc932015-04-12 09:27:43 +0100633 __ cfi().RestoreState();
634 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000635}
636
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100637void CodeGeneratorARM::Bind(HBasicBlock* block) {
638 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000639}
640
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100641Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
642 switch (load->GetType()) {
643 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100644 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100645 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100646
647 case Primitive::kPrimInt:
648 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100649 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100650 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100651
652 case Primitive::kPrimBoolean:
653 case Primitive::kPrimByte:
654 case Primitive::kPrimChar:
655 case Primitive::kPrimShort:
656 case Primitive::kPrimVoid:
657 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700658 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100659 }
660
661 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700662 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100663}
664
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100665Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100666 switch (type) {
667 case Primitive::kPrimBoolean:
668 case Primitive::kPrimByte:
669 case Primitive::kPrimChar:
670 case Primitive::kPrimShort:
671 case Primitive::kPrimInt:
672 case Primitive::kPrimNot: {
673 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000674 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100675 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100676 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100677 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000678 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100679 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100680 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100681
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000682 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100683 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000684 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100685 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000686 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100687 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000688 if (calling_convention.GetRegisterAt(index) == R1) {
689 // Skip R1, and use R2_R3 instead.
690 gp_index_++;
691 index++;
692 }
693 }
694 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
695 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000696 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000697 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000698 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100699 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000700 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
701 }
702 }
703
704 case Primitive::kPrimFloat: {
705 uint32_t stack_index = stack_index_++;
706 if (float_index_ % 2 == 0) {
707 float_index_ = std::max(double_index_, float_index_);
708 }
709 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
710 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
711 } else {
712 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
713 }
714 }
715
716 case Primitive::kPrimDouble: {
717 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
718 uint32_t stack_index = stack_index_;
719 stack_index_ += 2;
720 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
721 uint32_t index = double_index_;
722 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000723 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000724 calling_convention.GetFpuRegisterAt(index),
725 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000726 DCHECK(ExpectedPairLayout(result));
727 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000728 } else {
729 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100730 }
731 }
732
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100733 case Primitive::kPrimVoid:
734 LOG(FATAL) << "Unexpected parameter type " << type;
735 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100736 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100737 return Location();
738}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100739
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100740Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000741 switch (type) {
742 case Primitive::kPrimBoolean:
743 case Primitive::kPrimByte:
744 case Primitive::kPrimChar:
745 case Primitive::kPrimShort:
746 case Primitive::kPrimInt:
747 case Primitive::kPrimNot: {
748 return Location::RegisterLocation(R0);
749 }
750
751 case Primitive::kPrimFloat: {
752 return Location::FpuRegisterLocation(S0);
753 }
754
755 case Primitive::kPrimLong: {
756 return Location::RegisterPairLocation(R0, R1);
757 }
758
759 case Primitive::kPrimDouble: {
760 return Location::FpuRegisterPairLocation(S0, S1);
761 }
762
763 case Primitive::kPrimVoid:
764 return Location();
765 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100766
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000767 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000768}
769
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100770Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
771 return Location::RegisterLocation(kMethodRegisterArgument);
772}
773
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100774void CodeGeneratorARM::Move32(Location destination, Location source) {
775 if (source.Equals(destination)) {
776 return;
777 }
778 if (destination.IsRegister()) {
779 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000780 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100781 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000782 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100783 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000784 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100785 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100786 } else if (destination.IsFpuRegister()) {
787 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000788 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100789 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000790 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100791 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000792 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100793 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100794 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000795 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100796 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000797 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100798 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000799 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100800 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000801 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100802 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
803 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100804 }
805 }
806}
807
808void CodeGeneratorARM::Move64(Location destination, Location source) {
809 if (source.Equals(destination)) {
810 return;
811 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100812 if (destination.IsRegisterPair()) {
813 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000814 EmitParallelMoves(
815 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
816 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100817 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000818 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100819 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
820 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100821 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000822 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100823 } else {
824 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000825 DCHECK(ExpectedPairLayout(destination));
826 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
827 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100828 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000829 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100830 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000831 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
832 SP,
833 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100834 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000835 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100836 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100837 } else {
838 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100839 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000840 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100841 if (source.AsRegisterPairLow<Register>() == R1) {
842 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100843 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
844 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100845 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100846 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100847 SP, destination.GetStackIndex());
848 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000849 } else if (source.IsFpuRegisterPair()) {
850 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
851 SP,
852 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100853 } else {
854 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000855 EmitParallelMoves(
856 Location::StackSlot(source.GetStackIndex()),
857 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100858 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000859 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100860 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
861 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100862 }
863 }
864}
865
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100866void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100867 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100868 if (instruction->IsCurrentMethod()) {
869 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
870 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100871 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100872 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000873 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000874 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
875 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000876 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000877 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000878 } else {
879 DCHECK(location.IsStackSlot());
880 __ LoadImmediate(IP, value);
881 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
882 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000883 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000884 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000885 int64_t value = const_to_move->AsLongConstant()->GetValue();
886 if (location.IsRegisterPair()) {
887 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
888 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
889 } else {
890 DCHECK(location.IsDoubleStackSlot());
891 __ LoadImmediate(IP, Low32Bits(value));
892 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
893 __ LoadImmediate(IP, High32Bits(value));
894 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
895 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100896 }
Roland Levillain476df552014-10-09 17:51:36 +0100897 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100898 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
899 switch (instruction->GetType()) {
900 case Primitive::kPrimBoolean:
901 case Primitive::kPrimByte:
902 case Primitive::kPrimChar:
903 case Primitive::kPrimShort:
904 case Primitive::kPrimInt:
905 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100906 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100907 Move32(location, Location::StackSlot(stack_slot));
908 break;
909
910 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100911 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100912 Move64(location, Location::DoubleStackSlot(stack_slot));
913 break;
914
915 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100916 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100917 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000918 } else if (instruction->IsTemporary()) {
919 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000920 if (temp_location.IsStackSlot()) {
921 Move32(location, temp_location);
922 } else {
923 DCHECK(temp_location.IsDoubleStackSlot());
924 Move64(location, temp_location);
925 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000926 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100927 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100928 switch (instruction->GetType()) {
929 case Primitive::kPrimBoolean:
930 case Primitive::kPrimByte:
931 case Primitive::kPrimChar:
932 case Primitive::kPrimShort:
933 case Primitive::kPrimNot:
934 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100935 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100936 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100937 break;
938
939 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100940 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100941 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100942 break;
943
944 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100945 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100946 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000947 }
948}
949
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100950void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
951 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000952 uint32_t dex_pc,
953 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100954 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
955 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000956 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100957 DCHECK(instruction->IsSuspendCheck()
958 || instruction->IsBoundsCheck()
959 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000960 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000961 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100962 || !IsLeafMethod());
963}
964
David Brazdilfc6a86a2015-06-26 10:33:45 +0000965void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100966 DCHECK(!successor->IsExitBlock());
967
968 HBasicBlock* block = got->GetBlock();
969 HInstruction* previous = got->GetPrevious();
970
971 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000972 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100973 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
974 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
975 return;
976 }
977
978 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
979 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
980 }
981 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000982 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000983 }
984}
985
David Brazdilfc6a86a2015-06-26 10:33:45 +0000986void LocationsBuilderARM::VisitGoto(HGoto* got) {
987 got->SetLocations(nullptr);
988}
989
990void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
991 HandleGoto(got, got->GetSuccessor());
992}
993
994void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
995 try_boundary->SetLocations(nullptr);
996}
997
998void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
999 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1000 if (!successor->IsExitBlock()) {
1001 HandleGoto(try_boundary, successor);
1002 }
1003}
1004
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001005void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001006 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001007}
1008
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001009void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001010 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001011}
1012
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001013void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
1014 Label* true_target,
1015 Label* false_target,
1016 Label* always_true_target) {
1017 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001018 if (cond->IsIntConstant()) {
1019 // Constant condition, statically compared against 1.
1020 int32_t cond_value = cond->AsIntConstant()->GetValue();
1021 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001022 if (always_true_target != nullptr) {
1023 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001024 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001025 return;
1026 } else {
1027 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001028 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001029 } else {
1030 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1031 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001032 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
1033 __ cmp(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001034 ShifterOperand(0));
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001035 __ b(true_target, NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001036 } else {
1037 // Condition has not been materialized, use its inputs as the
1038 // comparison and its condition as the branch condition.
1039 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001040 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001041 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001042 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001043 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001044 } else {
1045 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001046 HConstant* constant = locations->InAt(1).GetConstant();
1047 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001048 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001049 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1050 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001051 } else {
1052 Register temp = IP;
1053 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001054 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001055 }
1056 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001057 __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001058 }
Dave Allison20dfc792014-06-16 20:44:29 -07001059 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001060 if (false_target != nullptr) {
1061 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001062 }
1063}
1064
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001065void LocationsBuilderARM::VisitIf(HIf* if_instr) {
1066 LocationSummary* locations =
1067 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
1068 HInstruction* cond = if_instr->InputAt(0);
1069 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1070 locations->SetInAt(0, Location::RequiresRegister());
1071 }
1072}
1073
1074void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1075 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1076 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1077 Label* always_true_target = true_target;
1078 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1079 if_instr->IfTrueSuccessor())) {
1080 always_true_target = nullptr;
1081 }
1082 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1083 if_instr->IfFalseSuccessor())) {
1084 false_target = nullptr;
1085 }
1086 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1087}
1088
1089void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1090 LocationSummary* locations = new (GetGraph()->GetArena())
1091 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1092 HInstruction* cond = deoptimize->InputAt(0);
1093 DCHECK(cond->IsCondition());
1094 if (cond->AsCondition()->NeedsMaterialization()) {
1095 locations->SetInAt(0, Location::RequiresRegister());
1096 }
1097}
1098
1099void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1100 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1101 DeoptimizationSlowPathARM(deoptimize);
1102 codegen_->AddSlowPath(slow_path);
1103 Label* slow_path_entry = slow_path->GetEntryLabel();
1104 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1105}
Dave Allison20dfc792014-06-16 20:44:29 -07001106
Roland Levillain0d37cd02015-05-27 16:39:19 +01001107void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001108 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001109 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001110 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain0d37cd02015-05-27 16:39:19 +01001111 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1112 if (cond->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001113 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001114 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001115}
1116
Roland Levillain0d37cd02015-05-27 16:39:19 +01001117void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
1118 if (!cond->NeedsMaterialization()) return;
1119 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001120 Register left = locations->InAt(0).AsRegister<Register>();
1121
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001122 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001123 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001124 } else {
1125 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -08001126 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001127 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001128 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1129 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001130 } else {
1131 Register temp = IP;
1132 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001133 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001134 }
Dave Allison20dfc792014-06-16 20:44:29 -07001135 }
Roland Levillain0d37cd02015-05-27 16:39:19 +01001136 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001137 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001138 ARMCondition(cond->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001139 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001140 ARMOppositeCondition(cond->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001141}
1142
1143void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1144 VisitCondition(comp);
1145}
1146
1147void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1148 VisitCondition(comp);
1149}
1150
1151void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1152 VisitCondition(comp);
1153}
1154
1155void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1156 VisitCondition(comp);
1157}
1158
1159void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1160 VisitCondition(comp);
1161}
1162
1163void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1164 VisitCondition(comp);
1165}
1166
1167void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1168 VisitCondition(comp);
1169}
1170
1171void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1172 VisitCondition(comp);
1173}
1174
1175void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1176 VisitCondition(comp);
1177}
1178
1179void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1180 VisitCondition(comp);
1181}
1182
1183void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1184 VisitCondition(comp);
1185}
1186
1187void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1188 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001189}
1190
1191void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001192 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001193}
1194
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001195void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1196 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001197}
1198
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001199void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001200 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001201}
1202
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001203void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001204 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001205 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001206}
1207
1208void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001209 LocationSummary* locations =
1210 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001211 switch (store->InputAt(1)->GetType()) {
1212 case Primitive::kPrimBoolean:
1213 case Primitive::kPrimByte:
1214 case Primitive::kPrimChar:
1215 case Primitive::kPrimShort:
1216 case Primitive::kPrimInt:
1217 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001218 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001219 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1220 break;
1221
1222 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001223 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001224 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1225 break;
1226
1227 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001228 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001229 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001230}
1231
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001232void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001233 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001234}
1235
1236void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001237 LocationSummary* locations =
1238 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001239 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001240}
1241
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001242void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001243 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001244 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001245}
1246
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001247void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1248 LocationSummary* locations =
1249 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1250 locations->SetOut(Location::ConstantLocation(constant));
1251}
1252
1253void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1254 // Will be generated at use site.
1255 UNUSED(constant);
1256}
1257
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001258void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001259 LocationSummary* locations =
1260 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001261 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001262}
1263
1264void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1265 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001266 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001267}
1268
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001269void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1270 LocationSummary* locations =
1271 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1272 locations->SetOut(Location::ConstantLocation(constant));
1273}
1274
1275void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1276 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001277 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001278}
1279
1280void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1281 LocationSummary* locations =
1282 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1283 locations->SetOut(Location::ConstantLocation(constant));
1284}
1285
1286void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1287 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001288 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001289}
1290
Calin Juravle27df7582015-04-17 19:12:31 +01001291void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1292 memory_barrier->SetLocations(nullptr);
1293}
1294
1295void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1296 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1297}
1298
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001299void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001300 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001301}
1302
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001303void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001304 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001305 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001306}
1307
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001308void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001309 LocationSummary* locations =
1310 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001311 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001312}
1313
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001314void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001315 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001316 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001317}
1318
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001319void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001320 // When we do not run baseline, explicit clinit checks triggered by static
1321 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1322 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001323
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001324 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1325 codegen_->GetInstructionSetFeatures());
1326 if (intrinsic.TryDispatch(invoke)) {
1327 return;
1328 }
1329
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001330 HandleInvoke(invoke);
1331}
1332
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001333static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1334 if (invoke->GetLocations()->Intrinsified()) {
1335 IntrinsicCodeGeneratorARM intrinsic(codegen);
1336 intrinsic.Dispatch(invoke);
1337 return true;
1338 }
1339 return false;
1340}
1341
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001342void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001343 // When we do not run baseline, explicit clinit checks triggered by static
1344 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1345 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001346
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001347 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1348 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001349 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001350
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001351 LocationSummary* locations = invoke->GetLocations();
1352 codegen_->GenerateStaticOrDirectCall(
1353 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001354 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001355}
1356
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001357void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001358 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001359 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001360}
1361
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001362void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001363 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1364 codegen_->GetInstructionSetFeatures());
1365 if (intrinsic.TryDispatch(invoke)) {
1366 return;
1367 }
1368
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001369 HandleInvoke(invoke);
1370}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001371
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001372void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001373 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1374 return;
1375 }
1376
Roland Levillain271ab9c2014-11-27 15:23:57 +00001377 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001378 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1379 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001380 LocationSummary* locations = invoke->GetLocations();
1381 Location receiver = locations->InAt(0);
1382 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1383 // temp = object->GetClass();
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001384 DCHECK(receiver.IsRegister());
1385 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00001386 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001387 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001388 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001389 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001390 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001391 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001392 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001393 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001394 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001395 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001396 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001397}
1398
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001399void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1400 HandleInvoke(invoke);
1401 // Add the hidden argument.
1402 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1403}
1404
1405void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1406 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001407 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001408 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1409 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001410 LocationSummary* locations = invoke->GetLocations();
1411 Location receiver = locations->InAt(0);
1412 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1413
1414 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001415 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1416 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001417
1418 // temp = object->GetClass();
1419 if (receiver.IsStackSlot()) {
1420 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1421 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1422 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001423 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001424 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001425 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001426 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001427 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001428 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001429 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1430 // LR = temp->GetEntryPoint();
1431 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1432 // LR();
1433 __ blx(LR);
1434 DCHECK(!codegen_->IsLeafMethod());
1435 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1436}
1437
Roland Levillain88cb1752014-10-20 16:36:47 +01001438void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1439 LocationSummary* locations =
1440 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1441 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001442 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001443 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001444 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1445 break;
1446 }
1447 case Primitive::kPrimLong: {
1448 locations->SetInAt(0, Location::RequiresRegister());
1449 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001450 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001451 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001452
Roland Levillain88cb1752014-10-20 16:36:47 +01001453 case Primitive::kPrimFloat:
1454 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001455 locations->SetInAt(0, Location::RequiresFpuRegister());
1456 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001457 break;
1458
1459 default:
1460 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1461 }
1462}
1463
1464void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1465 LocationSummary* locations = neg->GetLocations();
1466 Location out = locations->Out();
1467 Location in = locations->InAt(0);
1468 switch (neg->GetResultType()) {
1469 case Primitive::kPrimInt:
1470 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001471 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001472 break;
1473
1474 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001475 DCHECK(in.IsRegisterPair());
1476 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1477 __ rsbs(out.AsRegisterPairLow<Register>(),
1478 in.AsRegisterPairLow<Register>(),
1479 ShifterOperand(0));
1480 // We cannot emit an RSC (Reverse Subtract with Carry)
1481 // instruction here, as it does not exist in the Thumb-2
1482 // instruction set. We use the following approach
1483 // using SBC and SUB instead.
1484 //
1485 // out.hi = -C
1486 __ sbc(out.AsRegisterPairHigh<Register>(),
1487 out.AsRegisterPairHigh<Register>(),
1488 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1489 // out.hi = out.hi - in.hi
1490 __ sub(out.AsRegisterPairHigh<Register>(),
1491 out.AsRegisterPairHigh<Register>(),
1492 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1493 break;
1494
Roland Levillain88cb1752014-10-20 16:36:47 +01001495 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001496 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001497 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001498 break;
1499
Roland Levillain88cb1752014-10-20 16:36:47 +01001500 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001501 DCHECK(in.IsFpuRegisterPair());
1502 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1503 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001504 break;
1505
1506 default:
1507 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1508 }
1509}
1510
Roland Levillaindff1f282014-11-05 14:15:05 +00001511void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001512 Primitive::Type result_type = conversion->GetResultType();
1513 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001514 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001515
Roland Levillain5b3ee562015-04-14 16:02:41 +01001516 // The float-to-long, double-to-long and long-to-float type conversions
1517 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001518 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001519 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1520 && result_type == Primitive::kPrimLong)
1521 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001522 ? LocationSummary::kCall
1523 : LocationSummary::kNoCall;
1524 LocationSummary* locations =
1525 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1526
David Brazdilb2bd1c52015-03-25 11:17:37 +00001527 // The Java language does not allow treating boolean as an integral type but
1528 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001529
Roland Levillaindff1f282014-11-05 14:15:05 +00001530 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001531 case Primitive::kPrimByte:
1532 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001533 case Primitive::kPrimBoolean:
1534 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001535 case Primitive::kPrimShort:
1536 case Primitive::kPrimInt:
1537 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001538 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001539 locations->SetInAt(0, Location::RequiresRegister());
1540 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1541 break;
1542
1543 default:
1544 LOG(FATAL) << "Unexpected type conversion from " << input_type
1545 << " to " << result_type;
1546 }
1547 break;
1548
Roland Levillain01a8d712014-11-14 16:27:39 +00001549 case Primitive::kPrimShort:
1550 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001551 case Primitive::kPrimBoolean:
1552 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001553 case Primitive::kPrimByte:
1554 case Primitive::kPrimInt:
1555 case Primitive::kPrimChar:
1556 // Processing a Dex `int-to-short' instruction.
1557 locations->SetInAt(0, Location::RequiresRegister());
1558 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1559 break;
1560
1561 default:
1562 LOG(FATAL) << "Unexpected type conversion from " << input_type
1563 << " to " << result_type;
1564 }
1565 break;
1566
Roland Levillain946e1432014-11-11 17:35:19 +00001567 case Primitive::kPrimInt:
1568 switch (input_type) {
1569 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001570 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001571 locations->SetInAt(0, Location::Any());
1572 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1573 break;
1574
1575 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001576 // Processing a Dex `float-to-int' instruction.
1577 locations->SetInAt(0, Location::RequiresFpuRegister());
1578 locations->SetOut(Location::RequiresRegister());
1579 locations->AddTemp(Location::RequiresFpuRegister());
1580 break;
1581
Roland Levillain946e1432014-11-11 17:35:19 +00001582 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001583 // Processing a Dex `double-to-int' instruction.
1584 locations->SetInAt(0, Location::RequiresFpuRegister());
1585 locations->SetOut(Location::RequiresRegister());
1586 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001587 break;
1588
1589 default:
1590 LOG(FATAL) << "Unexpected type conversion from " << input_type
1591 << " to " << result_type;
1592 }
1593 break;
1594
Roland Levillaindff1f282014-11-05 14:15:05 +00001595 case Primitive::kPrimLong:
1596 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001597 case Primitive::kPrimBoolean:
1598 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001599 case Primitive::kPrimByte:
1600 case Primitive::kPrimShort:
1601 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001602 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001603 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001604 locations->SetInAt(0, Location::RequiresRegister());
1605 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1606 break;
1607
Roland Levillain624279f2014-12-04 11:54:28 +00001608 case Primitive::kPrimFloat: {
1609 // Processing a Dex `float-to-long' instruction.
1610 InvokeRuntimeCallingConvention calling_convention;
1611 locations->SetInAt(0, Location::FpuRegisterLocation(
1612 calling_convention.GetFpuRegisterAt(0)));
1613 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1614 break;
1615 }
1616
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001617 case Primitive::kPrimDouble: {
1618 // Processing a Dex `double-to-long' instruction.
1619 InvokeRuntimeCallingConvention calling_convention;
1620 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1621 calling_convention.GetFpuRegisterAt(0),
1622 calling_convention.GetFpuRegisterAt(1)));
1623 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001624 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001625 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001626
1627 default:
1628 LOG(FATAL) << "Unexpected type conversion from " << input_type
1629 << " to " << result_type;
1630 }
1631 break;
1632
Roland Levillain981e4542014-11-14 11:47:14 +00001633 case Primitive::kPrimChar:
1634 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001635 case Primitive::kPrimBoolean:
1636 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001637 case Primitive::kPrimByte:
1638 case Primitive::kPrimShort:
1639 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001640 // Processing a Dex `int-to-char' instruction.
1641 locations->SetInAt(0, Location::RequiresRegister());
1642 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1643 break;
1644
1645 default:
1646 LOG(FATAL) << "Unexpected type conversion from " << input_type
1647 << " to " << result_type;
1648 }
1649 break;
1650
Roland Levillaindff1f282014-11-05 14:15:05 +00001651 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001652 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001653 case Primitive::kPrimBoolean:
1654 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001655 case Primitive::kPrimByte:
1656 case Primitive::kPrimShort:
1657 case Primitive::kPrimInt:
1658 case Primitive::kPrimChar:
1659 // Processing a Dex `int-to-float' instruction.
1660 locations->SetInAt(0, Location::RequiresRegister());
1661 locations->SetOut(Location::RequiresFpuRegister());
1662 break;
1663
Roland Levillain5b3ee562015-04-14 16:02:41 +01001664 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001665 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001666 InvokeRuntimeCallingConvention calling_convention;
1667 locations->SetInAt(0, Location::RegisterPairLocation(
1668 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1669 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001670 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001671 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001672
Roland Levillaincff13742014-11-17 14:32:17 +00001673 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001674 // Processing a Dex `double-to-float' instruction.
1675 locations->SetInAt(0, Location::RequiresFpuRegister());
1676 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001677 break;
1678
1679 default:
1680 LOG(FATAL) << "Unexpected type conversion from " << input_type
1681 << " to " << result_type;
1682 };
1683 break;
1684
Roland Levillaindff1f282014-11-05 14:15:05 +00001685 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001686 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001687 case Primitive::kPrimBoolean:
1688 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001689 case Primitive::kPrimByte:
1690 case Primitive::kPrimShort:
1691 case Primitive::kPrimInt:
1692 case Primitive::kPrimChar:
1693 // Processing a Dex `int-to-double' instruction.
1694 locations->SetInAt(0, Location::RequiresRegister());
1695 locations->SetOut(Location::RequiresFpuRegister());
1696 break;
1697
1698 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001699 // Processing a Dex `long-to-double' instruction.
1700 locations->SetInAt(0, Location::RequiresRegister());
1701 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001702 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001703 locations->AddTemp(Location::RequiresFpuRegister());
1704 break;
1705
Roland Levillaincff13742014-11-17 14:32:17 +00001706 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001707 // Processing a Dex `float-to-double' instruction.
1708 locations->SetInAt(0, Location::RequiresFpuRegister());
1709 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001710 break;
1711
1712 default:
1713 LOG(FATAL) << "Unexpected type conversion from " << input_type
1714 << " to " << result_type;
1715 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001716 break;
1717
1718 default:
1719 LOG(FATAL) << "Unexpected type conversion from " << input_type
1720 << " to " << result_type;
1721 }
1722}
1723
1724void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1725 LocationSummary* locations = conversion->GetLocations();
1726 Location out = locations->Out();
1727 Location in = locations->InAt(0);
1728 Primitive::Type result_type = conversion->GetResultType();
1729 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001730 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001731 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001732 case Primitive::kPrimByte:
1733 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001734 case Primitive::kPrimBoolean:
1735 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001736 case Primitive::kPrimShort:
1737 case Primitive::kPrimInt:
1738 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001739 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001740 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001741 break;
1742
1743 default:
1744 LOG(FATAL) << "Unexpected type conversion from " << input_type
1745 << " to " << result_type;
1746 }
1747 break;
1748
Roland Levillain01a8d712014-11-14 16:27:39 +00001749 case Primitive::kPrimShort:
1750 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001751 case Primitive::kPrimBoolean:
1752 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001753 case Primitive::kPrimByte:
1754 case Primitive::kPrimInt:
1755 case Primitive::kPrimChar:
1756 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001757 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001758 break;
1759
1760 default:
1761 LOG(FATAL) << "Unexpected type conversion from " << input_type
1762 << " to " << result_type;
1763 }
1764 break;
1765
Roland Levillain946e1432014-11-11 17:35:19 +00001766 case Primitive::kPrimInt:
1767 switch (input_type) {
1768 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001769 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001770 DCHECK(out.IsRegister());
1771 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001772 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001773 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001774 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001775 } else {
1776 DCHECK(in.IsConstant());
1777 DCHECK(in.GetConstant()->IsLongConstant());
1778 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001779 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001780 }
1781 break;
1782
Roland Levillain3f8f9362014-12-02 17:45:01 +00001783 case Primitive::kPrimFloat: {
1784 // Processing a Dex `float-to-int' instruction.
1785 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1786 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1787 __ vcvtis(temp, temp);
1788 __ vmovrs(out.AsRegister<Register>(), temp);
1789 break;
1790 }
1791
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001792 case Primitive::kPrimDouble: {
1793 // Processing a Dex `double-to-int' instruction.
1794 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1795 DRegister temp_d = FromLowSToD(temp_s);
1796 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1797 __ vcvtid(temp_s, temp_d);
1798 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001799 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001800 }
Roland Levillain946e1432014-11-11 17:35:19 +00001801
1802 default:
1803 LOG(FATAL) << "Unexpected type conversion from " << input_type
1804 << " to " << result_type;
1805 }
1806 break;
1807
Roland Levillaindff1f282014-11-05 14:15:05 +00001808 case Primitive::kPrimLong:
1809 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001810 case Primitive::kPrimBoolean:
1811 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001812 case Primitive::kPrimByte:
1813 case Primitive::kPrimShort:
1814 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001815 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001816 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001817 DCHECK(out.IsRegisterPair());
1818 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001819 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001820 // Sign extension.
1821 __ Asr(out.AsRegisterPairHigh<Register>(),
1822 out.AsRegisterPairLow<Register>(),
1823 31);
1824 break;
1825
1826 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001827 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001828 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1829 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001830 conversion->GetDexPc(),
1831 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001832 break;
1833
Roland Levillaindff1f282014-11-05 14:15:05 +00001834 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001835 // Processing a Dex `double-to-long' instruction.
1836 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1837 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001838 conversion->GetDexPc(),
1839 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001840 break;
1841
1842 default:
1843 LOG(FATAL) << "Unexpected type conversion from " << input_type
1844 << " to " << result_type;
1845 }
1846 break;
1847
Roland Levillain981e4542014-11-14 11:47:14 +00001848 case Primitive::kPrimChar:
1849 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001850 case Primitive::kPrimBoolean:
1851 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001852 case Primitive::kPrimByte:
1853 case Primitive::kPrimShort:
1854 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001855 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001856 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001857 break;
1858
1859 default:
1860 LOG(FATAL) << "Unexpected type conversion from " << input_type
1861 << " to " << result_type;
1862 }
1863 break;
1864
Roland Levillaindff1f282014-11-05 14:15:05 +00001865 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001866 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001867 case Primitive::kPrimBoolean:
1868 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001869 case Primitive::kPrimByte:
1870 case Primitive::kPrimShort:
1871 case Primitive::kPrimInt:
1872 case Primitive::kPrimChar: {
1873 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001874 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1875 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001876 break;
1877 }
1878
Roland Levillain5b3ee562015-04-14 16:02:41 +01001879 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001880 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001881 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
1882 conversion,
1883 conversion->GetDexPc(),
1884 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001885 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00001886
Roland Levillaincff13742014-11-17 14:32:17 +00001887 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001888 // Processing a Dex `double-to-float' instruction.
1889 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1890 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001891 break;
1892
1893 default:
1894 LOG(FATAL) << "Unexpected type conversion from " << input_type
1895 << " to " << result_type;
1896 };
1897 break;
1898
Roland Levillaindff1f282014-11-05 14:15:05 +00001899 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001900 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001901 case Primitive::kPrimBoolean:
1902 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001903 case Primitive::kPrimByte:
1904 case Primitive::kPrimShort:
1905 case Primitive::kPrimInt:
1906 case Primitive::kPrimChar: {
1907 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001908 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001909 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1910 out.AsFpuRegisterPairLow<SRegister>());
1911 break;
1912 }
1913
Roland Levillain647b9ed2014-11-27 12:06:00 +00001914 case Primitive::kPrimLong: {
1915 // Processing a Dex `long-to-double' instruction.
1916 Register low = in.AsRegisterPairLow<Register>();
1917 Register high = in.AsRegisterPairHigh<Register>();
1918 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1919 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001920 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001921 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001922 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
1923 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001924
Roland Levillain682393c2015-04-14 15:57:52 +01001925 // temp_d = int-to-double(high)
1926 __ vmovsr(temp_s, high);
1927 __ vcvtdi(temp_d, temp_s);
1928 // constant_d = k2Pow32EncodingForDouble
1929 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
1930 // out_d = unsigned-to-double(low)
1931 __ vmovsr(out_s, low);
1932 __ vcvtdu(out_d, out_s);
1933 // out_d += temp_d * constant_d
1934 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001935 break;
1936 }
1937
Roland Levillaincff13742014-11-17 14:32:17 +00001938 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001939 // Processing a Dex `float-to-double' instruction.
1940 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1941 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001942 break;
1943
1944 default:
1945 LOG(FATAL) << "Unexpected type conversion from " << input_type
1946 << " to " << result_type;
1947 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001948 break;
1949
1950 default:
1951 LOG(FATAL) << "Unexpected type conversion from " << input_type
1952 << " to " << result_type;
1953 }
1954}
1955
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001956void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001957 LocationSummary* locations =
1958 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001959 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001960 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001961 locations->SetInAt(0, Location::RequiresRegister());
1962 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001963 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1964 break;
1965 }
1966
1967 case Primitive::kPrimLong: {
1968 locations->SetInAt(0, Location::RequiresRegister());
1969 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001970 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001971 break;
1972 }
1973
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001974 case Primitive::kPrimFloat:
1975 case Primitive::kPrimDouble: {
1976 locations->SetInAt(0, Location::RequiresFpuRegister());
1977 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001978 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001979 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001980 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001981
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001982 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001983 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001984 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001985}
1986
1987void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1988 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001989 Location out = locations->Out();
1990 Location first = locations->InAt(0);
1991 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001992 switch (add->GetResultType()) {
1993 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001994 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001995 __ add(out.AsRegister<Register>(),
1996 first.AsRegister<Register>(),
1997 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001998 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001999 __ AddConstant(out.AsRegister<Register>(),
2000 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002001 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002002 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002003 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002004
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002005 case Primitive::kPrimLong: {
2006 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002007 __ adds(out.AsRegisterPairLow<Register>(),
2008 first.AsRegisterPairLow<Register>(),
2009 ShifterOperand(second.AsRegisterPairLow<Register>()));
2010 __ adc(out.AsRegisterPairHigh<Register>(),
2011 first.AsRegisterPairHigh<Register>(),
2012 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002013 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002014 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002015
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002016 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002017 __ vadds(out.AsFpuRegister<SRegister>(),
2018 first.AsFpuRegister<SRegister>(),
2019 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002020 break;
2021
2022 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002023 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2024 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2025 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002026 break;
2027
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002028 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002029 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002030 }
2031}
2032
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002033void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002034 LocationSummary* locations =
2035 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002036 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002037 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002038 locations->SetInAt(0, Location::RequiresRegister());
2039 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002040 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2041 break;
2042 }
2043
2044 case Primitive::kPrimLong: {
2045 locations->SetInAt(0, Location::RequiresRegister());
2046 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002047 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002048 break;
2049 }
Calin Juravle11351682014-10-23 15:38:15 +01002050 case Primitive::kPrimFloat:
2051 case Primitive::kPrimDouble: {
2052 locations->SetInAt(0, Location::RequiresFpuRegister());
2053 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002054 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002055 break;
Calin Juravle11351682014-10-23 15:38:15 +01002056 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002057 default:
Calin Juravle11351682014-10-23 15:38:15 +01002058 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002059 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002060}
2061
2062void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2063 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002064 Location out = locations->Out();
2065 Location first = locations->InAt(0);
2066 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002067 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002068 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002069 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002070 __ sub(out.AsRegister<Register>(),
2071 first.AsRegister<Register>(),
2072 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002073 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002074 __ AddConstant(out.AsRegister<Register>(),
2075 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002076 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002077 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002078 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002079 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002080
Calin Juravle11351682014-10-23 15:38:15 +01002081 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002082 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002083 __ subs(out.AsRegisterPairLow<Register>(),
2084 first.AsRegisterPairLow<Register>(),
2085 ShifterOperand(second.AsRegisterPairLow<Register>()));
2086 __ sbc(out.AsRegisterPairHigh<Register>(),
2087 first.AsRegisterPairHigh<Register>(),
2088 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002089 break;
Calin Juravle11351682014-10-23 15:38:15 +01002090 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002091
Calin Juravle11351682014-10-23 15:38:15 +01002092 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002093 __ vsubs(out.AsFpuRegister<SRegister>(),
2094 first.AsFpuRegister<SRegister>(),
2095 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002096 break;
Calin Juravle11351682014-10-23 15:38:15 +01002097 }
2098
2099 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002100 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2101 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2102 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002103 break;
2104 }
2105
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002106
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002107 default:
Calin Juravle11351682014-10-23 15:38:15 +01002108 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002109 }
2110}
2111
Calin Juravle34bacdf2014-10-07 20:23:36 +01002112void LocationsBuilderARM::VisitMul(HMul* mul) {
2113 LocationSummary* locations =
2114 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2115 switch (mul->GetResultType()) {
2116 case Primitive::kPrimInt:
2117 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002118 locations->SetInAt(0, Location::RequiresRegister());
2119 locations->SetInAt(1, Location::RequiresRegister());
2120 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002121 break;
2122 }
2123
Calin Juravleb5bfa962014-10-21 18:02:24 +01002124 case Primitive::kPrimFloat:
2125 case Primitive::kPrimDouble: {
2126 locations->SetInAt(0, Location::RequiresFpuRegister());
2127 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002128 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002129 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002130 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002131
2132 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002133 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002134 }
2135}
2136
2137void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2138 LocationSummary* locations = mul->GetLocations();
2139 Location out = locations->Out();
2140 Location first = locations->InAt(0);
2141 Location second = locations->InAt(1);
2142 switch (mul->GetResultType()) {
2143 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002144 __ mul(out.AsRegister<Register>(),
2145 first.AsRegister<Register>(),
2146 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002147 break;
2148 }
2149 case Primitive::kPrimLong: {
2150 Register out_hi = out.AsRegisterPairHigh<Register>();
2151 Register out_lo = out.AsRegisterPairLow<Register>();
2152 Register in1_hi = first.AsRegisterPairHigh<Register>();
2153 Register in1_lo = first.AsRegisterPairLow<Register>();
2154 Register in2_hi = second.AsRegisterPairHigh<Register>();
2155 Register in2_lo = second.AsRegisterPairLow<Register>();
2156
2157 // Extra checks to protect caused by the existence of R1_R2.
2158 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2159 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2160 DCHECK_NE(out_hi, in1_lo);
2161 DCHECK_NE(out_hi, in2_lo);
2162
2163 // input: in1 - 64 bits, in2 - 64 bits
2164 // output: out
2165 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2166 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2167 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2168
2169 // IP <- in1.lo * in2.hi
2170 __ mul(IP, in1_lo, in2_hi);
2171 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2172 __ mla(out_hi, in1_hi, in2_lo, IP);
2173 // out.lo <- (in1.lo * in2.lo)[31:0];
2174 __ umull(out_lo, IP, in1_lo, in2_lo);
2175 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2176 __ add(out_hi, out_hi, ShifterOperand(IP));
2177 break;
2178 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002179
2180 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002181 __ vmuls(out.AsFpuRegister<SRegister>(),
2182 first.AsFpuRegister<SRegister>(),
2183 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002184 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002185 }
2186
2187 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002188 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2189 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2190 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002191 break;
2192 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002193
2194 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002195 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002196 }
2197}
2198
Zheng Xuc6667102015-05-15 16:08:45 +08002199void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2200 DCHECK(instruction->IsDiv() || instruction->IsRem());
2201 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2202
2203 LocationSummary* locations = instruction->GetLocations();
2204 Location second = locations->InAt(1);
2205 DCHECK(second.IsConstant());
2206
2207 Register out = locations->Out().AsRegister<Register>();
2208 Register dividend = locations->InAt(0).AsRegister<Register>();
2209 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2210 DCHECK(imm == 1 || imm == -1);
2211
2212 if (instruction->IsRem()) {
2213 __ LoadImmediate(out, 0);
2214 } else {
2215 if (imm == 1) {
2216 __ Mov(out, dividend);
2217 } else {
2218 __ rsb(out, dividend, ShifterOperand(0));
2219 }
2220 }
2221}
2222
2223void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2224 DCHECK(instruction->IsDiv() || instruction->IsRem());
2225 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2226
2227 LocationSummary* locations = instruction->GetLocations();
2228 Location second = locations->InAt(1);
2229 DCHECK(second.IsConstant());
2230
2231 Register out = locations->Out().AsRegister<Register>();
2232 Register dividend = locations->InAt(0).AsRegister<Register>();
2233 Register temp = locations->GetTemp(0).AsRegister<Register>();
2234 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002235 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002236 DCHECK(IsPowerOfTwo(abs_imm));
2237 int ctz_imm = CTZ(abs_imm);
2238
2239 if (ctz_imm == 1) {
2240 __ Lsr(temp, dividend, 32 - ctz_imm);
2241 } else {
2242 __ Asr(temp, dividend, 31);
2243 __ Lsr(temp, temp, 32 - ctz_imm);
2244 }
2245 __ add(out, temp, ShifterOperand(dividend));
2246
2247 if (instruction->IsDiv()) {
2248 __ Asr(out, out, ctz_imm);
2249 if (imm < 0) {
2250 __ rsb(out, out, ShifterOperand(0));
2251 }
2252 } else {
2253 __ ubfx(out, out, 0, ctz_imm);
2254 __ sub(out, out, ShifterOperand(temp));
2255 }
2256}
2257
2258void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2259 DCHECK(instruction->IsDiv() || instruction->IsRem());
2260 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2261
2262 LocationSummary* locations = instruction->GetLocations();
2263 Location second = locations->InAt(1);
2264 DCHECK(second.IsConstant());
2265
2266 Register out = locations->Out().AsRegister<Register>();
2267 Register dividend = locations->InAt(0).AsRegister<Register>();
2268 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2269 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2270 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2271
2272 int64_t magic;
2273 int shift;
2274 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2275
2276 __ LoadImmediate(temp1, magic);
2277 __ smull(temp2, temp1, dividend, temp1);
2278
2279 if (imm > 0 && magic < 0) {
2280 __ add(temp1, temp1, ShifterOperand(dividend));
2281 } else if (imm < 0 && magic > 0) {
2282 __ sub(temp1, temp1, ShifterOperand(dividend));
2283 }
2284
2285 if (shift != 0) {
2286 __ Asr(temp1, temp1, shift);
2287 }
2288
2289 if (instruction->IsDiv()) {
2290 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2291 } else {
2292 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2293 // TODO: Strength reduction for mls.
2294 __ LoadImmediate(temp2, imm);
2295 __ mls(out, temp1, temp2, dividend);
2296 }
2297}
2298
2299void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2300 DCHECK(instruction->IsDiv() || instruction->IsRem());
2301 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2302
2303 LocationSummary* locations = instruction->GetLocations();
2304 Location second = locations->InAt(1);
2305 DCHECK(second.IsConstant());
2306
2307 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2308 if (imm == 0) {
2309 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2310 } else if (imm == 1 || imm == -1) {
2311 DivRemOneOrMinusOne(instruction);
2312 } else if (IsPowerOfTwo(std::abs(imm))) {
2313 DivRemByPowerOfTwo(instruction);
2314 } else {
2315 DCHECK(imm <= -2 || imm >= 2);
2316 GenerateDivRemWithAnyConstant(instruction);
2317 }
2318}
2319
Calin Juravle7c4954d2014-10-28 16:57:40 +00002320void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002321 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2322 if (div->GetResultType() == Primitive::kPrimLong) {
2323 // pLdiv runtime call.
2324 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002325 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2326 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002327 } else if (div->GetResultType() == Primitive::kPrimInt &&
2328 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2329 // pIdivmod runtime call.
2330 call_kind = LocationSummary::kCall;
2331 }
2332
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002333 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2334
Calin Juravle7c4954d2014-10-28 16:57:40 +00002335 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002336 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002337 if (div->InputAt(1)->IsConstant()) {
2338 locations->SetInAt(0, Location::RequiresRegister());
2339 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2340 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2341 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2342 if (abs_imm <= 1) {
2343 // No temp register required.
2344 } else {
2345 locations->AddTemp(Location::RequiresRegister());
2346 if (!IsPowerOfTwo(abs_imm)) {
2347 locations->AddTemp(Location::RequiresRegister());
2348 }
2349 }
2350 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002351 locations->SetInAt(0, Location::RequiresRegister());
2352 locations->SetInAt(1, Location::RequiresRegister());
2353 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2354 } else {
2355 InvokeRuntimeCallingConvention calling_convention;
2356 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2357 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2358 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2359 // we only need the former.
2360 locations->SetOut(Location::RegisterLocation(R0));
2361 }
Calin Juravled0d48522014-11-04 16:40:20 +00002362 break;
2363 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002364 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002365 InvokeRuntimeCallingConvention calling_convention;
2366 locations->SetInAt(0, Location::RegisterPairLocation(
2367 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2368 locations->SetInAt(1, Location::RegisterPairLocation(
2369 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002370 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002371 break;
2372 }
2373 case Primitive::kPrimFloat:
2374 case Primitive::kPrimDouble: {
2375 locations->SetInAt(0, Location::RequiresFpuRegister());
2376 locations->SetInAt(1, Location::RequiresFpuRegister());
2377 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2378 break;
2379 }
2380
2381 default:
2382 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2383 }
2384}
2385
2386void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2387 LocationSummary* locations = div->GetLocations();
2388 Location out = locations->Out();
2389 Location first = locations->InAt(0);
2390 Location second = locations->InAt(1);
2391
2392 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002393 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002394 if (second.IsConstant()) {
2395 GenerateDivRemConstantIntegral(div);
2396 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002397 __ sdiv(out.AsRegister<Register>(),
2398 first.AsRegister<Register>(),
2399 second.AsRegister<Register>());
2400 } else {
2401 InvokeRuntimeCallingConvention calling_convention;
2402 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2403 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2404 DCHECK_EQ(R0, out.AsRegister<Register>());
2405
2406 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2407 }
Calin Juravled0d48522014-11-04 16:40:20 +00002408 break;
2409 }
2410
Calin Juravle7c4954d2014-10-28 16:57:40 +00002411 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002412 InvokeRuntimeCallingConvention calling_convention;
2413 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2414 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2415 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2416 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2417 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002418 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002419
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002420 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002421 break;
2422 }
2423
2424 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002425 __ vdivs(out.AsFpuRegister<SRegister>(),
2426 first.AsFpuRegister<SRegister>(),
2427 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002428 break;
2429 }
2430
2431 case Primitive::kPrimDouble: {
2432 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2433 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2434 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2435 break;
2436 }
2437
2438 default:
2439 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2440 }
2441}
2442
Calin Juravlebacfec32014-11-14 15:54:36 +00002443void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002444 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002445
2446 // Most remainders are implemented in the runtime.
2447 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002448 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2449 // sdiv will be replaced by other instruction sequence.
2450 call_kind = LocationSummary::kNoCall;
2451 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2452 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002453 // Have hardware divide instruction for int, do it with three instructions.
2454 call_kind = LocationSummary::kNoCall;
2455 }
2456
Calin Juravlebacfec32014-11-14 15:54:36 +00002457 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2458
Calin Juravled2ec87d2014-12-08 14:24:46 +00002459 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002460 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002461 if (rem->InputAt(1)->IsConstant()) {
2462 locations->SetInAt(0, Location::RequiresRegister());
2463 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2464 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2465 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2466 if (abs_imm <= 1) {
2467 // No temp register required.
2468 } else {
2469 locations->AddTemp(Location::RequiresRegister());
2470 if (!IsPowerOfTwo(abs_imm)) {
2471 locations->AddTemp(Location::RequiresRegister());
2472 }
2473 }
2474 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002475 locations->SetInAt(0, Location::RequiresRegister());
2476 locations->SetInAt(1, Location::RequiresRegister());
2477 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2478 locations->AddTemp(Location::RequiresRegister());
2479 } else {
2480 InvokeRuntimeCallingConvention calling_convention;
2481 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2482 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2483 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2484 // we only need the latter.
2485 locations->SetOut(Location::RegisterLocation(R1));
2486 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002487 break;
2488 }
2489 case Primitive::kPrimLong: {
2490 InvokeRuntimeCallingConvention calling_convention;
2491 locations->SetInAt(0, Location::RegisterPairLocation(
2492 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2493 locations->SetInAt(1, Location::RegisterPairLocation(
2494 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2495 // The runtime helper puts the output in R2,R3.
2496 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2497 break;
2498 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002499 case Primitive::kPrimFloat: {
2500 InvokeRuntimeCallingConvention calling_convention;
2501 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2502 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2503 locations->SetOut(Location::FpuRegisterLocation(S0));
2504 break;
2505 }
2506
Calin Juravlebacfec32014-11-14 15:54:36 +00002507 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002508 InvokeRuntimeCallingConvention calling_convention;
2509 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2510 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2511 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2512 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2513 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002514 break;
2515 }
2516
2517 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002518 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002519 }
2520}
2521
2522void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2523 LocationSummary* locations = rem->GetLocations();
2524 Location out = locations->Out();
2525 Location first = locations->InAt(0);
2526 Location second = locations->InAt(1);
2527
Calin Juravled2ec87d2014-12-08 14:24:46 +00002528 Primitive::Type type = rem->GetResultType();
2529 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002530 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002531 if (second.IsConstant()) {
2532 GenerateDivRemConstantIntegral(rem);
2533 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002534 Register reg1 = first.AsRegister<Register>();
2535 Register reg2 = second.AsRegister<Register>();
2536 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002537
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002538 // temp = reg1 / reg2 (integer division)
2539 // temp = temp * reg2
2540 // dest = reg1 - temp
2541 __ sdiv(temp, reg1, reg2);
2542 __ mul(temp, temp, reg2);
2543 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2544 } else {
2545 InvokeRuntimeCallingConvention calling_convention;
2546 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2547 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2548 DCHECK_EQ(R1, out.AsRegister<Register>());
2549
2550 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2551 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002552 break;
2553 }
2554
2555 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002556 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002557 break;
2558 }
2559
Calin Juravled2ec87d2014-12-08 14:24:46 +00002560 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002561 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002562 break;
2563 }
2564
Calin Juravlebacfec32014-11-14 15:54:36 +00002565 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002566 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002567 break;
2568 }
2569
2570 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002571 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002572 }
2573}
2574
Calin Juravled0d48522014-11-04 16:40:20 +00002575void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2576 LocationSummary* locations =
2577 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002578 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002579 if (instruction->HasUses()) {
2580 locations->SetOut(Location::SameAsFirstInput());
2581 }
2582}
2583
2584void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2585 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2586 codegen_->AddSlowPath(slow_path);
2587
2588 LocationSummary* locations = instruction->GetLocations();
2589 Location value = locations->InAt(0);
2590
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002591 switch (instruction->GetType()) {
2592 case Primitive::kPrimInt: {
2593 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002594 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002595 __ b(slow_path->GetEntryLabel(), EQ);
2596 } else {
2597 DCHECK(value.IsConstant()) << value;
2598 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2599 __ b(slow_path->GetEntryLabel());
2600 }
2601 }
2602 break;
2603 }
2604 case Primitive::kPrimLong: {
2605 if (value.IsRegisterPair()) {
2606 __ orrs(IP,
2607 value.AsRegisterPairLow<Register>(),
2608 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2609 __ b(slow_path->GetEntryLabel(), EQ);
2610 } else {
2611 DCHECK(value.IsConstant()) << value;
2612 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2613 __ b(slow_path->GetEntryLabel());
2614 }
2615 }
2616 break;
2617 default:
2618 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2619 }
2620 }
Calin Juravled0d48522014-11-04 16:40:20 +00002621}
2622
Calin Juravle9aec02f2014-11-18 23:06:35 +00002623void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2624 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2625
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002626 LocationSummary* locations =
2627 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002628
2629 switch (op->GetResultType()) {
2630 case Primitive::kPrimInt: {
2631 locations->SetInAt(0, Location::RequiresRegister());
2632 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002633 // Make the output overlap, as it will be used to hold the masked
2634 // second input.
2635 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002636 break;
2637 }
2638 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002639 locations->SetInAt(0, Location::RequiresRegister());
2640 locations->SetInAt(1, Location::RequiresRegister());
2641 locations->AddTemp(Location::RequiresRegister());
2642 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002643 break;
2644 }
2645 default:
2646 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2647 }
2648}
2649
2650void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2651 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2652
2653 LocationSummary* locations = op->GetLocations();
2654 Location out = locations->Out();
2655 Location first = locations->InAt(0);
2656 Location second = locations->InAt(1);
2657
2658 Primitive::Type type = op->GetResultType();
2659 switch (type) {
2660 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002661 Register out_reg = out.AsRegister<Register>();
2662 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002663 // Arm doesn't mask the shift count so we need to do it ourselves.
2664 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002665 Register second_reg = second.AsRegister<Register>();
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002666 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002667 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002668 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002669 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002670 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002671 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002672 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002673 }
2674 } else {
2675 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2676 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2677 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2678 __ Mov(out_reg, first_reg);
2679 } else if (op->IsShl()) {
2680 __ Lsl(out_reg, first_reg, shift_value);
2681 } else if (op->IsShr()) {
2682 __ Asr(out_reg, first_reg, shift_value);
2683 } else {
2684 __ Lsr(out_reg, first_reg, shift_value);
2685 }
2686 }
2687 break;
2688 }
2689 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002690 Register o_h = out.AsRegisterPairHigh<Register>();
2691 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002692
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002693 Register temp = locations->GetTemp(0).AsRegister<Register>();
2694
2695 Register high = first.AsRegisterPairHigh<Register>();
2696 Register low = first.AsRegisterPairLow<Register>();
2697
2698 Register second_reg = second.AsRegister<Register>();
2699
Calin Juravle9aec02f2014-11-18 23:06:35 +00002700 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002701 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002702 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002703 __ Lsl(o_h, high, o_l);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002704 // Shift the low part and `or` what overflew on the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002705 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002706 __ Lsr(temp, low, temp);
2707 __ orr(o_h, o_h, ShifterOperand(temp));
2708 // If the shift is > 32 bits, override the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002709 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002710 __ it(PL);
2711 __ Lsl(o_h, low, temp, false, PL);
2712 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002713 __ Lsl(o_l, low, o_l);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002714 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002715 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002716 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002717 __ Lsr(o_l, low, o_h);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002718 // Shift the high part and `or` what underflew on the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002719 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002720 __ Lsl(temp, high, temp);
2721 __ orr(o_l, o_l, ShifterOperand(temp));
2722 // If the shift is > 32 bits, override the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002723 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002724 __ it(PL);
2725 __ Asr(o_l, high, temp, false, PL);
2726 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002727 __ Asr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002728 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002729 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002730 // same as Shr except we use `Lsr`s and not `Asr`s
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002731 __ Lsr(o_l, low, o_h);
2732 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002733 __ Lsl(temp, high, temp);
2734 __ orr(o_l, o_l, ShifterOperand(temp));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002735 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002736 __ it(PL);
2737 __ Lsr(o_l, high, temp, false, PL);
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002738 __ Lsr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002739 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002740 break;
2741 }
2742 default:
2743 LOG(FATAL) << "Unexpected operation type " << type;
2744 }
2745}
2746
2747void LocationsBuilderARM::VisitShl(HShl* shl) {
2748 HandleShift(shl);
2749}
2750
2751void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2752 HandleShift(shl);
2753}
2754
2755void LocationsBuilderARM::VisitShr(HShr* shr) {
2756 HandleShift(shr);
2757}
2758
2759void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2760 HandleShift(shr);
2761}
2762
2763void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2764 HandleShift(ushr);
2765}
2766
2767void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2768 HandleShift(ushr);
2769}
2770
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002771void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002772 LocationSummary* locations =
2773 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002774 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002775 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002776 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002777 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002778}
2779
2780void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2781 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002782 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
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());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002802 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2803 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002804 instruction->GetDexPc(),
2805 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002806}
2807
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002808void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002809 LocationSummary* locations =
2810 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002811 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2812 if (location.IsStackSlot()) {
2813 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2814 } else if (location.IsDoubleStackSlot()) {
2815 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002816 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002817 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002818}
2819
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002820void InstructionCodeGeneratorARM::VisitParameterValue(
2821 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002822 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002823}
2824
2825void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
2826 LocationSummary* locations =
2827 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2828 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2829}
2830
2831void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2832 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002833}
2834
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002835void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002836 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002837 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002838 locations->SetInAt(0, Location::RequiresRegister());
2839 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002840}
2841
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002842void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2843 LocationSummary* locations = not_->GetLocations();
2844 Location out = locations->Out();
2845 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002846 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002847 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002848 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002849 break;
2850
2851 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002852 __ mvn(out.AsRegisterPairLow<Register>(),
2853 ShifterOperand(in.AsRegisterPairLow<Register>()));
2854 __ mvn(out.AsRegisterPairHigh<Register>(),
2855 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002856 break;
2857
2858 default:
2859 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2860 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002861}
2862
David Brazdil66d126e2015-04-03 16:02:44 +01002863void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2864 LocationSummary* locations =
2865 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2866 locations->SetInAt(0, Location::RequiresRegister());
2867 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2868}
2869
2870void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002871 LocationSummary* locations = bool_not->GetLocations();
2872 Location out = locations->Out();
2873 Location in = locations->InAt(0);
2874 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2875}
2876
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002877void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002878 LocationSummary* locations =
2879 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002880 switch (compare->InputAt(0)->GetType()) {
2881 case Primitive::kPrimLong: {
2882 locations->SetInAt(0, Location::RequiresRegister());
2883 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002884 // Output overlaps because it is written before doing the low comparison.
2885 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002886 break;
2887 }
2888 case Primitive::kPrimFloat:
2889 case Primitive::kPrimDouble: {
2890 locations->SetInAt(0, Location::RequiresFpuRegister());
2891 locations->SetInAt(1, Location::RequiresFpuRegister());
2892 locations->SetOut(Location::RequiresRegister());
2893 break;
2894 }
2895 default:
2896 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2897 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002898}
2899
2900void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002901 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002902 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002903 Location left = locations->InAt(0);
2904 Location right = locations->InAt(1);
2905
Vladimir Markocf93a5c2015-06-16 11:33:24 +00002906 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00002907 Primitive::Type type = compare->InputAt(0)->GetType();
2908 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002909 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002910 __ cmp(left.AsRegisterPairHigh<Register>(),
2911 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002912 __ b(&less, LT);
2913 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002914 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2915 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002916 __ cmp(left.AsRegisterPairLow<Register>(),
2917 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002918 break;
2919 }
2920 case Primitive::kPrimFloat:
2921 case Primitive::kPrimDouble: {
2922 __ LoadImmediate(out, 0);
2923 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002924 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002925 } else {
2926 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2927 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2928 }
2929 __ vmstat(); // transfer FP status register to ARM APSR.
2930 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002931 break;
2932 }
2933 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002934 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002935 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002936 __ b(&done, EQ);
2937 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2938
2939 __ Bind(&greater);
2940 __ LoadImmediate(out, 1);
2941 __ b(&done);
2942
2943 __ Bind(&less);
2944 __ LoadImmediate(out, -1);
2945
2946 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002947}
2948
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002949void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002950 LocationSummary* locations =
2951 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002952 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2953 locations->SetInAt(i, Location::Any());
2954 }
2955 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002956}
2957
2958void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002959 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002960 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002961}
2962
Calin Juravle52c48962014-12-16 17:02:57 +00002963void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2964 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07002965 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00002966 switch (kind) {
2967 case MemBarrierKind::kAnyStore:
2968 case MemBarrierKind::kLoadAny:
2969 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002970 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00002971 break;
2972 }
2973 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002974 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00002975 break;
2976 }
2977 default:
2978 LOG(FATAL) << "Unexpected memory barrier " << kind;
2979 }
Kenny Root1d8199d2015-06-02 11:01:10 -07002980 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00002981}
2982
2983void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2984 uint32_t offset,
2985 Register out_lo,
2986 Register out_hi) {
2987 if (offset != 0) {
2988 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002989 __ add(IP, addr, ShifterOperand(out_lo));
2990 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002991 }
2992 __ ldrexd(out_lo, out_hi, addr);
2993}
2994
2995void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2996 uint32_t offset,
2997 Register value_lo,
2998 Register value_hi,
2999 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003000 Register temp2,
3001 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003002 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003003 if (offset != 0) {
3004 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003005 __ add(IP, addr, ShifterOperand(temp1));
3006 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003007 }
3008 __ Bind(&fail);
3009 // We need a load followed by store. (The address used in a STREX instruction must
3010 // be the same as the address in the most recently executed LDREX instruction.)
3011 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003012 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003013 __ strexd(temp1, value_lo, value_hi, addr);
3014 __ cmp(temp1, ShifterOperand(0));
3015 __ b(&fail, NE);
3016}
3017
3018void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3019 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3020
Nicolas Geoffray39468442014-09-02 15:17:15 +01003021 LocationSummary* locations =
3022 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003023 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003024
Calin Juravle52c48962014-12-16 17:02:57 +00003025 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003026 if (Primitive::IsFloatingPointType(field_type)) {
3027 locations->SetInAt(1, Location::RequiresFpuRegister());
3028 } else {
3029 locations->SetInAt(1, Location::RequiresRegister());
3030 }
3031
Calin Juravle52c48962014-12-16 17:02:57 +00003032 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003033 bool generate_volatile = field_info.IsVolatile()
3034 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003035 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003036 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003037 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
3038 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003039 locations->AddTemp(Location::RequiresRegister());
3040 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003041 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003042 // Arm encoding have some additional constraints for ldrexd/strexd:
3043 // - registers need to be consecutive
3044 // - the first register should be even but not R14.
3045 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3046 // enable Arm encoding.
3047 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3048
3049 locations->AddTemp(Location::RequiresRegister());
3050 locations->AddTemp(Location::RequiresRegister());
3051 if (field_type == Primitive::kPrimDouble) {
3052 // For doubles we need two more registers to copy the value.
3053 locations->AddTemp(Location::RegisterLocation(R2));
3054 locations->AddTemp(Location::RegisterLocation(R3));
3055 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003056 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003057}
3058
Calin Juravle52c48962014-12-16 17:02:57 +00003059void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003060 const FieldInfo& field_info,
3061 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003062 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3063
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003064 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003065 Register base = locations->InAt(0).AsRegister<Register>();
3066 Location value = locations->InAt(1);
3067
3068 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003069 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003070 Primitive::Type field_type = field_info.GetFieldType();
3071 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3072
3073 if (is_volatile) {
3074 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3075 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003076
3077 switch (field_type) {
3078 case Primitive::kPrimBoolean:
3079 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003080 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003081 break;
3082 }
3083
3084 case Primitive::kPrimShort:
3085 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003086 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003087 break;
3088 }
3089
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003090 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003091 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00003092 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003093 break;
3094 }
3095
3096 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003097 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003098 GenerateWideAtomicStore(base, offset,
3099 value.AsRegisterPairLow<Register>(),
3100 value.AsRegisterPairHigh<Register>(),
3101 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003102 locations->GetTemp(1).AsRegister<Register>(),
3103 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003104 } else {
3105 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003106 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003107 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003108 break;
3109 }
3110
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003111 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003112 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003113 break;
3114 }
3115
3116 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003117 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003118 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003119 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3120 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3121
3122 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3123
3124 GenerateWideAtomicStore(base, offset,
3125 value_reg_lo,
3126 value_reg_hi,
3127 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003128 locations->GetTemp(3).AsRegister<Register>(),
3129 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003130 } else {
3131 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003132 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003133 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003134 break;
3135 }
3136
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003137 case Primitive::kPrimVoid:
3138 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003139 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003140 }
Calin Juravle52c48962014-12-16 17:02:57 +00003141
Calin Juravle77520bc2015-01-12 18:45:46 +00003142 // Longs and doubles are handled in the switch.
3143 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3144 codegen_->MaybeRecordImplicitNullCheck(instruction);
3145 }
3146
3147 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3148 Register temp = locations->GetTemp(0).AsRegister<Register>();
3149 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003150 codegen_->MarkGCCard(
3151 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003152 }
3153
Calin Juravle52c48962014-12-16 17:02:57 +00003154 if (is_volatile) {
3155 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3156 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003157}
3158
Calin Juravle52c48962014-12-16 17:02:57 +00003159void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3160 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003161 LocationSummary* locations =
3162 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003163 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003164
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003165 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003166 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003167 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003168 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003169
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003170 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3171 locations->SetOut(Location::RequiresFpuRegister());
3172 } else {
3173 locations->SetOut(Location::RequiresRegister(),
3174 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3175 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003176 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003177 // Arm encoding have some additional constraints for ldrexd/strexd:
3178 // - registers need to be consecutive
3179 // - the first register should be even but not R14.
3180 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3181 // enable Arm encoding.
3182 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3183 locations->AddTemp(Location::RequiresRegister());
3184 locations->AddTemp(Location::RequiresRegister());
3185 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003186}
3187
Calin Juravle52c48962014-12-16 17:02:57 +00003188void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3189 const FieldInfo& field_info) {
3190 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003191
Calin Juravle52c48962014-12-16 17:02:57 +00003192 LocationSummary* locations = instruction->GetLocations();
3193 Register base = locations->InAt(0).AsRegister<Register>();
3194 Location out = locations->Out();
3195 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003196 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003197 Primitive::Type field_type = field_info.GetFieldType();
3198 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3199
3200 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003201 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003202 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003203 break;
3204 }
3205
3206 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003207 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003208 break;
3209 }
3210
3211 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003212 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003213 break;
3214 }
3215
3216 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003217 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003218 break;
3219 }
3220
3221 case Primitive::kPrimInt:
3222 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003223 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003224 break;
3225 }
3226
3227 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003228 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003229 GenerateWideAtomicLoad(base, offset,
3230 out.AsRegisterPairLow<Register>(),
3231 out.AsRegisterPairHigh<Register>());
3232 } else {
3233 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3234 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003235 break;
3236 }
3237
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003238 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003239 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003240 break;
3241 }
3242
3243 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003244 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003245 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003246 Register lo = locations->GetTemp(0).AsRegister<Register>();
3247 Register hi = locations->GetTemp(1).AsRegister<Register>();
3248 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003249 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003250 __ vmovdrr(out_reg, lo, hi);
3251 } else {
3252 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003253 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003254 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003255 break;
3256 }
3257
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003258 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003259 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003260 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003261 }
Calin Juravle52c48962014-12-16 17:02:57 +00003262
Calin Juravle77520bc2015-01-12 18:45:46 +00003263 // Doubles are handled in the switch.
3264 if (field_type != Primitive::kPrimDouble) {
3265 codegen_->MaybeRecordImplicitNullCheck(instruction);
3266 }
3267
Calin Juravle52c48962014-12-16 17:02:57 +00003268 if (is_volatile) {
3269 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3270 }
3271}
3272
3273void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3274 HandleFieldSet(instruction, instruction->GetFieldInfo());
3275}
3276
3277void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003278 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003279}
3280
3281void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3282 HandleFieldGet(instruction, instruction->GetFieldInfo());
3283}
3284
3285void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3286 HandleFieldGet(instruction, instruction->GetFieldInfo());
3287}
3288
3289void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3290 HandleFieldGet(instruction, instruction->GetFieldInfo());
3291}
3292
3293void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3294 HandleFieldGet(instruction, instruction->GetFieldInfo());
3295}
3296
3297void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3298 HandleFieldSet(instruction, instruction->GetFieldInfo());
3299}
3300
3301void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003302 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003303}
3304
3305void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003306 LocationSummary* locations =
3307 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003308 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003309 if (instruction->HasUses()) {
3310 locations->SetOut(Location::SameAsFirstInput());
3311 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003312}
3313
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003314void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003315 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3316 return;
3317 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003318 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003319
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003320 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3321 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3322}
3323
3324void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003325 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003326 codegen_->AddSlowPath(slow_path);
3327
3328 LocationSummary* locations = instruction->GetLocations();
3329 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003330
Calin Juravle77520bc2015-01-12 18:45:46 +00003331 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3332 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003333}
3334
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003335void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3336 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3337 GenerateImplicitNullCheck(instruction);
3338 } else {
3339 GenerateExplicitNullCheck(instruction);
3340 }
3341}
3342
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003343void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003344 LocationSummary* locations =
3345 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003346 locations->SetInAt(0, Location::RequiresRegister());
3347 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003348 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3349 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3350 } else {
3351 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3352 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003353}
3354
3355void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3356 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003357 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003358 Location index = locations->InAt(1);
3359
3360 switch (instruction->GetType()) {
3361 case Primitive::kPrimBoolean: {
3362 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003363 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003364 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003365 size_t offset =
3366 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003367 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3368 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003369 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003370 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3371 }
3372 break;
3373 }
3374
3375 case Primitive::kPrimByte: {
3376 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003377 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003378 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003379 size_t offset =
3380 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003381 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3382 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003383 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003384 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3385 }
3386 break;
3387 }
3388
3389 case Primitive::kPrimShort: {
3390 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003391 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003392 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003393 size_t offset =
3394 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003395 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3396 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003397 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003398 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3399 }
3400 break;
3401 }
3402
3403 case Primitive::kPrimChar: {
3404 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003405 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003406 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003407 size_t offset =
3408 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003409 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3410 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003411 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003412 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3413 }
3414 break;
3415 }
3416
3417 case Primitive::kPrimInt:
3418 case Primitive::kPrimNot: {
Roland Levillain33d69032015-06-18 18:20:59 +01003419 static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
3420 "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003421 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003422 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003423 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003424 size_t offset =
3425 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003426 __ LoadFromOffset(kLoadWord, out, obj, offset);
3427 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003428 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003429 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3430 }
3431 break;
3432 }
3433
3434 case Primitive::kPrimLong: {
3435 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003436 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003437 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003438 size_t offset =
3439 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003440 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003441 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003442 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003443 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003444 }
3445 break;
3446 }
3447
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003448 case Primitive::kPrimFloat: {
3449 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3450 Location out = locations->Out();
3451 DCHECK(out.IsFpuRegister());
3452 if (index.IsConstant()) {
3453 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3454 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3455 } else {
3456 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3457 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3458 }
3459 break;
3460 }
3461
3462 case Primitive::kPrimDouble: {
3463 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3464 Location out = locations->Out();
3465 DCHECK(out.IsFpuRegisterPair());
3466 if (index.IsConstant()) {
3467 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3468 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3469 } else {
3470 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3471 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3472 }
3473 break;
3474 }
3475
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003476 case Primitive::kPrimVoid:
3477 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003478 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003479 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003480 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003481}
3482
3483void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003484 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003485
3486 bool needs_write_barrier =
3487 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3488 bool needs_runtime_call = instruction->NeedsTypeCheck();
3489
Nicolas Geoffray39468442014-09-02 15:17:15 +01003490 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003491 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3492 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003493 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003494 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3495 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3496 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003497 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003498 locations->SetInAt(0, Location::RequiresRegister());
3499 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003500 if (Primitive::IsFloatingPointType(value_type)) {
3501 locations->SetInAt(2, Location::RequiresFpuRegister());
3502 } else {
3503 locations->SetInAt(2, Location::RequiresRegister());
3504 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003505
3506 if (needs_write_barrier) {
3507 // Temporary registers for the write barrier.
3508 locations->AddTemp(Location::RequiresRegister());
3509 locations->AddTemp(Location::RequiresRegister());
3510 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003511 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003512}
3513
3514void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3515 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003516 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003517 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003518 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003519 bool needs_runtime_call = locations->WillCall();
3520 bool needs_write_barrier =
3521 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003522
3523 switch (value_type) {
3524 case Primitive::kPrimBoolean:
3525 case Primitive::kPrimByte: {
3526 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003527 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003528 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003529 size_t offset =
3530 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003531 __ StoreToOffset(kStoreByte, value, obj, offset);
3532 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003533 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003534 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3535 }
3536 break;
3537 }
3538
3539 case Primitive::kPrimShort:
3540 case Primitive::kPrimChar: {
3541 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003542 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003543 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003544 size_t offset =
3545 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003546 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3547 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003548 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003549 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3550 }
3551 break;
3552 }
3553
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003554 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003555 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003556 if (!needs_runtime_call) {
3557 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003558 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003559 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003560 size_t offset =
3561 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003562 __ StoreToOffset(kStoreWord, value, obj, offset);
3563 } else {
3564 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003565 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003566 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3567 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003568 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003569 if (needs_write_barrier) {
3570 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003571 Register temp = locations->GetTemp(0).AsRegister<Register>();
3572 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003573 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003574 }
3575 } else {
3576 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003577 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3578 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003579 instruction->GetDexPc(),
3580 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003581 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003582 break;
3583 }
3584
3585 case Primitive::kPrimLong: {
3586 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003587 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003588 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003589 size_t offset =
3590 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003591 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003592 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003593 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003594 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003595 }
3596 break;
3597 }
3598
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003599 case Primitive::kPrimFloat: {
3600 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3601 Location value = locations->InAt(2);
3602 DCHECK(value.IsFpuRegister());
3603 if (index.IsConstant()) {
3604 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3605 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3606 } else {
3607 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3608 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3609 }
3610 break;
3611 }
3612
3613 case Primitive::kPrimDouble: {
3614 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3615 Location value = locations->InAt(2);
3616 DCHECK(value.IsFpuRegisterPair());
3617 if (index.IsConstant()) {
3618 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3619 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3620 } else {
3621 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3622 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3623 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003624
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003625 break;
3626 }
3627
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003628 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003629 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003630 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003631 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003632
3633 // Ints and objects are handled in the switch.
3634 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3635 codegen_->MaybeRecordImplicitNullCheck(instruction);
3636 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003637}
3638
3639void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003640 LocationSummary* locations =
3641 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003642 locations->SetInAt(0, Location::RequiresRegister());
3643 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003644}
3645
3646void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3647 LocationSummary* locations = instruction->GetLocations();
3648 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003649 Register obj = locations->InAt(0).AsRegister<Register>();
3650 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003651 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003652 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003653}
3654
3655void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003656 LocationSummary* locations =
3657 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003658 locations->SetInAt(0, Location::RequiresRegister());
3659 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003660 if (instruction->HasUses()) {
3661 locations->SetOut(Location::SameAsFirstInput());
3662 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003663}
3664
3665void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3666 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003667 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003668 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003669 codegen_->AddSlowPath(slow_path);
3670
Roland Levillain271ab9c2014-11-27 15:23:57 +00003671 Register index = locations->InAt(0).AsRegister<Register>();
3672 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003673
3674 __ cmp(index, ShifterOperand(length));
3675 __ b(slow_path->GetEntryLabel(), CS);
3676}
3677
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003678void CodeGeneratorARM::MarkGCCard(Register temp,
3679 Register card,
3680 Register object,
3681 Register value,
3682 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003683 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003684 if (can_be_null) {
3685 __ CompareAndBranchIfZero(value, &is_null);
3686 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003687 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3688 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3689 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003690 if (can_be_null) {
3691 __ Bind(&is_null);
3692 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003693}
3694
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003695void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3696 temp->SetLocations(nullptr);
3697}
3698
3699void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3700 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003701 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003702}
3703
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003704void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003705 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003706 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003707}
3708
3709void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003710 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3711}
3712
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003713void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3714 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3715}
3716
3717void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003718 HBasicBlock* block = instruction->GetBlock();
3719 if (block->GetLoopInformation() != nullptr) {
3720 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3721 // The back edge will generate the suspend check.
3722 return;
3723 }
3724 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3725 // The goto will generate the suspend check.
3726 return;
3727 }
3728 GenerateSuspendCheck(instruction, nullptr);
3729}
3730
3731void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3732 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003733 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003734 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3735 if (slow_path == nullptr) {
3736 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3737 instruction->SetSlowPath(slow_path);
3738 codegen_->AddSlowPath(slow_path);
3739 if (successor != nullptr) {
3740 DCHECK(successor->IsLoopHeader());
3741 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3742 }
3743 } else {
3744 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3745 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003746
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003747 __ LoadFromOffset(
3748 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3749 __ cmp(IP, ShifterOperand(0));
3750 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003751 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003752 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003753 __ Bind(slow_path->GetReturnLabel());
3754 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003755 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003756 __ b(slow_path->GetEntryLabel());
3757 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003758}
3759
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003760ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3761 return codegen_->GetAssembler();
3762}
3763
3764void ParallelMoveResolverARM::EmitMove(size_t index) {
3765 MoveOperands* move = moves_.Get(index);
3766 Location source = move->GetSource();
3767 Location destination = move->GetDestination();
3768
3769 if (source.IsRegister()) {
3770 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003771 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003772 } else {
3773 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003774 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003775 SP, destination.GetStackIndex());
3776 }
3777 } else if (source.IsStackSlot()) {
3778 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003779 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003780 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003781 } else if (destination.IsFpuRegister()) {
3782 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003783 } else {
3784 DCHECK(destination.IsStackSlot());
3785 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3786 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3787 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003788 } else if (source.IsFpuRegister()) {
3789 if (destination.IsFpuRegister()) {
3790 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003791 } else {
3792 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003793 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3794 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003795 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003796 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003797 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3798 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003799 } else if (destination.IsRegisterPair()) {
3800 DCHECK(ExpectedPairLayout(destination));
3801 __ LoadFromOffset(
3802 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3803 } else {
3804 DCHECK(destination.IsFpuRegisterPair()) << destination;
3805 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3806 SP,
3807 source.GetStackIndex());
3808 }
3809 } else if (source.IsRegisterPair()) {
3810 if (destination.IsRegisterPair()) {
3811 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3812 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3813 } else {
3814 DCHECK(destination.IsDoubleStackSlot()) << destination;
3815 DCHECK(ExpectedPairLayout(source));
3816 __ StoreToOffset(
3817 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3818 }
3819 } else if (source.IsFpuRegisterPair()) {
3820 if (destination.IsFpuRegisterPair()) {
3821 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3822 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3823 } else {
3824 DCHECK(destination.IsDoubleStackSlot()) << destination;
3825 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3826 SP,
3827 destination.GetStackIndex());
3828 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003829 } else {
3830 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003831 HConstant* constant = source.GetConstant();
3832 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3833 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003834 if (destination.IsRegister()) {
3835 __ LoadImmediate(destination.AsRegister<Register>(), value);
3836 } else {
3837 DCHECK(destination.IsStackSlot());
3838 __ LoadImmediate(IP, value);
3839 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3840 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003841 } else if (constant->IsLongConstant()) {
3842 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003843 if (destination.IsRegisterPair()) {
3844 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3845 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003846 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003847 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003848 __ LoadImmediate(IP, Low32Bits(value));
3849 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3850 __ LoadImmediate(IP, High32Bits(value));
3851 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3852 }
3853 } else if (constant->IsDoubleConstant()) {
3854 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003855 if (destination.IsFpuRegisterPair()) {
3856 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003857 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003858 DCHECK(destination.IsDoubleStackSlot()) << destination;
3859 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003860 __ LoadImmediate(IP, Low32Bits(int_value));
3861 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3862 __ LoadImmediate(IP, High32Bits(int_value));
3863 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3864 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003865 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003866 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003867 float value = constant->AsFloatConstant()->GetValue();
3868 if (destination.IsFpuRegister()) {
3869 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3870 } else {
3871 DCHECK(destination.IsStackSlot());
3872 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3873 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3874 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003875 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003876 }
3877}
3878
3879void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3880 __ Mov(IP, reg);
3881 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3882 __ StoreToOffset(kStoreWord, IP, SP, mem);
3883}
3884
3885void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3886 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3887 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3888 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3889 SP, mem1 + stack_offset);
3890 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3891 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3892 SP, mem2 + stack_offset);
3893 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3894}
3895
3896void ParallelMoveResolverARM::EmitSwap(size_t index) {
3897 MoveOperands* move = moves_.Get(index);
3898 Location source = move->GetSource();
3899 Location destination = move->GetDestination();
3900
3901 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003902 DCHECK_NE(source.AsRegister<Register>(), IP);
3903 DCHECK_NE(destination.AsRegister<Register>(), IP);
3904 __ Mov(IP, source.AsRegister<Register>());
3905 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3906 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003907 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003908 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003909 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003910 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003911 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3912 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003913 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003914 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003915 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003916 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003917 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003918 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003919 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003920 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003921 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3922 destination.AsRegisterPairHigh<Register>(),
3923 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003924 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003925 Register low_reg = source.IsRegisterPair()
3926 ? source.AsRegisterPairLow<Register>()
3927 : destination.AsRegisterPairLow<Register>();
3928 int mem = source.IsRegisterPair()
3929 ? destination.GetStackIndex()
3930 : source.GetStackIndex();
3931 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003932 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003933 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003934 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003935 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003936 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3937 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003938 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003939 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003940 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003941 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3942 DRegister reg = source.IsFpuRegisterPair()
3943 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3944 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3945 int mem = source.IsFpuRegisterPair()
3946 ? destination.GetStackIndex()
3947 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003948 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003949 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003950 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003951 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3952 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3953 : destination.AsFpuRegister<SRegister>();
3954 int mem = source.IsFpuRegister()
3955 ? destination.GetStackIndex()
3956 : source.GetStackIndex();
3957
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003958 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003959 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003960 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003961 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003962 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3963 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003964 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003965 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003966 }
3967}
3968
3969void ParallelMoveResolverARM::SpillScratch(int reg) {
3970 __ Push(static_cast<Register>(reg));
3971}
3972
3973void ParallelMoveResolverARM::RestoreScratch(int reg) {
3974 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003975}
3976
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003977void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003978 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3979 ? LocationSummary::kCallOnSlowPath
3980 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003981 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003982 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003983 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003984 locations->SetOut(Location::RequiresRegister());
3985}
3986
3987void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003988 LocationSummary* locations = cls->GetLocations();
3989 Register out = locations->Out().AsRegister<Register>();
3990 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003991 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003992 DCHECK(!cls->CanCallRuntime());
3993 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003994 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003995 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003996 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003997 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003998 __ LoadFromOffset(kLoadWord,
3999 out,
4000 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004001 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004002 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004003
4004 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4005 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4006 codegen_->AddSlowPath(slow_path);
4007 __ cmp(out, ShifterOperand(0));
4008 __ b(slow_path->GetEntryLabel(), EQ);
4009 if (cls->MustGenerateClinitCheck()) {
4010 GenerateClassInitializationCheck(slow_path, out);
4011 } else {
4012 __ Bind(slow_path->GetExitLabel());
4013 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004014 }
4015}
4016
4017void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
4018 LocationSummary* locations =
4019 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
4020 locations->SetInAt(0, Location::RequiresRegister());
4021 if (check->HasUses()) {
4022 locations->SetOut(Location::SameAsFirstInput());
4023 }
4024}
4025
4026void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004027 // We assume the class is not null.
4028 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4029 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004030 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004031 GenerateClassInitializationCheck(slow_path,
4032 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004033}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004034
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004035void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
4036 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004037 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4038 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4039 __ b(slow_path->GetEntryLabel(), LT);
4040 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4041 // properly. Therefore, we do a memory fence.
4042 __ dmb(ISH);
4043 __ Bind(slow_path->GetExitLabel());
4044}
4045
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004046void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4047 LocationSummary* locations =
4048 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004049 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004050 locations->SetOut(Location::RequiresRegister());
4051}
4052
4053void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4054 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4055 codegen_->AddSlowPath(slow_path);
4056
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004057 LocationSummary* locations = load->GetLocations();
4058 Register out = locations->Out().AsRegister<Register>();
4059 Register current_method = locations->InAt(0).AsRegister<Register>();
4060 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004061 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004062 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004063 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
4064 __ cmp(out, ShifterOperand(0));
4065 __ b(slow_path->GetEntryLabel(), EQ);
4066 __ Bind(slow_path->GetExitLabel());
4067}
4068
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004069void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4070 LocationSummary* locations =
4071 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4072 locations->SetOut(Location::RequiresRegister());
4073}
4074
4075void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004076 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004077 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4078 __ LoadFromOffset(kLoadWord, out, TR, offset);
4079 __ LoadImmediate(IP, 0);
4080 __ StoreToOffset(kStoreWord, IP, TR, offset);
4081}
4082
4083void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4084 LocationSummary* locations =
4085 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4086 InvokeRuntimeCallingConvention calling_convention;
4087 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4088}
4089
4090void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4091 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004092 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004093}
4094
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004095void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004096 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4097 ? LocationSummary::kNoCall
4098 : LocationSummary::kCallOnSlowPath;
4099 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4100 locations->SetInAt(0, Location::RequiresRegister());
4101 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004102 // The out register is used as a temporary, so it overlaps with the inputs.
4103 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004104}
4105
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004106void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004107 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004108 Register obj = locations->InAt(0).AsRegister<Register>();
4109 Register cls = locations->InAt(1).AsRegister<Register>();
4110 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004111 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004112 Label done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004113 SlowPathCodeARM* slow_path = nullptr;
4114
4115 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004116 // avoid null check if we know obj is not null.
4117 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004118 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004119 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004120 // Compare the class of `obj` with `cls`.
4121 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
4122 __ cmp(out, ShifterOperand(cls));
4123 if (instruction->IsClassFinal()) {
4124 // Classes must be equal for the instanceof to succeed.
4125 __ b(&zero, NE);
4126 __ LoadImmediate(out, 1);
4127 __ b(&done);
4128 } else {
4129 // If the classes are not equal, we go into a slow path.
4130 DCHECK(locations->OnlyCallsOnSlowPath());
4131 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004132 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004133 codegen_->AddSlowPath(slow_path);
4134 __ b(slow_path->GetEntryLabel(), NE);
4135 __ LoadImmediate(out, 1);
4136 __ b(&done);
4137 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004138
4139 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4140 __ Bind(&zero);
4141 __ LoadImmediate(out, 0);
4142 }
4143
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004144 if (slow_path != nullptr) {
4145 __ Bind(slow_path->GetExitLabel());
4146 }
4147 __ Bind(&done);
4148}
4149
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004150void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4151 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4152 instruction, LocationSummary::kCallOnSlowPath);
4153 locations->SetInAt(0, Location::RequiresRegister());
4154 locations->SetInAt(1, Location::RequiresRegister());
4155 locations->AddTemp(Location::RequiresRegister());
4156}
4157
4158void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4159 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004160 Register obj = locations->InAt(0).AsRegister<Register>();
4161 Register cls = locations->InAt(1).AsRegister<Register>();
4162 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004163 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4164
4165 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4166 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4167 codegen_->AddSlowPath(slow_path);
4168
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004169 // avoid null check if we know obj is not null.
4170 if (instruction->MustDoNullCheck()) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004171 __ CompareAndBranchIfZero(obj, slow_path->GetExitLabel());
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004172 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004173 // Compare the class of `obj` with `cls`.
4174 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4175 __ cmp(temp, ShifterOperand(cls));
4176 __ b(slow_path->GetEntryLabel(), NE);
4177 __ Bind(slow_path->GetExitLabel());
4178}
4179
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004180void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4181 LocationSummary* locations =
4182 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4183 InvokeRuntimeCallingConvention calling_convention;
4184 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4185}
4186
4187void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4188 codegen_->InvokeRuntime(instruction->IsEnter()
4189 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4190 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004191 instruction->GetDexPc(),
4192 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004193}
4194
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004195void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4196void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4197void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4198
4199void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4200 LocationSummary* locations =
4201 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4202 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4203 || instruction->GetResultType() == Primitive::kPrimLong);
4204 locations->SetInAt(0, Location::RequiresRegister());
4205 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004206 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004207}
4208
4209void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4210 HandleBitwiseOperation(instruction);
4211}
4212
4213void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4214 HandleBitwiseOperation(instruction);
4215}
4216
4217void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4218 HandleBitwiseOperation(instruction);
4219}
4220
4221void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4222 LocationSummary* locations = instruction->GetLocations();
4223
4224 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004225 Register first = locations->InAt(0).AsRegister<Register>();
4226 Register second = locations->InAt(1).AsRegister<Register>();
4227 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004228 if (instruction->IsAnd()) {
4229 __ and_(out, first, ShifterOperand(second));
4230 } else if (instruction->IsOr()) {
4231 __ orr(out, first, ShifterOperand(second));
4232 } else {
4233 DCHECK(instruction->IsXor());
4234 __ eor(out, first, ShifterOperand(second));
4235 }
4236 } else {
4237 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4238 Location first = locations->InAt(0);
4239 Location second = locations->InAt(1);
4240 Location out = locations->Out();
4241 if (instruction->IsAnd()) {
4242 __ and_(out.AsRegisterPairLow<Register>(),
4243 first.AsRegisterPairLow<Register>(),
4244 ShifterOperand(second.AsRegisterPairLow<Register>()));
4245 __ and_(out.AsRegisterPairHigh<Register>(),
4246 first.AsRegisterPairHigh<Register>(),
4247 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4248 } else if (instruction->IsOr()) {
4249 __ orr(out.AsRegisterPairLow<Register>(),
4250 first.AsRegisterPairLow<Register>(),
4251 ShifterOperand(second.AsRegisterPairLow<Register>()));
4252 __ orr(out.AsRegisterPairHigh<Register>(),
4253 first.AsRegisterPairHigh<Register>(),
4254 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4255 } else {
4256 DCHECK(instruction->IsXor());
4257 __ eor(out.AsRegisterPairLow<Register>(),
4258 first.AsRegisterPairLow<Register>(),
4259 ShifterOperand(second.AsRegisterPairLow<Register>()));
4260 __ eor(out.AsRegisterPairHigh<Register>(),
4261 first.AsRegisterPairHigh<Register>(),
4262 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4263 }
4264 }
4265}
4266
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004267void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004268 // TODO: Implement all kinds of calls:
4269 // 1) boot -> boot
4270 // 2) app -> boot
4271 // 3) app -> app
4272 //
4273 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4274
Jeff Hao848f70a2014-01-15 13:49:50 -08004275 if (invoke->IsStringInit()) {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004276 Register reg = temp.AsRegister<Register>();
Jeff Hao848f70a2014-01-15 13:49:50 -08004277 // temp = thread->string_init_entrypoint
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004278 __ LoadFromOffset(kLoadWord, reg, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004279 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004280 __ LoadFromOffset(kLoadWord, LR, reg,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004281 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004282 kArmWordSize).Int32Value());
4283 // LR()
4284 __ blx(LR);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004285 } else if (invoke->IsRecursive()) {
4286 __ bl(GetFrameEntryLabel());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004287 } else {
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004288 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4289 Register method_reg;
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004290 Register reg = temp.AsRegister<Register>();
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004291 if (current_method.IsRegister()) {
4292 method_reg = current_method.AsRegister<Register>();
4293 } else {
4294 DCHECK(invoke->GetLocations()->Intrinsified());
4295 DCHECK(!current_method.IsValid());
4296 method_reg = reg;
4297 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4298 }
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004299 // reg = current_method->dex_cache_resolved_methods_;
4300 __ LoadFromOffset(
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004301 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004302 // reg = reg[index_in_cache]
4303 __ LoadFromOffset(
4304 kLoadWord, reg, reg, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4305 // LR = reg[offset_of_quick_compiled_code]
4306 __ LoadFromOffset(kLoadWord, LR, reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4307 kArmWordSize).Int32Value());
4308 // LR()
4309 __ blx(LR);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004310 }
4311
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004312 DCHECK(!IsLeafMethod());
4313}
4314
Calin Juravleb1498f62015-02-16 13:13:29 +00004315void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4316 // Nothing to do, this should be removed during prepare for register allocator.
4317 UNUSED(instruction);
4318 LOG(FATAL) << "Unreachable";
4319}
4320
4321void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4322 // Nothing to do, this should be removed during prepare for register allocator.
4323 UNUSED(instruction);
4324 LOG(FATAL) << "Unreachable";
4325}
4326
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004327} // namespace arm
4328} // namespace art