blob: d90bdd47e8b49a3028907e9bc28acab6bbd48ab7 [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"
Vladimir Marko58155012015-08-19 12:49:41 +000022#include "compiled_method.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070023#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010024#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080025#include "intrinsics.h"
26#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070027#include "mirror/array-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070028#include "mirror/class-inl.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070029#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010030#include "utils/arm/assembler_arm.h"
31#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000032#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010033#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000034
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000035namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010036
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000037namespace arm {
38
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000039static bool ExpectedPairLayout(Location location) {
40 // We expected this for both core and fpu register pairs.
41 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
42}
43
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010044static constexpr int kCurrentMethodStackOffset = 0;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +010045static constexpr Register kMethodRegisterArgument = R0;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010046
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000047// We unconditionally allocate R5 to ensure we can do long operations
48// with baseline.
49static constexpr Register kCoreSavedRegisterForBaseline = R5;
50static constexpr Register kCoreCalleeSaves[] =
51 { R5, R6, R7, R8, R10, R11, PC };
52static constexpr SRegister kFpuCalleeSaves[] =
53 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010054
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000055// D31 cannot be split into two S registers, and the register allocator only works on
56// S registers. Therefore there is no need to block it.
57static constexpr DRegister DTMP = D31;
58
Roland Levillain62a46b22015-06-01 18:24:13 +010059#define __ down_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010060#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010061
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010062class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010063 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010064 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010065
Alexandre Rames67555f72014-11-18 10:55:16 +000066 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010067 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010068 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010069 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000070 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010071 }
72
Alexandre Rames8158f282015-08-07 10:26:17 +010073 bool IsFatal() const OVERRIDE { return true; }
74
Alexandre Rames9931f312015-06-19 14:47:01 +010075 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
76
Nicolas Geoffraye5038322014-07-04 09:41:32 +010077 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010078 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010079 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
80};
81
Calin Juravled0d48522014-11-04 16:40:20 +000082class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
83 public:
84 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
85
Alexandre Rames67555f72014-11-18 10:55:16 +000086 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000087 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
88 __ Bind(GetEntryLabel());
89 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000090 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +000091 }
92
Alexandre Rames8158f282015-08-07 10:26:17 +010093 bool IsFatal() const OVERRIDE { return true; }
94
Alexandre Rames9931f312015-06-19 14:47:01 +010095 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
96
Calin Juravled0d48522014-11-04 16:40:20 +000097 private:
98 HDivZeroCheck* const instruction_;
99 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
100};
101
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100102class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000103 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000104 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100105 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000106
Alexandre Rames67555f72014-11-18 10:55:16 +0000107 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100108 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000109 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000110 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100111 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000112 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000113 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100114 if (successor_ == nullptr) {
115 __ b(GetReturnLabel());
116 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100117 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100118 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000119 }
120
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100121 Label* GetReturnLabel() {
122 DCHECK(successor_ == nullptr);
123 return &return_label_;
124 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000125
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100126 HBasicBlock* GetSuccessor() const {
127 return successor_;
128 }
129
Alexandre Rames9931f312015-06-19 14:47:01 +0100130 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; }
131
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132 private:
133 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100134 // If not null, the block to branch to after the suspend check.
135 HBasicBlock* const successor_;
136
137 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000138 Label return_label_;
139
140 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
141};
142
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100143class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100144 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100145 explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction)
146 : instruction_(instruction) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100147
Alexandre Rames67555f72014-11-18 10:55:16 +0000148 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100149 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100150 LocationSummary* locations = instruction_->GetLocations();
151
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000153 // We're moving two locations to locations that could overlap, so we need a parallel
154 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100155 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000156 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100157 locations->InAt(0),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000158 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100159 Primitive::kPrimInt,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100160 locations->InAt(1),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100161 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
162 Primitive::kPrimInt);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100163 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000164 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100165 }
166
Alexandre Rames8158f282015-08-07 10:26:17 +0100167 bool IsFatal() const OVERRIDE { return true; }
168
Alexandre Rames9931f312015-06-19 14:47:01 +0100169 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; }
170
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100171 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100172 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100173
174 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
175};
176
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000177class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100178 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000179 LoadClassSlowPathARM(HLoadClass* cls,
180 HInstruction* at,
181 uint32_t dex_pc,
182 bool do_clinit)
183 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
184 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
185 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100186
Alexandre Rames67555f72014-11-18 10:55:16 +0000187 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000188 LocationSummary* locations = at_->GetLocations();
189
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
191 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000192 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100193
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100194 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000195 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000196 int32_t entry_point_offset = do_clinit_
197 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
198 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000199 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200
201 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000202 Location out = locations->Out();
203 if (out.IsValid()) {
204 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000205 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
206 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000207 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100208 __ b(GetExitLabel());
209 }
210
Alexandre Rames9931f312015-06-19 14:47:01 +0100211 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
212
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100213 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000214 // The class this slow path will load.
215 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100216
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000217 // The instruction where this slow path is happening.
218 // (Might be the load class or an initialization check).
219 HInstruction* const at_;
220
221 // The dex PC of `at_`.
222 const uint32_t dex_pc_;
223
224 // Whether to initialize the class.
225 const bool do_clinit_;
226
227 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100228};
229
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000230class LoadStringSlowPathARM : public SlowPathCodeARM {
231 public:
232 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
233
Alexandre Rames67555f72014-11-18 10:55:16 +0000234 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000235 LocationSummary* locations = instruction_->GetLocations();
236 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
237
238 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
239 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000240 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000241
242 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800243 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000244 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000245 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000246 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
247
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000248 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000249 __ b(GetExitLabel());
250 }
251
Alexandre Rames9931f312015-06-19 14:47:01 +0100252 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
253
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000254 private:
255 HLoadString* const instruction_;
256
257 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
258};
259
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000260class TypeCheckSlowPathARM : public SlowPathCodeARM {
261 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100262 explicit TypeCheckSlowPathARM(HInstruction* instruction) : instruction_(instruction) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000263
Alexandre Rames67555f72014-11-18 10:55:16 +0000264 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000265 LocationSummary* locations = instruction_->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100266 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0)
267 : locations->Out();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000268 DCHECK(instruction_->IsCheckCast()
269 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000270
271 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
272 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000273 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000274
275 // We're moving two locations to locations that could overlap, so we need a parallel
276 // move resolver.
277 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000278 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100279 locations->InAt(1),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000280 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100281 Primitive::kPrimNot,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100282 object_class,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100283 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
284 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000286 if (instruction_->IsInstanceOf()) {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100287 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
288 instruction_,
289 instruction_->GetDexPc(),
290 this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000291 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
292 } else {
293 DCHECK(instruction_->IsCheckCast());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100294 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
295 instruction_,
296 instruction_->GetDexPc(),
297 this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000298 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000299
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000300 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000301 __ b(GetExitLabel());
302 }
303
Alexandre Rames9931f312015-06-19 14:47:01 +0100304 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
305
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000306 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000307 HInstruction* const instruction_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000308
309 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
310};
311
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700312class DeoptimizationSlowPathARM : public SlowPathCodeARM {
313 public:
314 explicit DeoptimizationSlowPathARM(HInstruction* instruction)
315 : instruction_(instruction) {}
316
317 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
318 __ Bind(GetEntryLabel());
319 SaveLiveRegisters(codegen, instruction_->GetLocations());
320 DCHECK(instruction_->IsDeoptimize());
321 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
322 uint32_t dex_pc = deoptimize->GetDexPc();
323 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
324 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
325 }
326
Alexandre Rames9931f312015-06-19 14:47:01 +0100327 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
328
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700329 private:
330 HInstruction* const instruction_;
331 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
332};
333
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000334#undef __
Roland Levillain62a46b22015-06-01 18:24:13 +0100335#define __ down_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700336
Roland Levillain4fa13f62015-07-06 18:11:54 +0100337inline Condition ARMSignedOrFPCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700338 switch (cond) {
339 case kCondEQ: return EQ;
340 case kCondNE: return NE;
341 case kCondLT: return LT;
342 case kCondLE: return LE;
343 case kCondGT: return GT;
344 case kCondGE: return GE;
Dave Allison20dfc792014-06-16 20:44:29 -0700345 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100346 LOG(FATAL) << "Unreachable";
347 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700348}
349
Roland Levillain4fa13f62015-07-06 18:11:54 +0100350inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700351 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100352 case kCondEQ: return EQ;
353 case kCondNE: return NE;
354 case kCondLT: return LO;
355 case kCondLE: return LS;
356 case kCondGT: return HI;
357 case kCondGE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700358 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100359 LOG(FATAL) << "Unreachable";
360 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700361}
362
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100363void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100364 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100365}
366
367void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100368 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100369}
370
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100371size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
372 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
373 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100374}
375
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100376size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
377 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
378 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100379}
380
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000381size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
382 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
383 return kArmWordSize;
384}
385
386size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
387 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
388 return kArmWordSize;
389}
390
Calin Juravle34166012014-12-19 17:22:29 +0000391CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000392 const ArmInstructionSetFeatures& isa_features,
393 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000394 : CodeGenerator(graph,
395 kNumberOfCoreRegisters,
396 kNumberOfSRegisters,
397 kNumberOfRegisterPairs,
398 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
399 arraysize(kCoreCalleeSaves)),
400 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
401 arraysize(kFpuCalleeSaves)),
402 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100403 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100404 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100405 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100406 move_resolver_(graph->GetArena(), this),
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000407 assembler_(),
Vladimir Marko58155012015-08-19 12:49:41 +0000408 isa_features_(isa_features),
409 method_patches_(MethodReferenceComparator(), graph->GetArena()->Adapter()),
410 call_patches_(MethodReferenceComparator(), graph->GetArena()->Adapter()),
411 relative_call_patches_(graph->GetArena()->Adapter()) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000412 // Save the PC register to mimic Quick.
413 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100414}
415
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000416void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
417 // Ensure that we fix up branches and literal loads and emit the literal pool.
418 __ FinalizeCode();
419
420 // Adjust native pc offsets in stack maps.
421 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
422 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
423 uint32_t new_position = __ GetAdjustedPosition(old_position);
424 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
425 }
426 // Adjust native pc offsets of block labels.
427 for (size_t block_idx = 0u, end = block_order_->Size(); block_idx != end; ++block_idx) {
428 HBasicBlock* block = block_order_->Get(block_idx);
429 // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid
430 // FirstNonEmptyBlock() which could lead to adjusting a label more than once.
431 DCHECK_LT(static_cast<size_t>(block->GetBlockId()), block_labels_.Size());
432 Label* block_label = &block_labels_.GetRawStorage()[block->GetBlockId()];
David Brazdilfc6a86a2015-06-26 10:33:45 +0000433 DCHECK_EQ(block_label->IsBound(), !block->IsSingleJump());
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000434 if (block_label->IsBound()) {
435 __ AdjustLabelPosition(block_label);
436 }
437 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100438 // Adjust pc offsets for the disassembly information.
439 if (disasm_info_ != nullptr) {
440 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
441 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
442 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
443 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
444 it.second.start = __ GetAdjustedPosition(it.second.start);
445 it.second.end = __ GetAdjustedPosition(it.second.end);
446 }
447 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
448 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
449 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
450 }
451 }
Vladimir Marko58155012015-08-19 12:49:41 +0000452 // Adjust pc offsets for relative call patches.
453 for (MethodPatchInfo<Label>& info : relative_call_patches_) {
454 __ AdjustLabelPosition(&info.label);
455 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000456
457 CodeGenerator::Finalize(allocator);
458}
459
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100460Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100461 switch (type) {
462 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100463 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100464 ArmManagedRegister pair =
465 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100466 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
467 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
468
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100469 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
470 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100471 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100472 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100473 }
474
475 case Primitive::kPrimByte:
476 case Primitive::kPrimBoolean:
477 case Primitive::kPrimChar:
478 case Primitive::kPrimShort:
479 case Primitive::kPrimInt:
480 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100481 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100482 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100483 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
484 ArmManagedRegister current =
485 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
486 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100487 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100488 }
489 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100490 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100491 }
492
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000493 case Primitive::kPrimFloat: {
494 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100495 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100496 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100497
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000498 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000499 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
500 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000501 return Location::FpuRegisterPairLocation(reg, reg + 1);
502 }
503
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100504 case Primitive::kPrimVoid:
505 LOG(FATAL) << "Unreachable type " << type;
506 }
507
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100508 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100509}
510
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000511void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100512 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100513 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100514
515 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100516 blocked_core_registers_[SP] = true;
517 blocked_core_registers_[LR] = true;
518 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100519
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100520 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100521 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100522
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100523 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100524 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100525
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000526 if (is_baseline) {
527 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
528 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
529 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000530
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000531 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
532
533 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
534 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
535 }
536 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100537
538 UpdateBlockedPairRegisters();
539}
540
541void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
542 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
543 ArmManagedRegister current =
544 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
545 if (blocked_core_registers_[current.AsRegisterPairLow()]
546 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
547 blocked_register_pairs_[i] = true;
548 }
549 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100550}
551
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100552InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
553 : HGraphVisitor(graph),
554 assembler_(codegen->GetAssembler()),
555 codegen_(codegen) {}
556
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000557void CodeGeneratorARM::ComputeSpillMask() {
558 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000559 // Save one extra register for baseline. Note that on thumb2, there is no easy
560 // instruction to restore just the PC, so this actually helps both baseline
561 // and non-baseline to save and restore at least two registers at entry and exit.
562 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000563 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
564 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
565 // We use vpush and vpop for saving and restoring floating point registers, which take
566 // a SRegister and the number of registers to save/restore after that SRegister. We
567 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
568 // but in the range.
569 if (fpu_spill_mask_ != 0) {
570 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
571 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
572 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
573 fpu_spill_mask_ |= (1 << i);
574 }
575 }
576}
577
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100578static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100579 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100580}
581
582static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100583 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100584}
585
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000586void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000587 bool skip_overflow_check =
588 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000589 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000590 __ Bind(&frame_entry_label_);
591
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000592 if (HasEmptyFrame()) {
593 return;
594 }
595
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100596 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000597 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
598 __ LoadFromOffset(kLoadWord, IP, IP, 0);
599 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100600 }
601
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000602 // PC is in the list of callee-save to mimic Quick, but we need to push
603 // LR at entry instead.
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100604 uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR;
605 __ PushList(push_mask);
606 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100607 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, push_mask, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000608 if (fpu_spill_mask_ != 0) {
609 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
610 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100611 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100612 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000613 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100614 int adjust = GetFrameSize() - FrameEntrySpillSize();
615 __ AddConstant(SP, -adjust);
616 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100617 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000618}
619
620void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000621 if (HasEmptyFrame()) {
622 __ bx(LR);
623 return;
624 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100625 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100626 int adjust = GetFrameSize() - FrameEntrySpillSize();
627 __ AddConstant(SP, adjust);
628 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000629 if (fpu_spill_mask_ != 0) {
630 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
631 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100632 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
633 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000634 }
635 __ PopList(core_spill_mask_);
David Srbeckyc34dc932015-04-12 09:27:43 +0100636 __ cfi().RestoreState();
637 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000638}
639
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100640void CodeGeneratorARM::Bind(HBasicBlock* block) {
641 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000642}
643
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100644Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
645 switch (load->GetType()) {
646 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100647 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100648 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100649
650 case Primitive::kPrimInt:
651 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100652 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100653 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100654
655 case Primitive::kPrimBoolean:
656 case Primitive::kPrimByte:
657 case Primitive::kPrimChar:
658 case Primitive::kPrimShort:
659 case Primitive::kPrimVoid:
660 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700661 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100662 }
663
664 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700665 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100666}
667
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100668Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100669 switch (type) {
670 case Primitive::kPrimBoolean:
671 case Primitive::kPrimByte:
672 case Primitive::kPrimChar:
673 case Primitive::kPrimShort:
674 case Primitive::kPrimInt:
675 case Primitive::kPrimNot: {
676 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000677 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100678 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100679 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100680 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000681 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100682 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100683 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100684
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000685 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100686 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000687 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100688 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000689 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100690 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000691 if (calling_convention.GetRegisterAt(index) == R1) {
692 // Skip R1, and use R2_R3 instead.
693 gp_index_++;
694 index++;
695 }
696 }
697 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
698 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000699 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000700 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000701 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100702 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000703 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
704 }
705 }
706
707 case Primitive::kPrimFloat: {
708 uint32_t stack_index = stack_index_++;
709 if (float_index_ % 2 == 0) {
710 float_index_ = std::max(double_index_, float_index_);
711 }
712 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
713 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
714 } else {
715 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
716 }
717 }
718
719 case Primitive::kPrimDouble: {
720 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
721 uint32_t stack_index = stack_index_;
722 stack_index_ += 2;
723 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
724 uint32_t index = double_index_;
725 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000726 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000727 calling_convention.GetFpuRegisterAt(index),
728 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000729 DCHECK(ExpectedPairLayout(result));
730 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000731 } else {
732 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100733 }
734 }
735
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100736 case Primitive::kPrimVoid:
737 LOG(FATAL) << "Unexpected parameter type " << type;
738 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100739 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100740 return Location();
741}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100742
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100743Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000744 switch (type) {
745 case Primitive::kPrimBoolean:
746 case Primitive::kPrimByte:
747 case Primitive::kPrimChar:
748 case Primitive::kPrimShort:
749 case Primitive::kPrimInt:
750 case Primitive::kPrimNot: {
751 return Location::RegisterLocation(R0);
752 }
753
754 case Primitive::kPrimFloat: {
755 return Location::FpuRegisterLocation(S0);
756 }
757
758 case Primitive::kPrimLong: {
759 return Location::RegisterPairLocation(R0, R1);
760 }
761
762 case Primitive::kPrimDouble: {
763 return Location::FpuRegisterPairLocation(S0, S1);
764 }
765
766 case Primitive::kPrimVoid:
767 return Location();
768 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100769
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000770 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000771}
772
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100773Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
774 return Location::RegisterLocation(kMethodRegisterArgument);
775}
776
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100777void CodeGeneratorARM::Move32(Location destination, Location source) {
778 if (source.Equals(destination)) {
779 return;
780 }
781 if (destination.IsRegister()) {
782 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000783 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100784 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000785 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100786 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000787 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100788 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100789 } else if (destination.IsFpuRegister()) {
790 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000791 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100792 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000793 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100794 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000795 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100796 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100797 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000798 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100799 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000800 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100801 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000802 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100803 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000804 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100805 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
806 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100807 }
808 }
809}
810
811void CodeGeneratorARM::Move64(Location destination, Location source) {
812 if (source.Equals(destination)) {
813 return;
814 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100815 if (destination.IsRegisterPair()) {
816 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000817 EmitParallelMoves(
818 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
819 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100820 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000821 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100822 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
823 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100824 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000825 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100826 } else {
827 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000828 DCHECK(ExpectedPairLayout(destination));
829 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
830 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100831 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000832 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100833 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000834 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
835 SP,
836 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100837 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000838 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100839 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100840 } else {
841 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100842 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000843 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100844 if (source.AsRegisterPairLow<Register>() == R1) {
845 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100846 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
847 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100848 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100849 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100850 SP, destination.GetStackIndex());
851 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000852 } else if (source.IsFpuRegisterPair()) {
853 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
854 SP,
855 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100856 } else {
857 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000858 EmitParallelMoves(
859 Location::StackSlot(source.GetStackIndex()),
860 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100861 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000862 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100863 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
864 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100865 }
866 }
867}
868
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100869void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100870 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100871 if (instruction->IsCurrentMethod()) {
872 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
873 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100874 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100875 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000876 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000877 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
878 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000879 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000880 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000881 } else {
882 DCHECK(location.IsStackSlot());
883 __ LoadImmediate(IP, value);
884 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
885 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000886 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000887 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000888 int64_t value = const_to_move->AsLongConstant()->GetValue();
889 if (location.IsRegisterPair()) {
890 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
891 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
892 } else {
893 DCHECK(location.IsDoubleStackSlot());
894 __ LoadImmediate(IP, Low32Bits(value));
895 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
896 __ LoadImmediate(IP, High32Bits(value));
897 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
898 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100899 }
Roland Levillain476df552014-10-09 17:51:36 +0100900 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100901 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
902 switch (instruction->GetType()) {
903 case Primitive::kPrimBoolean:
904 case Primitive::kPrimByte:
905 case Primitive::kPrimChar:
906 case Primitive::kPrimShort:
907 case Primitive::kPrimInt:
908 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100909 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100910 Move32(location, Location::StackSlot(stack_slot));
911 break;
912
913 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100914 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100915 Move64(location, Location::DoubleStackSlot(stack_slot));
916 break;
917
918 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100919 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100920 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000921 } else if (instruction->IsTemporary()) {
922 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000923 if (temp_location.IsStackSlot()) {
924 Move32(location, temp_location);
925 } else {
926 DCHECK(temp_location.IsDoubleStackSlot());
927 Move64(location, temp_location);
928 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000929 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100930 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100931 switch (instruction->GetType()) {
932 case Primitive::kPrimBoolean:
933 case Primitive::kPrimByte:
934 case Primitive::kPrimChar:
935 case Primitive::kPrimShort:
936 case Primitive::kPrimNot:
937 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100938 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100939 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100940 break;
941
942 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100943 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100944 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100945 break;
946
947 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100948 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100949 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000950 }
951}
952
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100953void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
954 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000955 uint32_t dex_pc,
956 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +0100957 ValidateInvokeRuntime(instruction, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100958 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
959 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000960 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100961}
962
David Brazdilfc6a86a2015-06-26 10:33:45 +0000963void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100964 DCHECK(!successor->IsExitBlock());
965
966 HBasicBlock* block = got->GetBlock();
967 HInstruction* previous = got->GetPrevious();
968
969 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000970 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100971 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
972 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
973 return;
974 }
975
976 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
977 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
978 }
979 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000980 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000981 }
982}
983
David Brazdilfc6a86a2015-06-26 10:33:45 +0000984void LocationsBuilderARM::VisitGoto(HGoto* got) {
985 got->SetLocations(nullptr);
986}
987
988void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
989 HandleGoto(got, got->GetSuccessor());
990}
991
992void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
993 try_boundary->SetLocations(nullptr);
994}
995
996void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
997 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
998 if (!successor->IsExitBlock()) {
999 HandleGoto(try_boundary, successor);
1000 }
1001}
1002
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001003void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001004 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001005}
1006
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001007void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001008 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001009}
1010
Roland Levillain4fa13f62015-07-06 18:11:54 +01001011void InstructionCodeGeneratorARM::GenerateCompareWithImmediate(Register left, int32_t right) {
1012 ShifterOperand operand;
1013 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, right, &operand)) {
1014 __ cmp(left, operand);
1015 } else {
1016 Register temp = IP;
1017 __ LoadImmediate(temp, right);
1018 __ cmp(left, ShifterOperand(temp));
1019 }
1020}
1021
1022void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1023 Label* true_label,
1024 Label* false_label) {
1025 __ vmstat(); // transfer FP status register to ARM APSR.
1026 if (cond->IsFPConditionTrueIfNaN()) {
1027 __ b(true_label, VS); // VS for unordered.
1028 } else if (cond->IsFPConditionFalseIfNaN()) {
1029 __ b(false_label, VS); // VS for unordered.
1030 }
1031 __ b(true_label, ARMSignedOrFPCondition(cond->GetCondition()));
1032}
1033
1034void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1035 Label* true_label,
1036 Label* false_label) {
1037 LocationSummary* locations = cond->GetLocations();
1038 Location left = locations->InAt(0);
1039 Location right = locations->InAt(1);
1040 IfCondition if_cond = cond->GetCondition();
1041
1042 Register left_high = left.AsRegisterPairHigh<Register>();
1043 Register left_low = left.AsRegisterPairLow<Register>();
1044 IfCondition true_high_cond = if_cond;
1045 IfCondition false_high_cond = cond->GetOppositeCondition();
1046 Condition final_condition = ARMUnsignedCondition(if_cond);
1047
1048 // Set the conditions for the test, remembering that == needs to be
1049 // decided using the low words.
1050 switch (if_cond) {
1051 case kCondEQ:
1052 case kCondNE:
1053 // Nothing to do.
1054 break;
1055 case kCondLT:
1056 false_high_cond = kCondGT;
1057 break;
1058 case kCondLE:
1059 true_high_cond = kCondLT;
1060 break;
1061 case kCondGT:
1062 false_high_cond = kCondLT;
1063 break;
1064 case kCondGE:
1065 true_high_cond = kCondGT;
1066 break;
1067 }
1068 if (right.IsConstant()) {
1069 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1070 int32_t val_low = Low32Bits(value);
1071 int32_t val_high = High32Bits(value);
1072
1073 GenerateCompareWithImmediate(left_high, val_high);
1074 if (if_cond == kCondNE) {
1075 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1076 } else if (if_cond == kCondEQ) {
1077 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1078 } else {
1079 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1080 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1081 }
1082 // Must be equal high, so compare the lows.
1083 GenerateCompareWithImmediate(left_low, val_low);
1084 } else {
1085 Register right_high = right.AsRegisterPairHigh<Register>();
1086 Register right_low = right.AsRegisterPairLow<Register>();
1087
1088 __ cmp(left_high, ShifterOperand(right_high));
1089 if (if_cond == kCondNE) {
1090 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1091 } else if (if_cond == kCondEQ) {
1092 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1093 } else {
1094 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1095 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1096 }
1097 // Must be equal high, so compare the lows.
1098 __ cmp(left_low, ShifterOperand(right_low));
1099 }
1100 // The last comparison might be unsigned.
1101 __ b(true_label, final_condition);
1102}
1103
1104void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HIf* if_instr,
1105 HCondition* condition,
1106 Label* true_target,
1107 Label* false_target,
1108 Label* always_true_target) {
1109 LocationSummary* locations = condition->GetLocations();
1110 Location left = locations->InAt(0);
1111 Location right = locations->InAt(1);
1112
1113 // We don't want true_target as a nullptr.
1114 if (true_target == nullptr) {
1115 true_target = always_true_target;
1116 }
1117 bool falls_through = (false_target == nullptr);
1118
1119 // FP compares don't like null false_targets.
1120 if (false_target == nullptr) {
1121 false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1122 }
1123
1124 Primitive::Type type = condition->InputAt(0)->GetType();
1125 switch (type) {
1126 case Primitive::kPrimLong:
1127 GenerateLongComparesAndJumps(condition, true_target, false_target);
1128 break;
1129 case Primitive::kPrimFloat:
1130 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1131 GenerateFPJumps(condition, true_target, false_target);
1132 break;
1133 case Primitive::kPrimDouble:
1134 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1135 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1136 GenerateFPJumps(condition, true_target, false_target);
1137 break;
1138 default:
1139 LOG(FATAL) << "Unexpected compare type " << type;
1140 }
1141
1142 if (!falls_through) {
1143 __ b(false_target);
1144 }
1145}
1146
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001147void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
1148 Label* true_target,
1149 Label* false_target,
1150 Label* always_true_target) {
1151 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001152 if (cond->IsIntConstant()) {
1153 // Constant condition, statically compared against 1.
1154 int32_t cond_value = cond->AsIntConstant()->GetValue();
1155 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001156 if (always_true_target != nullptr) {
1157 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001158 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001159 return;
1160 } else {
1161 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001162 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001163 } else {
1164 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1165 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001166 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01001167 __ CompareAndBranchIfNonZero(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
1168 true_target);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001169 } else {
1170 // Condition has not been materialized, use its inputs as the
1171 // comparison and its condition as the branch condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +01001172 Primitive::Type type =
1173 cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt;
1174 // Is this a long or FP comparison that has been folded into the HCondition?
1175 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1176 // Generate the comparison directly.
1177 GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(),
1178 true_target, false_target, always_true_target);
1179 return;
1180 }
1181
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001182 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001183 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001184 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain4fa13f62015-07-06 18:11:54 +01001185 Location right = locations->InAt(1);
1186 if (right.IsRegister()) {
1187 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001188 } else {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001189 DCHECK(right.IsConstant());
1190 GenerateCompareWithImmediate(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001191 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001192 __ b(true_target, ARMSignedOrFPCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001193 }
Dave Allison20dfc792014-06-16 20:44:29 -07001194 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001195 if (false_target != nullptr) {
1196 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001197 }
1198}
1199
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001200void LocationsBuilderARM::VisitIf(HIf* if_instr) {
1201 LocationSummary* locations =
1202 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
1203 HInstruction* cond = if_instr->InputAt(0);
1204 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1205 locations->SetInAt(0, Location::RequiresRegister());
1206 }
1207}
1208
1209void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1210 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1211 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1212 Label* always_true_target = true_target;
1213 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1214 if_instr->IfTrueSuccessor())) {
1215 always_true_target = nullptr;
1216 }
1217 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1218 if_instr->IfFalseSuccessor())) {
1219 false_target = nullptr;
1220 }
1221 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1222}
1223
1224void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1225 LocationSummary* locations = new (GetGraph()->GetArena())
1226 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1227 HInstruction* cond = deoptimize->InputAt(0);
1228 DCHECK(cond->IsCondition());
1229 if (cond->AsCondition()->NeedsMaterialization()) {
1230 locations->SetInAt(0, Location::RequiresRegister());
1231 }
1232}
1233
1234void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1235 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1236 DeoptimizationSlowPathARM(deoptimize);
1237 codegen_->AddSlowPath(slow_path);
1238 Label* slow_path_entry = slow_path->GetEntryLabel();
1239 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1240}
Dave Allison20dfc792014-06-16 20:44:29 -07001241
Roland Levillain0d37cd02015-05-27 16:39:19 +01001242void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001243 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001244 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001245 // Handle the long/FP comparisons made in instruction simplification.
1246 switch (cond->InputAt(0)->GetType()) {
1247 case Primitive::kPrimLong:
1248 locations->SetInAt(0, Location::RequiresRegister());
1249 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1250 if (cond->NeedsMaterialization()) {
1251 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1252 }
1253 break;
1254
1255 case Primitive::kPrimFloat:
1256 case Primitive::kPrimDouble:
1257 locations->SetInAt(0, Location::RequiresFpuRegister());
1258 locations->SetInAt(1, Location::RequiresFpuRegister());
1259 if (cond->NeedsMaterialization()) {
1260 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1261 }
1262 break;
1263
1264 default:
1265 locations->SetInAt(0, Location::RequiresRegister());
1266 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1267 if (cond->NeedsMaterialization()) {
1268 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1269 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001270 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001271}
1272
Roland Levillain0d37cd02015-05-27 16:39:19 +01001273void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001274 if (!cond->NeedsMaterialization()) {
1275 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001276 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001277
1278 LocationSummary* locations = cond->GetLocations();
1279 Location left = locations->InAt(0);
1280 Location right = locations->InAt(1);
1281 Register out = locations->Out().AsRegister<Register>();
1282 Label true_label, false_label;
1283
1284 switch (cond->InputAt(0)->GetType()) {
1285 default: {
1286 // Integer case.
1287 if (right.IsRegister()) {
1288 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1289 } else {
1290 DCHECK(right.IsConstant());
1291 GenerateCompareWithImmediate(left.AsRegister<Register>(),
1292 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
1293 }
1294 __ it(ARMSignedOrFPCondition(cond->GetCondition()), kItElse);
1295 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
1296 ARMSignedOrFPCondition(cond->GetCondition()));
1297 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
1298 ARMSignedOrFPCondition(cond->GetOppositeCondition()));
1299 return;
1300 }
1301 case Primitive::kPrimLong:
1302 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1303 break;
1304 case Primitive::kPrimFloat:
1305 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1306 GenerateFPJumps(cond, &true_label, &false_label);
1307 break;
1308 case Primitive::kPrimDouble:
1309 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1310 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1311 GenerateFPJumps(cond, &true_label, &false_label);
1312 break;
1313 }
1314
1315 // Convert the jumps into the result.
1316 Label done_label;
1317
1318 // False case: result = 0.
1319 __ Bind(&false_label);
1320 __ LoadImmediate(out, 0);
1321 __ b(&done_label);
1322
1323 // True case: result = 1.
1324 __ Bind(&true_label);
1325 __ LoadImmediate(out, 1);
1326 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001327}
1328
1329void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1330 VisitCondition(comp);
1331}
1332
1333void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1334 VisitCondition(comp);
1335}
1336
1337void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1338 VisitCondition(comp);
1339}
1340
1341void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1342 VisitCondition(comp);
1343}
1344
1345void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1346 VisitCondition(comp);
1347}
1348
1349void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1350 VisitCondition(comp);
1351}
1352
1353void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1354 VisitCondition(comp);
1355}
1356
1357void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1358 VisitCondition(comp);
1359}
1360
1361void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1362 VisitCondition(comp);
1363}
1364
1365void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1366 VisitCondition(comp);
1367}
1368
1369void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1370 VisitCondition(comp);
1371}
1372
1373void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1374 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001375}
1376
1377void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001378 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001379}
1380
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001381void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1382 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001383}
1384
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001385void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001386 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001387}
1388
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001389void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001390 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001391 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001392}
1393
1394void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001395 LocationSummary* locations =
1396 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001397 switch (store->InputAt(1)->GetType()) {
1398 case Primitive::kPrimBoolean:
1399 case Primitive::kPrimByte:
1400 case Primitive::kPrimChar:
1401 case Primitive::kPrimShort:
1402 case Primitive::kPrimInt:
1403 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001404 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001405 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1406 break;
1407
1408 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001409 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001410 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1411 break;
1412
1413 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001414 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001415 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001416}
1417
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001418void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001419 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001420}
1421
1422void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001423 LocationSummary* locations =
1424 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001425 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001426}
1427
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001428void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001429 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001430 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001431}
1432
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001433void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1434 LocationSummary* locations =
1435 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1436 locations->SetOut(Location::ConstantLocation(constant));
1437}
1438
1439void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1440 // Will be generated at use site.
1441 UNUSED(constant);
1442}
1443
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001444void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001445 LocationSummary* locations =
1446 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001447 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001448}
1449
1450void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1451 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001452 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001453}
1454
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001455void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1456 LocationSummary* locations =
1457 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1458 locations->SetOut(Location::ConstantLocation(constant));
1459}
1460
1461void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1462 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001463 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001464}
1465
1466void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1467 LocationSummary* locations =
1468 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1469 locations->SetOut(Location::ConstantLocation(constant));
1470}
1471
1472void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1473 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001474 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001475}
1476
Calin Juravle27df7582015-04-17 19:12:31 +01001477void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1478 memory_barrier->SetLocations(nullptr);
1479}
1480
1481void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1482 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1483}
1484
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001485void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001486 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001487}
1488
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001489void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001490 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001491 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001492}
1493
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001494void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001495 LocationSummary* locations =
1496 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001497 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001498}
1499
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001500void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001501 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001502 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001503}
1504
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001505void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001506 // When we do not run baseline, explicit clinit checks triggered by static
1507 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1508 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001509
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001510 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1511 codegen_->GetInstructionSetFeatures());
1512 if (intrinsic.TryDispatch(invoke)) {
1513 return;
1514 }
1515
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001516 HandleInvoke(invoke);
1517}
1518
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001519static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1520 if (invoke->GetLocations()->Intrinsified()) {
1521 IntrinsicCodeGeneratorARM intrinsic(codegen);
1522 intrinsic.Dispatch(invoke);
1523 return true;
1524 }
1525 return false;
1526}
1527
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001528void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001529 // When we do not run baseline, explicit clinit checks triggered by static
1530 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1531 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001532
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001533 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1534 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001535 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001536
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001537 LocationSummary* locations = invoke->GetLocations();
1538 codegen_->GenerateStaticOrDirectCall(
1539 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001540 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001541}
1542
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001543void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001544 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001545 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001546}
1547
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001548void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001549 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1550 codegen_->GetInstructionSetFeatures());
1551 if (intrinsic.TryDispatch(invoke)) {
1552 return;
1553 }
1554
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001555 HandleInvoke(invoke);
1556}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001557
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001558void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001559 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1560 return;
1561 }
1562
Roland Levillain271ab9c2014-11-27 15:23:57 +00001563 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001564 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1565 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001566 LocationSummary* locations = invoke->GetLocations();
1567 Location receiver = locations->InAt(0);
1568 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1569 // temp = object->GetClass();
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001570 DCHECK(receiver.IsRegister());
1571 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00001572 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001573 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001574 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001575 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001576 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001577 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001578 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001579 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001580 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001581 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001582 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001583 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001584}
1585
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001586void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1587 HandleInvoke(invoke);
1588 // Add the hidden argument.
1589 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1590}
1591
1592void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1593 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001594 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001595 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1596 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001597 LocationSummary* locations = invoke->GetLocations();
1598 Location receiver = locations->InAt(0);
1599 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1600
1601 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001602 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1603 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001604
1605 // temp = object->GetClass();
1606 if (receiver.IsStackSlot()) {
1607 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1608 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1609 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001610 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001611 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001612 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001613 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001614 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001615 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001616 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001617 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1618 // LR = temp->GetEntryPoint();
1619 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1620 // LR();
1621 __ blx(LR);
1622 DCHECK(!codegen_->IsLeafMethod());
1623 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1624}
1625
Roland Levillain88cb1752014-10-20 16:36:47 +01001626void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1627 LocationSummary* locations =
1628 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1629 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001630 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001631 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001632 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1633 break;
1634 }
1635 case Primitive::kPrimLong: {
1636 locations->SetInAt(0, Location::RequiresRegister());
1637 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001638 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001639 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001640
Roland Levillain88cb1752014-10-20 16:36:47 +01001641 case Primitive::kPrimFloat:
1642 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001643 locations->SetInAt(0, Location::RequiresFpuRegister());
1644 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001645 break;
1646
1647 default:
1648 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1649 }
1650}
1651
1652void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1653 LocationSummary* locations = neg->GetLocations();
1654 Location out = locations->Out();
1655 Location in = locations->InAt(0);
1656 switch (neg->GetResultType()) {
1657 case Primitive::kPrimInt:
1658 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001659 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001660 break;
1661
1662 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001663 DCHECK(in.IsRegisterPair());
1664 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1665 __ rsbs(out.AsRegisterPairLow<Register>(),
1666 in.AsRegisterPairLow<Register>(),
1667 ShifterOperand(0));
1668 // We cannot emit an RSC (Reverse Subtract with Carry)
1669 // instruction here, as it does not exist in the Thumb-2
1670 // instruction set. We use the following approach
1671 // using SBC and SUB instead.
1672 //
1673 // out.hi = -C
1674 __ sbc(out.AsRegisterPairHigh<Register>(),
1675 out.AsRegisterPairHigh<Register>(),
1676 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1677 // out.hi = out.hi - in.hi
1678 __ sub(out.AsRegisterPairHigh<Register>(),
1679 out.AsRegisterPairHigh<Register>(),
1680 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1681 break;
1682
Roland Levillain88cb1752014-10-20 16:36:47 +01001683 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001684 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001685 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001686 break;
1687
Roland Levillain88cb1752014-10-20 16:36:47 +01001688 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001689 DCHECK(in.IsFpuRegisterPair());
1690 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1691 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001692 break;
1693
1694 default:
1695 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1696 }
1697}
1698
Roland Levillaindff1f282014-11-05 14:15:05 +00001699void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001700 Primitive::Type result_type = conversion->GetResultType();
1701 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001702 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001703
Roland Levillain5b3ee562015-04-14 16:02:41 +01001704 // The float-to-long, double-to-long and long-to-float type conversions
1705 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001706 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001707 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1708 && result_type == Primitive::kPrimLong)
1709 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001710 ? LocationSummary::kCall
1711 : LocationSummary::kNoCall;
1712 LocationSummary* locations =
1713 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1714
David Brazdilb2bd1c52015-03-25 11:17:37 +00001715 // The Java language does not allow treating boolean as an integral type but
1716 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001717
Roland Levillaindff1f282014-11-05 14:15:05 +00001718 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001719 case Primitive::kPrimByte:
1720 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001721 case Primitive::kPrimBoolean:
1722 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001723 case Primitive::kPrimShort:
1724 case Primitive::kPrimInt:
1725 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001726 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001727 locations->SetInAt(0, Location::RequiresRegister());
1728 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1729 break;
1730
1731 default:
1732 LOG(FATAL) << "Unexpected type conversion from " << input_type
1733 << " to " << result_type;
1734 }
1735 break;
1736
Roland Levillain01a8d712014-11-14 16:27:39 +00001737 case Primitive::kPrimShort:
1738 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001739 case Primitive::kPrimBoolean:
1740 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001741 case Primitive::kPrimByte:
1742 case Primitive::kPrimInt:
1743 case Primitive::kPrimChar:
1744 // Processing a Dex `int-to-short' instruction.
1745 locations->SetInAt(0, Location::RequiresRegister());
1746 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1747 break;
1748
1749 default:
1750 LOG(FATAL) << "Unexpected type conversion from " << input_type
1751 << " to " << result_type;
1752 }
1753 break;
1754
Roland Levillain946e1432014-11-11 17:35:19 +00001755 case Primitive::kPrimInt:
1756 switch (input_type) {
1757 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001758 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001759 locations->SetInAt(0, Location::Any());
1760 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1761 break;
1762
1763 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001764 // Processing a Dex `float-to-int' instruction.
1765 locations->SetInAt(0, Location::RequiresFpuRegister());
1766 locations->SetOut(Location::RequiresRegister());
1767 locations->AddTemp(Location::RequiresFpuRegister());
1768 break;
1769
Roland Levillain946e1432014-11-11 17:35:19 +00001770 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001771 // Processing a Dex `double-to-int' instruction.
1772 locations->SetInAt(0, Location::RequiresFpuRegister());
1773 locations->SetOut(Location::RequiresRegister());
1774 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001775 break;
1776
1777 default:
1778 LOG(FATAL) << "Unexpected type conversion from " << input_type
1779 << " to " << result_type;
1780 }
1781 break;
1782
Roland Levillaindff1f282014-11-05 14:15:05 +00001783 case Primitive::kPrimLong:
1784 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001785 case Primitive::kPrimBoolean:
1786 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001787 case Primitive::kPrimByte:
1788 case Primitive::kPrimShort:
1789 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001790 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001791 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001792 locations->SetInAt(0, Location::RequiresRegister());
1793 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1794 break;
1795
Roland Levillain624279f2014-12-04 11:54:28 +00001796 case Primitive::kPrimFloat: {
1797 // Processing a Dex `float-to-long' instruction.
1798 InvokeRuntimeCallingConvention calling_convention;
1799 locations->SetInAt(0, Location::FpuRegisterLocation(
1800 calling_convention.GetFpuRegisterAt(0)));
1801 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1802 break;
1803 }
1804
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001805 case Primitive::kPrimDouble: {
1806 // Processing a Dex `double-to-long' instruction.
1807 InvokeRuntimeCallingConvention calling_convention;
1808 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1809 calling_convention.GetFpuRegisterAt(0),
1810 calling_convention.GetFpuRegisterAt(1)));
1811 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001812 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001813 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001814
1815 default:
1816 LOG(FATAL) << "Unexpected type conversion from " << input_type
1817 << " to " << result_type;
1818 }
1819 break;
1820
Roland Levillain981e4542014-11-14 11:47:14 +00001821 case Primitive::kPrimChar:
1822 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001823 case Primitive::kPrimBoolean:
1824 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001825 case Primitive::kPrimByte:
1826 case Primitive::kPrimShort:
1827 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001828 // Processing a Dex `int-to-char' instruction.
1829 locations->SetInAt(0, Location::RequiresRegister());
1830 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1831 break;
1832
1833 default:
1834 LOG(FATAL) << "Unexpected type conversion from " << input_type
1835 << " to " << result_type;
1836 }
1837 break;
1838
Roland Levillaindff1f282014-11-05 14:15:05 +00001839 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001840 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001841 case Primitive::kPrimBoolean:
1842 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001843 case Primitive::kPrimByte:
1844 case Primitive::kPrimShort:
1845 case Primitive::kPrimInt:
1846 case Primitive::kPrimChar:
1847 // Processing a Dex `int-to-float' instruction.
1848 locations->SetInAt(0, Location::RequiresRegister());
1849 locations->SetOut(Location::RequiresFpuRegister());
1850 break;
1851
Roland Levillain5b3ee562015-04-14 16:02:41 +01001852 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001853 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001854 InvokeRuntimeCallingConvention calling_convention;
1855 locations->SetInAt(0, Location::RegisterPairLocation(
1856 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1857 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001858 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001859 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001860
Roland Levillaincff13742014-11-17 14:32:17 +00001861 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001862 // Processing a Dex `double-to-float' instruction.
1863 locations->SetInAt(0, Location::RequiresFpuRegister());
1864 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001865 break;
1866
1867 default:
1868 LOG(FATAL) << "Unexpected type conversion from " << input_type
1869 << " to " << result_type;
1870 };
1871 break;
1872
Roland Levillaindff1f282014-11-05 14:15:05 +00001873 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001874 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001875 case Primitive::kPrimBoolean:
1876 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001877 case Primitive::kPrimByte:
1878 case Primitive::kPrimShort:
1879 case Primitive::kPrimInt:
1880 case Primitive::kPrimChar:
1881 // Processing a Dex `int-to-double' instruction.
1882 locations->SetInAt(0, Location::RequiresRegister());
1883 locations->SetOut(Location::RequiresFpuRegister());
1884 break;
1885
1886 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001887 // Processing a Dex `long-to-double' instruction.
1888 locations->SetInAt(0, Location::RequiresRegister());
1889 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001890 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001891 locations->AddTemp(Location::RequiresFpuRegister());
1892 break;
1893
Roland Levillaincff13742014-11-17 14:32:17 +00001894 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001895 // Processing a Dex `float-to-double' instruction.
1896 locations->SetInAt(0, Location::RequiresFpuRegister());
1897 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001898 break;
1899
1900 default:
1901 LOG(FATAL) << "Unexpected type conversion from " << input_type
1902 << " to " << result_type;
1903 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001904 break;
1905
1906 default:
1907 LOG(FATAL) << "Unexpected type conversion from " << input_type
1908 << " to " << result_type;
1909 }
1910}
1911
1912void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1913 LocationSummary* locations = conversion->GetLocations();
1914 Location out = locations->Out();
1915 Location in = locations->InAt(0);
1916 Primitive::Type result_type = conversion->GetResultType();
1917 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001918 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001919 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001920 case Primitive::kPrimByte:
1921 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001922 case Primitive::kPrimBoolean:
1923 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001924 case Primitive::kPrimShort:
1925 case Primitive::kPrimInt:
1926 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001927 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001928 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001929 break;
1930
1931 default:
1932 LOG(FATAL) << "Unexpected type conversion from " << input_type
1933 << " to " << result_type;
1934 }
1935 break;
1936
Roland Levillain01a8d712014-11-14 16:27:39 +00001937 case Primitive::kPrimShort:
1938 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001939 case Primitive::kPrimBoolean:
1940 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001941 case Primitive::kPrimByte:
1942 case Primitive::kPrimInt:
1943 case Primitive::kPrimChar:
1944 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001945 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001946 break;
1947
1948 default:
1949 LOG(FATAL) << "Unexpected type conversion from " << input_type
1950 << " to " << result_type;
1951 }
1952 break;
1953
Roland Levillain946e1432014-11-11 17:35:19 +00001954 case Primitive::kPrimInt:
1955 switch (input_type) {
1956 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001957 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001958 DCHECK(out.IsRegister());
1959 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001960 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001961 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001962 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001963 } else {
1964 DCHECK(in.IsConstant());
1965 DCHECK(in.GetConstant()->IsLongConstant());
1966 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001967 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001968 }
1969 break;
1970
Roland Levillain3f8f9362014-12-02 17:45:01 +00001971 case Primitive::kPrimFloat: {
1972 // Processing a Dex `float-to-int' instruction.
1973 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1974 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1975 __ vcvtis(temp, temp);
1976 __ vmovrs(out.AsRegister<Register>(), temp);
1977 break;
1978 }
1979
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001980 case Primitive::kPrimDouble: {
1981 // Processing a Dex `double-to-int' instruction.
1982 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1983 DRegister temp_d = FromLowSToD(temp_s);
1984 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1985 __ vcvtid(temp_s, temp_d);
1986 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001987 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001988 }
Roland Levillain946e1432014-11-11 17:35:19 +00001989
1990 default:
1991 LOG(FATAL) << "Unexpected type conversion from " << input_type
1992 << " to " << result_type;
1993 }
1994 break;
1995
Roland Levillaindff1f282014-11-05 14:15:05 +00001996 case Primitive::kPrimLong:
1997 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001998 case Primitive::kPrimBoolean:
1999 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002000 case Primitive::kPrimByte:
2001 case Primitive::kPrimShort:
2002 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002003 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002004 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002005 DCHECK(out.IsRegisterPair());
2006 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002007 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002008 // Sign extension.
2009 __ Asr(out.AsRegisterPairHigh<Register>(),
2010 out.AsRegisterPairLow<Register>(),
2011 31);
2012 break;
2013
2014 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002015 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00002016 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
2017 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002018 conversion->GetDexPc(),
2019 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00002020 break;
2021
Roland Levillaindff1f282014-11-05 14:15:05 +00002022 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002023 // Processing a Dex `double-to-long' instruction.
2024 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
2025 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002026 conversion->GetDexPc(),
2027 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00002028 break;
2029
2030 default:
2031 LOG(FATAL) << "Unexpected type conversion from " << input_type
2032 << " to " << result_type;
2033 }
2034 break;
2035
Roland Levillain981e4542014-11-14 11:47:14 +00002036 case Primitive::kPrimChar:
2037 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002038 case Primitive::kPrimBoolean:
2039 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002040 case Primitive::kPrimByte:
2041 case Primitive::kPrimShort:
2042 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002043 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002044 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002045 break;
2046
2047 default:
2048 LOG(FATAL) << "Unexpected type conversion from " << input_type
2049 << " to " << result_type;
2050 }
2051 break;
2052
Roland Levillaindff1f282014-11-05 14:15:05 +00002053 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002054 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002055 case Primitive::kPrimBoolean:
2056 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002057 case Primitive::kPrimByte:
2058 case Primitive::kPrimShort:
2059 case Primitive::kPrimInt:
2060 case Primitive::kPrimChar: {
2061 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002062 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2063 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002064 break;
2065 }
2066
Roland Levillain5b3ee562015-04-14 16:02:41 +01002067 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002068 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002069 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
2070 conversion,
2071 conversion->GetDexPc(),
2072 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00002073 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002074
Roland Levillaincff13742014-11-17 14:32:17 +00002075 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002076 // Processing a Dex `double-to-float' instruction.
2077 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2078 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002079 break;
2080
2081 default:
2082 LOG(FATAL) << "Unexpected type conversion from " << input_type
2083 << " to " << result_type;
2084 };
2085 break;
2086
Roland Levillaindff1f282014-11-05 14:15:05 +00002087 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002088 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002089 case Primitive::kPrimBoolean:
2090 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002091 case Primitive::kPrimByte:
2092 case Primitive::kPrimShort:
2093 case Primitive::kPrimInt:
2094 case Primitive::kPrimChar: {
2095 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002096 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002097 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2098 out.AsFpuRegisterPairLow<SRegister>());
2099 break;
2100 }
2101
Roland Levillain647b9ed2014-11-27 12:06:00 +00002102 case Primitive::kPrimLong: {
2103 // Processing a Dex `long-to-double' instruction.
2104 Register low = in.AsRegisterPairLow<Register>();
2105 Register high = in.AsRegisterPairHigh<Register>();
2106 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2107 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002108 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002109 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002110 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2111 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002112
Roland Levillain682393c2015-04-14 15:57:52 +01002113 // temp_d = int-to-double(high)
2114 __ vmovsr(temp_s, high);
2115 __ vcvtdi(temp_d, temp_s);
2116 // constant_d = k2Pow32EncodingForDouble
2117 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2118 // out_d = unsigned-to-double(low)
2119 __ vmovsr(out_s, low);
2120 __ vcvtdu(out_d, out_s);
2121 // out_d += temp_d * constant_d
2122 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002123 break;
2124 }
2125
Roland Levillaincff13742014-11-17 14:32:17 +00002126 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002127 // Processing a Dex `float-to-double' instruction.
2128 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2129 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002130 break;
2131
2132 default:
2133 LOG(FATAL) << "Unexpected type conversion from " << input_type
2134 << " to " << result_type;
2135 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002136 break;
2137
2138 default:
2139 LOG(FATAL) << "Unexpected type conversion from " << input_type
2140 << " to " << result_type;
2141 }
2142}
2143
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002144void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002145 LocationSummary* locations =
2146 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002147 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002148 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002149 locations->SetInAt(0, Location::RequiresRegister());
2150 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002151 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2152 break;
2153 }
2154
2155 case Primitive::kPrimLong: {
2156 locations->SetInAt(0, Location::RequiresRegister());
2157 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002158 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002159 break;
2160 }
2161
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002162 case Primitive::kPrimFloat:
2163 case Primitive::kPrimDouble: {
2164 locations->SetInAt(0, Location::RequiresFpuRegister());
2165 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002166 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002167 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002168 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002169
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002170 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002171 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002172 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002173}
2174
2175void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2176 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002177 Location out = locations->Out();
2178 Location first = locations->InAt(0);
2179 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002180 switch (add->GetResultType()) {
2181 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002182 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002183 __ add(out.AsRegister<Register>(),
2184 first.AsRegister<Register>(),
2185 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002186 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002187 __ AddConstant(out.AsRegister<Register>(),
2188 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002189 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002190 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002191 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002192
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002193 case Primitive::kPrimLong: {
2194 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002195 __ adds(out.AsRegisterPairLow<Register>(),
2196 first.AsRegisterPairLow<Register>(),
2197 ShifterOperand(second.AsRegisterPairLow<Register>()));
2198 __ adc(out.AsRegisterPairHigh<Register>(),
2199 first.AsRegisterPairHigh<Register>(),
2200 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002201 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002202 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002203
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002204 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002205 __ vadds(out.AsFpuRegister<SRegister>(),
2206 first.AsFpuRegister<SRegister>(),
2207 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002208 break;
2209
2210 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002211 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2212 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2213 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002214 break;
2215
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002216 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002217 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002218 }
2219}
2220
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002221void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002222 LocationSummary* locations =
2223 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002224 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002225 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002226 locations->SetInAt(0, Location::RequiresRegister());
2227 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002228 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2229 break;
2230 }
2231
2232 case Primitive::kPrimLong: {
2233 locations->SetInAt(0, Location::RequiresRegister());
2234 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002235 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002236 break;
2237 }
Calin Juravle11351682014-10-23 15:38:15 +01002238 case Primitive::kPrimFloat:
2239 case Primitive::kPrimDouble: {
2240 locations->SetInAt(0, Location::RequiresFpuRegister());
2241 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002242 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002243 break;
Calin Juravle11351682014-10-23 15:38:15 +01002244 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002245 default:
Calin Juravle11351682014-10-23 15:38:15 +01002246 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002247 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002248}
2249
2250void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2251 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002252 Location out = locations->Out();
2253 Location first = locations->InAt(0);
2254 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002255 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002256 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002257 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002258 __ sub(out.AsRegister<Register>(),
2259 first.AsRegister<Register>(),
2260 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002261 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002262 __ AddConstant(out.AsRegister<Register>(),
2263 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002264 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002265 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002266 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002267 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002268
Calin Juravle11351682014-10-23 15:38:15 +01002269 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002270 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002271 __ subs(out.AsRegisterPairLow<Register>(),
2272 first.AsRegisterPairLow<Register>(),
2273 ShifterOperand(second.AsRegisterPairLow<Register>()));
2274 __ sbc(out.AsRegisterPairHigh<Register>(),
2275 first.AsRegisterPairHigh<Register>(),
2276 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002277 break;
Calin Juravle11351682014-10-23 15:38:15 +01002278 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002279
Calin Juravle11351682014-10-23 15:38:15 +01002280 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002281 __ vsubs(out.AsFpuRegister<SRegister>(),
2282 first.AsFpuRegister<SRegister>(),
2283 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002284 break;
Calin Juravle11351682014-10-23 15:38:15 +01002285 }
2286
2287 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002288 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2289 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2290 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002291 break;
2292 }
2293
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002294
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002295 default:
Calin Juravle11351682014-10-23 15:38:15 +01002296 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002297 }
2298}
2299
Calin Juravle34bacdf2014-10-07 20:23:36 +01002300void LocationsBuilderARM::VisitMul(HMul* mul) {
2301 LocationSummary* locations =
2302 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2303 switch (mul->GetResultType()) {
2304 case Primitive::kPrimInt:
2305 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002306 locations->SetInAt(0, Location::RequiresRegister());
2307 locations->SetInAt(1, Location::RequiresRegister());
2308 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002309 break;
2310 }
2311
Calin Juravleb5bfa962014-10-21 18:02:24 +01002312 case Primitive::kPrimFloat:
2313 case Primitive::kPrimDouble: {
2314 locations->SetInAt(0, Location::RequiresFpuRegister());
2315 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002316 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002317 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002318 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002319
2320 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002321 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002322 }
2323}
2324
2325void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2326 LocationSummary* locations = mul->GetLocations();
2327 Location out = locations->Out();
2328 Location first = locations->InAt(0);
2329 Location second = locations->InAt(1);
2330 switch (mul->GetResultType()) {
2331 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002332 __ mul(out.AsRegister<Register>(),
2333 first.AsRegister<Register>(),
2334 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002335 break;
2336 }
2337 case Primitive::kPrimLong: {
2338 Register out_hi = out.AsRegisterPairHigh<Register>();
2339 Register out_lo = out.AsRegisterPairLow<Register>();
2340 Register in1_hi = first.AsRegisterPairHigh<Register>();
2341 Register in1_lo = first.AsRegisterPairLow<Register>();
2342 Register in2_hi = second.AsRegisterPairHigh<Register>();
2343 Register in2_lo = second.AsRegisterPairLow<Register>();
2344
2345 // Extra checks to protect caused by the existence of R1_R2.
2346 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2347 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2348 DCHECK_NE(out_hi, in1_lo);
2349 DCHECK_NE(out_hi, in2_lo);
2350
2351 // input: in1 - 64 bits, in2 - 64 bits
2352 // output: out
2353 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2354 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2355 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2356
2357 // IP <- in1.lo * in2.hi
2358 __ mul(IP, in1_lo, in2_hi);
2359 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2360 __ mla(out_hi, in1_hi, in2_lo, IP);
2361 // out.lo <- (in1.lo * in2.lo)[31:0];
2362 __ umull(out_lo, IP, in1_lo, in2_lo);
2363 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2364 __ add(out_hi, out_hi, ShifterOperand(IP));
2365 break;
2366 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002367
2368 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002369 __ vmuls(out.AsFpuRegister<SRegister>(),
2370 first.AsFpuRegister<SRegister>(),
2371 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002372 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002373 }
2374
2375 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002376 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2377 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2378 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002379 break;
2380 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002381
2382 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002383 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002384 }
2385}
2386
Zheng Xuc6667102015-05-15 16:08:45 +08002387void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2388 DCHECK(instruction->IsDiv() || instruction->IsRem());
2389 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2390
2391 LocationSummary* locations = instruction->GetLocations();
2392 Location second = locations->InAt(1);
2393 DCHECK(second.IsConstant());
2394
2395 Register out = locations->Out().AsRegister<Register>();
2396 Register dividend = locations->InAt(0).AsRegister<Register>();
2397 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2398 DCHECK(imm == 1 || imm == -1);
2399
2400 if (instruction->IsRem()) {
2401 __ LoadImmediate(out, 0);
2402 } else {
2403 if (imm == 1) {
2404 __ Mov(out, dividend);
2405 } else {
2406 __ rsb(out, dividend, ShifterOperand(0));
2407 }
2408 }
2409}
2410
2411void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2412 DCHECK(instruction->IsDiv() || instruction->IsRem());
2413 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2414
2415 LocationSummary* locations = instruction->GetLocations();
2416 Location second = locations->InAt(1);
2417 DCHECK(second.IsConstant());
2418
2419 Register out = locations->Out().AsRegister<Register>();
2420 Register dividend = locations->InAt(0).AsRegister<Register>();
2421 Register temp = locations->GetTemp(0).AsRegister<Register>();
2422 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002423 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002424 DCHECK(IsPowerOfTwo(abs_imm));
2425 int ctz_imm = CTZ(abs_imm);
2426
2427 if (ctz_imm == 1) {
2428 __ Lsr(temp, dividend, 32 - ctz_imm);
2429 } else {
2430 __ Asr(temp, dividend, 31);
2431 __ Lsr(temp, temp, 32 - ctz_imm);
2432 }
2433 __ add(out, temp, ShifterOperand(dividend));
2434
2435 if (instruction->IsDiv()) {
2436 __ Asr(out, out, ctz_imm);
2437 if (imm < 0) {
2438 __ rsb(out, out, ShifterOperand(0));
2439 }
2440 } else {
2441 __ ubfx(out, out, 0, ctz_imm);
2442 __ sub(out, out, ShifterOperand(temp));
2443 }
2444}
2445
2446void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2447 DCHECK(instruction->IsDiv() || instruction->IsRem());
2448 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2449
2450 LocationSummary* locations = instruction->GetLocations();
2451 Location second = locations->InAt(1);
2452 DCHECK(second.IsConstant());
2453
2454 Register out = locations->Out().AsRegister<Register>();
2455 Register dividend = locations->InAt(0).AsRegister<Register>();
2456 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2457 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2458 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2459
2460 int64_t magic;
2461 int shift;
2462 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2463
2464 __ LoadImmediate(temp1, magic);
2465 __ smull(temp2, temp1, dividend, temp1);
2466
2467 if (imm > 0 && magic < 0) {
2468 __ add(temp1, temp1, ShifterOperand(dividend));
2469 } else if (imm < 0 && magic > 0) {
2470 __ sub(temp1, temp1, ShifterOperand(dividend));
2471 }
2472
2473 if (shift != 0) {
2474 __ Asr(temp1, temp1, shift);
2475 }
2476
2477 if (instruction->IsDiv()) {
2478 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2479 } else {
2480 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2481 // TODO: Strength reduction for mls.
2482 __ LoadImmediate(temp2, imm);
2483 __ mls(out, temp1, temp2, dividend);
2484 }
2485}
2486
2487void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2488 DCHECK(instruction->IsDiv() || instruction->IsRem());
2489 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2490
2491 LocationSummary* locations = instruction->GetLocations();
2492 Location second = locations->InAt(1);
2493 DCHECK(second.IsConstant());
2494
2495 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2496 if (imm == 0) {
2497 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2498 } else if (imm == 1 || imm == -1) {
2499 DivRemOneOrMinusOne(instruction);
2500 } else if (IsPowerOfTwo(std::abs(imm))) {
2501 DivRemByPowerOfTwo(instruction);
2502 } else {
2503 DCHECK(imm <= -2 || imm >= 2);
2504 GenerateDivRemWithAnyConstant(instruction);
2505 }
2506}
2507
Calin Juravle7c4954d2014-10-28 16:57:40 +00002508void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002509 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2510 if (div->GetResultType() == Primitive::kPrimLong) {
2511 // pLdiv runtime call.
2512 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002513 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2514 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002515 } else if (div->GetResultType() == Primitive::kPrimInt &&
2516 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2517 // pIdivmod runtime call.
2518 call_kind = LocationSummary::kCall;
2519 }
2520
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002521 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2522
Calin Juravle7c4954d2014-10-28 16:57:40 +00002523 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002524 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002525 if (div->InputAt(1)->IsConstant()) {
2526 locations->SetInAt(0, Location::RequiresRegister());
2527 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2528 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2529 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2530 if (abs_imm <= 1) {
2531 // No temp register required.
2532 } else {
2533 locations->AddTemp(Location::RequiresRegister());
2534 if (!IsPowerOfTwo(abs_imm)) {
2535 locations->AddTemp(Location::RequiresRegister());
2536 }
2537 }
2538 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002539 locations->SetInAt(0, Location::RequiresRegister());
2540 locations->SetInAt(1, Location::RequiresRegister());
2541 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2542 } else {
2543 InvokeRuntimeCallingConvention calling_convention;
2544 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2545 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2546 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2547 // we only need the former.
2548 locations->SetOut(Location::RegisterLocation(R0));
2549 }
Calin Juravled0d48522014-11-04 16:40:20 +00002550 break;
2551 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002552 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002553 InvokeRuntimeCallingConvention calling_convention;
2554 locations->SetInAt(0, Location::RegisterPairLocation(
2555 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2556 locations->SetInAt(1, Location::RegisterPairLocation(
2557 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002558 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002559 break;
2560 }
2561 case Primitive::kPrimFloat:
2562 case Primitive::kPrimDouble: {
2563 locations->SetInAt(0, Location::RequiresFpuRegister());
2564 locations->SetInAt(1, Location::RequiresFpuRegister());
2565 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2566 break;
2567 }
2568
2569 default:
2570 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2571 }
2572}
2573
2574void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2575 LocationSummary* locations = div->GetLocations();
2576 Location out = locations->Out();
2577 Location first = locations->InAt(0);
2578 Location second = locations->InAt(1);
2579
2580 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002581 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002582 if (second.IsConstant()) {
2583 GenerateDivRemConstantIntegral(div);
2584 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002585 __ sdiv(out.AsRegister<Register>(),
2586 first.AsRegister<Register>(),
2587 second.AsRegister<Register>());
2588 } else {
2589 InvokeRuntimeCallingConvention calling_convention;
2590 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2591 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2592 DCHECK_EQ(R0, out.AsRegister<Register>());
2593
2594 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2595 }
Calin Juravled0d48522014-11-04 16:40:20 +00002596 break;
2597 }
2598
Calin Juravle7c4954d2014-10-28 16:57:40 +00002599 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002600 InvokeRuntimeCallingConvention calling_convention;
2601 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2602 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2603 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2604 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2605 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002606 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002607
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002608 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002609 break;
2610 }
2611
2612 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002613 __ vdivs(out.AsFpuRegister<SRegister>(),
2614 first.AsFpuRegister<SRegister>(),
2615 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002616 break;
2617 }
2618
2619 case Primitive::kPrimDouble: {
2620 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2621 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2622 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2623 break;
2624 }
2625
2626 default:
2627 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2628 }
2629}
2630
Calin Juravlebacfec32014-11-14 15:54:36 +00002631void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002632 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002633
2634 // Most remainders are implemented in the runtime.
2635 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002636 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2637 // sdiv will be replaced by other instruction sequence.
2638 call_kind = LocationSummary::kNoCall;
2639 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2640 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002641 // Have hardware divide instruction for int, do it with three instructions.
2642 call_kind = LocationSummary::kNoCall;
2643 }
2644
Calin Juravlebacfec32014-11-14 15:54:36 +00002645 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2646
Calin Juravled2ec87d2014-12-08 14:24:46 +00002647 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002648 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002649 if (rem->InputAt(1)->IsConstant()) {
2650 locations->SetInAt(0, Location::RequiresRegister());
2651 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2652 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2653 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2654 if (abs_imm <= 1) {
2655 // No temp register required.
2656 } else {
2657 locations->AddTemp(Location::RequiresRegister());
2658 if (!IsPowerOfTwo(abs_imm)) {
2659 locations->AddTemp(Location::RequiresRegister());
2660 }
2661 }
2662 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002663 locations->SetInAt(0, Location::RequiresRegister());
2664 locations->SetInAt(1, Location::RequiresRegister());
2665 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2666 locations->AddTemp(Location::RequiresRegister());
2667 } else {
2668 InvokeRuntimeCallingConvention calling_convention;
2669 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2670 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2671 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2672 // we only need the latter.
2673 locations->SetOut(Location::RegisterLocation(R1));
2674 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002675 break;
2676 }
2677 case Primitive::kPrimLong: {
2678 InvokeRuntimeCallingConvention calling_convention;
2679 locations->SetInAt(0, Location::RegisterPairLocation(
2680 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2681 locations->SetInAt(1, Location::RegisterPairLocation(
2682 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2683 // The runtime helper puts the output in R2,R3.
2684 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2685 break;
2686 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002687 case Primitive::kPrimFloat: {
2688 InvokeRuntimeCallingConvention calling_convention;
2689 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2690 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2691 locations->SetOut(Location::FpuRegisterLocation(S0));
2692 break;
2693 }
2694
Calin Juravlebacfec32014-11-14 15:54:36 +00002695 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002696 InvokeRuntimeCallingConvention calling_convention;
2697 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2698 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2699 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2700 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2701 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002702 break;
2703 }
2704
2705 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002706 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002707 }
2708}
2709
2710void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2711 LocationSummary* locations = rem->GetLocations();
2712 Location out = locations->Out();
2713 Location first = locations->InAt(0);
2714 Location second = locations->InAt(1);
2715
Calin Juravled2ec87d2014-12-08 14:24:46 +00002716 Primitive::Type type = rem->GetResultType();
2717 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002718 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002719 if (second.IsConstant()) {
2720 GenerateDivRemConstantIntegral(rem);
2721 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002722 Register reg1 = first.AsRegister<Register>();
2723 Register reg2 = second.AsRegister<Register>();
2724 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002725
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002726 // temp = reg1 / reg2 (integer division)
2727 // temp = temp * reg2
2728 // dest = reg1 - temp
2729 __ sdiv(temp, reg1, reg2);
2730 __ mul(temp, temp, reg2);
2731 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2732 } else {
2733 InvokeRuntimeCallingConvention calling_convention;
2734 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2735 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2736 DCHECK_EQ(R1, out.AsRegister<Register>());
2737
2738 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2739 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002740 break;
2741 }
2742
2743 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002744 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002745 break;
2746 }
2747
Calin Juravled2ec87d2014-12-08 14:24:46 +00002748 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002749 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002750 break;
2751 }
2752
Calin Juravlebacfec32014-11-14 15:54:36 +00002753 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002754 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002755 break;
2756 }
2757
2758 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002759 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002760 }
2761}
2762
Calin Juravled0d48522014-11-04 16:40:20 +00002763void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2764 LocationSummary* locations =
2765 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002766 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002767 if (instruction->HasUses()) {
2768 locations->SetOut(Location::SameAsFirstInput());
2769 }
2770}
2771
2772void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2773 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2774 codegen_->AddSlowPath(slow_path);
2775
2776 LocationSummary* locations = instruction->GetLocations();
2777 Location value = locations->InAt(0);
2778
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002779 switch (instruction->GetType()) {
Serguei Katkov8c0676c2015-08-03 13:55:33 +06002780 case Primitive::kPrimByte:
2781 case Primitive::kPrimChar:
2782 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002783 case Primitive::kPrimInt: {
2784 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01002785 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002786 } else {
2787 DCHECK(value.IsConstant()) << value;
2788 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2789 __ b(slow_path->GetEntryLabel());
2790 }
2791 }
2792 break;
2793 }
2794 case Primitive::kPrimLong: {
2795 if (value.IsRegisterPair()) {
2796 __ orrs(IP,
2797 value.AsRegisterPairLow<Register>(),
2798 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2799 __ b(slow_path->GetEntryLabel(), EQ);
2800 } else {
2801 DCHECK(value.IsConstant()) << value;
2802 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2803 __ b(slow_path->GetEntryLabel());
2804 }
2805 }
2806 break;
2807 default:
2808 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2809 }
2810 }
Calin Juravled0d48522014-11-04 16:40:20 +00002811}
2812
Calin Juravle9aec02f2014-11-18 23:06:35 +00002813void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2814 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2815
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002816 LocationSummary* locations =
2817 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002818
2819 switch (op->GetResultType()) {
2820 case Primitive::kPrimInt: {
2821 locations->SetInAt(0, Location::RequiresRegister());
2822 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002823 // Make the output overlap, as it will be used to hold the masked
2824 // second input.
2825 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002826 break;
2827 }
2828 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002829 locations->SetInAt(0, Location::RequiresRegister());
2830 locations->SetInAt(1, Location::RequiresRegister());
2831 locations->AddTemp(Location::RequiresRegister());
2832 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002833 break;
2834 }
2835 default:
2836 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2837 }
2838}
2839
2840void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2841 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2842
2843 LocationSummary* locations = op->GetLocations();
2844 Location out = locations->Out();
2845 Location first = locations->InAt(0);
2846 Location second = locations->InAt(1);
2847
2848 Primitive::Type type = op->GetResultType();
2849 switch (type) {
2850 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002851 Register out_reg = out.AsRegister<Register>();
2852 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002853 // Arm doesn't mask the shift count so we need to do it ourselves.
2854 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002855 Register second_reg = second.AsRegister<Register>();
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002856 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002857 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002858 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002859 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002860 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002861 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002862 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002863 }
2864 } else {
2865 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2866 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2867 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2868 __ Mov(out_reg, first_reg);
2869 } else if (op->IsShl()) {
2870 __ Lsl(out_reg, first_reg, shift_value);
2871 } else if (op->IsShr()) {
2872 __ Asr(out_reg, first_reg, shift_value);
2873 } else {
2874 __ Lsr(out_reg, first_reg, shift_value);
2875 }
2876 }
2877 break;
2878 }
2879 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002880 Register o_h = out.AsRegisterPairHigh<Register>();
2881 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002882
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002883 Register temp = locations->GetTemp(0).AsRegister<Register>();
2884
2885 Register high = first.AsRegisterPairHigh<Register>();
2886 Register low = first.AsRegisterPairLow<Register>();
2887
2888 Register second_reg = second.AsRegister<Register>();
2889
Calin Juravle9aec02f2014-11-18 23:06:35 +00002890 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002891 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002892 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002893 __ Lsl(o_h, high, o_l);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002894 // Shift the low part and `or` what overflew on the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002895 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002896 __ Lsr(temp, low, temp);
2897 __ orr(o_h, o_h, ShifterOperand(temp));
2898 // If the shift is > 32 bits, override the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002899 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002900 __ it(PL);
2901 __ Lsl(o_h, low, temp, false, PL);
2902 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002903 __ Lsl(o_l, low, o_l);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002904 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002905 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002906 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002907 __ Lsr(o_l, low, o_h);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002908 // Shift the high part and `or` what underflew on the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002909 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002910 __ Lsl(temp, high, temp);
2911 __ orr(o_l, o_l, ShifterOperand(temp));
2912 // If the shift is > 32 bits, override the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002913 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002914 __ it(PL);
2915 __ Asr(o_l, high, temp, false, PL);
2916 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002917 __ Asr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002918 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002919 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002920 // same as Shr except we use `Lsr`s and not `Asr`s
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002921 __ Lsr(o_l, low, o_h);
2922 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002923 __ Lsl(temp, high, temp);
2924 __ orr(o_l, o_l, ShifterOperand(temp));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002925 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002926 __ it(PL);
2927 __ Lsr(o_l, high, temp, false, PL);
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002928 __ Lsr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002929 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002930 break;
2931 }
2932 default:
2933 LOG(FATAL) << "Unexpected operation type " << type;
2934 }
2935}
2936
2937void LocationsBuilderARM::VisitShl(HShl* shl) {
2938 HandleShift(shl);
2939}
2940
2941void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2942 HandleShift(shl);
2943}
2944
2945void LocationsBuilderARM::VisitShr(HShr* shr) {
2946 HandleShift(shr);
2947}
2948
2949void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2950 HandleShift(shr);
2951}
2952
2953void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2954 HandleShift(ushr);
2955}
2956
2957void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2958 HandleShift(ushr);
2959}
2960
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002961void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002962 LocationSummary* locations =
2963 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002964 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002965 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002966 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002967 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002968}
2969
2970void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2971 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002972 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01002973 // Note: if heap poisoning is enabled, the entry point takes cares
2974 // of poisoning the reference.
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002975 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2976 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002977 instruction->GetDexPc(),
2978 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002979}
2980
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002981void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2982 LocationSummary* locations =
2983 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2984 InvokeRuntimeCallingConvention calling_convention;
2985 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002986 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002987 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002988 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002989}
2990
2991void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2992 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002993 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01002994 // Note: if heap poisoning is enabled, the entry point takes cares
2995 // of poisoning the reference.
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002996 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2997 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002998 instruction->GetDexPc(),
2999 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003000}
3001
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003002void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003003 LocationSummary* locations =
3004 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003005 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3006 if (location.IsStackSlot()) {
3007 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3008 } else if (location.IsDoubleStackSlot()) {
3009 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003010 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003011 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003012}
3013
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003014void InstructionCodeGeneratorARM::VisitParameterValue(
3015 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003016 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003017}
3018
3019void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3020 LocationSummary* locations =
3021 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3022 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3023}
3024
3025void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3026 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003027}
3028
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003029void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003030 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003031 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003032 locations->SetInAt(0, Location::RequiresRegister());
3033 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003034}
3035
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003036void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3037 LocationSummary* locations = not_->GetLocations();
3038 Location out = locations->Out();
3039 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003040 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003041 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003042 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003043 break;
3044
3045 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003046 __ mvn(out.AsRegisterPairLow<Register>(),
3047 ShifterOperand(in.AsRegisterPairLow<Register>()));
3048 __ mvn(out.AsRegisterPairHigh<Register>(),
3049 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003050 break;
3051
3052 default:
3053 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3054 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003055}
3056
David Brazdil66d126e2015-04-03 16:02:44 +01003057void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3058 LocationSummary* locations =
3059 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3060 locations->SetInAt(0, Location::RequiresRegister());
3061 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3062}
3063
3064void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003065 LocationSummary* locations = bool_not->GetLocations();
3066 Location out = locations->Out();
3067 Location in = locations->InAt(0);
3068 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3069}
3070
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003071void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003072 LocationSummary* locations =
3073 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003074 switch (compare->InputAt(0)->GetType()) {
3075 case Primitive::kPrimLong: {
3076 locations->SetInAt(0, Location::RequiresRegister());
3077 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003078 // Output overlaps because it is written before doing the low comparison.
3079 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003080 break;
3081 }
3082 case Primitive::kPrimFloat:
3083 case Primitive::kPrimDouble: {
3084 locations->SetInAt(0, Location::RequiresFpuRegister());
3085 locations->SetInAt(1, Location::RequiresFpuRegister());
3086 locations->SetOut(Location::RequiresRegister());
3087 break;
3088 }
3089 default:
3090 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3091 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003092}
3093
3094void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003095 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003096 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003097 Location left = locations->InAt(0);
3098 Location right = locations->InAt(1);
3099
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003100 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003101 Primitive::Type type = compare->InputAt(0)->GetType();
3102 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003103 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003104 __ cmp(left.AsRegisterPairHigh<Register>(),
3105 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003106 __ b(&less, LT);
3107 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003108 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003109 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003110 __ cmp(left.AsRegisterPairLow<Register>(),
3111 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00003112 break;
3113 }
3114 case Primitive::kPrimFloat:
3115 case Primitive::kPrimDouble: {
3116 __ LoadImmediate(out, 0);
3117 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003118 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00003119 } else {
3120 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
3121 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
3122 }
3123 __ vmstat(); // transfer FP status register to ARM APSR.
3124 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003125 break;
3126 }
3127 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003128 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003129 }
Calin Juravleddb7df22014-11-25 20:56:51 +00003130 __ b(&done, EQ);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003131 __ b(&less, LO); // LO is for both: unsigned compare for longs and 'less than' for floats.
Calin Juravleddb7df22014-11-25 20:56:51 +00003132
3133 __ Bind(&greater);
3134 __ LoadImmediate(out, 1);
3135 __ b(&done);
3136
3137 __ Bind(&less);
3138 __ LoadImmediate(out, -1);
3139
3140 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003141}
3142
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003143void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003144 LocationSummary* locations =
3145 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003146 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
3147 locations->SetInAt(i, Location::Any());
3148 }
3149 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003150}
3151
3152void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003153 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003154 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003155}
3156
Calin Juravle52c48962014-12-16 17:02:57 +00003157void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3158 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07003159 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00003160 switch (kind) {
3161 case MemBarrierKind::kAnyStore:
3162 case MemBarrierKind::kLoadAny:
3163 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003164 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003165 break;
3166 }
3167 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003168 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003169 break;
3170 }
3171 default:
3172 LOG(FATAL) << "Unexpected memory barrier " << kind;
3173 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003174 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003175}
3176
3177void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3178 uint32_t offset,
3179 Register out_lo,
3180 Register out_hi) {
3181 if (offset != 0) {
3182 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003183 __ add(IP, addr, ShifterOperand(out_lo));
3184 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003185 }
3186 __ ldrexd(out_lo, out_hi, addr);
3187}
3188
3189void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3190 uint32_t offset,
3191 Register value_lo,
3192 Register value_hi,
3193 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003194 Register temp2,
3195 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003196 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003197 if (offset != 0) {
3198 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003199 __ add(IP, addr, ShifterOperand(temp1));
3200 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003201 }
3202 __ Bind(&fail);
3203 // We need a load followed by store. (The address used in a STREX instruction must
3204 // be the same as the address in the most recently executed LDREX instruction.)
3205 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003206 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003207 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003208 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003209}
3210
3211void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3212 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3213
Nicolas Geoffray39468442014-09-02 15:17:15 +01003214 LocationSummary* locations =
3215 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003216 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003217
Calin Juravle52c48962014-12-16 17:02:57 +00003218 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003219 if (Primitive::IsFloatingPointType(field_type)) {
3220 locations->SetInAt(1, Location::RequiresFpuRegister());
3221 } else {
3222 locations->SetInAt(1, Location::RequiresRegister());
3223 }
3224
Calin Juravle52c48962014-12-16 17:02:57 +00003225 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003226 bool generate_volatile = field_info.IsVolatile()
3227 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003228 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003229 bool needs_write_barrier =
3230 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003231 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003232 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003233 if (needs_write_barrier) {
3234 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003235 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003236 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003237 // Arm encoding have some additional constraints for ldrexd/strexd:
3238 // - registers need to be consecutive
3239 // - the first register should be even but not R14.
3240 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3241 // enable Arm encoding.
3242 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3243
3244 locations->AddTemp(Location::RequiresRegister());
3245 locations->AddTemp(Location::RequiresRegister());
3246 if (field_type == Primitive::kPrimDouble) {
3247 // For doubles we need two more registers to copy the value.
3248 locations->AddTemp(Location::RegisterLocation(R2));
3249 locations->AddTemp(Location::RegisterLocation(R3));
3250 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003251 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003252}
3253
Calin Juravle52c48962014-12-16 17:02:57 +00003254void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003255 const FieldInfo& field_info,
3256 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003257 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3258
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003259 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003260 Register base = locations->InAt(0).AsRegister<Register>();
3261 Location value = locations->InAt(1);
3262
3263 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003264 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003265 Primitive::Type field_type = field_info.GetFieldType();
3266 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003267 bool needs_write_barrier =
3268 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003269
3270 if (is_volatile) {
3271 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3272 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003273
3274 switch (field_type) {
3275 case Primitive::kPrimBoolean:
3276 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003277 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003278 break;
3279 }
3280
3281 case Primitive::kPrimShort:
3282 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003283 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003284 break;
3285 }
3286
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003287 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003288 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003289 if (kPoisonHeapReferences && needs_write_barrier) {
3290 // Note that in the case where `value` is a null reference,
3291 // we do not enter this block, as a null reference does not
3292 // need poisoning.
3293 DCHECK_EQ(field_type, Primitive::kPrimNot);
3294 Register temp = locations->GetTemp(0).AsRegister<Register>();
3295 __ Mov(temp, value.AsRegister<Register>());
3296 __ PoisonHeapReference(temp);
3297 __ StoreToOffset(kStoreWord, temp, base, offset);
3298 } else {
3299 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3300 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003301 break;
3302 }
3303
3304 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003305 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003306 GenerateWideAtomicStore(base, offset,
3307 value.AsRegisterPairLow<Register>(),
3308 value.AsRegisterPairHigh<Register>(),
3309 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003310 locations->GetTemp(1).AsRegister<Register>(),
3311 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003312 } else {
3313 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003314 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003315 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003316 break;
3317 }
3318
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003319 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003320 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003321 break;
3322 }
3323
3324 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003325 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003326 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003327 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3328 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3329
3330 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3331
3332 GenerateWideAtomicStore(base, offset,
3333 value_reg_lo,
3334 value_reg_hi,
3335 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003336 locations->GetTemp(3).AsRegister<Register>(),
3337 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003338 } else {
3339 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003340 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003341 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003342 break;
3343 }
3344
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003345 case Primitive::kPrimVoid:
3346 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003347 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003348 }
Calin Juravle52c48962014-12-16 17:02:57 +00003349
Calin Juravle77520bc2015-01-12 18:45:46 +00003350 // Longs and doubles are handled in the switch.
3351 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3352 codegen_->MaybeRecordImplicitNullCheck(instruction);
3353 }
3354
3355 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3356 Register temp = locations->GetTemp(0).AsRegister<Register>();
3357 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003358 codegen_->MarkGCCard(
3359 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003360 }
3361
Calin Juravle52c48962014-12-16 17:02:57 +00003362 if (is_volatile) {
3363 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3364 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003365}
3366
Calin Juravle52c48962014-12-16 17:02:57 +00003367void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3368 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003369 LocationSummary* locations =
3370 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003371 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003372
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003373 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003374 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003375 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003376 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003377
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003378 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3379 locations->SetOut(Location::RequiresFpuRegister());
3380 } else {
3381 locations->SetOut(Location::RequiresRegister(),
3382 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3383 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003384 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003385 // Arm encoding have some additional constraints for ldrexd/strexd:
3386 // - registers need to be consecutive
3387 // - the first register should be even but not R14.
3388 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3389 // enable Arm encoding.
3390 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3391 locations->AddTemp(Location::RequiresRegister());
3392 locations->AddTemp(Location::RequiresRegister());
3393 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003394}
3395
Calin Juravle52c48962014-12-16 17:02:57 +00003396void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3397 const FieldInfo& field_info) {
3398 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003399
Calin Juravle52c48962014-12-16 17:02:57 +00003400 LocationSummary* locations = instruction->GetLocations();
3401 Register base = locations->InAt(0).AsRegister<Register>();
3402 Location out = locations->Out();
3403 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003404 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003405 Primitive::Type field_type = field_info.GetFieldType();
3406 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3407
3408 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003409 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003410 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003411 break;
3412 }
3413
3414 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003415 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003416 break;
3417 }
3418
3419 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003420 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003421 break;
3422 }
3423
3424 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003425 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003426 break;
3427 }
3428
3429 case Primitive::kPrimInt:
3430 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003431 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003432 break;
3433 }
3434
3435 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003436 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003437 GenerateWideAtomicLoad(base, offset,
3438 out.AsRegisterPairLow<Register>(),
3439 out.AsRegisterPairHigh<Register>());
3440 } else {
3441 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3442 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003443 break;
3444 }
3445
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003446 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003447 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003448 break;
3449 }
3450
3451 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003452 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003453 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003454 Register lo = locations->GetTemp(0).AsRegister<Register>();
3455 Register hi = locations->GetTemp(1).AsRegister<Register>();
3456 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003457 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003458 __ vmovdrr(out_reg, lo, hi);
3459 } else {
3460 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003461 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003462 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003463 break;
3464 }
3465
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003466 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003467 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003468 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003469 }
Calin Juravle52c48962014-12-16 17:02:57 +00003470
Calin Juravle77520bc2015-01-12 18:45:46 +00003471 // Doubles are handled in the switch.
3472 if (field_type != Primitive::kPrimDouble) {
3473 codegen_->MaybeRecordImplicitNullCheck(instruction);
3474 }
3475
Calin Juravle52c48962014-12-16 17:02:57 +00003476 if (is_volatile) {
3477 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3478 }
Roland Levillain4d027112015-07-01 15:41:14 +01003479
3480 if (field_type == Primitive::kPrimNot) {
3481 __ MaybeUnpoisonHeapReference(out.AsRegister<Register>());
3482 }
Calin Juravle52c48962014-12-16 17:02:57 +00003483}
3484
3485void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3486 HandleFieldSet(instruction, instruction->GetFieldInfo());
3487}
3488
3489void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003490 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003491}
3492
3493void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3494 HandleFieldGet(instruction, instruction->GetFieldInfo());
3495}
3496
3497void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3498 HandleFieldGet(instruction, instruction->GetFieldInfo());
3499}
3500
3501void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3502 HandleFieldGet(instruction, instruction->GetFieldInfo());
3503}
3504
3505void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3506 HandleFieldGet(instruction, instruction->GetFieldInfo());
3507}
3508
3509void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3510 HandleFieldSet(instruction, instruction->GetFieldInfo());
3511}
3512
3513void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003514 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003515}
3516
3517void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003518 LocationSummary* locations =
3519 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003520 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003521 if (instruction->HasUses()) {
3522 locations->SetOut(Location::SameAsFirstInput());
3523 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003524}
3525
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003526void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003527 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3528 return;
3529 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003530 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003531
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003532 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3533 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3534}
3535
3536void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003537 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003538 codegen_->AddSlowPath(slow_path);
3539
3540 LocationSummary* locations = instruction->GetLocations();
3541 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003542
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003543 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003544}
3545
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003546void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3547 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3548 GenerateImplicitNullCheck(instruction);
3549 } else {
3550 GenerateExplicitNullCheck(instruction);
3551 }
3552}
3553
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003554void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003555 LocationSummary* locations =
3556 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003557 locations->SetInAt(0, Location::RequiresRegister());
3558 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003559 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3560 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3561 } else {
3562 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3563 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003564}
3565
3566void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3567 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003568 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003569 Location index = locations->InAt(1);
Roland Levillain4d027112015-07-01 15:41:14 +01003570 Primitive::Type type = instruction->GetType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003571
Roland Levillain4d027112015-07-01 15:41:14 +01003572 switch (type) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003573 case Primitive::kPrimBoolean: {
3574 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003575 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003576 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003577 size_t offset =
3578 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003579 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3580 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003581 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003582 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3583 }
3584 break;
3585 }
3586
3587 case Primitive::kPrimByte: {
3588 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003589 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003590 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003591 size_t offset =
3592 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003593 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3594 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003595 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003596 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3597 }
3598 break;
3599 }
3600
3601 case Primitive::kPrimShort: {
3602 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003603 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003604 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003605 size_t offset =
3606 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003607 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3608 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003609 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003610 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3611 }
3612 break;
3613 }
3614
3615 case Primitive::kPrimChar: {
3616 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003617 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003618 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003619 size_t offset =
3620 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003621 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3622 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003623 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003624 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3625 }
3626 break;
3627 }
3628
3629 case Primitive::kPrimInt:
3630 case Primitive::kPrimNot: {
Roland Levillain33d69032015-06-18 18:20:59 +01003631 static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
3632 "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003633 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003634 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003635 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003636 size_t offset =
3637 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003638 __ LoadFromOffset(kLoadWord, out, obj, offset);
3639 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003640 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003641 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3642 }
3643 break;
3644 }
3645
3646 case Primitive::kPrimLong: {
3647 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003648 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003649 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003650 size_t offset =
3651 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003652 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003653 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003654 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003655 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003656 }
3657 break;
3658 }
3659
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003660 case Primitive::kPrimFloat: {
3661 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3662 Location out = locations->Out();
3663 DCHECK(out.IsFpuRegister());
3664 if (index.IsConstant()) {
3665 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3666 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3667 } else {
3668 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3669 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3670 }
3671 break;
3672 }
3673
3674 case Primitive::kPrimDouble: {
3675 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3676 Location out = locations->Out();
3677 DCHECK(out.IsFpuRegisterPair());
3678 if (index.IsConstant()) {
3679 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3680 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3681 } else {
3682 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3683 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3684 }
3685 break;
3686 }
3687
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003688 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01003689 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003690 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003691 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003692 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01003693
3694 if (type == Primitive::kPrimNot) {
3695 Register out = locations->Out().AsRegister<Register>();
3696 __ MaybeUnpoisonHeapReference(out);
3697 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003698}
3699
3700void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003701 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003702
3703 bool needs_write_barrier =
3704 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3705 bool needs_runtime_call = instruction->NeedsTypeCheck();
3706
Nicolas Geoffray39468442014-09-02 15:17:15 +01003707 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003708 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3709 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003710 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003711 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3712 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3713 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003714 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003715 locations->SetInAt(0, Location::RequiresRegister());
3716 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003717 if (Primitive::IsFloatingPointType(value_type)) {
3718 locations->SetInAt(2, Location::RequiresFpuRegister());
3719 } else {
3720 locations->SetInAt(2, Location::RequiresRegister());
3721 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003722
3723 if (needs_write_barrier) {
3724 // Temporary registers for the write barrier.
Roland Levillain4d027112015-07-01 15:41:14 +01003725 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003726 locations->AddTemp(Location::RequiresRegister());
3727 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003728 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003729}
3730
3731void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3732 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003733 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003734 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003735 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003736 bool needs_runtime_call = locations->WillCall();
3737 bool needs_write_barrier =
3738 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003739
3740 switch (value_type) {
3741 case Primitive::kPrimBoolean:
3742 case Primitive::kPrimByte: {
3743 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003744 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003745 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003746 size_t offset =
3747 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003748 __ StoreToOffset(kStoreByte, value, obj, offset);
3749 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003750 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003751 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3752 }
3753 break;
3754 }
3755
3756 case Primitive::kPrimShort:
3757 case Primitive::kPrimChar: {
3758 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003759 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003760 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003761 size_t offset =
3762 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003763 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3764 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003765 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003766 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3767 }
3768 break;
3769 }
3770
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003771 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003772 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003773 if (!needs_runtime_call) {
3774 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003775 Register value = locations->InAt(2).AsRegister<Register>();
Roland Levillain4d027112015-07-01 15:41:14 +01003776 Register source = value;
3777 if (kPoisonHeapReferences && needs_write_barrier) {
3778 // Note that in the case where `value` is a null reference,
3779 // we do not enter this block, as a null reference does not
3780 // need poisoning.
3781 DCHECK_EQ(value_type, Primitive::kPrimNot);
3782 Register temp = locations->GetTemp(0).AsRegister<Register>();
3783 __ Mov(temp, value);
3784 __ PoisonHeapReference(temp);
3785 source = temp;
3786 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003787 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003788 size_t offset =
3789 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillain4d027112015-07-01 15:41:14 +01003790 __ StoreToOffset(kStoreWord, source, obj, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003791 } else {
3792 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003793 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillain4d027112015-07-01 15:41:14 +01003794 __ StoreToOffset(kStoreWord, source, IP, data_offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003795 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003796 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003797 if (needs_write_barrier) {
3798 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003799 Register temp = locations->GetTemp(0).AsRegister<Register>();
3800 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003801 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003802 }
3803 } else {
3804 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain4d027112015-07-01 15:41:14 +01003805 // Note: if heap poisoning is enabled, pAputObject takes cares
3806 // of poisoning the reference.
Roland Levillain199f3362014-11-27 17:15:16 +00003807 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3808 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003809 instruction->GetDexPc(),
3810 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003811 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003812 break;
3813 }
3814
3815 case Primitive::kPrimLong: {
3816 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003817 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003818 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003819 size_t offset =
3820 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003821 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003822 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003823 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003824 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003825 }
3826 break;
3827 }
3828
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003829 case Primitive::kPrimFloat: {
3830 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3831 Location value = locations->InAt(2);
3832 DCHECK(value.IsFpuRegister());
3833 if (index.IsConstant()) {
3834 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3835 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3836 } else {
3837 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3838 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3839 }
3840 break;
3841 }
3842
3843 case Primitive::kPrimDouble: {
3844 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3845 Location value = locations->InAt(2);
3846 DCHECK(value.IsFpuRegisterPair());
3847 if (index.IsConstant()) {
3848 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3849 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3850 } else {
3851 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3852 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3853 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003854
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003855 break;
3856 }
3857
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003858 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003859 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003860 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003861 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003862
3863 // Ints and objects are handled in the switch.
3864 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3865 codegen_->MaybeRecordImplicitNullCheck(instruction);
3866 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003867}
3868
3869void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003870 LocationSummary* locations =
3871 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003872 locations->SetInAt(0, Location::RequiresRegister());
3873 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003874}
3875
3876void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3877 LocationSummary* locations = instruction->GetLocations();
3878 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003879 Register obj = locations->InAt(0).AsRegister<Register>();
3880 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003881 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003882 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003883}
3884
3885void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003886 LocationSummary* locations =
3887 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003888 locations->SetInAt(0, Location::RequiresRegister());
3889 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003890 if (instruction->HasUses()) {
3891 locations->SetOut(Location::SameAsFirstInput());
3892 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003893}
3894
3895void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3896 LocationSummary* locations = instruction->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01003897 SlowPathCodeARM* slow_path =
3898 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003899 codegen_->AddSlowPath(slow_path);
3900
Roland Levillain271ab9c2014-11-27 15:23:57 +00003901 Register index = locations->InAt(0).AsRegister<Register>();
3902 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003903
3904 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01003905 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003906}
3907
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003908void CodeGeneratorARM::MarkGCCard(Register temp,
3909 Register card,
3910 Register object,
3911 Register value,
3912 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003913 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003914 if (can_be_null) {
3915 __ CompareAndBranchIfZero(value, &is_null);
3916 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003917 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3918 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3919 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003920 if (can_be_null) {
3921 __ Bind(&is_null);
3922 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003923}
3924
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003925void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3926 temp->SetLocations(nullptr);
3927}
3928
3929void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3930 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003931 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003932}
3933
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003934void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003935 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003936 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003937}
3938
3939void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003940 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3941}
3942
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003943void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3944 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3945}
3946
3947void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003948 HBasicBlock* block = instruction->GetBlock();
3949 if (block->GetLoopInformation() != nullptr) {
3950 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3951 // The back edge will generate the suspend check.
3952 return;
3953 }
3954 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3955 // The goto will generate the suspend check.
3956 return;
3957 }
3958 GenerateSuspendCheck(instruction, nullptr);
3959}
3960
3961void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3962 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003963 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003964 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3965 if (slow_path == nullptr) {
3966 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3967 instruction->SetSlowPath(slow_path);
3968 codegen_->AddSlowPath(slow_path);
3969 if (successor != nullptr) {
3970 DCHECK(successor->IsLoopHeader());
3971 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3972 }
3973 } else {
3974 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3975 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003976
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003977 __ LoadFromOffset(
3978 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003979 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003980 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003981 __ Bind(slow_path->GetReturnLabel());
3982 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003983 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003984 __ b(slow_path->GetEntryLabel());
3985 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003986}
3987
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003988ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3989 return codegen_->GetAssembler();
3990}
3991
3992void ParallelMoveResolverARM::EmitMove(size_t index) {
3993 MoveOperands* move = moves_.Get(index);
3994 Location source = move->GetSource();
3995 Location destination = move->GetDestination();
3996
3997 if (source.IsRegister()) {
3998 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003999 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004000 } else {
4001 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00004002 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004003 SP, destination.GetStackIndex());
4004 }
4005 } else if (source.IsStackSlot()) {
4006 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004007 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004008 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004009 } else if (destination.IsFpuRegister()) {
4010 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004011 } else {
4012 DCHECK(destination.IsStackSlot());
4013 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
4014 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4015 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004016 } else if (source.IsFpuRegister()) {
4017 if (destination.IsFpuRegister()) {
4018 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004019 } else {
4020 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004021 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
4022 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004023 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004024 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004025 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
4026 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004027 } else if (destination.IsRegisterPair()) {
4028 DCHECK(ExpectedPairLayout(destination));
4029 __ LoadFromOffset(
4030 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
4031 } else {
4032 DCHECK(destination.IsFpuRegisterPair()) << destination;
4033 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4034 SP,
4035 source.GetStackIndex());
4036 }
4037 } else if (source.IsRegisterPair()) {
4038 if (destination.IsRegisterPair()) {
4039 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
4040 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
4041 } else {
4042 DCHECK(destination.IsDoubleStackSlot()) << destination;
4043 DCHECK(ExpectedPairLayout(source));
4044 __ StoreToOffset(
4045 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
4046 }
4047 } else if (source.IsFpuRegisterPair()) {
4048 if (destination.IsFpuRegisterPair()) {
4049 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4050 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
4051 } else {
4052 DCHECK(destination.IsDoubleStackSlot()) << destination;
4053 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
4054 SP,
4055 destination.GetStackIndex());
4056 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004057 } else {
4058 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00004059 HConstant* constant = source.GetConstant();
4060 if (constant->IsIntConstant() || constant->IsNullConstant()) {
4061 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004062 if (destination.IsRegister()) {
4063 __ LoadImmediate(destination.AsRegister<Register>(), value);
4064 } else {
4065 DCHECK(destination.IsStackSlot());
4066 __ LoadImmediate(IP, value);
4067 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4068 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004069 } else if (constant->IsLongConstant()) {
4070 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004071 if (destination.IsRegisterPair()) {
4072 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
4073 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004074 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004075 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004076 __ LoadImmediate(IP, Low32Bits(value));
4077 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4078 __ LoadImmediate(IP, High32Bits(value));
4079 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4080 }
4081 } else if (constant->IsDoubleConstant()) {
4082 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004083 if (destination.IsFpuRegisterPair()) {
4084 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004085 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004086 DCHECK(destination.IsDoubleStackSlot()) << destination;
4087 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004088 __ LoadImmediate(IP, Low32Bits(int_value));
4089 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4090 __ LoadImmediate(IP, High32Bits(int_value));
4091 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4092 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004093 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004094 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004095 float value = constant->AsFloatConstant()->GetValue();
4096 if (destination.IsFpuRegister()) {
4097 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
4098 } else {
4099 DCHECK(destination.IsStackSlot());
4100 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
4101 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4102 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004103 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004104 }
4105}
4106
4107void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
4108 __ Mov(IP, reg);
4109 __ LoadFromOffset(kLoadWord, reg, SP, mem);
4110 __ StoreToOffset(kStoreWord, IP, SP, mem);
4111}
4112
4113void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
4114 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
4115 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
4116 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
4117 SP, mem1 + stack_offset);
4118 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
4119 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
4120 SP, mem2 + stack_offset);
4121 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
4122}
4123
4124void ParallelMoveResolverARM::EmitSwap(size_t index) {
4125 MoveOperands* move = moves_.Get(index);
4126 Location source = move->GetSource();
4127 Location destination = move->GetDestination();
4128
4129 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004130 DCHECK_NE(source.AsRegister<Register>(), IP);
4131 DCHECK_NE(destination.AsRegister<Register>(), IP);
4132 __ Mov(IP, source.AsRegister<Register>());
4133 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
4134 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004135 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004136 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004137 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004138 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004139 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
4140 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004141 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004142 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004143 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004144 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004145 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004146 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004147 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004148 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004149 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
4150 destination.AsRegisterPairHigh<Register>(),
4151 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004152 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004153 Register low_reg = source.IsRegisterPair()
4154 ? source.AsRegisterPairLow<Register>()
4155 : destination.AsRegisterPairLow<Register>();
4156 int mem = source.IsRegisterPair()
4157 ? destination.GetStackIndex()
4158 : source.GetStackIndex();
4159 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004160 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004161 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004162 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004163 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004164 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
4165 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004166 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004167 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004168 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004169 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
4170 DRegister reg = source.IsFpuRegisterPair()
4171 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
4172 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
4173 int mem = source.IsFpuRegisterPair()
4174 ? destination.GetStackIndex()
4175 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004176 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004177 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004178 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004179 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
4180 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
4181 : destination.AsFpuRegister<SRegister>();
4182 int mem = source.IsFpuRegister()
4183 ? destination.GetStackIndex()
4184 : source.GetStackIndex();
4185
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004186 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004187 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004188 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004189 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004190 Exchange(source.GetStackIndex(), destination.GetStackIndex());
4191 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004192 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004193 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004194 }
4195}
4196
4197void ParallelMoveResolverARM::SpillScratch(int reg) {
4198 __ Push(static_cast<Register>(reg));
4199}
4200
4201void ParallelMoveResolverARM::RestoreScratch(int reg) {
4202 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004203}
4204
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004205void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004206 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
4207 ? LocationSummary::kCallOnSlowPath
4208 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004209 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004210 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004211 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004212 locations->SetOut(Location::RequiresRegister());
4213}
4214
4215void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004216 LocationSummary* locations = cls->GetLocations();
4217 Register out = locations->Out().AsRegister<Register>();
4218 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004219 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004220 DCHECK(!cls->CanCallRuntime());
4221 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004222 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004223 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004224 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004225 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004226 __ LoadFromOffset(kLoadWord,
4227 out,
4228 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004229 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004230 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Roland Levillain4d027112015-07-01 15:41:14 +01004231 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004232
4233 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4234 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4235 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004236 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004237 if (cls->MustGenerateClinitCheck()) {
4238 GenerateClassInitializationCheck(slow_path, out);
4239 } else {
4240 __ Bind(slow_path->GetExitLabel());
4241 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004242 }
4243}
4244
4245void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
4246 LocationSummary* locations =
4247 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
4248 locations->SetInAt(0, Location::RequiresRegister());
4249 if (check->HasUses()) {
4250 locations->SetOut(Location::SameAsFirstInput());
4251 }
4252}
4253
4254void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004255 // We assume the class is not null.
4256 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4257 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004258 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004259 GenerateClassInitializationCheck(slow_path,
4260 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004261}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004262
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004263void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
4264 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004265 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4266 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4267 __ b(slow_path->GetEntryLabel(), LT);
4268 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4269 // properly. Therefore, we do a memory fence.
4270 __ dmb(ISH);
4271 __ Bind(slow_path->GetExitLabel());
4272}
4273
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004274void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4275 LocationSummary* locations =
4276 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004277 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004278 locations->SetOut(Location::RequiresRegister());
4279}
4280
4281void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4282 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4283 codegen_->AddSlowPath(slow_path);
4284
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004285 LocationSummary* locations = load->GetLocations();
4286 Register out = locations->Out().AsRegister<Register>();
4287 Register current_method = locations->InAt(0).AsRegister<Register>();
4288 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004289 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004290 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Roland Levillain4d027112015-07-01 15:41:14 +01004291 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004292 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Roland Levillain4d027112015-07-01 15:41:14 +01004293 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004294 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004295 __ Bind(slow_path->GetExitLabel());
4296}
4297
David Brazdilcb1c0552015-08-04 16:22:25 +01004298static int32_t GetExceptionTlsOffset() {
4299 return Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4300}
4301
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004302void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4303 LocationSummary* locations =
4304 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4305 locations->SetOut(Location::RequiresRegister());
4306}
4307
4308void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004309 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01004310 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4311}
4312
4313void LocationsBuilderARM::VisitClearException(HClearException* clear) {
4314 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4315}
4316
4317void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004318 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01004319 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004320}
4321
4322void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4323 LocationSummary* locations =
4324 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4325 InvokeRuntimeCallingConvention calling_convention;
4326 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4327}
4328
4329void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4330 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004331 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004332}
4333
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004334void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004335 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4336 ? LocationSummary::kNoCall
4337 : LocationSummary::kCallOnSlowPath;
4338 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4339 locations->SetInAt(0, Location::RequiresRegister());
4340 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004341 // The out register is used as a temporary, so it overlaps with the inputs.
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004342 // Note that TypeCheckSlowPathARM uses this register too.
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004343 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004344}
4345
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004346void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004347 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004348 Register obj = locations->InAt(0).AsRegister<Register>();
4349 Register cls = locations->InAt(1).AsRegister<Register>();
4350 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004351 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004352 Label done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004353 SlowPathCodeARM* slow_path = nullptr;
4354
4355 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004356 // avoid null check if we know obj is not null.
4357 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004358 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004359 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004360 // Compare the class of `obj` with `cls`.
4361 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
Roland Levillain4d027112015-07-01 15:41:14 +01004362 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004363 __ cmp(out, ShifterOperand(cls));
4364 if (instruction->IsClassFinal()) {
4365 // Classes must be equal for the instanceof to succeed.
4366 __ b(&zero, NE);
4367 __ LoadImmediate(out, 1);
4368 __ b(&done);
4369 } else {
4370 // If the classes are not equal, we go into a slow path.
4371 DCHECK(locations->OnlyCallsOnSlowPath());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004372 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004373 codegen_->AddSlowPath(slow_path);
4374 __ b(slow_path->GetEntryLabel(), NE);
4375 __ LoadImmediate(out, 1);
4376 __ b(&done);
4377 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004378
4379 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4380 __ Bind(&zero);
4381 __ LoadImmediate(out, 0);
4382 }
4383
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004384 if (slow_path != nullptr) {
4385 __ Bind(slow_path->GetExitLabel());
4386 }
4387 __ Bind(&done);
4388}
4389
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004390void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4391 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4392 instruction, LocationSummary::kCallOnSlowPath);
4393 locations->SetInAt(0, Location::RequiresRegister());
4394 locations->SetInAt(1, Location::RequiresRegister());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004395 // Note that TypeCheckSlowPathARM uses this register too.
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004396 locations->AddTemp(Location::RequiresRegister());
4397}
4398
4399void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4400 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004401 Register obj = locations->InAt(0).AsRegister<Register>();
4402 Register cls = locations->InAt(1).AsRegister<Register>();
4403 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004404 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4405
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004406 SlowPathCodeARM* slow_path =
4407 new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004408 codegen_->AddSlowPath(slow_path);
4409
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004410 // avoid null check if we know obj is not null.
4411 if (instruction->MustDoNullCheck()) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004412 __ CompareAndBranchIfZero(obj, slow_path->GetExitLabel());
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004413 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004414 // Compare the class of `obj` with `cls`.
4415 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
Roland Levillain4d027112015-07-01 15:41:14 +01004416 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004417 __ cmp(temp, ShifterOperand(cls));
Roland Levillain4d027112015-07-01 15:41:14 +01004418 // The checkcast succeeds if the classes are equal (fast path).
4419 // Otherwise, we need to go into the slow path to check the types.
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004420 __ b(slow_path->GetEntryLabel(), NE);
4421 __ Bind(slow_path->GetExitLabel());
4422}
4423
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004424void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4425 LocationSummary* locations =
4426 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4427 InvokeRuntimeCallingConvention calling_convention;
4428 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4429}
4430
4431void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4432 codegen_->InvokeRuntime(instruction->IsEnter()
4433 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4434 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004435 instruction->GetDexPc(),
4436 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004437}
4438
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004439void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4440void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4441void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4442
4443void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4444 LocationSummary* locations =
4445 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4446 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4447 || instruction->GetResultType() == Primitive::kPrimLong);
4448 locations->SetInAt(0, Location::RequiresRegister());
4449 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004450 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004451}
4452
4453void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4454 HandleBitwiseOperation(instruction);
4455}
4456
4457void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4458 HandleBitwiseOperation(instruction);
4459}
4460
4461void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4462 HandleBitwiseOperation(instruction);
4463}
4464
4465void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4466 LocationSummary* locations = instruction->GetLocations();
4467
4468 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004469 Register first = locations->InAt(0).AsRegister<Register>();
4470 Register second = locations->InAt(1).AsRegister<Register>();
4471 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004472 if (instruction->IsAnd()) {
4473 __ and_(out, first, ShifterOperand(second));
4474 } else if (instruction->IsOr()) {
4475 __ orr(out, first, ShifterOperand(second));
4476 } else {
4477 DCHECK(instruction->IsXor());
4478 __ eor(out, first, ShifterOperand(second));
4479 }
4480 } else {
4481 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4482 Location first = locations->InAt(0);
4483 Location second = locations->InAt(1);
4484 Location out = locations->Out();
4485 if (instruction->IsAnd()) {
4486 __ and_(out.AsRegisterPairLow<Register>(),
4487 first.AsRegisterPairLow<Register>(),
4488 ShifterOperand(second.AsRegisterPairLow<Register>()));
4489 __ and_(out.AsRegisterPairHigh<Register>(),
4490 first.AsRegisterPairHigh<Register>(),
4491 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4492 } else if (instruction->IsOr()) {
4493 __ orr(out.AsRegisterPairLow<Register>(),
4494 first.AsRegisterPairLow<Register>(),
4495 ShifterOperand(second.AsRegisterPairLow<Register>()));
4496 __ orr(out.AsRegisterPairHigh<Register>(),
4497 first.AsRegisterPairHigh<Register>(),
4498 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4499 } else {
4500 DCHECK(instruction->IsXor());
4501 __ eor(out.AsRegisterPairLow<Register>(),
4502 first.AsRegisterPairLow<Register>(),
4503 ShifterOperand(second.AsRegisterPairLow<Register>()));
4504 __ eor(out.AsRegisterPairHigh<Register>(),
4505 first.AsRegisterPairHigh<Register>(),
4506 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4507 }
4508 }
4509}
4510
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004511void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00004512 // For better instruction scheduling we load the direct code pointer before the method pointer.
4513 bool direct_code_loaded = false;
4514 switch (invoke->GetCodePtrLocation()) {
4515 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
4516 if (IsSameDexFile(*invoke->GetTargetMethod().dex_file, GetGraph()->GetDexFile())) {
4517 break;
4518 }
4519 // Calls across dex files are more likely to exceed the available BL range,
4520 // so use absolute patch by falling through to kDirectCodeFixup.
4521 FALLTHROUGH_INTENDED;
4522 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4523 // LR = code address from literal pool with link-time patch.
4524 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
4525 direct_code_loaded = true;
4526 break;
4527 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4528 // LR = invoke->GetDirectCodePtr();
4529 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
4530 direct_code_loaded = true;
4531 break;
4532 default:
4533 break;
4534 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004535
Vladimir Marko58155012015-08-19 12:49:41 +00004536 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
4537 switch (invoke->GetMethodLoadKind()) {
4538 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
4539 // temp = thread->string_init_entrypoint
4540 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
4541 break;
4542 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
4543 callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4544 break;
4545 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
4546 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
4547 break;
4548 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
4549 __ LoadLiteral(temp.AsRegister<Register>(),
4550 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
4551 break;
4552 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
4553 // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod.
4554 FALLTHROUGH_INTENDED;
4555 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
4556 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4557 Register method_reg;
4558 Register reg = temp.AsRegister<Register>();
4559 if (current_method.IsRegister()) {
4560 method_reg = current_method.AsRegister<Register>();
4561 } else {
4562 DCHECK(invoke->GetLocations()->Intrinsified());
4563 DCHECK(!current_method.IsValid());
4564 method_reg = reg;
4565 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4566 }
4567 // temp = current_method->dex_cache_resolved_methods_;
4568 __ LoadFromOffset(
4569 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
4570 // temp = temp[index_in_cache]
4571 uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index;
4572 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
4573 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004574 }
Vladimir Marko58155012015-08-19 12:49:41 +00004575 }
4576
4577 switch (invoke->GetCodePtrLocation()) {
4578 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
4579 __ bl(GetFrameEntryLabel());
4580 break;
4581 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
4582 if (!direct_code_loaded) {
4583 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
4584 __ Bind(&relative_call_patches_.back().label);
4585 Label label;
4586 __ bl(&label); // Arbitrarily branch to the instruction after BL, override at link time.
4587 __ Bind(&label);
4588 break;
4589 }
4590 // If we loaded the direct code above, fall through.
4591 FALLTHROUGH_INTENDED;
4592 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4593 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4594 // LR prepared above for better instruction scheduling.
4595 DCHECK(direct_code_loaded);
4596 // LR()
4597 __ blx(LR);
4598 break;
4599 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
4600 // LR = callee_method->entry_point_from_quick_compiled_code_
4601 __ LoadFromOffset(
4602 kLoadWord, LR, callee_method.AsRegister<Register>(),
4603 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value());
4604 // LR()
4605 __ blx(LR);
4606 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004607 }
4608
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004609 DCHECK(!IsLeafMethod());
4610}
4611
Vladimir Marko58155012015-08-19 12:49:41 +00004612void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
4613 DCHECK(linker_patches->empty());
4614 size_t size = method_patches_.size() + call_patches_.size() + relative_call_patches_.size();
4615 linker_patches->reserve(size);
4616 for (const auto& entry : method_patches_) {
4617 const MethodReference& target_method = entry.first;
4618 Literal* literal = entry.second;
4619 DCHECK(literal->GetLabel()->IsBound());
4620 uint32_t literal_offset = literal->GetLabel()->Position();
4621 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
4622 target_method.dex_file,
4623 target_method.dex_method_index));
4624 }
4625 for (const auto& entry : call_patches_) {
4626 const MethodReference& target_method = entry.first;
4627 Literal* literal = entry.second;
4628 DCHECK(literal->GetLabel()->IsBound());
4629 uint32_t literal_offset = literal->GetLabel()->Position();
4630 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
4631 target_method.dex_file,
4632 target_method.dex_method_index));
4633 }
4634 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
4635 uint32_t literal_offset = info.label.Position();
4636 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
4637 info.target_method.dex_file,
4638 info.target_method.dex_method_index));
4639 }
4640}
4641
4642Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
4643 MethodToLiteralMap* map) {
4644 // Look up the literal for target_method.
4645 auto lb = map->lower_bound(target_method);
4646 if (lb != map->end() && !map->key_comp()(target_method, lb->first)) {
4647 return lb->second;
4648 }
4649 // We don't have a literal for this method yet, insert a new one.
4650 Literal* literal = __ NewLiteral<uint32_t>(0u);
4651 map->PutBefore(lb, target_method, literal);
4652 return literal;
4653}
4654
4655Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
4656 return DeduplicateMethodLiteral(target_method, &method_patches_);
4657}
4658
4659Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
4660 return DeduplicateMethodLiteral(target_method, &call_patches_);
4661}
4662
Calin Juravleb1498f62015-02-16 13:13:29 +00004663void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4664 // Nothing to do, this should be removed during prepare for register allocator.
4665 UNUSED(instruction);
4666 LOG(FATAL) << "Unreachable";
4667}
4668
4669void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4670 // Nothing to do, this should be removed during prepare for register allocator.
4671 UNUSED(instruction);
4672 LOG(FATAL) << "Unreachable";
4673}
4674
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01004675void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) {
4676 DCHECK(codegen_->IsBaseline());
4677 LocationSummary* locations =
4678 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4679 locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
4680}
4681
4682void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
4683 DCHECK(codegen_->IsBaseline());
4684 // Will be generated at use site.
4685}
4686
Roland Levillain4d027112015-07-01 15:41:14 +01004687#undef __
4688#undef QUICK_ENTRY_POINT
4689
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004690} // namespace arm
4691} // namespace art