blob: 6f89293018eefce6c3561941d93fe7813010f731 [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[] =
Andreas Gampe501fd632015-09-10 16:11:06 -070051 { R5, R6, R7, R8, R10, R11, LR };
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000052static 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());
David Brazdil77a48ae2015-09-15 12:34:04 +000069 if (instruction_->CanThrowIntoCatchBlock()) {
70 // Live registers will be restored in the catch block if caught.
71 SaveLiveRegisters(codegen, instruction_->GetLocations());
72 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010073 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000074 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010075 }
76
Alexandre Rames8158f282015-08-07 10:26:17 +010077 bool IsFatal() const OVERRIDE { return true; }
78
Alexandre Rames9931f312015-06-19 14:47:01 +010079 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
80
Nicolas Geoffraye5038322014-07-04 09:41:32 +010081 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010082 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010083 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
84};
85
Calin Juravled0d48522014-11-04 16:40:20 +000086class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
87 public:
88 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
89
Alexandre Rames67555f72014-11-18 10:55:16 +000090 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000091 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
92 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +000093 if (instruction_->CanThrowIntoCatchBlock()) {
94 // Live registers will be restored in the catch block if caught.
95 SaveLiveRegisters(codegen, instruction_->GetLocations());
96 }
Calin Juravled0d48522014-11-04 16:40:20 +000097 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000098 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +000099 }
100
Alexandre Rames8158f282015-08-07 10:26:17 +0100101 bool IsFatal() const OVERRIDE { return true; }
102
Alexandre Rames9931f312015-06-19 14:47:01 +0100103 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
104
Calin Juravled0d48522014-11-04 16:40:20 +0000105 private:
106 HDivZeroCheck* const instruction_;
107 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
108};
109
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100110class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000111 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000112 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100113 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000114
Alexandre Rames67555f72014-11-18 10:55:16 +0000115 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100116 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000117 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000118 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100119 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000120 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000121 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100122 if (successor_ == nullptr) {
123 __ b(GetReturnLabel());
124 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100125 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100126 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000127 }
128
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100129 Label* GetReturnLabel() {
130 DCHECK(successor_ == nullptr);
131 return &return_label_;
132 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000133
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100134 HBasicBlock* GetSuccessor() const {
135 return successor_;
136 }
137
Alexandre Rames9931f312015-06-19 14:47:01 +0100138 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; }
139
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000140 private:
141 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100142 // If not null, the block to branch to after the suspend check.
143 HBasicBlock* const successor_;
144
145 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000146 Label return_label_;
147
148 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
149};
150
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100151class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100153 explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction)
154 : instruction_(instruction) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100155
Alexandre Rames67555f72014-11-18 10:55:16 +0000156 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100157 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100158 LocationSummary* locations = instruction_->GetLocations();
159
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100160 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000161 if (instruction_->CanThrowIntoCatchBlock()) {
162 // Live registers will be restored in the catch block if caught.
163 SaveLiveRegisters(codegen, instruction_->GetLocations());
164 }
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000165 // We're moving two locations to locations that could overlap, so we need a parallel
166 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100167 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000168 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100169 locations->InAt(0),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000170 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100171 Primitive::kPrimInt,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100172 locations->InAt(1),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100173 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
174 Primitive::kPrimInt);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100175 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000176 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100177 }
178
Alexandre Rames8158f282015-08-07 10:26:17 +0100179 bool IsFatal() const OVERRIDE { return true; }
180
Alexandre Rames9931f312015-06-19 14:47:01 +0100181 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; }
182
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100183 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100184 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100185
186 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
187};
188
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000189class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000191 LoadClassSlowPathARM(HLoadClass* cls,
192 HInstruction* at,
193 uint32_t dex_pc,
194 bool do_clinit)
195 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
196 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
197 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100198
Alexandre Rames67555f72014-11-18 10:55:16 +0000199 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200 LocationSummary* locations = at_->GetLocations();
201
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100202 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
203 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000204 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100205
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100206 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000207 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000208 int32_t entry_point_offset = do_clinit_
209 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
210 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000211 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000212
213 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000214 Location out = locations->Out();
215 if (out.IsValid()) {
216 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000217 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
218 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000219 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100220 __ b(GetExitLabel());
221 }
222
Alexandre Rames9931f312015-06-19 14:47:01 +0100223 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
224
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100225 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000226 // The class this slow path will load.
227 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100228
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000229 // The instruction where this slow path is happening.
230 // (Might be the load class or an initialization check).
231 HInstruction* const at_;
232
233 // The dex PC of `at_`.
234 const uint32_t dex_pc_;
235
236 // Whether to initialize the class.
237 const bool do_clinit_;
238
239 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100240};
241
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000242class LoadStringSlowPathARM : public SlowPathCodeARM {
243 public:
244 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
245
Alexandre Rames67555f72014-11-18 10:55:16 +0000246 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000247 LocationSummary* locations = instruction_->GetLocations();
248 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
249
250 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
251 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000252 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000253
254 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800255 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000256 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000257 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000258 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
259
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000260 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000261 __ b(GetExitLabel());
262 }
263
Alexandre Rames9931f312015-06-19 14:47:01 +0100264 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
265
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000266 private:
267 HLoadString* const instruction_;
268
269 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
270};
271
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000272class TypeCheckSlowPathARM : public SlowPathCodeARM {
273 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100274 explicit TypeCheckSlowPathARM(HInstruction* instruction) : instruction_(instruction) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000275
Alexandre Rames67555f72014-11-18 10:55:16 +0000276 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000277 LocationSummary* locations = instruction_->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100278 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0)
279 : locations->Out();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000280 DCHECK(instruction_->IsCheckCast()
281 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000282
283 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
284 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000285 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000286
287 // We're moving two locations to locations that could overlap, so we need a parallel
288 // move resolver.
289 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000290 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100291 locations->InAt(1),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000292 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100293 Primitive::kPrimNot,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100294 object_class,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100295 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
296 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000297
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000298 if (instruction_->IsInstanceOf()) {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100299 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
300 instruction_,
301 instruction_->GetDexPc(),
302 this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000303 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
304 } else {
305 DCHECK(instruction_->IsCheckCast());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100306 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
307 instruction_,
308 instruction_->GetDexPc(),
309 this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000310 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000311
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000312 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000313 __ b(GetExitLabel());
314 }
315
Alexandre Rames9931f312015-06-19 14:47:01 +0100316 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
317
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000318 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000319 HInstruction* const instruction_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000320
321 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
322};
323
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700324class DeoptimizationSlowPathARM : public SlowPathCodeARM {
325 public:
326 explicit DeoptimizationSlowPathARM(HInstruction* instruction)
327 : instruction_(instruction) {}
328
329 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
330 __ Bind(GetEntryLabel());
331 SaveLiveRegisters(codegen, instruction_->GetLocations());
332 DCHECK(instruction_->IsDeoptimize());
333 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
334 uint32_t dex_pc = deoptimize->GetDexPc();
335 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
336 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
337 }
338
Alexandre Rames9931f312015-06-19 14:47:01 +0100339 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
340
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700341 private:
342 HInstruction* const instruction_;
343 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
344};
345
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000346#undef __
Roland Levillain62a46b22015-06-01 18:24:13 +0100347#define __ down_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700348
Roland Levillain4fa13f62015-07-06 18:11:54 +0100349inline Condition ARMSignedOrFPCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700350 switch (cond) {
351 case kCondEQ: return EQ;
352 case kCondNE: return NE;
353 case kCondLT: return LT;
354 case kCondLE: return LE;
355 case kCondGT: return GT;
356 case kCondGE: return GE;
Dave Allison20dfc792014-06-16 20:44:29 -0700357 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100358 LOG(FATAL) << "Unreachable";
359 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700360}
361
Roland Levillain4fa13f62015-07-06 18:11:54 +0100362inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700363 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100364 case kCondEQ: return EQ;
365 case kCondNE: return NE;
366 case kCondLT: return LO;
367 case kCondLE: return LS;
368 case kCondGT: return HI;
369 case kCondGE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700370 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100371 LOG(FATAL) << "Unreachable";
372 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700373}
374
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100375void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100376 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100377}
378
379void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100380 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100381}
382
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100383size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
384 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
385 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100386}
387
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100388size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
389 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
390 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100391}
392
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000393size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
394 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
395 return kArmWordSize;
396}
397
398size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
399 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
400 return kArmWordSize;
401}
402
Calin Juravle34166012014-12-19 17:22:29 +0000403CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000404 const ArmInstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100405 const CompilerOptions& compiler_options,
406 OptimizingCompilerStats* stats)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000407 : CodeGenerator(graph,
408 kNumberOfCoreRegisters,
409 kNumberOfSRegisters,
410 kNumberOfRegisterPairs,
411 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
412 arraysize(kCoreCalleeSaves)),
413 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
414 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100415 compiler_options,
416 stats),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100417 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100418 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100419 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100420 move_resolver_(graph->GetArena(), this),
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000421 assembler_(),
Vladimir Marko58155012015-08-19 12:49:41 +0000422 isa_features_(isa_features),
423 method_patches_(MethodReferenceComparator(), graph->GetArena()->Adapter()),
424 call_patches_(MethodReferenceComparator(), graph->GetArena()->Adapter()),
425 relative_call_patches_(graph->GetArena()->Adapter()) {
Andreas Gampe501fd632015-09-10 16:11:06 -0700426 // Always save the LR register to mimic Quick.
427 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100428}
429
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000430void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
431 // Ensure that we fix up branches and literal loads and emit the literal pool.
432 __ FinalizeCode();
433
434 // Adjust native pc offsets in stack maps.
435 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
436 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
437 uint32_t new_position = __ GetAdjustedPosition(old_position);
438 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
439 }
440 // Adjust native pc offsets of block labels.
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100441 for (HBasicBlock* block : *block_order_) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000442 // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid
443 // FirstNonEmptyBlock() which could lead to adjusting a label more than once.
444 DCHECK_LT(static_cast<size_t>(block->GetBlockId()), block_labels_.Size());
445 Label* block_label = &block_labels_.GetRawStorage()[block->GetBlockId()];
David Brazdilfc6a86a2015-06-26 10:33:45 +0000446 DCHECK_EQ(block_label->IsBound(), !block->IsSingleJump());
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000447 if (block_label->IsBound()) {
448 __ AdjustLabelPosition(block_label);
449 }
450 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100451 // Adjust pc offsets for the disassembly information.
452 if (disasm_info_ != nullptr) {
453 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
454 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
455 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
456 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
457 it.second.start = __ GetAdjustedPosition(it.second.start);
458 it.second.end = __ GetAdjustedPosition(it.second.end);
459 }
460 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
461 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
462 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
463 }
464 }
Vladimir Marko58155012015-08-19 12:49:41 +0000465 // Adjust pc offsets for relative call patches.
466 for (MethodPatchInfo<Label>& info : relative_call_patches_) {
467 __ AdjustLabelPosition(&info.label);
468 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000469
470 CodeGenerator::Finalize(allocator);
471}
472
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100473Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100474 switch (type) {
475 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100476 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100477 ArmManagedRegister pair =
478 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100479 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
480 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
481
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100482 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
483 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100484 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100485 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100486 }
487
488 case Primitive::kPrimByte:
489 case Primitive::kPrimBoolean:
490 case Primitive::kPrimChar:
491 case Primitive::kPrimShort:
492 case Primitive::kPrimInt:
493 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100494 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100495 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100496 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
497 ArmManagedRegister current =
498 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
499 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100500 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100501 }
502 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100503 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100504 }
505
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000506 case Primitive::kPrimFloat: {
507 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100508 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100509 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100510
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000511 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000512 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
513 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000514 return Location::FpuRegisterPairLocation(reg, reg + 1);
515 }
516
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100517 case Primitive::kPrimVoid:
518 LOG(FATAL) << "Unreachable type " << type;
519 }
520
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100521 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100522}
523
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000524void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100525 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100526 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100527
528 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100529 blocked_core_registers_[SP] = true;
530 blocked_core_registers_[LR] = true;
531 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100532
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100533 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100534 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100535
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100536 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100537 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100538
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000539 if (is_baseline) {
540 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
541 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
542 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000543
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000544 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
545
546 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
547 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
548 }
549 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100550
551 UpdateBlockedPairRegisters();
552}
553
554void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
555 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
556 ArmManagedRegister current =
557 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
558 if (blocked_core_registers_[current.AsRegisterPairLow()]
559 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
560 blocked_register_pairs_[i] = true;
561 }
562 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100563}
564
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100565InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
566 : HGraphVisitor(graph),
567 assembler_(codegen->GetAssembler()),
568 codegen_(codegen) {}
569
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000570void CodeGeneratorARM::ComputeSpillMask() {
571 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000572 // Save one extra register for baseline. Note that on thumb2, there is no easy
573 // instruction to restore just the PC, so this actually helps both baseline
574 // and non-baseline to save and restore at least two registers at entry and exit.
575 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000576 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
577 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
578 // We use vpush and vpop for saving and restoring floating point registers, which take
579 // a SRegister and the number of registers to save/restore after that SRegister. We
580 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
581 // but in the range.
582 if (fpu_spill_mask_ != 0) {
583 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
584 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
585 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
586 fpu_spill_mask_ |= (1 << i);
587 }
588 }
589}
590
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100591static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100592 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100593}
594
595static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100596 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100597}
598
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000599void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000600 bool skip_overflow_check =
601 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000602 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000603 __ Bind(&frame_entry_label_);
604
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000605 if (HasEmptyFrame()) {
606 return;
607 }
608
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100609 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000610 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
611 __ LoadFromOffset(kLoadWord, IP, IP, 0);
612 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100613 }
614
Andreas Gampe501fd632015-09-10 16:11:06 -0700615 __ PushList(core_spill_mask_);
616 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_));
617 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000618 if (fpu_spill_mask_ != 0) {
619 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
620 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100621 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100622 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000623 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100624 int adjust = GetFrameSize() - FrameEntrySpillSize();
625 __ AddConstant(SP, -adjust);
626 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100627 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000628}
629
630void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000631 if (HasEmptyFrame()) {
632 __ bx(LR);
633 return;
634 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100635 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100636 int adjust = GetFrameSize() - FrameEntrySpillSize();
637 __ AddConstant(SP, adjust);
638 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000639 if (fpu_spill_mask_ != 0) {
640 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
641 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100642 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
643 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000644 }
Andreas Gampe501fd632015-09-10 16:11:06 -0700645 // Pop LR into PC to return.
646 DCHECK_NE(core_spill_mask_ & (1 << LR), 0U);
647 uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC;
648 __ PopList(pop_mask);
David Srbeckyc34dc932015-04-12 09:27:43 +0100649 __ cfi().RestoreState();
650 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000651}
652
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100653void CodeGeneratorARM::Bind(HBasicBlock* block) {
654 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000655}
656
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100657Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
658 switch (load->GetType()) {
659 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100660 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100661 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100662
663 case Primitive::kPrimInt:
664 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100665 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100666 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100667
668 case Primitive::kPrimBoolean:
669 case Primitive::kPrimByte:
670 case Primitive::kPrimChar:
671 case Primitive::kPrimShort:
672 case Primitive::kPrimVoid:
673 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700674 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100675 }
676
677 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700678 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100679}
680
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100681Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100682 switch (type) {
683 case Primitive::kPrimBoolean:
684 case Primitive::kPrimByte:
685 case Primitive::kPrimChar:
686 case Primitive::kPrimShort:
687 case Primitive::kPrimInt:
688 case Primitive::kPrimNot: {
689 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000690 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100691 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100692 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100693 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000694 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100695 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100696 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100697
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000698 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100699 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000700 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100701 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000702 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100703 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000704 if (calling_convention.GetRegisterAt(index) == R1) {
705 // Skip R1, and use R2_R3 instead.
706 gp_index_++;
707 index++;
708 }
709 }
710 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
711 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000712 calling_convention.GetRegisterAt(index + 1));
Calin Juravle175dc732015-08-25 15:42:32 +0100713
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000714 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000715 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100716 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000717 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
718 }
719 }
720
721 case Primitive::kPrimFloat: {
722 uint32_t stack_index = stack_index_++;
723 if (float_index_ % 2 == 0) {
724 float_index_ = std::max(double_index_, float_index_);
725 }
726 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
727 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
728 } else {
729 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
730 }
731 }
732
733 case Primitive::kPrimDouble: {
734 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
735 uint32_t stack_index = stack_index_;
736 stack_index_ += 2;
737 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
738 uint32_t index = double_index_;
739 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000740 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000741 calling_convention.GetFpuRegisterAt(index),
742 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000743 DCHECK(ExpectedPairLayout(result));
744 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000745 } else {
746 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100747 }
748 }
749
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100750 case Primitive::kPrimVoid:
751 LOG(FATAL) << "Unexpected parameter type " << type;
752 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100753 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100754 return Location();
755}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100756
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100757Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000758 switch (type) {
759 case Primitive::kPrimBoolean:
760 case Primitive::kPrimByte:
761 case Primitive::kPrimChar:
762 case Primitive::kPrimShort:
763 case Primitive::kPrimInt:
764 case Primitive::kPrimNot: {
765 return Location::RegisterLocation(R0);
766 }
767
768 case Primitive::kPrimFloat: {
769 return Location::FpuRegisterLocation(S0);
770 }
771
772 case Primitive::kPrimLong: {
773 return Location::RegisterPairLocation(R0, R1);
774 }
775
776 case Primitive::kPrimDouble: {
777 return Location::FpuRegisterPairLocation(S0, S1);
778 }
779
780 case Primitive::kPrimVoid:
781 return Location();
782 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100783
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000784 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000785}
786
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100787Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
788 return Location::RegisterLocation(kMethodRegisterArgument);
789}
790
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100791void CodeGeneratorARM::Move32(Location destination, Location source) {
792 if (source.Equals(destination)) {
793 return;
794 }
795 if (destination.IsRegister()) {
796 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000797 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100798 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000799 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100800 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000801 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100802 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100803 } else if (destination.IsFpuRegister()) {
804 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000805 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100806 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000807 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100808 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000809 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100810 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100811 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000812 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100813 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000814 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100815 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000816 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100817 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000818 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100819 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
820 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100821 }
822 }
823}
824
825void CodeGeneratorARM::Move64(Location destination, Location source) {
826 if (source.Equals(destination)) {
827 return;
828 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100829 if (destination.IsRegisterPair()) {
830 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000831 EmitParallelMoves(
832 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
833 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100834 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000835 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100836 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
837 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100838 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000839 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100840 } else {
841 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000842 DCHECK(ExpectedPairLayout(destination));
843 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
844 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100845 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000846 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100847 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000848 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
849 SP,
850 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100851 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000852 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100853 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100854 } else {
855 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100856 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000857 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100858 if (source.AsRegisterPairLow<Register>() == R1) {
859 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100860 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
861 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100862 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100863 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100864 SP, destination.GetStackIndex());
865 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000866 } else if (source.IsFpuRegisterPair()) {
867 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
868 SP,
869 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100870 } else {
871 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000872 EmitParallelMoves(
873 Location::StackSlot(source.GetStackIndex()),
874 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100875 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000876 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100877 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
878 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100879 }
880 }
881}
882
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100883void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100884 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100885 if (instruction->IsCurrentMethod()) {
886 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
887 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100888 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100889 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000890 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000891 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
892 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000893 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000894 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000895 } else {
896 DCHECK(location.IsStackSlot());
897 __ LoadImmediate(IP, value);
898 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
899 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000900 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000901 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000902 int64_t value = const_to_move->AsLongConstant()->GetValue();
903 if (location.IsRegisterPair()) {
904 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
905 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
906 } else {
907 DCHECK(location.IsDoubleStackSlot());
908 __ LoadImmediate(IP, Low32Bits(value));
909 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
910 __ LoadImmediate(IP, High32Bits(value));
911 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
912 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100913 }
Roland Levillain476df552014-10-09 17:51:36 +0100914 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100915 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
916 switch (instruction->GetType()) {
917 case Primitive::kPrimBoolean:
918 case Primitive::kPrimByte:
919 case Primitive::kPrimChar:
920 case Primitive::kPrimShort:
921 case Primitive::kPrimInt:
922 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100923 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100924 Move32(location, Location::StackSlot(stack_slot));
925 break;
926
927 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100928 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100929 Move64(location, Location::DoubleStackSlot(stack_slot));
930 break;
931
932 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100933 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100934 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000935 } else if (instruction->IsTemporary()) {
936 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000937 if (temp_location.IsStackSlot()) {
938 Move32(location, temp_location);
939 } else {
940 DCHECK(temp_location.IsDoubleStackSlot());
941 Move64(location, temp_location);
942 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000943 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100944 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100945 switch (instruction->GetType()) {
946 case Primitive::kPrimBoolean:
947 case Primitive::kPrimByte:
948 case Primitive::kPrimChar:
949 case Primitive::kPrimShort:
950 case Primitive::kPrimNot:
951 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100952 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100953 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100954 break;
955
956 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100957 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100958 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100959 break;
960
961 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100962 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100963 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000964 }
965}
966
Calin Juravle175dc732015-08-25 15:42:32 +0100967void CodeGeneratorARM::MoveConstant(Location location, int32_t value) {
968 DCHECK(location.IsRegister());
969 __ LoadImmediate(location.AsRegister<Register>(), value);
970}
971
972void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint,
973 HInstruction* instruction,
974 uint32_t dex_pc,
975 SlowPathCode* slow_path) {
976 InvokeRuntime(GetThreadOffset<kArmWordSize>(entrypoint).Int32Value(),
977 instruction,
978 dex_pc,
979 slow_path);
980}
981
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100982void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
983 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000984 uint32_t dex_pc,
985 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +0100986 ValidateInvokeRuntime(instruction, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100987 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
988 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000989 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100990}
991
David Brazdilfc6a86a2015-06-26 10:33:45 +0000992void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100993 DCHECK(!successor->IsExitBlock());
994
995 HBasicBlock* block = got->GetBlock();
996 HInstruction* previous = got->GetPrevious();
997
998 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000999 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001000 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1001 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1002 return;
1003 }
1004
1005 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1006 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1007 }
1008 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001009 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001010 }
1011}
1012
David Brazdilfc6a86a2015-06-26 10:33:45 +00001013void LocationsBuilderARM::VisitGoto(HGoto* got) {
1014 got->SetLocations(nullptr);
1015}
1016
1017void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1018 HandleGoto(got, got->GetSuccessor());
1019}
1020
1021void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1022 try_boundary->SetLocations(nullptr);
1023}
1024
1025void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1026 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1027 if (!successor->IsExitBlock()) {
1028 HandleGoto(try_boundary, successor);
1029 }
1030}
1031
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001032void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001033 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001034}
1035
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001036void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001037 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001038}
1039
Roland Levillain4fa13f62015-07-06 18:11:54 +01001040void InstructionCodeGeneratorARM::GenerateCompareWithImmediate(Register left, int32_t right) {
1041 ShifterOperand operand;
1042 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, right, &operand)) {
1043 __ cmp(left, operand);
1044 } else {
1045 Register temp = IP;
1046 __ LoadImmediate(temp, right);
1047 __ cmp(left, ShifterOperand(temp));
1048 }
1049}
1050
1051void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1052 Label* true_label,
1053 Label* false_label) {
1054 __ vmstat(); // transfer FP status register to ARM APSR.
1055 if (cond->IsFPConditionTrueIfNaN()) {
1056 __ b(true_label, VS); // VS for unordered.
1057 } else if (cond->IsFPConditionFalseIfNaN()) {
1058 __ b(false_label, VS); // VS for unordered.
1059 }
1060 __ b(true_label, ARMSignedOrFPCondition(cond->GetCondition()));
1061}
1062
1063void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1064 Label* true_label,
1065 Label* false_label) {
1066 LocationSummary* locations = cond->GetLocations();
1067 Location left = locations->InAt(0);
1068 Location right = locations->InAt(1);
1069 IfCondition if_cond = cond->GetCondition();
1070
1071 Register left_high = left.AsRegisterPairHigh<Register>();
1072 Register left_low = left.AsRegisterPairLow<Register>();
1073 IfCondition true_high_cond = if_cond;
1074 IfCondition false_high_cond = cond->GetOppositeCondition();
1075 Condition final_condition = ARMUnsignedCondition(if_cond);
1076
1077 // Set the conditions for the test, remembering that == needs to be
1078 // decided using the low words.
1079 switch (if_cond) {
1080 case kCondEQ:
1081 case kCondNE:
1082 // Nothing to do.
1083 break;
1084 case kCondLT:
1085 false_high_cond = kCondGT;
1086 break;
1087 case kCondLE:
1088 true_high_cond = kCondLT;
1089 break;
1090 case kCondGT:
1091 false_high_cond = kCondLT;
1092 break;
1093 case kCondGE:
1094 true_high_cond = kCondGT;
1095 break;
1096 }
1097 if (right.IsConstant()) {
1098 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1099 int32_t val_low = Low32Bits(value);
1100 int32_t val_high = High32Bits(value);
1101
1102 GenerateCompareWithImmediate(left_high, val_high);
1103 if (if_cond == kCondNE) {
1104 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1105 } else if (if_cond == kCondEQ) {
1106 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1107 } else {
1108 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1109 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1110 }
1111 // Must be equal high, so compare the lows.
1112 GenerateCompareWithImmediate(left_low, val_low);
1113 } else {
1114 Register right_high = right.AsRegisterPairHigh<Register>();
1115 Register right_low = right.AsRegisterPairLow<Register>();
1116
1117 __ cmp(left_high, ShifterOperand(right_high));
1118 if (if_cond == kCondNE) {
1119 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1120 } else if (if_cond == kCondEQ) {
1121 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1122 } else {
1123 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1124 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1125 }
1126 // Must be equal high, so compare the lows.
1127 __ cmp(left_low, ShifterOperand(right_low));
1128 }
1129 // The last comparison might be unsigned.
1130 __ b(true_label, final_condition);
1131}
1132
1133void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HIf* if_instr,
1134 HCondition* condition,
1135 Label* true_target,
1136 Label* false_target,
1137 Label* always_true_target) {
1138 LocationSummary* locations = condition->GetLocations();
1139 Location left = locations->InAt(0);
1140 Location right = locations->InAt(1);
1141
1142 // We don't want true_target as a nullptr.
1143 if (true_target == nullptr) {
1144 true_target = always_true_target;
1145 }
1146 bool falls_through = (false_target == nullptr);
1147
1148 // FP compares don't like null false_targets.
1149 if (false_target == nullptr) {
1150 false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1151 }
1152
1153 Primitive::Type type = condition->InputAt(0)->GetType();
1154 switch (type) {
1155 case Primitive::kPrimLong:
1156 GenerateLongComparesAndJumps(condition, true_target, false_target);
1157 break;
1158 case Primitive::kPrimFloat:
1159 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1160 GenerateFPJumps(condition, true_target, false_target);
1161 break;
1162 case Primitive::kPrimDouble:
1163 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1164 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1165 GenerateFPJumps(condition, true_target, false_target);
1166 break;
1167 default:
1168 LOG(FATAL) << "Unexpected compare type " << type;
1169 }
1170
1171 if (!falls_through) {
1172 __ b(false_target);
1173 }
1174}
1175
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001176void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
1177 Label* true_target,
1178 Label* false_target,
1179 Label* always_true_target) {
1180 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001181 if (cond->IsIntConstant()) {
1182 // Constant condition, statically compared against 1.
1183 int32_t cond_value = cond->AsIntConstant()->GetValue();
1184 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001185 if (always_true_target != nullptr) {
1186 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001187 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001188 return;
1189 } else {
1190 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001191 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001192 } else {
1193 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1194 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001195 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01001196 __ CompareAndBranchIfNonZero(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
1197 true_target);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001198 } else {
1199 // Condition has not been materialized, use its inputs as the
1200 // comparison and its condition as the branch condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +01001201 Primitive::Type type =
1202 cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt;
1203 // Is this a long or FP comparison that has been folded into the HCondition?
1204 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1205 // Generate the comparison directly.
1206 GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(),
1207 true_target, false_target, always_true_target);
1208 return;
1209 }
1210
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001211 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001212 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001213 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain4fa13f62015-07-06 18:11:54 +01001214 Location right = locations->InAt(1);
1215 if (right.IsRegister()) {
1216 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001217 } else {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001218 DCHECK(right.IsConstant());
1219 GenerateCompareWithImmediate(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001220 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001221 __ b(true_target, ARMSignedOrFPCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001222 }
Dave Allison20dfc792014-06-16 20:44:29 -07001223 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001224 if (false_target != nullptr) {
1225 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001226 }
1227}
1228
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001229void LocationsBuilderARM::VisitIf(HIf* if_instr) {
1230 LocationSummary* locations =
1231 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
1232 HInstruction* cond = if_instr->InputAt(0);
1233 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1234 locations->SetInAt(0, Location::RequiresRegister());
1235 }
1236}
1237
1238void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1239 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1240 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1241 Label* always_true_target = true_target;
1242 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1243 if_instr->IfTrueSuccessor())) {
1244 always_true_target = nullptr;
1245 }
1246 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1247 if_instr->IfFalseSuccessor())) {
1248 false_target = nullptr;
1249 }
1250 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1251}
1252
1253void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1254 LocationSummary* locations = new (GetGraph()->GetArena())
1255 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1256 HInstruction* cond = deoptimize->InputAt(0);
1257 DCHECK(cond->IsCondition());
1258 if (cond->AsCondition()->NeedsMaterialization()) {
1259 locations->SetInAt(0, Location::RequiresRegister());
1260 }
1261}
1262
1263void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1264 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1265 DeoptimizationSlowPathARM(deoptimize);
1266 codegen_->AddSlowPath(slow_path);
1267 Label* slow_path_entry = slow_path->GetEntryLabel();
1268 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1269}
Dave Allison20dfc792014-06-16 20:44:29 -07001270
Roland Levillain0d37cd02015-05-27 16:39:19 +01001271void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001272 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001273 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001274 // Handle the long/FP comparisons made in instruction simplification.
1275 switch (cond->InputAt(0)->GetType()) {
1276 case Primitive::kPrimLong:
1277 locations->SetInAt(0, Location::RequiresRegister());
1278 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1279 if (cond->NeedsMaterialization()) {
1280 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1281 }
1282 break;
1283
1284 case Primitive::kPrimFloat:
1285 case Primitive::kPrimDouble:
1286 locations->SetInAt(0, Location::RequiresFpuRegister());
1287 locations->SetInAt(1, Location::RequiresFpuRegister());
1288 if (cond->NeedsMaterialization()) {
1289 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1290 }
1291 break;
1292
1293 default:
1294 locations->SetInAt(0, Location::RequiresRegister());
1295 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1296 if (cond->NeedsMaterialization()) {
1297 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1298 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001299 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001300}
1301
Roland Levillain0d37cd02015-05-27 16:39:19 +01001302void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001303 if (!cond->NeedsMaterialization()) {
1304 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001305 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001306
1307 LocationSummary* locations = cond->GetLocations();
1308 Location left = locations->InAt(0);
1309 Location right = locations->InAt(1);
1310 Register out = locations->Out().AsRegister<Register>();
1311 Label true_label, false_label;
1312
1313 switch (cond->InputAt(0)->GetType()) {
1314 default: {
1315 // Integer case.
1316 if (right.IsRegister()) {
1317 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1318 } else {
1319 DCHECK(right.IsConstant());
1320 GenerateCompareWithImmediate(left.AsRegister<Register>(),
1321 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
1322 }
1323 __ it(ARMSignedOrFPCondition(cond->GetCondition()), kItElse);
1324 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
1325 ARMSignedOrFPCondition(cond->GetCondition()));
1326 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
1327 ARMSignedOrFPCondition(cond->GetOppositeCondition()));
1328 return;
1329 }
1330 case Primitive::kPrimLong:
1331 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1332 break;
1333 case Primitive::kPrimFloat:
1334 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1335 GenerateFPJumps(cond, &true_label, &false_label);
1336 break;
1337 case Primitive::kPrimDouble:
1338 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1339 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1340 GenerateFPJumps(cond, &true_label, &false_label);
1341 break;
1342 }
1343
1344 // Convert the jumps into the result.
1345 Label done_label;
1346
1347 // False case: result = 0.
1348 __ Bind(&false_label);
1349 __ LoadImmediate(out, 0);
1350 __ b(&done_label);
1351
1352 // True case: result = 1.
1353 __ Bind(&true_label);
1354 __ LoadImmediate(out, 1);
1355 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001356}
1357
1358void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1359 VisitCondition(comp);
1360}
1361
1362void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1363 VisitCondition(comp);
1364}
1365
1366void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1367 VisitCondition(comp);
1368}
1369
1370void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1371 VisitCondition(comp);
1372}
1373
1374void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1375 VisitCondition(comp);
1376}
1377
1378void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1379 VisitCondition(comp);
1380}
1381
1382void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1383 VisitCondition(comp);
1384}
1385
1386void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1387 VisitCondition(comp);
1388}
1389
1390void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1391 VisitCondition(comp);
1392}
1393
1394void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1395 VisitCondition(comp);
1396}
1397
1398void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1399 VisitCondition(comp);
1400}
1401
1402void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1403 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001404}
1405
1406void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001407 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001408}
1409
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001410void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1411 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001412}
1413
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001414void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001415 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001416}
1417
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001418void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001419 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001420 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001421}
1422
1423void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001424 LocationSummary* locations =
1425 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001426 switch (store->InputAt(1)->GetType()) {
1427 case Primitive::kPrimBoolean:
1428 case Primitive::kPrimByte:
1429 case Primitive::kPrimChar:
1430 case Primitive::kPrimShort:
1431 case Primitive::kPrimInt:
1432 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001433 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001434 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1435 break;
1436
1437 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001438 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001439 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1440 break;
1441
1442 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001443 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001444 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001445}
1446
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001447void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001448 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001449}
1450
1451void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001452 LocationSummary* locations =
1453 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001454 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001455}
1456
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001457void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001458 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001459 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001460}
1461
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001462void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1463 LocationSummary* locations =
1464 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1465 locations->SetOut(Location::ConstantLocation(constant));
1466}
1467
1468void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1469 // Will be generated at use site.
1470 UNUSED(constant);
1471}
1472
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001473void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001474 LocationSummary* locations =
1475 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001476 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001477}
1478
1479void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1480 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001481 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001482}
1483
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001484void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1485 LocationSummary* locations =
1486 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1487 locations->SetOut(Location::ConstantLocation(constant));
1488}
1489
1490void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1491 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001492 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001493}
1494
1495void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1496 LocationSummary* locations =
1497 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1498 locations->SetOut(Location::ConstantLocation(constant));
1499}
1500
1501void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1502 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001503 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001504}
1505
Calin Juravle27df7582015-04-17 19:12:31 +01001506void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1507 memory_barrier->SetLocations(nullptr);
1508}
1509
1510void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1511 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1512}
1513
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001514void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001515 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001516}
1517
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001518void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001519 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001520 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001521}
1522
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001523void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001524 LocationSummary* locations =
1525 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001526 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001527}
1528
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001529void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001530 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001531 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001532}
1533
Calin Juravle175dc732015-08-25 15:42:32 +01001534void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1535 // The trampoline uses the same calling convention as dex calling conventions,
1536 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
1537 // the method_idx.
1538 HandleInvoke(invoke);
1539}
1540
1541void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1542 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
1543}
1544
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001545void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001546 // When we do not run baseline, explicit clinit checks triggered by static
1547 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1548 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001549
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001550 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1551 codegen_->GetInstructionSetFeatures());
1552 if (intrinsic.TryDispatch(invoke)) {
1553 return;
1554 }
1555
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001556 HandleInvoke(invoke);
1557}
1558
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001559static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1560 if (invoke->GetLocations()->Intrinsified()) {
1561 IntrinsicCodeGeneratorARM intrinsic(codegen);
1562 intrinsic.Dispatch(invoke);
1563 return true;
1564 }
1565 return false;
1566}
1567
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001568void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001569 // When we do not run baseline, explicit clinit checks triggered by static
1570 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1571 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001572
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001573 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1574 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001575 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001576
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001577 LocationSummary* locations = invoke->GetLocations();
1578 codegen_->GenerateStaticOrDirectCall(
1579 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001580 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001581}
1582
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001583void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001584 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001585 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001586}
1587
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001588void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001589 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1590 codegen_->GetInstructionSetFeatures());
1591 if (intrinsic.TryDispatch(invoke)) {
1592 return;
1593 }
1594
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001595 HandleInvoke(invoke);
1596}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001597
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001598void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001599 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1600 return;
1601 }
1602
Andreas Gampebfb5ba92015-09-01 15:45:02 +00001603 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001604 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001605 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001606}
1607
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001608void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1609 HandleInvoke(invoke);
1610 // Add the hidden argument.
1611 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1612}
1613
1614void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1615 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001616 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001617 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1618 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001619 LocationSummary* locations = invoke->GetLocations();
1620 Location receiver = locations->InAt(0);
1621 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1622
1623 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001624 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1625 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001626
1627 // temp = object->GetClass();
1628 if (receiver.IsStackSlot()) {
1629 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1630 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1631 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001632 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001633 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001634 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001635 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001636 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001637 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001638 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001639 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1640 // LR = temp->GetEntryPoint();
1641 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1642 // LR();
1643 __ blx(LR);
1644 DCHECK(!codegen_->IsLeafMethod());
1645 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1646}
1647
Roland Levillain88cb1752014-10-20 16:36:47 +01001648void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1649 LocationSummary* locations =
1650 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1651 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001652 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001653 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001654 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1655 break;
1656 }
1657 case Primitive::kPrimLong: {
1658 locations->SetInAt(0, Location::RequiresRegister());
1659 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001660 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001661 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001662
Roland Levillain88cb1752014-10-20 16:36:47 +01001663 case Primitive::kPrimFloat:
1664 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001665 locations->SetInAt(0, Location::RequiresFpuRegister());
1666 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001667 break;
1668
1669 default:
1670 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1671 }
1672}
1673
1674void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1675 LocationSummary* locations = neg->GetLocations();
1676 Location out = locations->Out();
1677 Location in = locations->InAt(0);
1678 switch (neg->GetResultType()) {
1679 case Primitive::kPrimInt:
1680 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001681 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001682 break;
1683
1684 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001685 DCHECK(in.IsRegisterPair());
1686 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1687 __ rsbs(out.AsRegisterPairLow<Register>(),
1688 in.AsRegisterPairLow<Register>(),
1689 ShifterOperand(0));
1690 // We cannot emit an RSC (Reverse Subtract with Carry)
1691 // instruction here, as it does not exist in the Thumb-2
1692 // instruction set. We use the following approach
1693 // using SBC and SUB instead.
1694 //
1695 // out.hi = -C
1696 __ sbc(out.AsRegisterPairHigh<Register>(),
1697 out.AsRegisterPairHigh<Register>(),
1698 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1699 // out.hi = out.hi - in.hi
1700 __ sub(out.AsRegisterPairHigh<Register>(),
1701 out.AsRegisterPairHigh<Register>(),
1702 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1703 break;
1704
Roland Levillain88cb1752014-10-20 16:36:47 +01001705 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001706 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001707 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001708 break;
1709
Roland Levillain88cb1752014-10-20 16:36:47 +01001710 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001711 DCHECK(in.IsFpuRegisterPair());
1712 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1713 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001714 break;
1715
1716 default:
1717 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1718 }
1719}
1720
Roland Levillaindff1f282014-11-05 14:15:05 +00001721void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001722 Primitive::Type result_type = conversion->GetResultType();
1723 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001724 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001725
Roland Levillain5b3ee562015-04-14 16:02:41 +01001726 // The float-to-long, double-to-long and long-to-float type conversions
1727 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001728 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001729 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1730 && result_type == Primitive::kPrimLong)
1731 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001732 ? LocationSummary::kCall
1733 : LocationSummary::kNoCall;
1734 LocationSummary* locations =
1735 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1736
David Brazdilb2bd1c52015-03-25 11:17:37 +00001737 // The Java language does not allow treating boolean as an integral type but
1738 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001739
Roland Levillaindff1f282014-11-05 14:15:05 +00001740 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001741 case Primitive::kPrimByte:
1742 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001743 case Primitive::kPrimBoolean:
1744 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001745 case Primitive::kPrimShort:
1746 case Primitive::kPrimInt:
1747 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001748 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001749 locations->SetInAt(0, Location::RequiresRegister());
1750 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1751 break;
1752
1753 default:
1754 LOG(FATAL) << "Unexpected type conversion from " << input_type
1755 << " to " << result_type;
1756 }
1757 break;
1758
Roland Levillain01a8d712014-11-14 16:27:39 +00001759 case Primitive::kPrimShort:
1760 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001761 case Primitive::kPrimBoolean:
1762 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001763 case Primitive::kPrimByte:
1764 case Primitive::kPrimInt:
1765 case Primitive::kPrimChar:
1766 // Processing a Dex `int-to-short' instruction.
1767 locations->SetInAt(0, Location::RequiresRegister());
1768 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1769 break;
1770
1771 default:
1772 LOG(FATAL) << "Unexpected type conversion from " << input_type
1773 << " to " << result_type;
1774 }
1775 break;
1776
Roland Levillain946e1432014-11-11 17:35:19 +00001777 case Primitive::kPrimInt:
1778 switch (input_type) {
1779 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001780 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001781 locations->SetInAt(0, Location::Any());
1782 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1783 break;
1784
1785 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001786 // Processing a Dex `float-to-int' instruction.
1787 locations->SetInAt(0, Location::RequiresFpuRegister());
1788 locations->SetOut(Location::RequiresRegister());
1789 locations->AddTemp(Location::RequiresFpuRegister());
1790 break;
1791
Roland Levillain946e1432014-11-11 17:35:19 +00001792 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001793 // Processing a Dex `double-to-int' instruction.
1794 locations->SetInAt(0, Location::RequiresFpuRegister());
1795 locations->SetOut(Location::RequiresRegister());
1796 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001797 break;
1798
1799 default:
1800 LOG(FATAL) << "Unexpected type conversion from " << input_type
1801 << " to " << result_type;
1802 }
1803 break;
1804
Roland Levillaindff1f282014-11-05 14:15:05 +00001805 case Primitive::kPrimLong:
1806 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001807 case Primitive::kPrimBoolean:
1808 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001809 case Primitive::kPrimByte:
1810 case Primitive::kPrimShort:
1811 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001812 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001813 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001814 locations->SetInAt(0, Location::RequiresRegister());
1815 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1816 break;
1817
Roland Levillain624279f2014-12-04 11:54:28 +00001818 case Primitive::kPrimFloat: {
1819 // Processing a Dex `float-to-long' instruction.
1820 InvokeRuntimeCallingConvention calling_convention;
1821 locations->SetInAt(0, Location::FpuRegisterLocation(
1822 calling_convention.GetFpuRegisterAt(0)));
1823 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1824 break;
1825 }
1826
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001827 case Primitive::kPrimDouble: {
1828 // Processing a Dex `double-to-long' instruction.
1829 InvokeRuntimeCallingConvention calling_convention;
1830 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1831 calling_convention.GetFpuRegisterAt(0),
1832 calling_convention.GetFpuRegisterAt(1)));
1833 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001834 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001835 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001836
1837 default:
1838 LOG(FATAL) << "Unexpected type conversion from " << input_type
1839 << " to " << result_type;
1840 }
1841 break;
1842
Roland Levillain981e4542014-11-14 11:47:14 +00001843 case Primitive::kPrimChar:
1844 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001845 case Primitive::kPrimBoolean:
1846 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001847 case Primitive::kPrimByte:
1848 case Primitive::kPrimShort:
1849 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001850 // Processing a Dex `int-to-char' instruction.
1851 locations->SetInAt(0, Location::RequiresRegister());
1852 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1853 break;
1854
1855 default:
1856 LOG(FATAL) << "Unexpected type conversion from " << input_type
1857 << " to " << result_type;
1858 }
1859 break;
1860
Roland Levillaindff1f282014-11-05 14:15:05 +00001861 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001862 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001863 case Primitive::kPrimBoolean:
1864 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001865 case Primitive::kPrimByte:
1866 case Primitive::kPrimShort:
1867 case Primitive::kPrimInt:
1868 case Primitive::kPrimChar:
1869 // Processing a Dex `int-to-float' instruction.
1870 locations->SetInAt(0, Location::RequiresRegister());
1871 locations->SetOut(Location::RequiresFpuRegister());
1872 break;
1873
Roland Levillain5b3ee562015-04-14 16:02:41 +01001874 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001875 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001876 InvokeRuntimeCallingConvention calling_convention;
1877 locations->SetInAt(0, Location::RegisterPairLocation(
1878 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1879 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001880 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001881 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001882
Roland Levillaincff13742014-11-17 14:32:17 +00001883 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001884 // Processing a Dex `double-to-float' instruction.
1885 locations->SetInAt(0, Location::RequiresFpuRegister());
1886 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001887 break;
1888
1889 default:
1890 LOG(FATAL) << "Unexpected type conversion from " << input_type
1891 << " to " << result_type;
1892 };
1893 break;
1894
Roland Levillaindff1f282014-11-05 14:15:05 +00001895 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001896 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001897 case Primitive::kPrimBoolean:
1898 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001899 case Primitive::kPrimByte:
1900 case Primitive::kPrimShort:
1901 case Primitive::kPrimInt:
1902 case Primitive::kPrimChar:
1903 // Processing a Dex `int-to-double' instruction.
1904 locations->SetInAt(0, Location::RequiresRegister());
1905 locations->SetOut(Location::RequiresFpuRegister());
1906 break;
1907
1908 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001909 // Processing a Dex `long-to-double' instruction.
1910 locations->SetInAt(0, Location::RequiresRegister());
1911 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001912 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001913 locations->AddTemp(Location::RequiresFpuRegister());
1914 break;
1915
Roland Levillaincff13742014-11-17 14:32:17 +00001916 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001917 // Processing a Dex `float-to-double' instruction.
1918 locations->SetInAt(0, Location::RequiresFpuRegister());
1919 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001920 break;
1921
1922 default:
1923 LOG(FATAL) << "Unexpected type conversion from " << input_type
1924 << " to " << result_type;
1925 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001926 break;
1927
1928 default:
1929 LOG(FATAL) << "Unexpected type conversion from " << input_type
1930 << " to " << result_type;
1931 }
1932}
1933
1934void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1935 LocationSummary* locations = conversion->GetLocations();
1936 Location out = locations->Out();
1937 Location in = locations->InAt(0);
1938 Primitive::Type result_type = conversion->GetResultType();
1939 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001940 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001941 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001942 case Primitive::kPrimByte:
1943 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001944 case Primitive::kPrimBoolean:
1945 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001946 case Primitive::kPrimShort:
1947 case Primitive::kPrimInt:
1948 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001949 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001950 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001951 break;
1952
1953 default:
1954 LOG(FATAL) << "Unexpected type conversion from " << input_type
1955 << " to " << result_type;
1956 }
1957 break;
1958
Roland Levillain01a8d712014-11-14 16:27:39 +00001959 case Primitive::kPrimShort:
1960 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001961 case Primitive::kPrimBoolean:
1962 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001963 case Primitive::kPrimByte:
1964 case Primitive::kPrimInt:
1965 case Primitive::kPrimChar:
1966 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001967 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001968 break;
1969
1970 default:
1971 LOG(FATAL) << "Unexpected type conversion from " << input_type
1972 << " to " << result_type;
1973 }
1974 break;
1975
Roland Levillain946e1432014-11-11 17:35:19 +00001976 case Primitive::kPrimInt:
1977 switch (input_type) {
1978 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001979 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001980 DCHECK(out.IsRegister());
1981 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001982 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001983 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001984 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001985 } else {
1986 DCHECK(in.IsConstant());
1987 DCHECK(in.GetConstant()->IsLongConstant());
1988 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001989 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001990 }
1991 break;
1992
Roland Levillain3f8f9362014-12-02 17:45:01 +00001993 case Primitive::kPrimFloat: {
1994 // Processing a Dex `float-to-int' instruction.
1995 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1996 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1997 __ vcvtis(temp, temp);
1998 __ vmovrs(out.AsRegister<Register>(), temp);
1999 break;
2000 }
2001
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002002 case Primitive::kPrimDouble: {
2003 // Processing a Dex `double-to-int' instruction.
2004 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
2005 DRegister temp_d = FromLowSToD(temp_s);
2006 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
2007 __ vcvtid(temp_s, temp_d);
2008 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002009 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002010 }
Roland Levillain946e1432014-11-11 17:35:19 +00002011
2012 default:
2013 LOG(FATAL) << "Unexpected type conversion from " << input_type
2014 << " to " << result_type;
2015 }
2016 break;
2017
Roland Levillaindff1f282014-11-05 14:15:05 +00002018 case Primitive::kPrimLong:
2019 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002020 case Primitive::kPrimBoolean:
2021 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002022 case Primitive::kPrimByte:
2023 case Primitive::kPrimShort:
2024 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002025 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002026 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002027 DCHECK(out.IsRegisterPair());
2028 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002029 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002030 // Sign extension.
2031 __ Asr(out.AsRegisterPairHigh<Register>(),
2032 out.AsRegisterPairLow<Register>(),
2033 31);
2034 break;
2035
2036 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002037 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00002038 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
2039 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002040 conversion->GetDexPc(),
2041 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00002042 break;
2043
Roland Levillaindff1f282014-11-05 14:15:05 +00002044 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002045 // Processing a Dex `double-to-long' instruction.
2046 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
2047 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002048 conversion->GetDexPc(),
2049 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00002050 break;
2051
2052 default:
2053 LOG(FATAL) << "Unexpected type conversion from " << input_type
2054 << " to " << result_type;
2055 }
2056 break;
2057
Roland Levillain981e4542014-11-14 11:47:14 +00002058 case Primitive::kPrimChar:
2059 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002060 case Primitive::kPrimBoolean:
2061 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002062 case Primitive::kPrimByte:
2063 case Primitive::kPrimShort:
2064 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002065 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002066 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002067 break;
2068
2069 default:
2070 LOG(FATAL) << "Unexpected type conversion from " << input_type
2071 << " to " << result_type;
2072 }
2073 break;
2074
Roland Levillaindff1f282014-11-05 14:15:05 +00002075 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002076 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002077 case Primitive::kPrimBoolean:
2078 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002079 case Primitive::kPrimByte:
2080 case Primitive::kPrimShort:
2081 case Primitive::kPrimInt:
2082 case Primitive::kPrimChar: {
2083 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002084 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2085 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002086 break;
2087 }
2088
Roland Levillain5b3ee562015-04-14 16:02:41 +01002089 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002090 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002091 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
2092 conversion,
2093 conversion->GetDexPc(),
2094 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00002095 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002096
Roland Levillaincff13742014-11-17 14:32:17 +00002097 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002098 // Processing a Dex `double-to-float' instruction.
2099 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2100 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002101 break;
2102
2103 default:
2104 LOG(FATAL) << "Unexpected type conversion from " << input_type
2105 << " to " << result_type;
2106 };
2107 break;
2108
Roland Levillaindff1f282014-11-05 14:15:05 +00002109 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002110 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002111 case Primitive::kPrimBoolean:
2112 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002113 case Primitive::kPrimByte:
2114 case Primitive::kPrimShort:
2115 case Primitive::kPrimInt:
2116 case Primitive::kPrimChar: {
2117 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002118 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002119 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2120 out.AsFpuRegisterPairLow<SRegister>());
2121 break;
2122 }
2123
Roland Levillain647b9ed2014-11-27 12:06:00 +00002124 case Primitive::kPrimLong: {
2125 // Processing a Dex `long-to-double' instruction.
2126 Register low = in.AsRegisterPairLow<Register>();
2127 Register high = in.AsRegisterPairHigh<Register>();
2128 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2129 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002130 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002131 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002132 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2133 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002134
Roland Levillain682393c2015-04-14 15:57:52 +01002135 // temp_d = int-to-double(high)
2136 __ vmovsr(temp_s, high);
2137 __ vcvtdi(temp_d, temp_s);
2138 // constant_d = k2Pow32EncodingForDouble
2139 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2140 // out_d = unsigned-to-double(low)
2141 __ vmovsr(out_s, low);
2142 __ vcvtdu(out_d, out_s);
2143 // out_d += temp_d * constant_d
2144 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002145 break;
2146 }
2147
Roland Levillaincff13742014-11-17 14:32:17 +00002148 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002149 // Processing a Dex `float-to-double' instruction.
2150 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2151 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002152 break;
2153
2154 default:
2155 LOG(FATAL) << "Unexpected type conversion from " << input_type
2156 << " to " << result_type;
2157 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002158 break;
2159
2160 default:
2161 LOG(FATAL) << "Unexpected type conversion from " << input_type
2162 << " to " << result_type;
2163 }
2164}
2165
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002166void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002167 LocationSummary* locations =
2168 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002169 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002170 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002171 locations->SetInAt(0, Location::RequiresRegister());
2172 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002173 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2174 break;
2175 }
2176
2177 case Primitive::kPrimLong: {
2178 locations->SetInAt(0, Location::RequiresRegister());
2179 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002180 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002181 break;
2182 }
2183
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002184 case Primitive::kPrimFloat:
2185 case Primitive::kPrimDouble: {
2186 locations->SetInAt(0, Location::RequiresFpuRegister());
2187 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002188 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002189 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002190 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002191
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002192 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002193 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002194 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002195}
2196
2197void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2198 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002199 Location out = locations->Out();
2200 Location first = locations->InAt(0);
2201 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002202 switch (add->GetResultType()) {
2203 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002204 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002205 __ add(out.AsRegister<Register>(),
2206 first.AsRegister<Register>(),
2207 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002208 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002209 __ AddConstant(out.AsRegister<Register>(),
2210 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002211 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002212 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002213 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002214
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002215 case Primitive::kPrimLong: {
2216 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002217 __ adds(out.AsRegisterPairLow<Register>(),
2218 first.AsRegisterPairLow<Register>(),
2219 ShifterOperand(second.AsRegisterPairLow<Register>()));
2220 __ adc(out.AsRegisterPairHigh<Register>(),
2221 first.AsRegisterPairHigh<Register>(),
2222 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002223 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002224 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002225
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002226 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002227 __ vadds(out.AsFpuRegister<SRegister>(),
2228 first.AsFpuRegister<SRegister>(),
2229 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002230 break;
2231
2232 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002233 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2234 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2235 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002236 break;
2237
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002238 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002239 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002240 }
2241}
2242
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002243void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002244 LocationSummary* locations =
2245 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002246 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002247 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002248 locations->SetInAt(0, Location::RequiresRegister());
2249 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002250 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2251 break;
2252 }
2253
2254 case Primitive::kPrimLong: {
2255 locations->SetInAt(0, Location::RequiresRegister());
2256 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002257 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002258 break;
2259 }
Calin Juravle11351682014-10-23 15:38:15 +01002260 case Primitive::kPrimFloat:
2261 case Primitive::kPrimDouble: {
2262 locations->SetInAt(0, Location::RequiresFpuRegister());
2263 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002264 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002265 break;
Calin Juravle11351682014-10-23 15:38:15 +01002266 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002267 default:
Calin Juravle11351682014-10-23 15:38:15 +01002268 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002269 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002270}
2271
2272void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2273 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002274 Location out = locations->Out();
2275 Location first = locations->InAt(0);
2276 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002277 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002278 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002279 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002280 __ sub(out.AsRegister<Register>(),
2281 first.AsRegister<Register>(),
2282 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002283 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002284 __ AddConstant(out.AsRegister<Register>(),
2285 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002286 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002287 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002288 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002289 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002290
Calin Juravle11351682014-10-23 15:38:15 +01002291 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002292 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002293 __ subs(out.AsRegisterPairLow<Register>(),
2294 first.AsRegisterPairLow<Register>(),
2295 ShifterOperand(second.AsRegisterPairLow<Register>()));
2296 __ sbc(out.AsRegisterPairHigh<Register>(),
2297 first.AsRegisterPairHigh<Register>(),
2298 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002299 break;
Calin Juravle11351682014-10-23 15:38:15 +01002300 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002301
Calin Juravle11351682014-10-23 15:38:15 +01002302 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002303 __ vsubs(out.AsFpuRegister<SRegister>(),
2304 first.AsFpuRegister<SRegister>(),
2305 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002306 break;
Calin Juravle11351682014-10-23 15:38:15 +01002307 }
2308
2309 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002310 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2311 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2312 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002313 break;
2314 }
2315
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002316
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002317 default:
Calin Juravle11351682014-10-23 15:38:15 +01002318 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002319 }
2320}
2321
Calin Juravle34bacdf2014-10-07 20:23:36 +01002322void LocationsBuilderARM::VisitMul(HMul* mul) {
2323 LocationSummary* locations =
2324 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2325 switch (mul->GetResultType()) {
2326 case Primitive::kPrimInt:
2327 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002328 locations->SetInAt(0, Location::RequiresRegister());
2329 locations->SetInAt(1, Location::RequiresRegister());
2330 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002331 break;
2332 }
2333
Calin Juravleb5bfa962014-10-21 18:02:24 +01002334 case Primitive::kPrimFloat:
2335 case Primitive::kPrimDouble: {
2336 locations->SetInAt(0, Location::RequiresFpuRegister());
2337 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002338 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002339 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002340 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002341
2342 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002343 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002344 }
2345}
2346
2347void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2348 LocationSummary* locations = mul->GetLocations();
2349 Location out = locations->Out();
2350 Location first = locations->InAt(0);
2351 Location second = locations->InAt(1);
2352 switch (mul->GetResultType()) {
2353 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002354 __ mul(out.AsRegister<Register>(),
2355 first.AsRegister<Register>(),
2356 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002357 break;
2358 }
2359 case Primitive::kPrimLong: {
2360 Register out_hi = out.AsRegisterPairHigh<Register>();
2361 Register out_lo = out.AsRegisterPairLow<Register>();
2362 Register in1_hi = first.AsRegisterPairHigh<Register>();
2363 Register in1_lo = first.AsRegisterPairLow<Register>();
2364 Register in2_hi = second.AsRegisterPairHigh<Register>();
2365 Register in2_lo = second.AsRegisterPairLow<Register>();
2366
2367 // Extra checks to protect caused by the existence of R1_R2.
2368 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2369 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2370 DCHECK_NE(out_hi, in1_lo);
2371 DCHECK_NE(out_hi, in2_lo);
2372
2373 // input: in1 - 64 bits, in2 - 64 bits
2374 // output: out
2375 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2376 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2377 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2378
2379 // IP <- in1.lo * in2.hi
2380 __ mul(IP, in1_lo, in2_hi);
2381 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2382 __ mla(out_hi, in1_hi, in2_lo, IP);
2383 // out.lo <- (in1.lo * in2.lo)[31:0];
2384 __ umull(out_lo, IP, in1_lo, in2_lo);
2385 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2386 __ add(out_hi, out_hi, ShifterOperand(IP));
2387 break;
2388 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002389
2390 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002391 __ vmuls(out.AsFpuRegister<SRegister>(),
2392 first.AsFpuRegister<SRegister>(),
2393 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002394 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002395 }
2396
2397 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002398 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2399 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2400 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002401 break;
2402 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002403
2404 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002405 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002406 }
2407}
2408
Zheng Xuc6667102015-05-15 16:08:45 +08002409void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2410 DCHECK(instruction->IsDiv() || instruction->IsRem());
2411 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2412
2413 LocationSummary* locations = instruction->GetLocations();
2414 Location second = locations->InAt(1);
2415 DCHECK(second.IsConstant());
2416
2417 Register out = locations->Out().AsRegister<Register>();
2418 Register dividend = locations->InAt(0).AsRegister<Register>();
2419 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2420 DCHECK(imm == 1 || imm == -1);
2421
2422 if (instruction->IsRem()) {
2423 __ LoadImmediate(out, 0);
2424 } else {
2425 if (imm == 1) {
2426 __ Mov(out, dividend);
2427 } else {
2428 __ rsb(out, dividend, ShifterOperand(0));
2429 }
2430 }
2431}
2432
2433void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2434 DCHECK(instruction->IsDiv() || instruction->IsRem());
2435 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2436
2437 LocationSummary* locations = instruction->GetLocations();
2438 Location second = locations->InAt(1);
2439 DCHECK(second.IsConstant());
2440
2441 Register out = locations->Out().AsRegister<Register>();
2442 Register dividend = locations->InAt(0).AsRegister<Register>();
2443 Register temp = locations->GetTemp(0).AsRegister<Register>();
2444 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002445 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002446 DCHECK(IsPowerOfTwo(abs_imm));
2447 int ctz_imm = CTZ(abs_imm);
2448
2449 if (ctz_imm == 1) {
2450 __ Lsr(temp, dividend, 32 - ctz_imm);
2451 } else {
2452 __ Asr(temp, dividend, 31);
2453 __ Lsr(temp, temp, 32 - ctz_imm);
2454 }
2455 __ add(out, temp, ShifterOperand(dividend));
2456
2457 if (instruction->IsDiv()) {
2458 __ Asr(out, out, ctz_imm);
2459 if (imm < 0) {
2460 __ rsb(out, out, ShifterOperand(0));
2461 }
2462 } else {
2463 __ ubfx(out, out, 0, ctz_imm);
2464 __ sub(out, out, ShifterOperand(temp));
2465 }
2466}
2467
2468void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2469 DCHECK(instruction->IsDiv() || instruction->IsRem());
2470 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2471
2472 LocationSummary* locations = instruction->GetLocations();
2473 Location second = locations->InAt(1);
2474 DCHECK(second.IsConstant());
2475
2476 Register out = locations->Out().AsRegister<Register>();
2477 Register dividend = locations->InAt(0).AsRegister<Register>();
2478 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2479 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2480 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2481
2482 int64_t magic;
2483 int shift;
2484 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2485
2486 __ LoadImmediate(temp1, magic);
2487 __ smull(temp2, temp1, dividend, temp1);
2488
2489 if (imm > 0 && magic < 0) {
2490 __ add(temp1, temp1, ShifterOperand(dividend));
2491 } else if (imm < 0 && magic > 0) {
2492 __ sub(temp1, temp1, ShifterOperand(dividend));
2493 }
2494
2495 if (shift != 0) {
2496 __ Asr(temp1, temp1, shift);
2497 }
2498
2499 if (instruction->IsDiv()) {
2500 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2501 } else {
2502 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2503 // TODO: Strength reduction for mls.
2504 __ LoadImmediate(temp2, imm);
2505 __ mls(out, temp1, temp2, dividend);
2506 }
2507}
2508
2509void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2510 DCHECK(instruction->IsDiv() || instruction->IsRem());
2511 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2512
2513 LocationSummary* locations = instruction->GetLocations();
2514 Location second = locations->InAt(1);
2515 DCHECK(second.IsConstant());
2516
2517 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2518 if (imm == 0) {
2519 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2520 } else if (imm == 1 || imm == -1) {
2521 DivRemOneOrMinusOne(instruction);
2522 } else if (IsPowerOfTwo(std::abs(imm))) {
2523 DivRemByPowerOfTwo(instruction);
2524 } else {
2525 DCHECK(imm <= -2 || imm >= 2);
2526 GenerateDivRemWithAnyConstant(instruction);
2527 }
2528}
2529
Calin Juravle7c4954d2014-10-28 16:57:40 +00002530void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002531 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2532 if (div->GetResultType() == Primitive::kPrimLong) {
2533 // pLdiv runtime call.
2534 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002535 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2536 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002537 } else if (div->GetResultType() == Primitive::kPrimInt &&
2538 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2539 // pIdivmod runtime call.
2540 call_kind = LocationSummary::kCall;
2541 }
2542
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002543 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2544
Calin Juravle7c4954d2014-10-28 16:57:40 +00002545 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002546 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002547 if (div->InputAt(1)->IsConstant()) {
2548 locations->SetInAt(0, Location::RequiresRegister());
2549 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2550 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2551 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2552 if (abs_imm <= 1) {
2553 // No temp register required.
2554 } else {
2555 locations->AddTemp(Location::RequiresRegister());
2556 if (!IsPowerOfTwo(abs_imm)) {
2557 locations->AddTemp(Location::RequiresRegister());
2558 }
2559 }
2560 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002561 locations->SetInAt(0, Location::RequiresRegister());
2562 locations->SetInAt(1, Location::RequiresRegister());
2563 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2564 } else {
2565 InvokeRuntimeCallingConvention calling_convention;
2566 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2567 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2568 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2569 // we only need the former.
2570 locations->SetOut(Location::RegisterLocation(R0));
2571 }
Calin Juravled0d48522014-11-04 16:40:20 +00002572 break;
2573 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002574 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002575 InvokeRuntimeCallingConvention calling_convention;
2576 locations->SetInAt(0, Location::RegisterPairLocation(
2577 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2578 locations->SetInAt(1, Location::RegisterPairLocation(
2579 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002580 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002581 break;
2582 }
2583 case Primitive::kPrimFloat:
2584 case Primitive::kPrimDouble: {
2585 locations->SetInAt(0, Location::RequiresFpuRegister());
2586 locations->SetInAt(1, Location::RequiresFpuRegister());
2587 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2588 break;
2589 }
2590
2591 default:
2592 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2593 }
2594}
2595
2596void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2597 LocationSummary* locations = div->GetLocations();
2598 Location out = locations->Out();
2599 Location first = locations->InAt(0);
2600 Location second = locations->InAt(1);
2601
2602 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002603 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002604 if (second.IsConstant()) {
2605 GenerateDivRemConstantIntegral(div);
2606 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002607 __ sdiv(out.AsRegister<Register>(),
2608 first.AsRegister<Register>(),
2609 second.AsRegister<Register>());
2610 } else {
2611 InvokeRuntimeCallingConvention calling_convention;
2612 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2613 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2614 DCHECK_EQ(R0, out.AsRegister<Register>());
2615
2616 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2617 }
Calin Juravled0d48522014-11-04 16:40:20 +00002618 break;
2619 }
2620
Calin Juravle7c4954d2014-10-28 16:57:40 +00002621 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002622 InvokeRuntimeCallingConvention calling_convention;
2623 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2624 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2625 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2626 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2627 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002628 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002629
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002630 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002631 break;
2632 }
2633
2634 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002635 __ vdivs(out.AsFpuRegister<SRegister>(),
2636 first.AsFpuRegister<SRegister>(),
2637 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002638 break;
2639 }
2640
2641 case Primitive::kPrimDouble: {
2642 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2643 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2644 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2645 break;
2646 }
2647
2648 default:
2649 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2650 }
2651}
2652
Calin Juravlebacfec32014-11-14 15:54:36 +00002653void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002654 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002655
2656 // Most remainders are implemented in the runtime.
2657 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002658 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2659 // sdiv will be replaced by other instruction sequence.
2660 call_kind = LocationSummary::kNoCall;
2661 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2662 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002663 // Have hardware divide instruction for int, do it with three instructions.
2664 call_kind = LocationSummary::kNoCall;
2665 }
2666
Calin Juravlebacfec32014-11-14 15:54:36 +00002667 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2668
Calin Juravled2ec87d2014-12-08 14:24:46 +00002669 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002670 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002671 if (rem->InputAt(1)->IsConstant()) {
2672 locations->SetInAt(0, Location::RequiresRegister());
2673 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2674 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2675 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2676 if (abs_imm <= 1) {
2677 // No temp register required.
2678 } else {
2679 locations->AddTemp(Location::RequiresRegister());
2680 if (!IsPowerOfTwo(abs_imm)) {
2681 locations->AddTemp(Location::RequiresRegister());
2682 }
2683 }
2684 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002685 locations->SetInAt(0, Location::RequiresRegister());
2686 locations->SetInAt(1, Location::RequiresRegister());
2687 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2688 locations->AddTemp(Location::RequiresRegister());
2689 } else {
2690 InvokeRuntimeCallingConvention calling_convention;
2691 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2692 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2693 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2694 // we only need the latter.
2695 locations->SetOut(Location::RegisterLocation(R1));
2696 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002697 break;
2698 }
2699 case Primitive::kPrimLong: {
2700 InvokeRuntimeCallingConvention calling_convention;
2701 locations->SetInAt(0, Location::RegisterPairLocation(
2702 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2703 locations->SetInAt(1, Location::RegisterPairLocation(
2704 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2705 // The runtime helper puts the output in R2,R3.
2706 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2707 break;
2708 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002709 case Primitive::kPrimFloat: {
2710 InvokeRuntimeCallingConvention calling_convention;
2711 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2712 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2713 locations->SetOut(Location::FpuRegisterLocation(S0));
2714 break;
2715 }
2716
Calin Juravlebacfec32014-11-14 15:54:36 +00002717 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002718 InvokeRuntimeCallingConvention calling_convention;
2719 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2720 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2721 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2722 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2723 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002724 break;
2725 }
2726
2727 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002728 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002729 }
2730}
2731
2732void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2733 LocationSummary* locations = rem->GetLocations();
2734 Location out = locations->Out();
2735 Location first = locations->InAt(0);
2736 Location second = locations->InAt(1);
2737
Calin Juravled2ec87d2014-12-08 14:24:46 +00002738 Primitive::Type type = rem->GetResultType();
2739 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002740 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002741 if (second.IsConstant()) {
2742 GenerateDivRemConstantIntegral(rem);
2743 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002744 Register reg1 = first.AsRegister<Register>();
2745 Register reg2 = second.AsRegister<Register>();
2746 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002747
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002748 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002749 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002750 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002751 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002752 } else {
2753 InvokeRuntimeCallingConvention calling_convention;
2754 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2755 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2756 DCHECK_EQ(R1, out.AsRegister<Register>());
2757
2758 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2759 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002760 break;
2761 }
2762
2763 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002764 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002765 break;
2766 }
2767
Calin Juravled2ec87d2014-12-08 14:24:46 +00002768 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002769 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002770 break;
2771 }
2772
Calin Juravlebacfec32014-11-14 15:54:36 +00002773 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002774 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002775 break;
2776 }
2777
2778 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002779 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002780 }
2781}
2782
Calin Juravled0d48522014-11-04 16:40:20 +00002783void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00002784 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2785 ? LocationSummary::kCallOnSlowPath
2786 : LocationSummary::kNoCall;
2787 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002788 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002789 if (instruction->HasUses()) {
2790 locations->SetOut(Location::SameAsFirstInput());
2791 }
2792}
2793
2794void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2795 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2796 codegen_->AddSlowPath(slow_path);
2797
2798 LocationSummary* locations = instruction->GetLocations();
2799 Location value = locations->InAt(0);
2800
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002801 switch (instruction->GetType()) {
Serguei Katkov8c0676c2015-08-03 13:55:33 +06002802 case Primitive::kPrimByte:
2803 case Primitive::kPrimChar:
2804 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002805 case Primitive::kPrimInt: {
2806 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01002807 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002808 } else {
2809 DCHECK(value.IsConstant()) << value;
2810 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2811 __ b(slow_path->GetEntryLabel());
2812 }
2813 }
2814 break;
2815 }
2816 case Primitive::kPrimLong: {
2817 if (value.IsRegisterPair()) {
2818 __ orrs(IP,
2819 value.AsRegisterPairLow<Register>(),
2820 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2821 __ b(slow_path->GetEntryLabel(), EQ);
2822 } else {
2823 DCHECK(value.IsConstant()) << value;
2824 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2825 __ b(slow_path->GetEntryLabel());
2826 }
2827 }
2828 break;
2829 default:
2830 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2831 }
2832 }
Calin Juravled0d48522014-11-04 16:40:20 +00002833}
2834
Calin Juravle9aec02f2014-11-18 23:06:35 +00002835void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2836 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2837
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002838 LocationSummary* locations =
2839 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002840
2841 switch (op->GetResultType()) {
2842 case Primitive::kPrimInt: {
2843 locations->SetInAt(0, Location::RequiresRegister());
2844 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002845 // Make the output overlap, as it will be used to hold the masked
2846 // second input.
2847 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002848 break;
2849 }
2850 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002851 locations->SetInAt(0, Location::RequiresRegister());
2852 locations->SetInAt(1, Location::RequiresRegister());
2853 locations->AddTemp(Location::RequiresRegister());
2854 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002855 break;
2856 }
2857 default:
2858 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2859 }
2860}
2861
2862void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2863 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2864
2865 LocationSummary* locations = op->GetLocations();
2866 Location out = locations->Out();
2867 Location first = locations->InAt(0);
2868 Location second = locations->InAt(1);
2869
2870 Primitive::Type type = op->GetResultType();
2871 switch (type) {
2872 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002873 Register out_reg = out.AsRegister<Register>();
2874 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002875 // Arm doesn't mask the shift count so we need to do it ourselves.
2876 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002877 Register second_reg = second.AsRegister<Register>();
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002878 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002879 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002880 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002881 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002882 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002883 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002884 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002885 }
2886 } else {
2887 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2888 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2889 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2890 __ Mov(out_reg, first_reg);
2891 } else if (op->IsShl()) {
2892 __ Lsl(out_reg, first_reg, shift_value);
2893 } else if (op->IsShr()) {
2894 __ Asr(out_reg, first_reg, shift_value);
2895 } else {
2896 __ Lsr(out_reg, first_reg, shift_value);
2897 }
2898 }
2899 break;
2900 }
2901 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002902 Register o_h = out.AsRegisterPairHigh<Register>();
2903 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002904
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002905 Register temp = locations->GetTemp(0).AsRegister<Register>();
2906
2907 Register high = first.AsRegisterPairHigh<Register>();
2908 Register low = first.AsRegisterPairLow<Register>();
2909
2910 Register second_reg = second.AsRegister<Register>();
2911
Calin Juravle9aec02f2014-11-18 23:06:35 +00002912 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002913 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002914 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002915 __ Lsl(o_h, high, o_l);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002916 // Shift the low part and `or` what overflew on the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002917 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002918 __ Lsr(temp, low, temp);
2919 __ orr(o_h, o_h, ShifterOperand(temp));
2920 // If the shift is > 32 bits, override the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002921 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002922 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002923 __ Lsl(o_h, low, temp, PL);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002924 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002925 __ Lsl(o_l, low, o_l);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002926 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002927 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002928 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002929 __ Lsr(o_l, low, o_h);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002930 // Shift the high part and `or` what underflew on the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002931 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002932 __ Lsl(temp, high, temp);
2933 __ orr(o_l, o_l, ShifterOperand(temp));
2934 // If the shift is > 32 bits, override the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002935 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002936 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002937 __ Asr(o_l, high, temp, PL);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002938 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002939 __ Asr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002940 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002941 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002942 // same as Shr except we use `Lsr`s and not `Asr`s
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002943 __ Lsr(o_l, low, o_h);
2944 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002945 __ Lsl(temp, high, temp);
2946 __ orr(o_l, o_l, ShifterOperand(temp));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002947 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002948 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002949 __ Lsr(o_l, high, temp, PL);
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002950 __ Lsr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002951 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002952 break;
2953 }
2954 default:
2955 LOG(FATAL) << "Unexpected operation type " << type;
2956 }
2957}
2958
2959void LocationsBuilderARM::VisitShl(HShl* shl) {
2960 HandleShift(shl);
2961}
2962
2963void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2964 HandleShift(shl);
2965}
2966
2967void LocationsBuilderARM::VisitShr(HShr* shr) {
2968 HandleShift(shr);
2969}
2970
2971void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2972 HandleShift(shr);
2973}
2974
2975void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2976 HandleShift(ushr);
2977}
2978
2979void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2980 HandleShift(ushr);
2981}
2982
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002983void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002984 LocationSummary* locations =
2985 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002986 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002987 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002988 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002989 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002990}
2991
2992void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2993 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002994 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01002995 // Note: if heap poisoning is enabled, the entry point takes cares
2996 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01002997 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002998 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002999 instruction->GetDexPc(),
3000 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003001}
3002
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003003void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3004 LocationSummary* locations =
3005 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3006 InvokeRuntimeCallingConvention calling_convention;
3007 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003008 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003009 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003010 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003011}
3012
3013void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3014 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003015 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003016 // Note: if heap poisoning is enabled, the entry point takes cares
3017 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01003018 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003019 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003020 instruction->GetDexPc(),
3021 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003022}
3023
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003024void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003025 LocationSummary* locations =
3026 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003027 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3028 if (location.IsStackSlot()) {
3029 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3030 } else if (location.IsDoubleStackSlot()) {
3031 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003032 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003033 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003034}
3035
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003036void InstructionCodeGeneratorARM::VisitParameterValue(
3037 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003038 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003039}
3040
3041void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3042 LocationSummary* locations =
3043 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3044 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3045}
3046
3047void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3048 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003049}
3050
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003051void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003052 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003053 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003054 locations->SetInAt(0, Location::RequiresRegister());
3055 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003056}
3057
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003058void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3059 LocationSummary* locations = not_->GetLocations();
3060 Location out = locations->Out();
3061 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003062 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003063 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003064 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003065 break;
3066
3067 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003068 __ mvn(out.AsRegisterPairLow<Register>(),
3069 ShifterOperand(in.AsRegisterPairLow<Register>()));
3070 __ mvn(out.AsRegisterPairHigh<Register>(),
3071 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003072 break;
3073
3074 default:
3075 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3076 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003077}
3078
David Brazdil66d126e2015-04-03 16:02:44 +01003079void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3080 LocationSummary* locations =
3081 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3082 locations->SetInAt(0, Location::RequiresRegister());
3083 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3084}
3085
3086void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003087 LocationSummary* locations = bool_not->GetLocations();
3088 Location out = locations->Out();
3089 Location in = locations->InAt(0);
3090 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3091}
3092
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003093void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003094 LocationSummary* locations =
3095 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003096 switch (compare->InputAt(0)->GetType()) {
3097 case Primitive::kPrimLong: {
3098 locations->SetInAt(0, Location::RequiresRegister());
3099 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003100 // Output overlaps because it is written before doing the low comparison.
3101 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003102 break;
3103 }
3104 case Primitive::kPrimFloat:
3105 case Primitive::kPrimDouble: {
3106 locations->SetInAt(0, Location::RequiresFpuRegister());
3107 locations->SetInAt(1, Location::RequiresFpuRegister());
3108 locations->SetOut(Location::RequiresRegister());
3109 break;
3110 }
3111 default:
3112 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3113 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003114}
3115
3116void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003117 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003118 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003119 Location left = locations->InAt(0);
3120 Location right = locations->InAt(1);
3121
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003122 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003123 Primitive::Type type = compare->InputAt(0)->GetType();
3124 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003125 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003126 __ cmp(left.AsRegisterPairHigh<Register>(),
3127 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003128 __ b(&less, LT);
3129 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003130 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003131 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003132 __ cmp(left.AsRegisterPairLow<Register>(),
3133 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00003134 break;
3135 }
3136 case Primitive::kPrimFloat:
3137 case Primitive::kPrimDouble: {
3138 __ LoadImmediate(out, 0);
3139 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003140 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00003141 } else {
3142 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
3143 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
3144 }
3145 __ vmstat(); // transfer FP status register to ARM APSR.
3146 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003147 break;
3148 }
3149 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003150 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003151 }
Calin Juravleddb7df22014-11-25 20:56:51 +00003152 __ b(&done, EQ);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003153 __ b(&less, LO); // LO is for both: unsigned compare for longs and 'less than' for floats.
Calin Juravleddb7df22014-11-25 20:56:51 +00003154
3155 __ Bind(&greater);
3156 __ LoadImmediate(out, 1);
3157 __ b(&done);
3158
3159 __ Bind(&less);
3160 __ LoadImmediate(out, -1);
3161
3162 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003163}
3164
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003165void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003166 LocationSummary* locations =
3167 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003168 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
3169 locations->SetInAt(i, Location::Any());
3170 }
3171 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003172}
3173
3174void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003175 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003176 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003177}
3178
Calin Juravle52c48962014-12-16 17:02:57 +00003179void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3180 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07003181 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00003182 switch (kind) {
3183 case MemBarrierKind::kAnyStore:
3184 case MemBarrierKind::kLoadAny:
3185 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003186 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003187 break;
3188 }
3189 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003190 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003191 break;
3192 }
3193 default:
3194 LOG(FATAL) << "Unexpected memory barrier " << kind;
3195 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003196 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003197}
3198
3199void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3200 uint32_t offset,
3201 Register out_lo,
3202 Register out_hi) {
3203 if (offset != 0) {
3204 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003205 __ add(IP, addr, ShifterOperand(out_lo));
3206 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003207 }
3208 __ ldrexd(out_lo, out_hi, addr);
3209}
3210
3211void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3212 uint32_t offset,
3213 Register value_lo,
3214 Register value_hi,
3215 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003216 Register temp2,
3217 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003218 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003219 if (offset != 0) {
3220 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003221 __ add(IP, addr, ShifterOperand(temp1));
3222 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003223 }
3224 __ Bind(&fail);
3225 // We need a load followed by store. (The address used in a STREX instruction must
3226 // be the same as the address in the most recently executed LDREX instruction.)
3227 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003228 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003229 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003230 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003231}
3232
3233void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3234 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3235
Nicolas Geoffray39468442014-09-02 15:17:15 +01003236 LocationSummary* locations =
3237 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003238 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003239
Calin Juravle52c48962014-12-16 17:02:57 +00003240 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003241 if (Primitive::IsFloatingPointType(field_type)) {
3242 locations->SetInAt(1, Location::RequiresFpuRegister());
3243 } else {
3244 locations->SetInAt(1, Location::RequiresRegister());
3245 }
3246
Calin Juravle52c48962014-12-16 17:02:57 +00003247 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003248 bool generate_volatile = field_info.IsVolatile()
3249 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003250 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003251 bool needs_write_barrier =
3252 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003253 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003254 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003255 if (needs_write_barrier) {
3256 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003257 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003258 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003259 // Arm encoding have some additional constraints for ldrexd/strexd:
3260 // - registers need to be consecutive
3261 // - the first register should be even but not R14.
3262 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3263 // enable Arm encoding.
3264 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3265
3266 locations->AddTemp(Location::RequiresRegister());
3267 locations->AddTemp(Location::RequiresRegister());
3268 if (field_type == Primitive::kPrimDouble) {
3269 // For doubles we need two more registers to copy the value.
3270 locations->AddTemp(Location::RegisterLocation(R2));
3271 locations->AddTemp(Location::RegisterLocation(R3));
3272 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003273 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003274}
3275
Calin Juravle52c48962014-12-16 17:02:57 +00003276void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003277 const FieldInfo& field_info,
3278 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003279 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3280
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003281 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003282 Register base = locations->InAt(0).AsRegister<Register>();
3283 Location value = locations->InAt(1);
3284
3285 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003286 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003287 Primitive::Type field_type = field_info.GetFieldType();
3288 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003289 bool needs_write_barrier =
3290 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003291
3292 if (is_volatile) {
3293 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3294 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003295
3296 switch (field_type) {
3297 case Primitive::kPrimBoolean:
3298 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003299 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003300 break;
3301 }
3302
3303 case Primitive::kPrimShort:
3304 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003305 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003306 break;
3307 }
3308
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003309 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003310 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003311 if (kPoisonHeapReferences && needs_write_barrier) {
3312 // Note that in the case where `value` is a null reference,
3313 // we do not enter this block, as a null reference does not
3314 // need poisoning.
3315 DCHECK_EQ(field_type, Primitive::kPrimNot);
3316 Register temp = locations->GetTemp(0).AsRegister<Register>();
3317 __ Mov(temp, value.AsRegister<Register>());
3318 __ PoisonHeapReference(temp);
3319 __ StoreToOffset(kStoreWord, temp, base, offset);
3320 } else {
3321 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3322 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003323 break;
3324 }
3325
3326 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003327 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003328 GenerateWideAtomicStore(base, offset,
3329 value.AsRegisterPairLow<Register>(),
3330 value.AsRegisterPairHigh<Register>(),
3331 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003332 locations->GetTemp(1).AsRegister<Register>(),
3333 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003334 } else {
3335 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003336 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003337 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003338 break;
3339 }
3340
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003341 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003342 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003343 break;
3344 }
3345
3346 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003347 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003348 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003349 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3350 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3351
3352 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3353
3354 GenerateWideAtomicStore(base, offset,
3355 value_reg_lo,
3356 value_reg_hi,
3357 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003358 locations->GetTemp(3).AsRegister<Register>(),
3359 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003360 } else {
3361 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003362 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003363 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003364 break;
3365 }
3366
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003367 case Primitive::kPrimVoid:
3368 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003369 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003370 }
Calin Juravle52c48962014-12-16 17:02:57 +00003371
Calin Juravle77520bc2015-01-12 18:45:46 +00003372 // Longs and doubles are handled in the switch.
3373 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3374 codegen_->MaybeRecordImplicitNullCheck(instruction);
3375 }
3376
3377 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3378 Register temp = locations->GetTemp(0).AsRegister<Register>();
3379 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003380 codegen_->MarkGCCard(
3381 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003382 }
3383
Calin Juravle52c48962014-12-16 17:02:57 +00003384 if (is_volatile) {
3385 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3386 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003387}
3388
Calin Juravle52c48962014-12-16 17:02:57 +00003389void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3390 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003391 LocationSummary* locations =
3392 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003393 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003394
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003395 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003396 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003397 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003398 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003399
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003400 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3401 locations->SetOut(Location::RequiresFpuRegister());
3402 } else {
3403 locations->SetOut(Location::RequiresRegister(),
3404 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3405 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003406 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003407 // Arm encoding have some additional constraints for ldrexd/strexd:
3408 // - registers need to be consecutive
3409 // - the first register should be even but not R14.
3410 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3411 // enable Arm encoding.
3412 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3413 locations->AddTemp(Location::RequiresRegister());
3414 locations->AddTemp(Location::RequiresRegister());
3415 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003416}
3417
Calin Juravle52c48962014-12-16 17:02:57 +00003418void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3419 const FieldInfo& field_info) {
3420 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003421
Calin Juravle52c48962014-12-16 17:02:57 +00003422 LocationSummary* locations = instruction->GetLocations();
3423 Register base = locations->InAt(0).AsRegister<Register>();
3424 Location out = locations->Out();
3425 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003426 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003427 Primitive::Type field_type = field_info.GetFieldType();
3428 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3429
3430 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003431 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003432 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003433 break;
3434 }
3435
3436 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003437 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003438 break;
3439 }
3440
3441 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003442 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003443 break;
3444 }
3445
3446 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003447 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003448 break;
3449 }
3450
3451 case Primitive::kPrimInt:
3452 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003453 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003454 break;
3455 }
3456
3457 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003458 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003459 GenerateWideAtomicLoad(base, offset,
3460 out.AsRegisterPairLow<Register>(),
3461 out.AsRegisterPairHigh<Register>());
3462 } else {
3463 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3464 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003465 break;
3466 }
3467
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003468 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003469 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003470 break;
3471 }
3472
3473 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003474 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003475 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003476 Register lo = locations->GetTemp(0).AsRegister<Register>();
3477 Register hi = locations->GetTemp(1).AsRegister<Register>();
3478 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003479 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003480 __ vmovdrr(out_reg, lo, hi);
3481 } else {
3482 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003483 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003484 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003485 break;
3486 }
3487
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003488 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003489 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003490 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003491 }
Calin Juravle52c48962014-12-16 17:02:57 +00003492
Calin Juravle77520bc2015-01-12 18:45:46 +00003493 // Doubles are handled in the switch.
3494 if (field_type != Primitive::kPrimDouble) {
3495 codegen_->MaybeRecordImplicitNullCheck(instruction);
3496 }
3497
Calin Juravle52c48962014-12-16 17:02:57 +00003498 if (is_volatile) {
3499 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3500 }
Roland Levillain4d027112015-07-01 15:41:14 +01003501
3502 if (field_type == Primitive::kPrimNot) {
3503 __ MaybeUnpoisonHeapReference(out.AsRegister<Register>());
3504 }
Calin Juravle52c48962014-12-16 17:02:57 +00003505}
3506
3507void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3508 HandleFieldSet(instruction, instruction->GetFieldInfo());
3509}
3510
3511void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003512 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003513}
3514
3515void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3516 HandleFieldGet(instruction, instruction->GetFieldInfo());
3517}
3518
3519void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3520 HandleFieldGet(instruction, instruction->GetFieldInfo());
3521}
3522
3523void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3524 HandleFieldGet(instruction, instruction->GetFieldInfo());
3525}
3526
3527void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3528 HandleFieldGet(instruction, instruction->GetFieldInfo());
3529}
3530
3531void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3532 HandleFieldSet(instruction, instruction->GetFieldInfo());
3533}
3534
3535void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003536 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003537}
3538
3539void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003540 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3541 ? LocationSummary::kCallOnSlowPath
3542 : LocationSummary::kNoCall;
3543 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravle77520bc2015-01-12 18:45:46 +00003544 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003545 if (instruction->HasUses()) {
3546 locations->SetOut(Location::SameAsFirstInput());
3547 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003548}
3549
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003550void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003551 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3552 return;
3553 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003554 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003555
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003556 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3557 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3558}
3559
3560void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003561 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003562 codegen_->AddSlowPath(slow_path);
3563
3564 LocationSummary* locations = instruction->GetLocations();
3565 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003566
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003567 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003568}
3569
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003570void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003571 if (codegen_->IsImplicitNullCheckAllowed(instruction)) {
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003572 GenerateImplicitNullCheck(instruction);
3573 } else {
3574 GenerateExplicitNullCheck(instruction);
3575 }
3576}
3577
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003578void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003579 LocationSummary* locations =
3580 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003581 locations->SetInAt(0, Location::RequiresRegister());
3582 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003583 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3584 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3585 } else {
3586 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3587 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003588}
3589
3590void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3591 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003592 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003593 Location index = locations->InAt(1);
Roland Levillain4d027112015-07-01 15:41:14 +01003594 Primitive::Type type = instruction->GetType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003595
Roland Levillain4d027112015-07-01 15:41:14 +01003596 switch (type) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003597 case Primitive::kPrimBoolean: {
3598 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003599 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003600 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003601 size_t offset =
3602 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003603 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3604 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003605 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003606 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3607 }
3608 break;
3609 }
3610
3611 case Primitive::kPrimByte: {
3612 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003613 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003614 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003615 size_t offset =
3616 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003617 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3618 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003619 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003620 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3621 }
3622 break;
3623 }
3624
3625 case Primitive::kPrimShort: {
3626 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003627 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003628 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003629 size_t offset =
3630 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003631 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3632 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003633 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003634 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3635 }
3636 break;
3637 }
3638
3639 case Primitive::kPrimChar: {
3640 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003641 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003642 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003643 size_t offset =
3644 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003645 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3646 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003647 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003648 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3649 }
3650 break;
3651 }
3652
3653 case Primitive::kPrimInt:
3654 case Primitive::kPrimNot: {
Roland Levillain33d69032015-06-18 18:20:59 +01003655 static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
3656 "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003657 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003658 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003659 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003660 size_t offset =
3661 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003662 __ LoadFromOffset(kLoadWord, out, obj, offset);
3663 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003664 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003665 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3666 }
3667 break;
3668 }
3669
3670 case Primitive::kPrimLong: {
3671 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003672 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003673 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003674 size_t offset =
3675 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003676 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003677 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003678 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003679 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003680 }
3681 break;
3682 }
3683
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003684 case Primitive::kPrimFloat: {
3685 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3686 Location out = locations->Out();
3687 DCHECK(out.IsFpuRegister());
3688 if (index.IsConstant()) {
3689 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3690 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3691 } else {
3692 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3693 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3694 }
3695 break;
3696 }
3697
3698 case Primitive::kPrimDouble: {
3699 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3700 Location out = locations->Out();
3701 DCHECK(out.IsFpuRegisterPair());
3702 if (index.IsConstant()) {
3703 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3704 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3705 } else {
3706 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3707 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3708 }
3709 break;
3710 }
3711
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003712 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01003713 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003714 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003715 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003716 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01003717
3718 if (type == Primitive::kPrimNot) {
3719 Register out = locations->Out().AsRegister<Register>();
3720 __ MaybeUnpoisonHeapReference(out);
3721 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003722}
3723
3724void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003725 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003726
3727 bool needs_write_barrier =
3728 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3729 bool needs_runtime_call = instruction->NeedsTypeCheck();
3730
Nicolas Geoffray39468442014-09-02 15:17:15 +01003731 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003732 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3733 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003734 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003735 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3736 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3737 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003738 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003739 locations->SetInAt(0, Location::RequiresRegister());
3740 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003741 if (Primitive::IsFloatingPointType(value_type)) {
3742 locations->SetInAt(2, Location::RequiresFpuRegister());
3743 } else {
3744 locations->SetInAt(2, Location::RequiresRegister());
3745 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003746
3747 if (needs_write_barrier) {
3748 // Temporary registers for the write barrier.
Roland Levillain4d027112015-07-01 15:41:14 +01003749 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003750 locations->AddTemp(Location::RequiresRegister());
3751 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003752 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003753}
3754
3755void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3756 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003757 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003758 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003759 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003760 bool needs_runtime_call = locations->WillCall();
3761 bool needs_write_barrier =
3762 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003763
3764 switch (value_type) {
3765 case Primitive::kPrimBoolean:
3766 case Primitive::kPrimByte: {
3767 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003768 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003769 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003770 size_t offset =
3771 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003772 __ StoreToOffset(kStoreByte, value, obj, offset);
3773 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003774 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003775 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3776 }
3777 break;
3778 }
3779
3780 case Primitive::kPrimShort:
3781 case Primitive::kPrimChar: {
3782 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003783 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003784 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003785 size_t offset =
3786 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003787 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3788 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003789 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003790 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3791 }
3792 break;
3793 }
3794
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003795 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003796 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003797 if (!needs_runtime_call) {
3798 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003799 Register value = locations->InAt(2).AsRegister<Register>();
Roland Levillain4d027112015-07-01 15:41:14 +01003800 Register source = value;
3801 if (kPoisonHeapReferences && needs_write_barrier) {
3802 // Note that in the case where `value` is a null reference,
3803 // we do not enter this block, as a null reference does not
3804 // need poisoning.
3805 DCHECK_EQ(value_type, Primitive::kPrimNot);
3806 Register temp = locations->GetTemp(0).AsRegister<Register>();
3807 __ Mov(temp, value);
3808 __ PoisonHeapReference(temp);
3809 source = temp;
3810 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003811 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003812 size_t offset =
3813 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillain4d027112015-07-01 15:41:14 +01003814 __ StoreToOffset(kStoreWord, source, obj, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003815 } else {
3816 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003817 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillain4d027112015-07-01 15:41:14 +01003818 __ StoreToOffset(kStoreWord, source, IP, data_offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003819 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003820 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003821 if (needs_write_barrier) {
3822 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003823 Register temp = locations->GetTemp(0).AsRegister<Register>();
3824 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003825 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003826 }
3827 } else {
3828 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain4d027112015-07-01 15:41:14 +01003829 // Note: if heap poisoning is enabled, pAputObject takes cares
3830 // of poisoning the reference.
Roland Levillain199f3362014-11-27 17:15:16 +00003831 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3832 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003833 instruction->GetDexPc(),
3834 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003835 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003836 break;
3837 }
3838
3839 case Primitive::kPrimLong: {
3840 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003841 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003842 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003843 size_t offset =
3844 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003845 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003846 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003847 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003848 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003849 }
3850 break;
3851 }
3852
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003853 case Primitive::kPrimFloat: {
3854 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3855 Location value = locations->InAt(2);
3856 DCHECK(value.IsFpuRegister());
3857 if (index.IsConstant()) {
3858 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3859 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3860 } else {
3861 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3862 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3863 }
3864 break;
3865 }
3866
3867 case Primitive::kPrimDouble: {
3868 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3869 Location value = locations->InAt(2);
3870 DCHECK(value.IsFpuRegisterPair());
3871 if (index.IsConstant()) {
3872 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3873 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3874 } else {
3875 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3876 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3877 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003878
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003879 break;
3880 }
3881
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003882 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003883 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003884 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003885 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003886
3887 // Ints and objects are handled in the switch.
3888 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3889 codegen_->MaybeRecordImplicitNullCheck(instruction);
3890 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003891}
3892
3893void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003894 LocationSummary* locations =
3895 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003896 locations->SetInAt(0, Location::RequiresRegister());
3897 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003898}
3899
3900void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3901 LocationSummary* locations = instruction->GetLocations();
3902 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003903 Register obj = locations->InAt(0).AsRegister<Register>();
3904 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003905 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003906 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003907}
3908
3909void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003910 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3911 ? LocationSummary::kCallOnSlowPath
3912 : LocationSummary::kNoCall;
3913 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003914 locations->SetInAt(0, Location::RequiresRegister());
3915 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003916 if (instruction->HasUses()) {
3917 locations->SetOut(Location::SameAsFirstInput());
3918 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003919}
3920
3921void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3922 LocationSummary* locations = instruction->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01003923 SlowPathCodeARM* slow_path =
3924 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003925 codegen_->AddSlowPath(slow_path);
3926
Roland Levillain271ab9c2014-11-27 15:23:57 +00003927 Register index = locations->InAt(0).AsRegister<Register>();
3928 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003929
3930 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01003931 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003932}
3933
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003934void CodeGeneratorARM::MarkGCCard(Register temp,
3935 Register card,
3936 Register object,
3937 Register value,
3938 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003939 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003940 if (can_be_null) {
3941 __ CompareAndBranchIfZero(value, &is_null);
3942 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003943 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3944 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3945 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003946 if (can_be_null) {
3947 __ Bind(&is_null);
3948 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003949}
3950
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003951void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3952 temp->SetLocations(nullptr);
3953}
3954
3955void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3956 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003957 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003958}
3959
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003960void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003961 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003962 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003963}
3964
3965void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003966 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3967}
3968
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003969void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3970 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3971}
3972
3973void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003974 HBasicBlock* block = instruction->GetBlock();
3975 if (block->GetLoopInformation() != nullptr) {
3976 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3977 // The back edge will generate the suspend check.
3978 return;
3979 }
3980 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3981 // The goto will generate the suspend check.
3982 return;
3983 }
3984 GenerateSuspendCheck(instruction, nullptr);
3985}
3986
3987void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3988 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003989 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003990 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3991 if (slow_path == nullptr) {
3992 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3993 instruction->SetSlowPath(slow_path);
3994 codegen_->AddSlowPath(slow_path);
3995 if (successor != nullptr) {
3996 DCHECK(successor->IsLoopHeader());
3997 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3998 }
3999 } else {
4000 DCHECK_EQ(slow_path->GetSuccessor(), successor);
4001 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004002
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00004003 __ LoadFromOffset(
4004 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004005 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004006 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004007 __ Bind(slow_path->GetReturnLabel());
4008 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004009 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004010 __ b(slow_path->GetEntryLabel());
4011 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004012}
4013
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004014ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
4015 return codegen_->GetAssembler();
4016}
4017
4018void ParallelMoveResolverARM::EmitMove(size_t index) {
4019 MoveOperands* move = moves_.Get(index);
4020 Location source = move->GetSource();
4021 Location destination = move->GetDestination();
4022
4023 if (source.IsRegister()) {
4024 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004025 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004026 } else {
4027 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00004028 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004029 SP, destination.GetStackIndex());
4030 }
4031 } else if (source.IsStackSlot()) {
4032 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004033 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004034 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004035 } else if (destination.IsFpuRegister()) {
4036 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004037 } else {
4038 DCHECK(destination.IsStackSlot());
4039 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
4040 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4041 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004042 } else if (source.IsFpuRegister()) {
4043 if (destination.IsFpuRegister()) {
4044 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004045 } else {
4046 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004047 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
4048 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004049 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004050 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004051 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
4052 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004053 } else if (destination.IsRegisterPair()) {
4054 DCHECK(ExpectedPairLayout(destination));
4055 __ LoadFromOffset(
4056 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
4057 } else {
4058 DCHECK(destination.IsFpuRegisterPair()) << destination;
4059 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4060 SP,
4061 source.GetStackIndex());
4062 }
4063 } else if (source.IsRegisterPair()) {
4064 if (destination.IsRegisterPair()) {
4065 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
4066 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
4067 } else {
4068 DCHECK(destination.IsDoubleStackSlot()) << destination;
4069 DCHECK(ExpectedPairLayout(source));
4070 __ StoreToOffset(
4071 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
4072 }
4073 } else if (source.IsFpuRegisterPair()) {
4074 if (destination.IsFpuRegisterPair()) {
4075 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4076 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
4077 } else {
4078 DCHECK(destination.IsDoubleStackSlot()) << destination;
4079 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
4080 SP,
4081 destination.GetStackIndex());
4082 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004083 } else {
4084 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00004085 HConstant* constant = source.GetConstant();
4086 if (constant->IsIntConstant() || constant->IsNullConstant()) {
4087 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004088 if (destination.IsRegister()) {
4089 __ LoadImmediate(destination.AsRegister<Register>(), value);
4090 } else {
4091 DCHECK(destination.IsStackSlot());
4092 __ LoadImmediate(IP, value);
4093 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4094 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004095 } else if (constant->IsLongConstant()) {
4096 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004097 if (destination.IsRegisterPair()) {
4098 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
4099 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004100 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004101 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004102 __ LoadImmediate(IP, Low32Bits(value));
4103 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4104 __ LoadImmediate(IP, High32Bits(value));
4105 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4106 }
4107 } else if (constant->IsDoubleConstant()) {
4108 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004109 if (destination.IsFpuRegisterPair()) {
4110 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004111 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004112 DCHECK(destination.IsDoubleStackSlot()) << destination;
4113 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004114 __ LoadImmediate(IP, Low32Bits(int_value));
4115 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4116 __ LoadImmediate(IP, High32Bits(int_value));
4117 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4118 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004119 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004120 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004121 float value = constant->AsFloatConstant()->GetValue();
4122 if (destination.IsFpuRegister()) {
4123 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
4124 } else {
4125 DCHECK(destination.IsStackSlot());
4126 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
4127 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4128 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004129 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004130 }
4131}
4132
4133void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
4134 __ Mov(IP, reg);
4135 __ LoadFromOffset(kLoadWord, reg, SP, mem);
4136 __ StoreToOffset(kStoreWord, IP, SP, mem);
4137}
4138
4139void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
4140 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
4141 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
4142 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
4143 SP, mem1 + stack_offset);
4144 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
4145 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
4146 SP, mem2 + stack_offset);
4147 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
4148}
4149
4150void ParallelMoveResolverARM::EmitSwap(size_t index) {
4151 MoveOperands* move = moves_.Get(index);
4152 Location source = move->GetSource();
4153 Location destination = move->GetDestination();
4154
4155 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004156 DCHECK_NE(source.AsRegister<Register>(), IP);
4157 DCHECK_NE(destination.AsRegister<Register>(), IP);
4158 __ Mov(IP, source.AsRegister<Register>());
4159 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
4160 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004161 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004162 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004163 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004164 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004165 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
4166 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004167 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004168 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004169 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004170 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004171 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004172 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004173 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004174 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004175 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
4176 destination.AsRegisterPairHigh<Register>(),
4177 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004178 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004179 Register low_reg = source.IsRegisterPair()
4180 ? source.AsRegisterPairLow<Register>()
4181 : destination.AsRegisterPairLow<Register>();
4182 int mem = source.IsRegisterPair()
4183 ? destination.GetStackIndex()
4184 : source.GetStackIndex();
4185 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004186 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004187 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004188 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004189 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004190 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
4191 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004192 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004193 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004194 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004195 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
4196 DRegister reg = source.IsFpuRegisterPair()
4197 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
4198 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
4199 int mem = source.IsFpuRegisterPair()
4200 ? destination.GetStackIndex()
4201 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004202 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004203 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004204 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004205 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
4206 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
4207 : destination.AsFpuRegister<SRegister>();
4208 int mem = source.IsFpuRegister()
4209 ? destination.GetStackIndex()
4210 : source.GetStackIndex();
4211
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004212 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004213 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004214 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004215 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004216 Exchange(source.GetStackIndex(), destination.GetStackIndex());
4217 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004218 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004219 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004220 }
4221}
4222
4223void ParallelMoveResolverARM::SpillScratch(int reg) {
4224 __ Push(static_cast<Register>(reg));
4225}
4226
4227void ParallelMoveResolverARM::RestoreScratch(int reg) {
4228 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004229}
4230
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004231void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004232 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
4233 ? LocationSummary::kCallOnSlowPath
4234 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004235 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004236 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004237 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004238 locations->SetOut(Location::RequiresRegister());
4239}
4240
4241void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004242 LocationSummary* locations = cls->GetLocations();
4243 Register out = locations->Out().AsRegister<Register>();
4244 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004245 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004246 DCHECK(!cls->CanCallRuntime());
4247 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004248 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004249 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004250 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004251 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004252 __ LoadFromOffset(kLoadWord,
4253 out,
4254 current_method,
Vladimir Marko05792b92015-08-03 11:56:49 +01004255 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004256 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01004257 // TODO: We will need a read barrier here.
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004258
4259 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4260 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4261 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004262 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004263 if (cls->MustGenerateClinitCheck()) {
4264 GenerateClassInitializationCheck(slow_path, out);
4265 } else {
4266 __ Bind(slow_path->GetExitLabel());
4267 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004268 }
4269}
4270
4271void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
4272 LocationSummary* locations =
4273 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
4274 locations->SetInAt(0, Location::RequiresRegister());
4275 if (check->HasUses()) {
4276 locations->SetOut(Location::SameAsFirstInput());
4277 }
4278}
4279
4280void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004281 // We assume the class is not null.
4282 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4283 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004284 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004285 GenerateClassInitializationCheck(slow_path,
4286 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004287}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004288
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004289void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
4290 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004291 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4292 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4293 __ b(slow_path->GetEntryLabel(), LT);
4294 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4295 // properly. Therefore, we do a memory fence.
4296 __ dmb(ISH);
4297 __ Bind(slow_path->GetExitLabel());
4298}
4299
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004300void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4301 LocationSummary* locations =
4302 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004303 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004304 locations->SetOut(Location::RequiresRegister());
4305}
4306
4307void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4308 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4309 codegen_->AddSlowPath(slow_path);
4310
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004311 LocationSummary* locations = load->GetLocations();
4312 Register out = locations->Out().AsRegister<Register>();
4313 Register current_method = locations->InAt(0).AsRegister<Register>();
4314 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004315 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004316 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004317 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01004318 // TODO: We will need a read barrier here.
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004319 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004320 __ Bind(slow_path->GetExitLabel());
4321}
4322
David Brazdilcb1c0552015-08-04 16:22:25 +01004323static int32_t GetExceptionTlsOffset() {
4324 return Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4325}
4326
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004327void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4328 LocationSummary* locations =
4329 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4330 locations->SetOut(Location::RequiresRegister());
4331}
4332
4333void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004334 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01004335 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4336}
4337
4338void LocationsBuilderARM::VisitClearException(HClearException* clear) {
4339 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4340}
4341
4342void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004343 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01004344 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004345}
4346
4347void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4348 LocationSummary* locations =
4349 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4350 InvokeRuntimeCallingConvention calling_convention;
4351 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4352}
4353
4354void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4355 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004356 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004357}
4358
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004359void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004360 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4361 ? LocationSummary::kNoCall
4362 : LocationSummary::kCallOnSlowPath;
4363 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4364 locations->SetInAt(0, Location::RequiresRegister());
4365 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004366 // The out register is used as a temporary, so it overlaps with the inputs.
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004367 // Note that TypeCheckSlowPathARM uses this register too.
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004368 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004369}
4370
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004371void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004372 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004373 Register obj = locations->InAt(0).AsRegister<Register>();
4374 Register cls = locations->InAt(1).AsRegister<Register>();
4375 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004376 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004377 Label done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004378 SlowPathCodeARM* slow_path = nullptr;
4379
4380 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004381 // avoid null check if we know obj is not null.
4382 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004383 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004384 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004385 // Compare the class of `obj` with `cls`.
4386 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
Roland Levillain4d027112015-07-01 15:41:14 +01004387 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004388 __ cmp(out, ShifterOperand(cls));
4389 if (instruction->IsClassFinal()) {
4390 // Classes must be equal for the instanceof to succeed.
4391 __ b(&zero, NE);
4392 __ LoadImmediate(out, 1);
4393 __ b(&done);
4394 } else {
4395 // If the classes are not equal, we go into a slow path.
4396 DCHECK(locations->OnlyCallsOnSlowPath());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004397 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004398 codegen_->AddSlowPath(slow_path);
4399 __ b(slow_path->GetEntryLabel(), NE);
4400 __ LoadImmediate(out, 1);
4401 __ b(&done);
4402 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004403
4404 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4405 __ Bind(&zero);
4406 __ LoadImmediate(out, 0);
4407 }
4408
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004409 if (slow_path != nullptr) {
4410 __ Bind(slow_path->GetExitLabel());
4411 }
4412 __ Bind(&done);
4413}
4414
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004415void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4416 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4417 instruction, LocationSummary::kCallOnSlowPath);
4418 locations->SetInAt(0, Location::RequiresRegister());
4419 locations->SetInAt(1, Location::RequiresRegister());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004420 // Note that TypeCheckSlowPathARM uses this register too.
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004421 locations->AddTemp(Location::RequiresRegister());
4422}
4423
4424void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4425 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004426 Register obj = locations->InAt(0).AsRegister<Register>();
4427 Register cls = locations->InAt(1).AsRegister<Register>();
4428 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004429 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4430
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004431 SlowPathCodeARM* slow_path =
4432 new (GetGraph()->GetArena()) TypeCheckSlowPathARM(instruction);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004433 codegen_->AddSlowPath(slow_path);
4434
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004435 // avoid null check if we know obj is not null.
4436 if (instruction->MustDoNullCheck()) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004437 __ CompareAndBranchIfZero(obj, slow_path->GetExitLabel());
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004438 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004439 // Compare the class of `obj` with `cls`.
4440 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
Roland Levillain4d027112015-07-01 15:41:14 +01004441 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004442 __ cmp(temp, ShifterOperand(cls));
Roland Levillain4d027112015-07-01 15:41:14 +01004443 // The checkcast succeeds if the classes are equal (fast path).
4444 // Otherwise, we need to go into the slow path to check the types.
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004445 __ b(slow_path->GetEntryLabel(), NE);
4446 __ Bind(slow_path->GetExitLabel());
4447}
4448
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004449void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4450 LocationSummary* locations =
4451 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4452 InvokeRuntimeCallingConvention calling_convention;
4453 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4454}
4455
4456void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4457 codegen_->InvokeRuntime(instruction->IsEnter()
4458 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4459 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004460 instruction->GetDexPc(),
4461 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004462}
4463
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004464void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4465void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4466void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4467
4468void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4469 LocationSummary* locations =
4470 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4471 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4472 || instruction->GetResultType() == Primitive::kPrimLong);
4473 locations->SetInAt(0, Location::RequiresRegister());
4474 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004475 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004476}
4477
4478void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4479 HandleBitwiseOperation(instruction);
4480}
4481
4482void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4483 HandleBitwiseOperation(instruction);
4484}
4485
4486void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4487 HandleBitwiseOperation(instruction);
4488}
4489
4490void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4491 LocationSummary* locations = instruction->GetLocations();
4492
4493 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004494 Register first = locations->InAt(0).AsRegister<Register>();
4495 Register second = locations->InAt(1).AsRegister<Register>();
4496 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004497 if (instruction->IsAnd()) {
4498 __ and_(out, first, ShifterOperand(second));
4499 } else if (instruction->IsOr()) {
4500 __ orr(out, first, ShifterOperand(second));
4501 } else {
4502 DCHECK(instruction->IsXor());
4503 __ eor(out, first, ShifterOperand(second));
4504 }
4505 } else {
4506 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4507 Location first = locations->InAt(0);
4508 Location second = locations->InAt(1);
4509 Location out = locations->Out();
4510 if (instruction->IsAnd()) {
4511 __ and_(out.AsRegisterPairLow<Register>(),
4512 first.AsRegisterPairLow<Register>(),
4513 ShifterOperand(second.AsRegisterPairLow<Register>()));
4514 __ and_(out.AsRegisterPairHigh<Register>(),
4515 first.AsRegisterPairHigh<Register>(),
4516 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4517 } else if (instruction->IsOr()) {
4518 __ orr(out.AsRegisterPairLow<Register>(),
4519 first.AsRegisterPairLow<Register>(),
4520 ShifterOperand(second.AsRegisterPairLow<Register>()));
4521 __ orr(out.AsRegisterPairHigh<Register>(),
4522 first.AsRegisterPairHigh<Register>(),
4523 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4524 } else {
4525 DCHECK(instruction->IsXor());
4526 __ eor(out.AsRegisterPairLow<Register>(),
4527 first.AsRegisterPairLow<Register>(),
4528 ShifterOperand(second.AsRegisterPairLow<Register>()));
4529 __ eor(out.AsRegisterPairHigh<Register>(),
4530 first.AsRegisterPairHigh<Register>(),
4531 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4532 }
4533 }
4534}
4535
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004536void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00004537 // For better instruction scheduling we load the direct code pointer before the method pointer.
4538 bool direct_code_loaded = false;
4539 switch (invoke->GetCodePtrLocation()) {
4540 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
4541 if (IsSameDexFile(*invoke->GetTargetMethod().dex_file, GetGraph()->GetDexFile())) {
4542 break;
4543 }
4544 // Calls across dex files are more likely to exceed the available BL range,
4545 // so use absolute patch by falling through to kDirectCodeFixup.
4546 FALLTHROUGH_INTENDED;
4547 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4548 // LR = code address from literal pool with link-time patch.
4549 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
4550 direct_code_loaded = true;
4551 break;
4552 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4553 // LR = invoke->GetDirectCodePtr();
4554 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
4555 direct_code_loaded = true;
4556 break;
4557 default:
4558 break;
4559 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004560
Vladimir Marko58155012015-08-19 12:49:41 +00004561 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
4562 switch (invoke->GetMethodLoadKind()) {
4563 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
4564 // temp = thread->string_init_entrypoint
4565 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
4566 break;
4567 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
4568 callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4569 break;
4570 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
4571 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
4572 break;
4573 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
4574 __ LoadLiteral(temp.AsRegister<Register>(),
4575 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
4576 break;
4577 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
4578 // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod.
4579 FALLTHROUGH_INTENDED;
4580 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
4581 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4582 Register method_reg;
4583 Register reg = temp.AsRegister<Register>();
4584 if (current_method.IsRegister()) {
4585 method_reg = current_method.AsRegister<Register>();
4586 } else {
4587 DCHECK(invoke->GetLocations()->Intrinsified());
4588 DCHECK(!current_method.IsValid());
4589 method_reg = reg;
4590 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4591 }
4592 // temp = current_method->dex_cache_resolved_methods_;
4593 __ LoadFromOffset(
Vladimir Marko05792b92015-08-03 11:56:49 +01004594 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset(
4595 kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00004596 // temp = temp[index_in_cache]
4597 uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index;
4598 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
4599 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004600 }
Vladimir Marko58155012015-08-19 12:49:41 +00004601 }
4602
4603 switch (invoke->GetCodePtrLocation()) {
4604 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
4605 __ bl(GetFrameEntryLabel());
4606 break;
4607 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
4608 if (!direct_code_loaded) {
4609 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
4610 __ Bind(&relative_call_patches_.back().label);
4611 Label label;
4612 __ bl(&label); // Arbitrarily branch to the instruction after BL, override at link time.
4613 __ Bind(&label);
4614 break;
4615 }
4616 // If we loaded the direct code above, fall through.
4617 FALLTHROUGH_INTENDED;
4618 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4619 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4620 // LR prepared above for better instruction scheduling.
4621 DCHECK(direct_code_loaded);
4622 // LR()
4623 __ blx(LR);
4624 break;
4625 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
4626 // LR = callee_method->entry_point_from_quick_compiled_code_
4627 __ LoadFromOffset(
4628 kLoadWord, LR, callee_method.AsRegister<Register>(),
4629 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value());
4630 // LR()
4631 __ blx(LR);
4632 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004633 }
4634
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004635 DCHECK(!IsLeafMethod());
4636}
4637
Andreas Gampebfb5ba92015-09-01 15:45:02 +00004638void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
4639 Register temp = temp_location.AsRegister<Register>();
4640 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
4641 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
4642 LocationSummary* locations = invoke->GetLocations();
4643 Location receiver = locations->InAt(0);
4644 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4645 // temp = object->GetClass();
4646 DCHECK(receiver.IsRegister());
4647 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
4648 MaybeRecordImplicitNullCheck(invoke);
4649 __ MaybeUnpoisonHeapReference(temp);
4650 // temp = temp->GetMethodAt(method_offset);
4651 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4652 kArmWordSize).Int32Value();
4653 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
4654 // LR = temp->GetEntryPoint();
4655 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
4656 // LR();
4657 __ blx(LR);
4658}
4659
Vladimir Marko58155012015-08-19 12:49:41 +00004660void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
4661 DCHECK(linker_patches->empty());
4662 size_t size = method_patches_.size() + call_patches_.size() + relative_call_patches_.size();
4663 linker_patches->reserve(size);
4664 for (const auto& entry : method_patches_) {
4665 const MethodReference& target_method = entry.first;
4666 Literal* literal = entry.second;
4667 DCHECK(literal->GetLabel()->IsBound());
4668 uint32_t literal_offset = literal->GetLabel()->Position();
4669 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
4670 target_method.dex_file,
4671 target_method.dex_method_index));
4672 }
4673 for (const auto& entry : call_patches_) {
4674 const MethodReference& target_method = entry.first;
4675 Literal* literal = entry.second;
4676 DCHECK(literal->GetLabel()->IsBound());
4677 uint32_t literal_offset = literal->GetLabel()->Position();
4678 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
4679 target_method.dex_file,
4680 target_method.dex_method_index));
4681 }
4682 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
4683 uint32_t literal_offset = info.label.Position();
4684 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
4685 info.target_method.dex_file,
4686 info.target_method.dex_method_index));
4687 }
4688}
4689
4690Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
4691 MethodToLiteralMap* map) {
4692 // Look up the literal for target_method.
4693 auto lb = map->lower_bound(target_method);
4694 if (lb != map->end() && !map->key_comp()(target_method, lb->first)) {
4695 return lb->second;
4696 }
4697 // We don't have a literal for this method yet, insert a new one.
4698 Literal* literal = __ NewLiteral<uint32_t>(0u);
4699 map->PutBefore(lb, target_method, literal);
4700 return literal;
4701}
4702
4703Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
4704 return DeduplicateMethodLiteral(target_method, &method_patches_);
4705}
4706
4707Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
4708 return DeduplicateMethodLiteral(target_method, &call_patches_);
4709}
4710
Calin Juravleb1498f62015-02-16 13:13:29 +00004711void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4712 // Nothing to do, this should be removed during prepare for register allocator.
4713 UNUSED(instruction);
4714 LOG(FATAL) << "Unreachable";
4715}
4716
4717void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4718 // Nothing to do, this should be removed during prepare for register allocator.
4719 UNUSED(instruction);
4720 LOG(FATAL) << "Unreachable";
4721}
4722
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01004723void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) {
4724 DCHECK(codegen_->IsBaseline());
4725 LocationSummary* locations =
4726 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4727 locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
4728}
4729
4730void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
4731 DCHECK(codegen_->IsBaseline());
4732 // Will be generated at use site.
4733}
4734
Roland Levillain4d027112015-07-01 15:41:14 +01004735#undef __
4736#undef QUICK_ENTRY_POINT
4737
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004738} // namespace arm
4739} // namespace art