blob: 1b849a2fea721cbe3ddd15b18aac07bc11821900 [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
Andreas Gampe85b62f22015-09-09 13:15:38 -070062class NullCheckSlowPathARM : public SlowPathCode {
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
Andreas Gampe85b62f22015-09-09 13:15:38 -070086class DivZeroCheckSlowPathARM : public SlowPathCode {
Calin Juravled0d48522014-11-04 16:40:20 +000087 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
Andreas Gampe85b62f22015-09-09 13:15:38 -0700110class SuspendCheckSlowPathARM : public SlowPathCode {
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
Andreas Gampe85b62f22015-09-09 13:15:38 -0700151class BoundsCheckSlowPathARM : public SlowPathCode {
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
Andreas Gampe85b62f22015-09-09 13:15:38 -0700189class LoadClassSlowPathARM : public SlowPathCode {
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
Andreas Gampe85b62f22015-09-09 13:15:38 -0700242class LoadStringSlowPathARM : public SlowPathCode {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000243 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
Andreas Gampe85b62f22015-09-09 13:15:38 -0700272class TypeCheckSlowPathARM : public SlowPathCode {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000273 public:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000274 TypeCheckSlowPathARM(HInstruction* instruction, bool is_fatal)
275 : instruction_(instruction), is_fatal_(is_fatal) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000276
Alexandre Rames67555f72014-11-18 10:55:16 +0000277 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000278 LocationSummary* locations = instruction_->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100279 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0)
280 : locations->Out();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000281 DCHECK(instruction_->IsCheckCast()
282 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000283
284 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
285 __ Bind(GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000286
287 if (instruction_->IsCheckCast()) {
288 // The codegen for the instruction overwrites `temp`, so put it back in place.
289 Register obj = locations->InAt(0).AsRegister<Register>();
290 Register temp = locations->GetTemp(0).AsRegister<Register>();
291 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
292 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
293 __ MaybeUnpoisonHeapReference(temp);
294 }
295
296 if (!is_fatal_) {
297 SaveLiveRegisters(codegen, locations);
298 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000299
300 // We're moving two locations to locations that could overlap, so we need a parallel
301 // move resolver.
302 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000303 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100304 locations->InAt(1),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000305 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100306 Primitive::kPrimNot,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100307 object_class,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100308 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
309 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000310
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000311 if (instruction_->IsInstanceOf()) {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100312 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
313 instruction_,
314 instruction_->GetDexPc(),
315 this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000316 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
317 } else {
318 DCHECK(instruction_->IsCheckCast());
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100319 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
320 instruction_,
321 instruction_->GetDexPc(),
322 this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000323 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000324
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000325 if (!is_fatal_) {
326 RestoreLiveRegisters(codegen, locations);
327 __ b(GetExitLabel());
328 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000329 }
330
Alexandre Rames9931f312015-06-19 14:47:01 +0100331 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
332
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000333 bool IsFatal() const OVERRIDE { return is_fatal_; }
334
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000335 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000336 HInstruction* const instruction_;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000337 const bool is_fatal_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000338
339 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
340};
341
Andreas Gampe85b62f22015-09-09 13:15:38 -0700342class DeoptimizationSlowPathARM : public SlowPathCode {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700343 public:
344 explicit DeoptimizationSlowPathARM(HInstruction* instruction)
345 : instruction_(instruction) {}
346
347 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
348 __ Bind(GetEntryLabel());
349 SaveLiveRegisters(codegen, instruction_->GetLocations());
350 DCHECK(instruction_->IsDeoptimize());
351 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
352 uint32_t dex_pc = deoptimize->GetDexPc();
353 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
354 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
355 }
356
Alexandre Rames9931f312015-06-19 14:47:01 +0100357 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
358
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700359 private:
360 HInstruction* const instruction_;
361 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
362};
363
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100364class ArraySetSlowPathARM : public SlowPathCode {
365 public:
366 explicit ArraySetSlowPathARM(HInstruction* instruction) : instruction_(instruction) {}
367
368 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
369 LocationSummary* locations = instruction_->GetLocations();
370 __ Bind(GetEntryLabel());
371 SaveLiveRegisters(codegen, locations);
372
373 InvokeRuntimeCallingConvention calling_convention;
374 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
375 parallel_move.AddMove(
376 locations->InAt(0),
377 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
378 Primitive::kPrimNot,
379 nullptr);
380 parallel_move.AddMove(
381 locations->InAt(1),
382 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
383 Primitive::kPrimInt,
384 nullptr);
385 parallel_move.AddMove(
386 locations->InAt(2),
387 Location::RegisterLocation(calling_convention.GetRegisterAt(2)),
388 Primitive::kPrimNot,
389 nullptr);
390 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
391
392 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
393 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
394 instruction_,
395 instruction_->GetDexPc(),
396 this);
397 RestoreLiveRegisters(codegen, locations);
398 __ b(GetExitLabel());
399 }
400
401 const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM"; }
402
403 private:
404 HInstruction* const instruction_;
405
406 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM);
407};
408
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000409#undef __
Roland Levillain62a46b22015-06-01 18:24:13 +0100410#define __ down_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700411
Roland Levillain4fa13f62015-07-06 18:11:54 +0100412inline Condition ARMSignedOrFPCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700413 switch (cond) {
414 case kCondEQ: return EQ;
415 case kCondNE: return NE;
416 case kCondLT: return LT;
417 case kCondLE: return LE;
418 case kCondGT: return GT;
419 case kCondGE: return GE;
Dave Allison20dfc792014-06-16 20:44:29 -0700420 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100421 LOG(FATAL) << "Unreachable";
422 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700423}
424
Roland Levillain4fa13f62015-07-06 18:11:54 +0100425inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700426 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100427 case kCondEQ: return EQ;
428 case kCondNE: return NE;
429 case kCondLT: return LO;
430 case kCondLE: return LS;
431 case kCondGT: return HI;
432 case kCondGE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700433 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100434 LOG(FATAL) << "Unreachable";
435 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700436}
437
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100438void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100439 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100440}
441
442void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100443 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100444}
445
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100446size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
447 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
448 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100449}
450
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100451size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
452 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
453 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100454}
455
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000456size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
457 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
458 return kArmWordSize;
459}
460
461size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
462 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
463 return kArmWordSize;
464}
465
Calin Juravle34166012014-12-19 17:22:29 +0000466CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000467 const ArmInstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100468 const CompilerOptions& compiler_options,
469 OptimizingCompilerStats* stats)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000470 : CodeGenerator(graph,
471 kNumberOfCoreRegisters,
472 kNumberOfSRegisters,
473 kNumberOfRegisterPairs,
474 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
475 arraysize(kCoreCalleeSaves)),
476 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
477 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100478 compiler_options,
479 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100480 block_labels_(nullptr),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100481 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100482 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100483 move_resolver_(graph->GetArena(), this),
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000484 assembler_(),
Vladimir Marko58155012015-08-19 12:49:41 +0000485 isa_features_(isa_features),
486 method_patches_(MethodReferenceComparator(), graph->GetArena()->Adapter()),
487 call_patches_(MethodReferenceComparator(), graph->GetArena()->Adapter()),
488 relative_call_patches_(graph->GetArena()->Adapter()) {
Andreas Gampe501fd632015-09-10 16:11:06 -0700489 // Always save the LR register to mimic Quick.
490 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100491}
492
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000493void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
494 // Ensure that we fix up branches and literal loads and emit the literal pool.
495 __ FinalizeCode();
496
497 // Adjust native pc offsets in stack maps.
498 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
499 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
500 uint32_t new_position = __ GetAdjustedPosition(old_position);
501 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
502 }
503 // Adjust native pc offsets of block labels.
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100504 for (HBasicBlock* block : *block_order_) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000505 // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid
506 // FirstNonEmptyBlock() which could lead to adjusting a label more than once.
Vladimir Marko225b6462015-09-28 12:17:40 +0100507 DCHECK_LT(block->GetBlockId(), GetGraph()->GetBlocks().size());
508 Label* block_label = &block_labels_[block->GetBlockId()];
David Brazdilfc6a86a2015-06-26 10:33:45 +0000509 DCHECK_EQ(block_label->IsBound(), !block->IsSingleJump());
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000510 if (block_label->IsBound()) {
511 __ AdjustLabelPosition(block_label);
512 }
513 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100514 // Adjust pc offsets for the disassembly information.
515 if (disasm_info_ != nullptr) {
516 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
517 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
518 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
519 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
520 it.second.start = __ GetAdjustedPosition(it.second.start);
521 it.second.end = __ GetAdjustedPosition(it.second.end);
522 }
523 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
524 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
525 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
526 }
527 }
Vladimir Marko58155012015-08-19 12:49:41 +0000528 // Adjust pc offsets for relative call patches.
529 for (MethodPatchInfo<Label>& info : relative_call_patches_) {
530 __ AdjustLabelPosition(&info.label);
531 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000532
533 CodeGenerator::Finalize(allocator);
534}
535
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100536Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100537 switch (type) {
538 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100539 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100540 ArmManagedRegister pair =
541 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100542 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
543 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
544
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100545 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
546 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100547 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100548 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100549 }
550
551 case Primitive::kPrimByte:
552 case Primitive::kPrimBoolean:
553 case Primitive::kPrimChar:
554 case Primitive::kPrimShort:
555 case Primitive::kPrimInt:
556 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100557 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100558 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100559 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
560 ArmManagedRegister current =
561 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
562 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100563 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100564 }
565 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100566 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100567 }
568
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000569 case Primitive::kPrimFloat: {
570 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100571 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100572 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100573
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000574 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000575 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
576 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000577 return Location::FpuRegisterPairLocation(reg, reg + 1);
578 }
579
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100580 case Primitive::kPrimVoid:
581 LOG(FATAL) << "Unreachable type " << type;
582 }
583
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100584 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100585}
586
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000587void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100588 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100589 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100590
591 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100592 blocked_core_registers_[SP] = true;
593 blocked_core_registers_[LR] = true;
594 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100595
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100596 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100597 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100598
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100599 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100600 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100601
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000602 if (is_baseline) {
603 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
604 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
605 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000606
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000607 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
608
609 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
610 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
611 }
612 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100613
614 UpdateBlockedPairRegisters();
615}
616
617void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
618 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
619 ArmManagedRegister current =
620 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
621 if (blocked_core_registers_[current.AsRegisterPairLow()]
622 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
623 blocked_register_pairs_[i] = true;
624 }
625 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100626}
627
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100628InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
629 : HGraphVisitor(graph),
630 assembler_(codegen->GetAssembler()),
631 codegen_(codegen) {}
632
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000633void CodeGeneratorARM::ComputeSpillMask() {
634 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000635 // Save one extra register for baseline. Note that on thumb2, there is no easy
636 // instruction to restore just the PC, so this actually helps both baseline
637 // and non-baseline to save and restore at least two registers at entry and exit.
638 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000639 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
640 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
641 // We use vpush and vpop for saving and restoring floating point registers, which take
642 // a SRegister and the number of registers to save/restore after that SRegister. We
643 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
644 // but in the range.
645 if (fpu_spill_mask_ != 0) {
646 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
647 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
648 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
649 fpu_spill_mask_ |= (1 << i);
650 }
651 }
652}
653
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100654static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100655 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100656}
657
658static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100659 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100660}
661
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000662void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000663 bool skip_overflow_check =
664 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000665 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000666 __ Bind(&frame_entry_label_);
667
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000668 if (HasEmptyFrame()) {
669 return;
670 }
671
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100672 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000673 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
674 __ LoadFromOffset(kLoadWord, IP, IP, 0);
675 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100676 }
677
Andreas Gampe501fd632015-09-10 16:11:06 -0700678 __ PushList(core_spill_mask_);
679 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_));
680 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000681 if (fpu_spill_mask_ != 0) {
682 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
683 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100684 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100685 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000686 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100687 int adjust = GetFrameSize() - FrameEntrySpillSize();
688 __ AddConstant(SP, -adjust);
689 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100690 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000691}
692
693void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000694 if (HasEmptyFrame()) {
695 __ bx(LR);
696 return;
697 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100698 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100699 int adjust = GetFrameSize() - FrameEntrySpillSize();
700 __ AddConstant(SP, adjust);
701 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000702 if (fpu_spill_mask_ != 0) {
703 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
704 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100705 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
706 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000707 }
Andreas Gampe501fd632015-09-10 16:11:06 -0700708 // Pop LR into PC to return.
709 DCHECK_NE(core_spill_mask_ & (1 << LR), 0U);
710 uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC;
711 __ PopList(pop_mask);
David Srbeckyc34dc932015-04-12 09:27:43 +0100712 __ cfi().RestoreState();
713 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000714}
715
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100716void CodeGeneratorARM::Bind(HBasicBlock* block) {
717 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000718}
719
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100720Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
721 switch (load->GetType()) {
722 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100723 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100724 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100725
726 case Primitive::kPrimInt:
727 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100728 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100729 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100730
731 case Primitive::kPrimBoolean:
732 case Primitive::kPrimByte:
733 case Primitive::kPrimChar:
734 case Primitive::kPrimShort:
735 case Primitive::kPrimVoid:
736 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700737 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100738 }
739
740 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700741 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100742}
743
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100744Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100745 switch (type) {
746 case Primitive::kPrimBoolean:
747 case Primitive::kPrimByte:
748 case Primitive::kPrimChar:
749 case Primitive::kPrimShort:
750 case Primitive::kPrimInt:
751 case Primitive::kPrimNot: {
752 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000753 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100754 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100755 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100756 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000757 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100758 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100759 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100760
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000761 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100762 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000763 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100764 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000765 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100766 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000767 if (calling_convention.GetRegisterAt(index) == R1) {
768 // Skip R1, and use R2_R3 instead.
769 gp_index_++;
770 index++;
771 }
772 }
773 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
774 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000775 calling_convention.GetRegisterAt(index + 1));
Calin Juravle175dc732015-08-25 15:42:32 +0100776
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000777 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000778 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100779 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000780 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
781 }
782 }
783
784 case Primitive::kPrimFloat: {
785 uint32_t stack_index = stack_index_++;
786 if (float_index_ % 2 == 0) {
787 float_index_ = std::max(double_index_, float_index_);
788 }
789 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
790 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
791 } else {
792 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
793 }
794 }
795
796 case Primitive::kPrimDouble: {
797 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
798 uint32_t stack_index = stack_index_;
799 stack_index_ += 2;
800 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
801 uint32_t index = double_index_;
802 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000803 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000804 calling_convention.GetFpuRegisterAt(index),
805 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000806 DCHECK(ExpectedPairLayout(result));
807 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000808 } else {
809 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100810 }
811 }
812
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100813 case Primitive::kPrimVoid:
814 LOG(FATAL) << "Unexpected parameter type " << type;
815 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100816 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100817 return Location();
818}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100819
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100820Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000821 switch (type) {
822 case Primitive::kPrimBoolean:
823 case Primitive::kPrimByte:
824 case Primitive::kPrimChar:
825 case Primitive::kPrimShort:
826 case Primitive::kPrimInt:
827 case Primitive::kPrimNot: {
828 return Location::RegisterLocation(R0);
829 }
830
831 case Primitive::kPrimFloat: {
832 return Location::FpuRegisterLocation(S0);
833 }
834
835 case Primitive::kPrimLong: {
836 return Location::RegisterPairLocation(R0, R1);
837 }
838
839 case Primitive::kPrimDouble: {
840 return Location::FpuRegisterPairLocation(S0, S1);
841 }
842
843 case Primitive::kPrimVoid:
844 return Location();
845 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100846
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000847 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000848}
849
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100850Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
851 return Location::RegisterLocation(kMethodRegisterArgument);
852}
853
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100854void CodeGeneratorARM::Move32(Location destination, Location source) {
855 if (source.Equals(destination)) {
856 return;
857 }
858 if (destination.IsRegister()) {
859 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000860 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100861 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000862 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100863 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000864 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100865 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100866 } else if (destination.IsFpuRegister()) {
867 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000868 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100869 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000870 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100871 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000872 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100873 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100874 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000875 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100876 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000877 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100878 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000879 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100880 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000881 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100882 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
883 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100884 }
885 }
886}
887
888void CodeGeneratorARM::Move64(Location destination, Location source) {
889 if (source.Equals(destination)) {
890 return;
891 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100892 if (destination.IsRegisterPair()) {
893 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000894 EmitParallelMoves(
895 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
896 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100897 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000898 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100899 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
900 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100901 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000902 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100903 } else {
904 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000905 DCHECK(ExpectedPairLayout(destination));
906 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
907 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100908 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000909 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100910 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000911 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
912 SP,
913 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100914 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000915 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100916 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100917 } else {
918 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100919 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000920 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100921 if (source.AsRegisterPairLow<Register>() == R1) {
922 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100923 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
924 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100925 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100926 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100927 SP, destination.GetStackIndex());
928 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000929 } else if (source.IsFpuRegisterPair()) {
930 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
931 SP,
932 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100933 } else {
934 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000935 EmitParallelMoves(
936 Location::StackSlot(source.GetStackIndex()),
937 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100938 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000939 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100940 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
941 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100942 }
943 }
944}
945
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100946void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100947 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100948 if (instruction->IsCurrentMethod()) {
949 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
950 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100951 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100952 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000953 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000954 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
955 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000956 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000957 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000958 } else {
959 DCHECK(location.IsStackSlot());
960 __ LoadImmediate(IP, value);
961 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
962 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000963 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000964 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000965 int64_t value = const_to_move->AsLongConstant()->GetValue();
966 if (location.IsRegisterPair()) {
967 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
968 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
969 } else {
970 DCHECK(location.IsDoubleStackSlot());
971 __ LoadImmediate(IP, Low32Bits(value));
972 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
973 __ LoadImmediate(IP, High32Bits(value));
974 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
975 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100976 }
Roland Levillain476df552014-10-09 17:51:36 +0100977 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100978 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
979 switch (instruction->GetType()) {
980 case Primitive::kPrimBoolean:
981 case Primitive::kPrimByte:
982 case Primitive::kPrimChar:
983 case Primitive::kPrimShort:
984 case Primitive::kPrimInt:
985 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100986 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100987 Move32(location, Location::StackSlot(stack_slot));
988 break;
989
990 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100991 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100992 Move64(location, Location::DoubleStackSlot(stack_slot));
993 break;
994
995 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100996 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100997 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000998 } else if (instruction->IsTemporary()) {
999 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001000 if (temp_location.IsStackSlot()) {
1001 Move32(location, temp_location);
1002 } else {
1003 DCHECK(temp_location.IsDoubleStackSlot());
1004 Move64(location, temp_location);
1005 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001006 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001007 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001008 switch (instruction->GetType()) {
1009 case Primitive::kPrimBoolean:
1010 case Primitive::kPrimByte:
1011 case Primitive::kPrimChar:
1012 case Primitive::kPrimShort:
1013 case Primitive::kPrimNot:
1014 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001015 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001016 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001017 break;
1018
1019 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001020 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001021 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001022 break;
1023
1024 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001025 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001026 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001027 }
1028}
1029
Calin Juravle175dc732015-08-25 15:42:32 +01001030void CodeGeneratorARM::MoveConstant(Location location, int32_t value) {
1031 DCHECK(location.IsRegister());
1032 __ LoadImmediate(location.AsRegister<Register>(), value);
1033}
1034
1035void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint,
1036 HInstruction* instruction,
1037 uint32_t dex_pc,
1038 SlowPathCode* slow_path) {
1039 InvokeRuntime(GetThreadOffset<kArmWordSize>(entrypoint).Int32Value(),
1040 instruction,
1041 dex_pc,
1042 slow_path);
1043}
1044
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001045void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
1046 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001047 uint32_t dex_pc,
1048 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001049 ValidateInvokeRuntime(instruction, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001050 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1051 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001052 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001053}
1054
David Brazdilfc6a86a2015-06-26 10:33:45 +00001055void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001056 DCHECK(!successor->IsExitBlock());
1057
1058 HBasicBlock* block = got->GetBlock();
1059 HInstruction* previous = got->GetPrevious();
1060
1061 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +00001062 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001063 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1064 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1065 return;
1066 }
1067
1068 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1069 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1070 }
1071 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001072 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001073 }
1074}
1075
David Brazdilfc6a86a2015-06-26 10:33:45 +00001076void LocationsBuilderARM::VisitGoto(HGoto* got) {
1077 got->SetLocations(nullptr);
1078}
1079
1080void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1081 HandleGoto(got, got->GetSuccessor());
1082}
1083
1084void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1085 try_boundary->SetLocations(nullptr);
1086}
1087
1088void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1089 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1090 if (!successor->IsExitBlock()) {
1091 HandleGoto(try_boundary, successor);
1092 }
1093}
1094
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001095void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001096 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001097}
1098
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001099void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001100 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001101}
1102
Roland Levillain4fa13f62015-07-06 18:11:54 +01001103void InstructionCodeGeneratorARM::GenerateCompareWithImmediate(Register left, int32_t right) {
1104 ShifterOperand operand;
1105 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, right, &operand)) {
1106 __ cmp(left, operand);
1107 } else {
1108 Register temp = IP;
1109 __ LoadImmediate(temp, right);
1110 __ cmp(left, ShifterOperand(temp));
1111 }
1112}
1113
1114void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1115 Label* true_label,
1116 Label* false_label) {
1117 __ vmstat(); // transfer FP status register to ARM APSR.
1118 if (cond->IsFPConditionTrueIfNaN()) {
1119 __ b(true_label, VS); // VS for unordered.
1120 } else if (cond->IsFPConditionFalseIfNaN()) {
1121 __ b(false_label, VS); // VS for unordered.
1122 }
1123 __ b(true_label, ARMSignedOrFPCondition(cond->GetCondition()));
1124}
1125
1126void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1127 Label* true_label,
1128 Label* false_label) {
1129 LocationSummary* locations = cond->GetLocations();
1130 Location left = locations->InAt(0);
1131 Location right = locations->InAt(1);
1132 IfCondition if_cond = cond->GetCondition();
1133
1134 Register left_high = left.AsRegisterPairHigh<Register>();
1135 Register left_low = left.AsRegisterPairLow<Register>();
1136 IfCondition true_high_cond = if_cond;
1137 IfCondition false_high_cond = cond->GetOppositeCondition();
1138 Condition final_condition = ARMUnsignedCondition(if_cond);
1139
1140 // Set the conditions for the test, remembering that == needs to be
1141 // decided using the low words.
1142 switch (if_cond) {
1143 case kCondEQ:
1144 case kCondNE:
1145 // Nothing to do.
1146 break;
1147 case kCondLT:
1148 false_high_cond = kCondGT;
1149 break;
1150 case kCondLE:
1151 true_high_cond = kCondLT;
1152 break;
1153 case kCondGT:
1154 false_high_cond = kCondLT;
1155 break;
1156 case kCondGE:
1157 true_high_cond = kCondGT;
1158 break;
1159 }
1160 if (right.IsConstant()) {
1161 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1162 int32_t val_low = Low32Bits(value);
1163 int32_t val_high = High32Bits(value);
1164
1165 GenerateCompareWithImmediate(left_high, val_high);
1166 if (if_cond == kCondNE) {
1167 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1168 } else if (if_cond == kCondEQ) {
1169 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1170 } else {
1171 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1172 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1173 }
1174 // Must be equal high, so compare the lows.
1175 GenerateCompareWithImmediate(left_low, val_low);
1176 } else {
1177 Register right_high = right.AsRegisterPairHigh<Register>();
1178 Register right_low = right.AsRegisterPairLow<Register>();
1179
1180 __ cmp(left_high, ShifterOperand(right_high));
1181 if (if_cond == kCondNE) {
1182 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1183 } else if (if_cond == kCondEQ) {
1184 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1185 } else {
1186 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1187 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1188 }
1189 // Must be equal high, so compare the lows.
1190 __ cmp(left_low, ShifterOperand(right_low));
1191 }
1192 // The last comparison might be unsigned.
1193 __ b(true_label, final_condition);
1194}
1195
1196void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HIf* if_instr,
1197 HCondition* condition,
1198 Label* true_target,
1199 Label* false_target,
1200 Label* always_true_target) {
1201 LocationSummary* locations = condition->GetLocations();
1202 Location left = locations->InAt(0);
1203 Location right = locations->InAt(1);
1204
1205 // We don't want true_target as a nullptr.
1206 if (true_target == nullptr) {
1207 true_target = always_true_target;
1208 }
1209 bool falls_through = (false_target == nullptr);
1210
1211 // FP compares don't like null false_targets.
1212 if (false_target == nullptr) {
1213 false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1214 }
1215
1216 Primitive::Type type = condition->InputAt(0)->GetType();
1217 switch (type) {
1218 case Primitive::kPrimLong:
1219 GenerateLongComparesAndJumps(condition, true_target, false_target);
1220 break;
1221 case Primitive::kPrimFloat:
1222 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1223 GenerateFPJumps(condition, true_target, false_target);
1224 break;
1225 case Primitive::kPrimDouble:
1226 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1227 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1228 GenerateFPJumps(condition, true_target, false_target);
1229 break;
1230 default:
1231 LOG(FATAL) << "Unexpected compare type " << type;
1232 }
1233
1234 if (!falls_through) {
1235 __ b(false_target);
1236 }
1237}
1238
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001239void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
1240 Label* true_target,
1241 Label* false_target,
1242 Label* always_true_target) {
1243 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001244 if (cond->IsIntConstant()) {
1245 // Constant condition, statically compared against 1.
1246 int32_t cond_value = cond->AsIntConstant()->GetValue();
1247 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001248 if (always_true_target != nullptr) {
1249 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001250 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001251 return;
1252 } else {
1253 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001254 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001255 } else {
1256 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1257 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001258 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01001259 __ CompareAndBranchIfNonZero(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
1260 true_target);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001261 } else {
1262 // Condition has not been materialized, use its inputs as the
1263 // comparison and its condition as the branch condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +01001264 Primitive::Type type =
1265 cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt;
1266 // Is this a long or FP comparison that has been folded into the HCondition?
1267 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1268 // Generate the comparison directly.
1269 GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(),
1270 true_target, false_target, always_true_target);
1271 return;
1272 }
1273
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001274 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001275 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001276 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain4fa13f62015-07-06 18:11:54 +01001277 Location right = locations->InAt(1);
1278 if (right.IsRegister()) {
1279 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001280 } else {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001281 DCHECK(right.IsConstant());
1282 GenerateCompareWithImmediate(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001283 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001284 __ b(true_target, ARMSignedOrFPCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001285 }
Dave Allison20dfc792014-06-16 20:44:29 -07001286 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001287 if (false_target != nullptr) {
1288 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001289 }
1290}
1291
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001292void LocationsBuilderARM::VisitIf(HIf* if_instr) {
1293 LocationSummary* locations =
1294 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
1295 HInstruction* cond = if_instr->InputAt(0);
1296 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1297 locations->SetInAt(0, Location::RequiresRegister());
1298 }
1299}
1300
1301void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1302 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1303 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1304 Label* always_true_target = true_target;
1305 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1306 if_instr->IfTrueSuccessor())) {
1307 always_true_target = nullptr;
1308 }
1309 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1310 if_instr->IfFalseSuccessor())) {
1311 false_target = nullptr;
1312 }
1313 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1314}
1315
1316void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1317 LocationSummary* locations = new (GetGraph()->GetArena())
1318 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1319 HInstruction* cond = deoptimize->InputAt(0);
1320 DCHECK(cond->IsCondition());
1321 if (cond->AsCondition()->NeedsMaterialization()) {
1322 locations->SetInAt(0, Location::RequiresRegister());
1323 }
1324}
1325
1326void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07001327 SlowPathCode* slow_path = new (GetGraph()->GetArena())
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001328 DeoptimizationSlowPathARM(deoptimize);
1329 codegen_->AddSlowPath(slow_path);
1330 Label* slow_path_entry = slow_path->GetEntryLabel();
1331 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1332}
Dave Allison20dfc792014-06-16 20:44:29 -07001333
Roland Levillain0d37cd02015-05-27 16:39:19 +01001334void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001335 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001336 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001337 // Handle the long/FP comparisons made in instruction simplification.
1338 switch (cond->InputAt(0)->GetType()) {
1339 case Primitive::kPrimLong:
1340 locations->SetInAt(0, Location::RequiresRegister());
1341 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1342 if (cond->NeedsMaterialization()) {
1343 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1344 }
1345 break;
1346
1347 case Primitive::kPrimFloat:
1348 case Primitive::kPrimDouble:
1349 locations->SetInAt(0, Location::RequiresFpuRegister());
1350 locations->SetInAt(1, Location::RequiresFpuRegister());
1351 if (cond->NeedsMaterialization()) {
1352 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1353 }
1354 break;
1355
1356 default:
1357 locations->SetInAt(0, Location::RequiresRegister());
1358 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1359 if (cond->NeedsMaterialization()) {
1360 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1361 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001362 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001363}
1364
Roland Levillain0d37cd02015-05-27 16:39:19 +01001365void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001366 if (!cond->NeedsMaterialization()) {
1367 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001368 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001369
1370 LocationSummary* locations = cond->GetLocations();
1371 Location left = locations->InAt(0);
1372 Location right = locations->InAt(1);
1373 Register out = locations->Out().AsRegister<Register>();
1374 Label true_label, false_label;
1375
1376 switch (cond->InputAt(0)->GetType()) {
1377 default: {
1378 // Integer case.
1379 if (right.IsRegister()) {
1380 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1381 } else {
1382 DCHECK(right.IsConstant());
1383 GenerateCompareWithImmediate(left.AsRegister<Register>(),
1384 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
1385 }
1386 __ it(ARMSignedOrFPCondition(cond->GetCondition()), kItElse);
1387 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
1388 ARMSignedOrFPCondition(cond->GetCondition()));
1389 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
1390 ARMSignedOrFPCondition(cond->GetOppositeCondition()));
1391 return;
1392 }
1393 case Primitive::kPrimLong:
1394 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1395 break;
1396 case Primitive::kPrimFloat:
1397 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1398 GenerateFPJumps(cond, &true_label, &false_label);
1399 break;
1400 case Primitive::kPrimDouble:
1401 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1402 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1403 GenerateFPJumps(cond, &true_label, &false_label);
1404 break;
1405 }
1406
1407 // Convert the jumps into the result.
1408 Label done_label;
1409
1410 // False case: result = 0.
1411 __ Bind(&false_label);
1412 __ LoadImmediate(out, 0);
1413 __ b(&done_label);
1414
1415 // True case: result = 1.
1416 __ Bind(&true_label);
1417 __ LoadImmediate(out, 1);
1418 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001419}
1420
1421void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1422 VisitCondition(comp);
1423}
1424
1425void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1426 VisitCondition(comp);
1427}
1428
1429void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1430 VisitCondition(comp);
1431}
1432
1433void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1434 VisitCondition(comp);
1435}
1436
1437void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1438 VisitCondition(comp);
1439}
1440
1441void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1442 VisitCondition(comp);
1443}
1444
1445void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1446 VisitCondition(comp);
1447}
1448
1449void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1450 VisitCondition(comp);
1451}
1452
1453void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1454 VisitCondition(comp);
1455}
1456
1457void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1458 VisitCondition(comp);
1459}
1460
1461void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1462 VisitCondition(comp);
1463}
1464
1465void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1466 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001467}
1468
1469void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001470 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001471}
1472
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001473void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1474 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001475}
1476
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001477void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001478 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001479}
1480
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001481void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001482 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001483 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001484}
1485
1486void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001487 LocationSummary* locations =
1488 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001489 switch (store->InputAt(1)->GetType()) {
1490 case Primitive::kPrimBoolean:
1491 case Primitive::kPrimByte:
1492 case Primitive::kPrimChar:
1493 case Primitive::kPrimShort:
1494 case Primitive::kPrimInt:
1495 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001496 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001497 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1498 break;
1499
1500 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001501 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001502 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1503 break;
1504
1505 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001506 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001507 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001508}
1509
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001510void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001511 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001512}
1513
1514void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001515 LocationSummary* locations =
1516 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001517 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001518}
1519
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001520void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001521 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001522 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001523}
1524
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001525void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1526 LocationSummary* locations =
1527 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1528 locations->SetOut(Location::ConstantLocation(constant));
1529}
1530
1531void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1532 // Will be generated at use site.
1533 UNUSED(constant);
1534}
1535
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001536void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001537 LocationSummary* locations =
1538 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001539 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001540}
1541
1542void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1543 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001544 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001545}
1546
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001547void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1548 LocationSummary* locations =
1549 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1550 locations->SetOut(Location::ConstantLocation(constant));
1551}
1552
1553void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1554 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001555 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001556}
1557
1558void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1559 LocationSummary* locations =
1560 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1561 locations->SetOut(Location::ConstantLocation(constant));
1562}
1563
1564void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1565 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001566 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001567}
1568
Calin Juravle27df7582015-04-17 19:12:31 +01001569void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1570 memory_barrier->SetLocations(nullptr);
1571}
1572
1573void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1574 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1575}
1576
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001577void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001578 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001579}
1580
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001581void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001582 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001583 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001584}
1585
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001586void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001587 LocationSummary* locations =
1588 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001589 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001590}
1591
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001592void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001593 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001594 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001595}
1596
Calin Juravle175dc732015-08-25 15:42:32 +01001597void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1598 // The trampoline uses the same calling convention as dex calling conventions,
1599 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
1600 // the method_idx.
1601 HandleInvoke(invoke);
1602}
1603
1604void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1605 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
1606}
1607
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001608void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001609 // When we do not run baseline, explicit clinit checks triggered by static
1610 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1611 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001612
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001613 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1614 codegen_->GetInstructionSetFeatures());
1615 if (intrinsic.TryDispatch(invoke)) {
1616 return;
1617 }
1618
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001619 HandleInvoke(invoke);
1620}
1621
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001622static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1623 if (invoke->GetLocations()->Intrinsified()) {
1624 IntrinsicCodeGeneratorARM intrinsic(codegen);
1625 intrinsic.Dispatch(invoke);
1626 return true;
1627 }
1628 return false;
1629}
1630
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001631void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001632 // When we do not run baseline, explicit clinit checks triggered by static
1633 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1634 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001635
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001636 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1637 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001638 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001639
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001640 LocationSummary* locations = invoke->GetLocations();
1641 codegen_->GenerateStaticOrDirectCall(
1642 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001643 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001644}
1645
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001646void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001647 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001648 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001649}
1650
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001651void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001652 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1653 codegen_->GetInstructionSetFeatures());
1654 if (intrinsic.TryDispatch(invoke)) {
1655 return;
1656 }
1657
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001658 HandleInvoke(invoke);
1659}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001660
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001661void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001662 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1663 return;
1664 }
1665
Andreas Gampebfb5ba92015-09-01 15:45:02 +00001666 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001667 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001668 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001669}
1670
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001671void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1672 HandleInvoke(invoke);
1673 // Add the hidden argument.
1674 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1675}
1676
1677void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1678 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001679 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001680 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1681 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001682 LocationSummary* locations = invoke->GetLocations();
1683 Location receiver = locations->InAt(0);
1684 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1685
1686 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001687 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1688 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001689
1690 // temp = object->GetClass();
1691 if (receiver.IsStackSlot()) {
1692 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1693 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1694 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001695 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001696 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001697 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001698 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001699 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001700 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001701 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001702 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1703 // LR = temp->GetEntryPoint();
1704 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1705 // LR();
1706 __ blx(LR);
1707 DCHECK(!codegen_->IsLeafMethod());
1708 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1709}
1710
Roland Levillain88cb1752014-10-20 16:36:47 +01001711void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1712 LocationSummary* locations =
1713 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1714 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001715 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001716 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001717 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1718 break;
1719 }
1720 case Primitive::kPrimLong: {
1721 locations->SetInAt(0, Location::RequiresRegister());
1722 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001723 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001724 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001725
Roland Levillain88cb1752014-10-20 16:36:47 +01001726 case Primitive::kPrimFloat:
1727 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001728 locations->SetInAt(0, Location::RequiresFpuRegister());
1729 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001730 break;
1731
1732 default:
1733 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1734 }
1735}
1736
1737void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1738 LocationSummary* locations = neg->GetLocations();
1739 Location out = locations->Out();
1740 Location in = locations->InAt(0);
1741 switch (neg->GetResultType()) {
1742 case Primitive::kPrimInt:
1743 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001744 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001745 break;
1746
1747 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001748 DCHECK(in.IsRegisterPair());
1749 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1750 __ rsbs(out.AsRegisterPairLow<Register>(),
1751 in.AsRegisterPairLow<Register>(),
1752 ShifterOperand(0));
1753 // We cannot emit an RSC (Reverse Subtract with Carry)
1754 // instruction here, as it does not exist in the Thumb-2
1755 // instruction set. We use the following approach
1756 // using SBC and SUB instead.
1757 //
1758 // out.hi = -C
1759 __ sbc(out.AsRegisterPairHigh<Register>(),
1760 out.AsRegisterPairHigh<Register>(),
1761 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1762 // out.hi = out.hi - in.hi
1763 __ sub(out.AsRegisterPairHigh<Register>(),
1764 out.AsRegisterPairHigh<Register>(),
1765 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1766 break;
1767
Roland Levillain88cb1752014-10-20 16:36:47 +01001768 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001769 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001770 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001771 break;
1772
Roland Levillain88cb1752014-10-20 16:36:47 +01001773 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001774 DCHECK(in.IsFpuRegisterPair());
1775 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1776 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001777 break;
1778
1779 default:
1780 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1781 }
1782}
1783
Roland Levillaindff1f282014-11-05 14:15:05 +00001784void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001785 Primitive::Type result_type = conversion->GetResultType();
1786 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001787 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001788
Roland Levillain5b3ee562015-04-14 16:02:41 +01001789 // The float-to-long, double-to-long and long-to-float type conversions
1790 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001791 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001792 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1793 && result_type == Primitive::kPrimLong)
1794 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001795 ? LocationSummary::kCall
1796 : LocationSummary::kNoCall;
1797 LocationSummary* locations =
1798 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1799
David Brazdilb2bd1c52015-03-25 11:17:37 +00001800 // The Java language does not allow treating boolean as an integral type but
1801 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001802
Roland Levillaindff1f282014-11-05 14:15:05 +00001803 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001804 case Primitive::kPrimByte:
1805 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001806 case Primitive::kPrimBoolean:
1807 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001808 case Primitive::kPrimShort:
1809 case Primitive::kPrimInt:
1810 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001811 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001812 locations->SetInAt(0, Location::RequiresRegister());
1813 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1814 break;
1815
1816 default:
1817 LOG(FATAL) << "Unexpected type conversion from " << input_type
1818 << " to " << result_type;
1819 }
1820 break;
1821
Roland Levillain01a8d712014-11-14 16:27:39 +00001822 case Primitive::kPrimShort:
1823 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001824 case Primitive::kPrimBoolean:
1825 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001826 case Primitive::kPrimByte:
1827 case Primitive::kPrimInt:
1828 case Primitive::kPrimChar:
1829 // Processing a Dex `int-to-short' instruction.
1830 locations->SetInAt(0, Location::RequiresRegister());
1831 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1832 break;
1833
1834 default:
1835 LOG(FATAL) << "Unexpected type conversion from " << input_type
1836 << " to " << result_type;
1837 }
1838 break;
1839
Roland Levillain946e1432014-11-11 17:35:19 +00001840 case Primitive::kPrimInt:
1841 switch (input_type) {
1842 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001843 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001844 locations->SetInAt(0, Location::Any());
1845 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1846 break;
1847
1848 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001849 // Processing a Dex `float-to-int' instruction.
1850 locations->SetInAt(0, Location::RequiresFpuRegister());
1851 locations->SetOut(Location::RequiresRegister());
1852 locations->AddTemp(Location::RequiresFpuRegister());
1853 break;
1854
Roland Levillain946e1432014-11-11 17:35:19 +00001855 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001856 // Processing a Dex `double-to-int' instruction.
1857 locations->SetInAt(0, Location::RequiresFpuRegister());
1858 locations->SetOut(Location::RequiresRegister());
1859 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001860 break;
1861
1862 default:
1863 LOG(FATAL) << "Unexpected type conversion from " << input_type
1864 << " to " << result_type;
1865 }
1866 break;
1867
Roland Levillaindff1f282014-11-05 14:15:05 +00001868 case Primitive::kPrimLong:
1869 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001870 case Primitive::kPrimBoolean:
1871 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001872 case Primitive::kPrimByte:
1873 case Primitive::kPrimShort:
1874 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001875 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001876 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001877 locations->SetInAt(0, Location::RequiresRegister());
1878 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1879 break;
1880
Roland Levillain624279f2014-12-04 11:54:28 +00001881 case Primitive::kPrimFloat: {
1882 // Processing a Dex `float-to-long' instruction.
1883 InvokeRuntimeCallingConvention calling_convention;
1884 locations->SetInAt(0, Location::FpuRegisterLocation(
1885 calling_convention.GetFpuRegisterAt(0)));
1886 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1887 break;
1888 }
1889
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001890 case Primitive::kPrimDouble: {
1891 // Processing a Dex `double-to-long' instruction.
1892 InvokeRuntimeCallingConvention calling_convention;
1893 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1894 calling_convention.GetFpuRegisterAt(0),
1895 calling_convention.GetFpuRegisterAt(1)));
1896 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001897 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001898 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001899
1900 default:
1901 LOG(FATAL) << "Unexpected type conversion from " << input_type
1902 << " to " << result_type;
1903 }
1904 break;
1905
Roland Levillain981e4542014-11-14 11:47:14 +00001906 case Primitive::kPrimChar:
1907 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001908 case Primitive::kPrimBoolean:
1909 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001910 case Primitive::kPrimByte:
1911 case Primitive::kPrimShort:
1912 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001913 // Processing a Dex `int-to-char' instruction.
1914 locations->SetInAt(0, Location::RequiresRegister());
1915 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1916 break;
1917
1918 default:
1919 LOG(FATAL) << "Unexpected type conversion from " << input_type
1920 << " to " << result_type;
1921 }
1922 break;
1923
Roland Levillaindff1f282014-11-05 14:15:05 +00001924 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001925 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001926 case Primitive::kPrimBoolean:
1927 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001928 case Primitive::kPrimByte:
1929 case Primitive::kPrimShort:
1930 case Primitive::kPrimInt:
1931 case Primitive::kPrimChar:
1932 // Processing a Dex `int-to-float' instruction.
1933 locations->SetInAt(0, Location::RequiresRegister());
1934 locations->SetOut(Location::RequiresFpuRegister());
1935 break;
1936
Roland Levillain5b3ee562015-04-14 16:02:41 +01001937 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001938 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001939 InvokeRuntimeCallingConvention calling_convention;
1940 locations->SetInAt(0, Location::RegisterPairLocation(
1941 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1942 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001943 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001944 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001945
Roland Levillaincff13742014-11-17 14:32:17 +00001946 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001947 // Processing a Dex `double-to-float' instruction.
1948 locations->SetInAt(0, Location::RequiresFpuRegister());
1949 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001950 break;
1951
1952 default:
1953 LOG(FATAL) << "Unexpected type conversion from " << input_type
1954 << " to " << result_type;
1955 };
1956 break;
1957
Roland Levillaindff1f282014-11-05 14:15:05 +00001958 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001959 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001960 case Primitive::kPrimBoolean:
1961 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001962 case Primitive::kPrimByte:
1963 case Primitive::kPrimShort:
1964 case Primitive::kPrimInt:
1965 case Primitive::kPrimChar:
1966 // Processing a Dex `int-to-double' instruction.
1967 locations->SetInAt(0, Location::RequiresRegister());
1968 locations->SetOut(Location::RequiresFpuRegister());
1969 break;
1970
1971 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001972 // Processing a Dex `long-to-double' instruction.
1973 locations->SetInAt(0, Location::RequiresRegister());
1974 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001975 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001976 locations->AddTemp(Location::RequiresFpuRegister());
1977 break;
1978
Roland Levillaincff13742014-11-17 14:32:17 +00001979 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001980 // Processing a Dex `float-to-double' instruction.
1981 locations->SetInAt(0, Location::RequiresFpuRegister());
1982 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001983 break;
1984
1985 default:
1986 LOG(FATAL) << "Unexpected type conversion from " << input_type
1987 << " to " << result_type;
1988 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001989 break;
1990
1991 default:
1992 LOG(FATAL) << "Unexpected type conversion from " << input_type
1993 << " to " << result_type;
1994 }
1995}
1996
1997void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1998 LocationSummary* locations = conversion->GetLocations();
1999 Location out = locations->Out();
2000 Location in = locations->InAt(0);
2001 Primitive::Type result_type = conversion->GetResultType();
2002 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002003 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00002004 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002005 case Primitive::kPrimByte:
2006 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002007 case Primitive::kPrimBoolean:
2008 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002009 case Primitive::kPrimShort:
2010 case Primitive::kPrimInt:
2011 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002012 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002013 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002014 break;
2015
2016 default:
2017 LOG(FATAL) << "Unexpected type conversion from " << input_type
2018 << " to " << result_type;
2019 }
2020 break;
2021
Roland Levillain01a8d712014-11-14 16:27:39 +00002022 case Primitive::kPrimShort:
2023 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002024 case Primitive::kPrimBoolean:
2025 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002026 case Primitive::kPrimByte:
2027 case Primitive::kPrimInt:
2028 case Primitive::kPrimChar:
2029 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002030 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00002031 break;
2032
2033 default:
2034 LOG(FATAL) << "Unexpected type conversion from " << input_type
2035 << " to " << result_type;
2036 }
2037 break;
2038
Roland Levillain946e1432014-11-11 17:35:19 +00002039 case Primitive::kPrimInt:
2040 switch (input_type) {
2041 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002042 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002043 DCHECK(out.IsRegister());
2044 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002045 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00002046 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002047 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00002048 } else {
2049 DCHECK(in.IsConstant());
2050 DCHECK(in.GetConstant()->IsLongConstant());
2051 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002052 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00002053 }
2054 break;
2055
Roland Levillain3f8f9362014-12-02 17:45:01 +00002056 case Primitive::kPrimFloat: {
2057 // Processing a Dex `float-to-int' instruction.
2058 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
2059 __ vmovs(temp, in.AsFpuRegister<SRegister>());
2060 __ vcvtis(temp, temp);
2061 __ vmovrs(out.AsRegister<Register>(), temp);
2062 break;
2063 }
2064
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002065 case Primitive::kPrimDouble: {
2066 // Processing a Dex `double-to-int' instruction.
2067 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
2068 DRegister temp_d = FromLowSToD(temp_s);
2069 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
2070 __ vcvtid(temp_s, temp_d);
2071 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002072 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002073 }
Roland Levillain946e1432014-11-11 17:35:19 +00002074
2075 default:
2076 LOG(FATAL) << "Unexpected type conversion from " << input_type
2077 << " to " << result_type;
2078 }
2079 break;
2080
Roland Levillaindff1f282014-11-05 14:15:05 +00002081 case Primitive::kPrimLong:
2082 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002083 case Primitive::kPrimBoolean:
2084 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002085 case Primitive::kPrimByte:
2086 case Primitive::kPrimShort:
2087 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002088 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002089 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002090 DCHECK(out.IsRegisterPair());
2091 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002092 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002093 // Sign extension.
2094 __ Asr(out.AsRegisterPairHigh<Register>(),
2095 out.AsRegisterPairLow<Register>(),
2096 31);
2097 break;
2098
2099 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002100 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00002101 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
2102 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002103 conversion->GetDexPc(),
2104 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00002105 break;
2106
Roland Levillaindff1f282014-11-05 14:15:05 +00002107 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002108 // Processing a Dex `double-to-long' instruction.
2109 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
2110 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002111 conversion->GetDexPc(),
2112 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00002113 break;
2114
2115 default:
2116 LOG(FATAL) << "Unexpected type conversion from " << input_type
2117 << " to " << result_type;
2118 }
2119 break;
2120
Roland Levillain981e4542014-11-14 11:47:14 +00002121 case Primitive::kPrimChar:
2122 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002123 case Primitive::kPrimBoolean:
2124 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002125 case Primitive::kPrimByte:
2126 case Primitive::kPrimShort:
2127 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002128 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002129 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002130 break;
2131
2132 default:
2133 LOG(FATAL) << "Unexpected type conversion from " << input_type
2134 << " to " << result_type;
2135 }
2136 break;
2137
Roland Levillaindff1f282014-11-05 14:15:05 +00002138 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002139 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002140 case Primitive::kPrimBoolean:
2141 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002142 case Primitive::kPrimByte:
2143 case Primitive::kPrimShort:
2144 case Primitive::kPrimInt:
2145 case Primitive::kPrimChar: {
2146 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002147 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2148 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002149 break;
2150 }
2151
Roland Levillain5b3ee562015-04-14 16:02:41 +01002152 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002153 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002154 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
2155 conversion,
2156 conversion->GetDexPc(),
2157 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00002158 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002159
Roland Levillaincff13742014-11-17 14:32:17 +00002160 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002161 // Processing a Dex `double-to-float' instruction.
2162 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2163 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002164 break;
2165
2166 default:
2167 LOG(FATAL) << "Unexpected type conversion from " << input_type
2168 << " to " << result_type;
2169 };
2170 break;
2171
Roland Levillaindff1f282014-11-05 14:15:05 +00002172 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002173 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002174 case Primitive::kPrimBoolean:
2175 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002176 case Primitive::kPrimByte:
2177 case Primitive::kPrimShort:
2178 case Primitive::kPrimInt:
2179 case Primitive::kPrimChar: {
2180 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002181 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002182 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2183 out.AsFpuRegisterPairLow<SRegister>());
2184 break;
2185 }
2186
Roland Levillain647b9ed2014-11-27 12:06:00 +00002187 case Primitive::kPrimLong: {
2188 // Processing a Dex `long-to-double' instruction.
2189 Register low = in.AsRegisterPairLow<Register>();
2190 Register high = in.AsRegisterPairHigh<Register>();
2191 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2192 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002193 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002194 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002195 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2196 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002197
Roland Levillain682393c2015-04-14 15:57:52 +01002198 // temp_d = int-to-double(high)
2199 __ vmovsr(temp_s, high);
2200 __ vcvtdi(temp_d, temp_s);
2201 // constant_d = k2Pow32EncodingForDouble
2202 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2203 // out_d = unsigned-to-double(low)
2204 __ vmovsr(out_s, low);
2205 __ vcvtdu(out_d, out_s);
2206 // out_d += temp_d * constant_d
2207 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002208 break;
2209 }
2210
Roland Levillaincff13742014-11-17 14:32:17 +00002211 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002212 // Processing a Dex `float-to-double' instruction.
2213 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2214 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002215 break;
2216
2217 default:
2218 LOG(FATAL) << "Unexpected type conversion from " << input_type
2219 << " to " << result_type;
2220 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002221 break;
2222
2223 default:
2224 LOG(FATAL) << "Unexpected type conversion from " << input_type
2225 << " to " << result_type;
2226 }
2227}
2228
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002229void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002230 LocationSummary* locations =
2231 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002232 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002233 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002234 locations->SetInAt(0, Location::RequiresRegister());
2235 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002236 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2237 break;
2238 }
2239
2240 case Primitive::kPrimLong: {
2241 locations->SetInAt(0, Location::RequiresRegister());
2242 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002243 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002244 break;
2245 }
2246
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002247 case Primitive::kPrimFloat:
2248 case Primitive::kPrimDouble: {
2249 locations->SetInAt(0, Location::RequiresFpuRegister());
2250 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002251 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002252 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002253 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002254
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002255 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002256 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002257 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002258}
2259
2260void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2261 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002262 Location out = locations->Out();
2263 Location first = locations->InAt(0);
2264 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002265 switch (add->GetResultType()) {
2266 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002267 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002268 __ add(out.AsRegister<Register>(),
2269 first.AsRegister<Register>(),
2270 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002271 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002272 __ AddConstant(out.AsRegister<Register>(),
2273 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002274 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002275 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002276 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002277
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002278 case Primitive::kPrimLong: {
2279 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002280 __ adds(out.AsRegisterPairLow<Register>(),
2281 first.AsRegisterPairLow<Register>(),
2282 ShifterOperand(second.AsRegisterPairLow<Register>()));
2283 __ adc(out.AsRegisterPairHigh<Register>(),
2284 first.AsRegisterPairHigh<Register>(),
2285 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002286 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002287 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002288
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002289 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002290 __ vadds(out.AsFpuRegister<SRegister>(),
2291 first.AsFpuRegister<SRegister>(),
2292 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002293 break;
2294
2295 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002296 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2297 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2298 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002299 break;
2300
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002301 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002302 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002303 }
2304}
2305
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002306void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002307 LocationSummary* locations =
2308 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002309 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002310 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002311 locations->SetInAt(0, Location::RequiresRegister());
2312 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002313 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2314 break;
2315 }
2316
2317 case Primitive::kPrimLong: {
2318 locations->SetInAt(0, Location::RequiresRegister());
2319 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002320 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002321 break;
2322 }
Calin Juravle11351682014-10-23 15:38:15 +01002323 case Primitive::kPrimFloat:
2324 case Primitive::kPrimDouble: {
2325 locations->SetInAt(0, Location::RequiresFpuRegister());
2326 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002327 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002328 break;
Calin Juravle11351682014-10-23 15:38:15 +01002329 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002330 default:
Calin Juravle11351682014-10-23 15:38:15 +01002331 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002332 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002333}
2334
2335void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2336 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002337 Location out = locations->Out();
2338 Location first = locations->InAt(0);
2339 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002340 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002341 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002342 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002343 __ sub(out.AsRegister<Register>(),
2344 first.AsRegister<Register>(),
2345 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002346 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002347 __ AddConstant(out.AsRegister<Register>(),
2348 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002349 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002350 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002351 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002352 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002353
Calin Juravle11351682014-10-23 15:38:15 +01002354 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002355 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002356 __ subs(out.AsRegisterPairLow<Register>(),
2357 first.AsRegisterPairLow<Register>(),
2358 ShifterOperand(second.AsRegisterPairLow<Register>()));
2359 __ sbc(out.AsRegisterPairHigh<Register>(),
2360 first.AsRegisterPairHigh<Register>(),
2361 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002362 break;
Calin Juravle11351682014-10-23 15:38:15 +01002363 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002364
Calin Juravle11351682014-10-23 15:38:15 +01002365 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002366 __ vsubs(out.AsFpuRegister<SRegister>(),
2367 first.AsFpuRegister<SRegister>(),
2368 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002369 break;
Calin Juravle11351682014-10-23 15:38:15 +01002370 }
2371
2372 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002373 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2374 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2375 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002376 break;
2377 }
2378
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002379
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002380 default:
Calin Juravle11351682014-10-23 15:38:15 +01002381 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002382 }
2383}
2384
Calin Juravle34bacdf2014-10-07 20:23:36 +01002385void LocationsBuilderARM::VisitMul(HMul* mul) {
2386 LocationSummary* locations =
2387 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2388 switch (mul->GetResultType()) {
2389 case Primitive::kPrimInt:
2390 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002391 locations->SetInAt(0, Location::RequiresRegister());
2392 locations->SetInAt(1, Location::RequiresRegister());
2393 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002394 break;
2395 }
2396
Calin Juravleb5bfa962014-10-21 18:02:24 +01002397 case Primitive::kPrimFloat:
2398 case Primitive::kPrimDouble: {
2399 locations->SetInAt(0, Location::RequiresFpuRegister());
2400 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002401 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002402 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002403 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002404
2405 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002406 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002407 }
2408}
2409
2410void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2411 LocationSummary* locations = mul->GetLocations();
2412 Location out = locations->Out();
2413 Location first = locations->InAt(0);
2414 Location second = locations->InAt(1);
2415 switch (mul->GetResultType()) {
2416 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002417 __ mul(out.AsRegister<Register>(),
2418 first.AsRegister<Register>(),
2419 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002420 break;
2421 }
2422 case Primitive::kPrimLong: {
2423 Register out_hi = out.AsRegisterPairHigh<Register>();
2424 Register out_lo = out.AsRegisterPairLow<Register>();
2425 Register in1_hi = first.AsRegisterPairHigh<Register>();
2426 Register in1_lo = first.AsRegisterPairLow<Register>();
2427 Register in2_hi = second.AsRegisterPairHigh<Register>();
2428 Register in2_lo = second.AsRegisterPairLow<Register>();
2429
2430 // Extra checks to protect caused by the existence of R1_R2.
2431 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2432 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2433 DCHECK_NE(out_hi, in1_lo);
2434 DCHECK_NE(out_hi, in2_lo);
2435
2436 // input: in1 - 64 bits, in2 - 64 bits
2437 // output: out
2438 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2439 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2440 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2441
2442 // IP <- in1.lo * in2.hi
2443 __ mul(IP, in1_lo, in2_hi);
2444 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2445 __ mla(out_hi, in1_hi, in2_lo, IP);
2446 // out.lo <- (in1.lo * in2.lo)[31:0];
2447 __ umull(out_lo, IP, in1_lo, in2_lo);
2448 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2449 __ add(out_hi, out_hi, ShifterOperand(IP));
2450 break;
2451 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002452
2453 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002454 __ vmuls(out.AsFpuRegister<SRegister>(),
2455 first.AsFpuRegister<SRegister>(),
2456 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002457 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002458 }
2459
2460 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002461 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2462 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2463 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002464 break;
2465 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002466
2467 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002468 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002469 }
2470}
2471
Zheng Xuc6667102015-05-15 16:08:45 +08002472void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2473 DCHECK(instruction->IsDiv() || instruction->IsRem());
2474 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2475
2476 LocationSummary* locations = instruction->GetLocations();
2477 Location second = locations->InAt(1);
2478 DCHECK(second.IsConstant());
2479
2480 Register out = locations->Out().AsRegister<Register>();
2481 Register dividend = locations->InAt(0).AsRegister<Register>();
2482 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2483 DCHECK(imm == 1 || imm == -1);
2484
2485 if (instruction->IsRem()) {
2486 __ LoadImmediate(out, 0);
2487 } else {
2488 if (imm == 1) {
2489 __ Mov(out, dividend);
2490 } else {
2491 __ rsb(out, dividend, ShifterOperand(0));
2492 }
2493 }
2494}
2495
2496void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2497 DCHECK(instruction->IsDiv() || instruction->IsRem());
2498 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2499
2500 LocationSummary* locations = instruction->GetLocations();
2501 Location second = locations->InAt(1);
2502 DCHECK(second.IsConstant());
2503
2504 Register out = locations->Out().AsRegister<Register>();
2505 Register dividend = locations->InAt(0).AsRegister<Register>();
2506 Register temp = locations->GetTemp(0).AsRegister<Register>();
2507 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002508 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002509 DCHECK(IsPowerOfTwo(abs_imm));
2510 int ctz_imm = CTZ(abs_imm);
2511
2512 if (ctz_imm == 1) {
2513 __ Lsr(temp, dividend, 32 - ctz_imm);
2514 } else {
2515 __ Asr(temp, dividend, 31);
2516 __ Lsr(temp, temp, 32 - ctz_imm);
2517 }
2518 __ add(out, temp, ShifterOperand(dividend));
2519
2520 if (instruction->IsDiv()) {
2521 __ Asr(out, out, ctz_imm);
2522 if (imm < 0) {
2523 __ rsb(out, out, ShifterOperand(0));
2524 }
2525 } else {
2526 __ ubfx(out, out, 0, ctz_imm);
2527 __ sub(out, out, ShifterOperand(temp));
2528 }
2529}
2530
2531void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2532 DCHECK(instruction->IsDiv() || instruction->IsRem());
2533 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2534
2535 LocationSummary* locations = instruction->GetLocations();
2536 Location second = locations->InAt(1);
2537 DCHECK(second.IsConstant());
2538
2539 Register out = locations->Out().AsRegister<Register>();
2540 Register dividend = locations->InAt(0).AsRegister<Register>();
2541 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2542 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2543 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2544
2545 int64_t magic;
2546 int shift;
2547 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2548
2549 __ LoadImmediate(temp1, magic);
2550 __ smull(temp2, temp1, dividend, temp1);
2551
2552 if (imm > 0 && magic < 0) {
2553 __ add(temp1, temp1, ShifterOperand(dividend));
2554 } else if (imm < 0 && magic > 0) {
2555 __ sub(temp1, temp1, ShifterOperand(dividend));
2556 }
2557
2558 if (shift != 0) {
2559 __ Asr(temp1, temp1, shift);
2560 }
2561
2562 if (instruction->IsDiv()) {
2563 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2564 } else {
2565 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2566 // TODO: Strength reduction for mls.
2567 __ LoadImmediate(temp2, imm);
2568 __ mls(out, temp1, temp2, dividend);
2569 }
2570}
2571
2572void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2573 DCHECK(instruction->IsDiv() || instruction->IsRem());
2574 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2575
2576 LocationSummary* locations = instruction->GetLocations();
2577 Location second = locations->InAt(1);
2578 DCHECK(second.IsConstant());
2579
2580 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2581 if (imm == 0) {
2582 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2583 } else if (imm == 1 || imm == -1) {
2584 DivRemOneOrMinusOne(instruction);
2585 } else if (IsPowerOfTwo(std::abs(imm))) {
2586 DivRemByPowerOfTwo(instruction);
2587 } else {
2588 DCHECK(imm <= -2 || imm >= 2);
2589 GenerateDivRemWithAnyConstant(instruction);
2590 }
2591}
2592
Calin Juravle7c4954d2014-10-28 16:57:40 +00002593void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002594 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2595 if (div->GetResultType() == Primitive::kPrimLong) {
2596 // pLdiv runtime call.
2597 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002598 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2599 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002600 } else if (div->GetResultType() == Primitive::kPrimInt &&
2601 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2602 // pIdivmod runtime call.
2603 call_kind = LocationSummary::kCall;
2604 }
2605
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002606 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2607
Calin Juravle7c4954d2014-10-28 16:57:40 +00002608 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002609 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002610 if (div->InputAt(1)->IsConstant()) {
2611 locations->SetInAt(0, Location::RequiresRegister());
2612 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2613 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2614 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2615 if (abs_imm <= 1) {
2616 // No temp register required.
2617 } else {
2618 locations->AddTemp(Location::RequiresRegister());
2619 if (!IsPowerOfTwo(abs_imm)) {
2620 locations->AddTemp(Location::RequiresRegister());
2621 }
2622 }
2623 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002624 locations->SetInAt(0, Location::RequiresRegister());
2625 locations->SetInAt(1, Location::RequiresRegister());
2626 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2627 } else {
2628 InvokeRuntimeCallingConvention calling_convention;
2629 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2630 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2631 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2632 // we only need the former.
2633 locations->SetOut(Location::RegisterLocation(R0));
2634 }
Calin Juravled0d48522014-11-04 16:40:20 +00002635 break;
2636 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002637 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002638 InvokeRuntimeCallingConvention calling_convention;
2639 locations->SetInAt(0, Location::RegisterPairLocation(
2640 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2641 locations->SetInAt(1, Location::RegisterPairLocation(
2642 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002643 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002644 break;
2645 }
2646 case Primitive::kPrimFloat:
2647 case Primitive::kPrimDouble: {
2648 locations->SetInAt(0, Location::RequiresFpuRegister());
2649 locations->SetInAt(1, Location::RequiresFpuRegister());
2650 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2651 break;
2652 }
2653
2654 default:
2655 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2656 }
2657}
2658
2659void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2660 LocationSummary* locations = div->GetLocations();
2661 Location out = locations->Out();
2662 Location first = locations->InAt(0);
2663 Location second = locations->InAt(1);
2664
2665 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002666 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002667 if (second.IsConstant()) {
2668 GenerateDivRemConstantIntegral(div);
2669 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002670 __ sdiv(out.AsRegister<Register>(),
2671 first.AsRegister<Register>(),
2672 second.AsRegister<Register>());
2673 } else {
2674 InvokeRuntimeCallingConvention calling_convention;
2675 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2676 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2677 DCHECK_EQ(R0, out.AsRegister<Register>());
2678
2679 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2680 }
Calin Juravled0d48522014-11-04 16:40:20 +00002681 break;
2682 }
2683
Calin Juravle7c4954d2014-10-28 16:57:40 +00002684 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002685 InvokeRuntimeCallingConvention calling_convention;
2686 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2687 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2688 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2689 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2690 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002691 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002692
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002693 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002694 break;
2695 }
2696
2697 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002698 __ vdivs(out.AsFpuRegister<SRegister>(),
2699 first.AsFpuRegister<SRegister>(),
2700 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002701 break;
2702 }
2703
2704 case Primitive::kPrimDouble: {
2705 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2706 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2707 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2708 break;
2709 }
2710
2711 default:
2712 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2713 }
2714}
2715
Calin Juravlebacfec32014-11-14 15:54:36 +00002716void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002717 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002718
2719 // Most remainders are implemented in the runtime.
2720 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002721 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2722 // sdiv will be replaced by other instruction sequence.
2723 call_kind = LocationSummary::kNoCall;
2724 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2725 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002726 // Have hardware divide instruction for int, do it with three instructions.
2727 call_kind = LocationSummary::kNoCall;
2728 }
2729
Calin Juravlebacfec32014-11-14 15:54:36 +00002730 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2731
Calin Juravled2ec87d2014-12-08 14:24:46 +00002732 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002733 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002734 if (rem->InputAt(1)->IsConstant()) {
2735 locations->SetInAt(0, Location::RequiresRegister());
2736 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2737 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2738 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2739 if (abs_imm <= 1) {
2740 // No temp register required.
2741 } else {
2742 locations->AddTemp(Location::RequiresRegister());
2743 if (!IsPowerOfTwo(abs_imm)) {
2744 locations->AddTemp(Location::RequiresRegister());
2745 }
2746 }
2747 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002748 locations->SetInAt(0, Location::RequiresRegister());
2749 locations->SetInAt(1, Location::RequiresRegister());
2750 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2751 locations->AddTemp(Location::RequiresRegister());
2752 } else {
2753 InvokeRuntimeCallingConvention calling_convention;
2754 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2755 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2756 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2757 // we only need the latter.
2758 locations->SetOut(Location::RegisterLocation(R1));
2759 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002760 break;
2761 }
2762 case Primitive::kPrimLong: {
2763 InvokeRuntimeCallingConvention calling_convention;
2764 locations->SetInAt(0, Location::RegisterPairLocation(
2765 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2766 locations->SetInAt(1, Location::RegisterPairLocation(
2767 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2768 // The runtime helper puts the output in R2,R3.
2769 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2770 break;
2771 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002772 case Primitive::kPrimFloat: {
2773 InvokeRuntimeCallingConvention calling_convention;
2774 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2775 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2776 locations->SetOut(Location::FpuRegisterLocation(S0));
2777 break;
2778 }
2779
Calin Juravlebacfec32014-11-14 15:54:36 +00002780 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002781 InvokeRuntimeCallingConvention calling_convention;
2782 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2783 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2784 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2785 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2786 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002787 break;
2788 }
2789
2790 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002791 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002792 }
2793}
2794
2795void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2796 LocationSummary* locations = rem->GetLocations();
2797 Location out = locations->Out();
2798 Location first = locations->InAt(0);
2799 Location second = locations->InAt(1);
2800
Calin Juravled2ec87d2014-12-08 14:24:46 +00002801 Primitive::Type type = rem->GetResultType();
2802 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002803 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002804 if (second.IsConstant()) {
2805 GenerateDivRemConstantIntegral(rem);
2806 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002807 Register reg1 = first.AsRegister<Register>();
2808 Register reg2 = second.AsRegister<Register>();
2809 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002810
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002811 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002812 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002813 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002814 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002815 } else {
2816 InvokeRuntimeCallingConvention calling_convention;
2817 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2818 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2819 DCHECK_EQ(R1, out.AsRegister<Register>());
2820
2821 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2822 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002823 break;
2824 }
2825
2826 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002827 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002828 break;
2829 }
2830
Calin Juravled2ec87d2014-12-08 14:24:46 +00002831 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002832 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002833 break;
2834 }
2835
Calin Juravlebacfec32014-11-14 15:54:36 +00002836 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002837 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002838 break;
2839 }
2840
2841 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002842 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002843 }
2844}
2845
Calin Juravled0d48522014-11-04 16:40:20 +00002846void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00002847 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2848 ? LocationSummary::kCallOnSlowPath
2849 : LocationSummary::kNoCall;
2850 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002851 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002852 if (instruction->HasUses()) {
2853 locations->SetOut(Location::SameAsFirstInput());
2854 }
2855}
2856
2857void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07002858 SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
Calin Juravled0d48522014-11-04 16:40:20 +00002859 codegen_->AddSlowPath(slow_path);
2860
2861 LocationSummary* locations = instruction->GetLocations();
2862 Location value = locations->InAt(0);
2863
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002864 switch (instruction->GetType()) {
Serguei Katkov8c0676c2015-08-03 13:55:33 +06002865 case Primitive::kPrimByte:
2866 case Primitive::kPrimChar:
2867 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002868 case Primitive::kPrimInt: {
2869 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01002870 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002871 } else {
2872 DCHECK(value.IsConstant()) << value;
2873 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2874 __ b(slow_path->GetEntryLabel());
2875 }
2876 }
2877 break;
2878 }
2879 case Primitive::kPrimLong: {
2880 if (value.IsRegisterPair()) {
2881 __ orrs(IP,
2882 value.AsRegisterPairLow<Register>(),
2883 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2884 __ b(slow_path->GetEntryLabel(), EQ);
2885 } else {
2886 DCHECK(value.IsConstant()) << value;
2887 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2888 __ b(slow_path->GetEntryLabel());
2889 }
2890 }
2891 break;
2892 default:
2893 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2894 }
2895 }
Calin Juravled0d48522014-11-04 16:40:20 +00002896}
2897
Calin Juravle9aec02f2014-11-18 23:06:35 +00002898void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2899 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2900
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002901 LocationSummary* locations =
2902 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002903
2904 switch (op->GetResultType()) {
2905 case Primitive::kPrimInt: {
2906 locations->SetInAt(0, Location::RequiresRegister());
2907 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002908 // Make the output overlap, as it will be used to hold the masked
2909 // second input.
2910 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002911 break;
2912 }
2913 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002914 locations->SetInAt(0, Location::RequiresRegister());
2915 locations->SetInAt(1, Location::RequiresRegister());
2916 locations->AddTemp(Location::RequiresRegister());
2917 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002918 break;
2919 }
2920 default:
2921 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2922 }
2923}
2924
2925void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2926 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2927
2928 LocationSummary* locations = op->GetLocations();
2929 Location out = locations->Out();
2930 Location first = locations->InAt(0);
2931 Location second = locations->InAt(1);
2932
2933 Primitive::Type type = op->GetResultType();
2934 switch (type) {
2935 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002936 Register out_reg = out.AsRegister<Register>();
2937 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002938 // Arm doesn't mask the shift count so we need to do it ourselves.
2939 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002940 Register second_reg = second.AsRegister<Register>();
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002941 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002942 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002943 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002944 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002945 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002946 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002947 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002948 }
2949 } else {
2950 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2951 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2952 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2953 __ Mov(out_reg, first_reg);
2954 } else if (op->IsShl()) {
2955 __ Lsl(out_reg, first_reg, shift_value);
2956 } else if (op->IsShr()) {
2957 __ Asr(out_reg, first_reg, shift_value);
2958 } else {
2959 __ Lsr(out_reg, first_reg, shift_value);
2960 }
2961 }
2962 break;
2963 }
2964 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002965 Register o_h = out.AsRegisterPairHigh<Register>();
2966 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002967
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002968 Register temp = locations->GetTemp(0).AsRegister<Register>();
2969
2970 Register high = first.AsRegisterPairHigh<Register>();
2971 Register low = first.AsRegisterPairLow<Register>();
2972
2973 Register second_reg = second.AsRegister<Register>();
2974
Calin Juravle9aec02f2014-11-18 23:06:35 +00002975 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002976 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002977 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002978 __ Lsl(o_h, high, o_l);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002979 // Shift the low part and `or` what overflew on the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002980 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002981 __ Lsr(temp, low, temp);
2982 __ orr(o_h, o_h, ShifterOperand(temp));
2983 // If the shift is > 32 bits, override the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002984 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002985 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002986 __ Lsl(o_h, low, temp, PL);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002987 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002988 __ Lsl(o_l, low, o_l);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002989 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002990 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002991 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002992 __ Lsr(o_l, low, o_h);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002993 // Shift the high part and `or` what underflew on the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002994 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002995 __ Lsl(temp, high, temp);
2996 __ orr(o_l, o_l, ShifterOperand(temp));
2997 // If the shift is > 32 bits, override the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002998 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002999 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003000 __ Asr(o_l, high, temp, PL);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003001 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003002 __ Asr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003003 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003004 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003005 // same as Shr except we use `Lsr`s and not `Asr`s
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003006 __ Lsr(o_l, low, o_h);
3007 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003008 __ Lsl(temp, high, temp);
3009 __ orr(o_l, o_l, ShifterOperand(temp));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003010 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003011 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003012 __ Lsr(o_l, high, temp, PL);
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003013 __ Lsr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003014 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003015 break;
3016 }
3017 default:
3018 LOG(FATAL) << "Unexpected operation type " << type;
3019 }
3020}
3021
3022void LocationsBuilderARM::VisitShl(HShl* shl) {
3023 HandleShift(shl);
3024}
3025
3026void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
3027 HandleShift(shl);
3028}
3029
3030void LocationsBuilderARM::VisitShr(HShr* shr) {
3031 HandleShift(shr);
3032}
3033
3034void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
3035 HandleShift(shr);
3036}
3037
3038void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
3039 HandleShift(ushr);
3040}
3041
3042void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
3043 HandleShift(ushr);
3044}
3045
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003046void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003047 LocationSummary* locations =
3048 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01003049 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003050 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003051 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003052 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003053}
3054
3055void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
3056 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003057 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003058 // Note: if heap poisoning is enabled, the entry point takes cares
3059 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01003060 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003061 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003062 instruction->GetDexPc(),
3063 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003064}
3065
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003066void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3067 LocationSummary* locations =
3068 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3069 InvokeRuntimeCallingConvention calling_convention;
3070 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003071 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003072 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003073 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003074}
3075
3076void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3077 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003078 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003079 // Note: if heap poisoning is enabled, the entry point takes cares
3080 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01003081 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003082 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003083 instruction->GetDexPc(),
3084 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003085}
3086
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003087void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003088 LocationSummary* locations =
3089 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003090 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3091 if (location.IsStackSlot()) {
3092 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3093 } else if (location.IsDoubleStackSlot()) {
3094 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003095 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003096 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003097}
3098
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003099void InstructionCodeGeneratorARM::VisitParameterValue(
3100 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003101 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003102}
3103
3104void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3105 LocationSummary* locations =
3106 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3107 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3108}
3109
3110void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3111 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003112}
3113
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003114void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003115 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003116 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003117 locations->SetInAt(0, Location::RequiresRegister());
3118 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003119}
3120
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003121void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3122 LocationSummary* locations = not_->GetLocations();
3123 Location out = locations->Out();
3124 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003125 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003126 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003127 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003128 break;
3129
3130 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003131 __ mvn(out.AsRegisterPairLow<Register>(),
3132 ShifterOperand(in.AsRegisterPairLow<Register>()));
3133 __ mvn(out.AsRegisterPairHigh<Register>(),
3134 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003135 break;
3136
3137 default:
3138 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3139 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003140}
3141
David Brazdil66d126e2015-04-03 16:02:44 +01003142void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3143 LocationSummary* locations =
3144 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3145 locations->SetInAt(0, Location::RequiresRegister());
3146 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3147}
3148
3149void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003150 LocationSummary* locations = bool_not->GetLocations();
3151 Location out = locations->Out();
3152 Location in = locations->InAt(0);
3153 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3154}
3155
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003156void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003157 LocationSummary* locations =
3158 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003159 switch (compare->InputAt(0)->GetType()) {
3160 case Primitive::kPrimLong: {
3161 locations->SetInAt(0, Location::RequiresRegister());
3162 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003163 // Output overlaps because it is written before doing the low comparison.
3164 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003165 break;
3166 }
3167 case Primitive::kPrimFloat:
3168 case Primitive::kPrimDouble: {
3169 locations->SetInAt(0, Location::RequiresFpuRegister());
3170 locations->SetInAt(1, Location::RequiresFpuRegister());
3171 locations->SetOut(Location::RequiresRegister());
3172 break;
3173 }
3174 default:
3175 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3176 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003177}
3178
3179void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003180 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003181 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003182 Location left = locations->InAt(0);
3183 Location right = locations->InAt(1);
3184
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003185 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003186 Primitive::Type type = compare->InputAt(0)->GetType();
3187 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003188 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003189 __ cmp(left.AsRegisterPairHigh<Register>(),
3190 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003191 __ b(&less, LT);
3192 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003193 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003194 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003195 __ cmp(left.AsRegisterPairLow<Register>(),
3196 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00003197 break;
3198 }
3199 case Primitive::kPrimFloat:
3200 case Primitive::kPrimDouble: {
3201 __ LoadImmediate(out, 0);
3202 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003203 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00003204 } else {
3205 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
3206 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
3207 }
3208 __ vmstat(); // transfer FP status register to ARM APSR.
3209 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003210 break;
3211 }
3212 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003213 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003214 }
Calin Juravleddb7df22014-11-25 20:56:51 +00003215 __ b(&done, EQ);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003216 __ b(&less, LO); // LO is for both: unsigned compare for longs and 'less than' for floats.
Calin Juravleddb7df22014-11-25 20:56:51 +00003217
3218 __ Bind(&greater);
3219 __ LoadImmediate(out, 1);
3220 __ b(&done);
3221
3222 __ Bind(&less);
3223 __ LoadImmediate(out, -1);
3224
3225 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003226}
3227
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003228void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003229 LocationSummary* locations =
3230 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003231 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
3232 locations->SetInAt(i, Location::Any());
3233 }
3234 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003235}
3236
3237void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003238 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003239 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003240}
3241
Calin Juravle52c48962014-12-16 17:02:57 +00003242void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3243 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07003244 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00003245 switch (kind) {
3246 case MemBarrierKind::kAnyStore:
3247 case MemBarrierKind::kLoadAny:
3248 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003249 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003250 break;
3251 }
3252 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003253 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003254 break;
3255 }
3256 default:
3257 LOG(FATAL) << "Unexpected memory barrier " << kind;
3258 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003259 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003260}
3261
3262void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3263 uint32_t offset,
3264 Register out_lo,
3265 Register out_hi) {
3266 if (offset != 0) {
3267 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003268 __ add(IP, addr, ShifterOperand(out_lo));
3269 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003270 }
3271 __ ldrexd(out_lo, out_hi, addr);
3272}
3273
3274void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3275 uint32_t offset,
3276 Register value_lo,
3277 Register value_hi,
3278 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003279 Register temp2,
3280 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003281 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003282 if (offset != 0) {
3283 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003284 __ add(IP, addr, ShifterOperand(temp1));
3285 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003286 }
3287 __ Bind(&fail);
3288 // We need a load followed by store. (The address used in a STREX instruction must
3289 // be the same as the address in the most recently executed LDREX instruction.)
3290 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003291 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003292 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003293 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003294}
3295
3296void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3297 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3298
Nicolas Geoffray39468442014-09-02 15:17:15 +01003299 LocationSummary* locations =
3300 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003301 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003302
Calin Juravle52c48962014-12-16 17:02:57 +00003303 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003304 if (Primitive::IsFloatingPointType(field_type)) {
3305 locations->SetInAt(1, Location::RequiresFpuRegister());
3306 } else {
3307 locations->SetInAt(1, Location::RequiresRegister());
3308 }
3309
Calin Juravle52c48962014-12-16 17:02:57 +00003310 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003311 bool generate_volatile = field_info.IsVolatile()
3312 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003313 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003314 bool needs_write_barrier =
3315 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003316 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003317 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003318 if (needs_write_barrier) {
3319 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003320 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003321 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003322 // Arm encoding have some additional constraints for ldrexd/strexd:
3323 // - registers need to be consecutive
3324 // - the first register should be even but not R14.
3325 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3326 // enable Arm encoding.
3327 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3328
3329 locations->AddTemp(Location::RequiresRegister());
3330 locations->AddTemp(Location::RequiresRegister());
3331 if (field_type == Primitive::kPrimDouble) {
3332 // For doubles we need two more registers to copy the value.
3333 locations->AddTemp(Location::RegisterLocation(R2));
3334 locations->AddTemp(Location::RegisterLocation(R3));
3335 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003336 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003337}
3338
Calin Juravle52c48962014-12-16 17:02:57 +00003339void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003340 const FieldInfo& field_info,
3341 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003342 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3343
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003344 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003345 Register base = locations->InAt(0).AsRegister<Register>();
3346 Location value = locations->InAt(1);
3347
3348 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003349 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003350 Primitive::Type field_type = field_info.GetFieldType();
3351 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003352 bool needs_write_barrier =
3353 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003354
3355 if (is_volatile) {
3356 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3357 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003358
3359 switch (field_type) {
3360 case Primitive::kPrimBoolean:
3361 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003362 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003363 break;
3364 }
3365
3366 case Primitive::kPrimShort:
3367 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003368 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003369 break;
3370 }
3371
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003372 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003373 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003374 if (kPoisonHeapReferences && needs_write_barrier) {
3375 // Note that in the case where `value` is a null reference,
3376 // we do not enter this block, as a null reference does not
3377 // need poisoning.
3378 DCHECK_EQ(field_type, Primitive::kPrimNot);
3379 Register temp = locations->GetTemp(0).AsRegister<Register>();
3380 __ Mov(temp, value.AsRegister<Register>());
3381 __ PoisonHeapReference(temp);
3382 __ StoreToOffset(kStoreWord, temp, base, offset);
3383 } else {
3384 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3385 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003386 break;
3387 }
3388
3389 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003390 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003391 GenerateWideAtomicStore(base, offset,
3392 value.AsRegisterPairLow<Register>(),
3393 value.AsRegisterPairHigh<Register>(),
3394 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003395 locations->GetTemp(1).AsRegister<Register>(),
3396 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003397 } else {
3398 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003399 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003400 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003401 break;
3402 }
3403
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003404 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003405 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003406 break;
3407 }
3408
3409 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003410 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003411 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003412 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3413 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3414
3415 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3416
3417 GenerateWideAtomicStore(base, offset,
3418 value_reg_lo,
3419 value_reg_hi,
3420 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003421 locations->GetTemp(3).AsRegister<Register>(),
3422 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003423 } else {
3424 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003425 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003426 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003427 break;
3428 }
3429
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003430 case Primitive::kPrimVoid:
3431 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003432 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003433 }
Calin Juravle52c48962014-12-16 17:02:57 +00003434
Calin Juravle77520bc2015-01-12 18:45:46 +00003435 // Longs and doubles are handled in the switch.
3436 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3437 codegen_->MaybeRecordImplicitNullCheck(instruction);
3438 }
3439
3440 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3441 Register temp = locations->GetTemp(0).AsRegister<Register>();
3442 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003443 codegen_->MarkGCCard(
3444 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003445 }
3446
Calin Juravle52c48962014-12-16 17:02:57 +00003447 if (is_volatile) {
3448 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3449 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003450}
3451
Calin Juravle52c48962014-12-16 17:02:57 +00003452void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3453 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003454 LocationSummary* locations =
3455 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003456 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003457
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003458 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003459 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003460 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003461 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003462
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003463 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3464 locations->SetOut(Location::RequiresFpuRegister());
3465 } else {
3466 locations->SetOut(Location::RequiresRegister(),
3467 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3468 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003469 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003470 // Arm encoding have some additional constraints for ldrexd/strexd:
3471 // - registers need to be consecutive
3472 // - the first register should be even but not R14.
3473 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3474 // enable Arm encoding.
3475 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3476 locations->AddTemp(Location::RequiresRegister());
3477 locations->AddTemp(Location::RequiresRegister());
3478 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003479}
3480
Calin Juravle52c48962014-12-16 17:02:57 +00003481void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3482 const FieldInfo& field_info) {
3483 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003484
Calin Juravle52c48962014-12-16 17:02:57 +00003485 LocationSummary* locations = instruction->GetLocations();
3486 Register base = locations->InAt(0).AsRegister<Register>();
3487 Location out = locations->Out();
3488 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003489 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003490 Primitive::Type field_type = field_info.GetFieldType();
3491 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3492
3493 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003494 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003495 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003496 break;
3497 }
3498
3499 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003500 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003501 break;
3502 }
3503
3504 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003505 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003506 break;
3507 }
3508
3509 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003510 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003511 break;
3512 }
3513
3514 case Primitive::kPrimInt:
3515 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003516 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003517 break;
3518 }
3519
3520 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003521 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003522 GenerateWideAtomicLoad(base, offset,
3523 out.AsRegisterPairLow<Register>(),
3524 out.AsRegisterPairHigh<Register>());
3525 } else {
3526 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3527 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003528 break;
3529 }
3530
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003531 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003532 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003533 break;
3534 }
3535
3536 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003537 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003538 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003539 Register lo = locations->GetTemp(0).AsRegister<Register>();
3540 Register hi = locations->GetTemp(1).AsRegister<Register>();
3541 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003542 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003543 __ vmovdrr(out_reg, lo, hi);
3544 } else {
3545 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003546 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003547 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003548 break;
3549 }
3550
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003551 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003552 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003553 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003554 }
Calin Juravle52c48962014-12-16 17:02:57 +00003555
Calin Juravle77520bc2015-01-12 18:45:46 +00003556 // Doubles are handled in the switch.
3557 if (field_type != Primitive::kPrimDouble) {
3558 codegen_->MaybeRecordImplicitNullCheck(instruction);
3559 }
3560
Calin Juravle52c48962014-12-16 17:02:57 +00003561 if (is_volatile) {
3562 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3563 }
Roland Levillain4d027112015-07-01 15:41:14 +01003564
3565 if (field_type == Primitive::kPrimNot) {
3566 __ MaybeUnpoisonHeapReference(out.AsRegister<Register>());
3567 }
Calin Juravle52c48962014-12-16 17:02:57 +00003568}
3569
3570void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3571 HandleFieldSet(instruction, instruction->GetFieldInfo());
3572}
3573
3574void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003575 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003576}
3577
3578void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3579 HandleFieldGet(instruction, instruction->GetFieldInfo());
3580}
3581
3582void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3583 HandleFieldGet(instruction, instruction->GetFieldInfo());
3584}
3585
3586void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3587 HandleFieldGet(instruction, instruction->GetFieldInfo());
3588}
3589
3590void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3591 HandleFieldGet(instruction, instruction->GetFieldInfo());
3592}
3593
3594void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3595 HandleFieldSet(instruction, instruction->GetFieldInfo());
3596}
3597
3598void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003599 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003600}
3601
3602void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003603 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3604 ? LocationSummary::kCallOnSlowPath
3605 : LocationSummary::kNoCall;
3606 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravle77520bc2015-01-12 18:45:46 +00003607 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003608 if (instruction->HasUses()) {
3609 locations->SetOut(Location::SameAsFirstInput());
3610 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003611}
3612
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003613void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003614 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3615 return;
3616 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003617 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003618
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003619 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3620 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3621}
3622
3623void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07003624 SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003625 codegen_->AddSlowPath(slow_path);
3626
3627 LocationSummary* locations = instruction->GetLocations();
3628 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003629
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003630 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003631}
3632
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003633void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003634 if (codegen_->IsImplicitNullCheckAllowed(instruction)) {
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003635 GenerateImplicitNullCheck(instruction);
3636 } else {
3637 GenerateExplicitNullCheck(instruction);
3638 }
3639}
3640
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003641void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003642 LocationSummary* locations =
3643 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003644 locations->SetInAt(0, Location::RequiresRegister());
3645 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003646 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3647 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3648 } else {
3649 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3650 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003651}
3652
3653void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3654 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003655 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003656 Location index = locations->InAt(1);
Roland Levillain4d027112015-07-01 15:41:14 +01003657 Primitive::Type type = instruction->GetType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003658
Roland Levillain4d027112015-07-01 15:41:14 +01003659 switch (type) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003660 case Primitive::kPrimBoolean: {
3661 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003662 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003663 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003664 size_t offset =
3665 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003666 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3667 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003668 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003669 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3670 }
3671 break;
3672 }
3673
3674 case Primitive::kPrimByte: {
3675 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003676 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003677 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003678 size_t offset =
3679 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003680 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3681 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003682 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003683 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3684 }
3685 break;
3686 }
3687
3688 case Primitive::kPrimShort: {
3689 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003690 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003691 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003692 size_t offset =
3693 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003694 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3695 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003696 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003697 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3698 }
3699 break;
3700 }
3701
3702 case Primitive::kPrimChar: {
3703 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003704 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003705 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003706 size_t offset =
3707 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003708 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3709 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003710 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003711 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3712 }
3713 break;
3714 }
3715
3716 case Primitive::kPrimInt:
3717 case Primitive::kPrimNot: {
Roland Levillain33d69032015-06-18 18:20:59 +01003718 static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
3719 "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003720 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003721 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003722 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003723 size_t offset =
3724 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003725 __ LoadFromOffset(kLoadWord, out, obj, offset);
3726 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003727 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003728 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3729 }
3730 break;
3731 }
3732
3733 case Primitive::kPrimLong: {
3734 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003735 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003736 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003737 size_t offset =
3738 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003739 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003740 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003741 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003742 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003743 }
3744 break;
3745 }
3746
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003747 case Primitive::kPrimFloat: {
3748 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3749 Location out = locations->Out();
3750 DCHECK(out.IsFpuRegister());
3751 if (index.IsConstant()) {
3752 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3753 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3754 } else {
3755 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3756 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3757 }
3758 break;
3759 }
3760
3761 case Primitive::kPrimDouble: {
3762 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3763 Location out = locations->Out();
3764 DCHECK(out.IsFpuRegisterPair());
3765 if (index.IsConstant()) {
3766 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3767 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3768 } else {
3769 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3770 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3771 }
3772 break;
3773 }
3774
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003775 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01003776 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003777 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003778 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003779 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01003780
3781 if (type == Primitive::kPrimNot) {
3782 Register out = locations->Out().AsRegister<Register>();
3783 __ MaybeUnpoisonHeapReference(out);
3784 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003785}
3786
3787void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003788 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003789
3790 bool needs_write_barrier =
3791 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003792 bool may_need_runtime_call = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003793
Nicolas Geoffray39468442014-09-02 15:17:15 +01003794 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003795 instruction,
3796 may_need_runtime_call ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall);
3797 locations->SetInAt(0, Location::RequiresRegister());
3798 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3799 if (Primitive::IsFloatingPointType(value_type)) {
3800 locations->SetInAt(2, Location::RequiresFpuRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003801 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003802 locations->SetInAt(2, Location::RequiresRegister());
3803 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003804
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003805 if (needs_write_barrier) {
3806 // Temporary registers for the write barrier.
3807 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
3808 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003809 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003810}
3811
3812void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3813 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003814 Register array = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003815 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003816 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003817 bool may_need_runtime_call = locations->CanCall();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003818 bool needs_write_barrier =
3819 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003820
3821 switch (value_type) {
3822 case Primitive::kPrimBoolean:
3823 case Primitive::kPrimByte: {
3824 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003825 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003826 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003827 size_t offset =
3828 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003829 __ StoreToOffset(kStoreByte, value, array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003830 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003831 __ add(IP, array, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003832 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3833 }
3834 break;
3835 }
3836
3837 case Primitive::kPrimShort:
3838 case Primitive::kPrimChar: {
3839 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003840 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003841 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003842 size_t offset =
3843 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003844 __ StoreToOffset(kStoreHalfword, value, array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003845 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003846 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003847 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3848 }
3849 break;
3850 }
3851
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003852 case Primitive::kPrimNot: {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003853 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
3854 Register value = locations->InAt(2).AsRegister<Register>();
3855 Register source = value;
3856
3857 if (instruction->InputAt(2)->IsNullConstant()) {
3858 // Just setting null.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003859 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003860 size_t offset =
3861 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003862 __ StoreToOffset(kStoreWord, source, array, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003863 } else {
3864 DCHECK(index.IsRegister()) << index;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003865 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillain4d027112015-07-01 15:41:14 +01003866 __ StoreToOffset(kStoreWord, source, IP, data_offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003867 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003868 break;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003869 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003870
3871 DCHECK(needs_write_barrier);
3872 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
3873 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
3874 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3875 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
3876 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
3877 Label done;
3878 SlowPathCode* slow_path = nullptr;
3879
3880 if (may_need_runtime_call) {
3881 slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction);
3882 codegen_->AddSlowPath(slow_path);
3883 if (instruction->GetValueCanBeNull()) {
3884 Label non_zero;
3885 __ CompareAndBranchIfNonZero(value, &non_zero);
3886 if (index.IsConstant()) {
3887 size_t offset =
3888 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3889 __ StoreToOffset(kStoreWord, value, array, offset);
3890 } else {
3891 DCHECK(index.IsRegister()) << index;
3892 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3893 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3894 }
3895 codegen_->MaybeRecordImplicitNullCheck(instruction);
3896 __ b(&done);
3897 __ Bind(&non_zero);
3898 }
3899
3900 __ LoadFromOffset(kLoadWord, temp1, array, class_offset);
3901 codegen_->MaybeRecordImplicitNullCheck(instruction);
3902 __ MaybeUnpoisonHeapReference(temp1);
3903 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
3904 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
3905 // No need to poison/unpoison, we're comparing two poisoined references.
3906 __ cmp(temp1, ShifterOperand(temp2));
3907 if (instruction->StaticTypeOfArrayIsObjectArray()) {
3908 Label do_put;
3909 __ b(&do_put, EQ);
3910 __ MaybeUnpoisonHeapReference(temp1);
3911 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
3912 // No need to poison/unpoison, we're comparing against null.
3913 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
3914 __ Bind(&do_put);
3915 } else {
3916 __ b(slow_path->GetEntryLabel(), NE);
3917 }
3918 }
3919
3920 if (kPoisonHeapReferences) {
3921 // Note that in the case where `value` is a null reference,
3922 // we do not enter this block, as a null reference does not
3923 // need poisoning.
3924 DCHECK_EQ(value_type, Primitive::kPrimNot);
3925 __ Mov(temp1, value);
3926 __ PoisonHeapReference(temp1);
3927 source = temp1;
3928 }
3929
3930 if (index.IsConstant()) {
3931 size_t offset =
3932 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3933 __ StoreToOffset(kStoreWord, source, array, offset);
3934 } else {
3935 DCHECK(index.IsRegister()) << index;
3936 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3937 __ StoreToOffset(kStoreWord, source, IP, data_offset);
3938 }
3939
3940 if (!may_need_runtime_call) {
3941 codegen_->MaybeRecordImplicitNullCheck(instruction);
3942 }
3943
3944 codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull());
3945
3946 if (done.IsLinked()) {
3947 __ Bind(&done);
3948 }
3949
3950 if (slow_path != nullptr) {
3951 __ Bind(slow_path->GetExitLabel());
3952 }
3953
3954 break;
3955 }
3956
3957 case Primitive::kPrimInt: {
3958 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
3959 Register value = locations->InAt(2).AsRegister<Register>();
3960 if (index.IsConstant()) {
3961 size_t offset =
3962 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3963 __ StoreToOffset(kStoreWord, value, array, offset);
3964 } else {
3965 DCHECK(index.IsRegister()) << index;
3966 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3967 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3968 }
3969
3970 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003971 break;
3972 }
3973
3974 case Primitive::kPrimLong: {
3975 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003976 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003977 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003978 size_t offset =
3979 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003980 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003981 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003982 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003983 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003984 }
3985 break;
3986 }
3987
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003988 case Primitive::kPrimFloat: {
3989 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3990 Location value = locations->InAt(2);
3991 DCHECK(value.IsFpuRegister());
3992 if (index.IsConstant()) {
3993 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003994 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003995 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003996 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003997 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3998 }
3999 break;
4000 }
4001
4002 case Primitive::kPrimDouble: {
4003 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
4004 Location value = locations->InAt(2);
4005 DCHECK(value.IsFpuRegisterPair());
4006 if (index.IsConstant()) {
4007 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004008 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004009 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004010 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004011 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
4012 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004013
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004014 break;
4015 }
4016
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004017 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004018 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004019 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004020 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004021
4022 // Ints and objects are handled in the switch.
4023 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
4024 codegen_->MaybeRecordImplicitNullCheck(instruction);
4025 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004026}
4027
4028void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004029 LocationSummary* locations =
4030 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004031 locations->SetInAt(0, Location::RequiresRegister());
4032 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004033}
4034
4035void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
4036 LocationSummary* locations = instruction->GetLocations();
4037 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004038 Register obj = locations->InAt(0).AsRegister<Register>();
4039 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004040 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004041 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004042}
4043
4044void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004045 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4046 ? LocationSummary::kCallOnSlowPath
4047 : LocationSummary::kNoCall;
4048 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004049 locations->SetInAt(0, Location::RequiresRegister());
4050 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004051 if (instruction->HasUses()) {
4052 locations->SetOut(Location::SameAsFirstInput());
4053 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004054}
4055
4056void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
4057 LocationSummary* locations = instruction->GetLocations();
Andreas Gampe85b62f22015-09-09 13:15:38 -07004058 SlowPathCode* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004059 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004060 codegen_->AddSlowPath(slow_path);
4061
Roland Levillain271ab9c2014-11-27 15:23:57 +00004062 Register index = locations->InAt(0).AsRegister<Register>();
4063 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004064
4065 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01004066 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004067}
4068
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004069void CodeGeneratorARM::MarkGCCard(Register temp,
4070 Register card,
4071 Register object,
4072 Register value,
4073 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004074 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004075 if (can_be_null) {
4076 __ CompareAndBranchIfZero(value, &is_null);
4077 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004078 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
4079 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
4080 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004081 if (can_be_null) {
4082 __ Bind(&is_null);
4083 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004084}
4085
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004086void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
4087 temp->SetLocations(nullptr);
4088}
4089
4090void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
4091 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07004092 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004093}
4094
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004095void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07004096 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004097 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004098}
4099
4100void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004101 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
4102}
4103
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004104void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
4105 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
4106}
4107
4108void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004109 HBasicBlock* block = instruction->GetBlock();
4110 if (block->GetLoopInformation() != nullptr) {
4111 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
4112 // The back edge will generate the suspend check.
4113 return;
4114 }
4115 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
4116 // The goto will generate the suspend check.
4117 return;
4118 }
4119 GenerateSuspendCheck(instruction, nullptr);
4120}
4121
4122void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
4123 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004124 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01004125 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
4126 if (slow_path == nullptr) {
4127 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
4128 instruction->SetSlowPath(slow_path);
4129 codegen_->AddSlowPath(slow_path);
4130 if (successor != nullptr) {
4131 DCHECK(successor->IsLoopHeader());
4132 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
4133 }
4134 } else {
4135 DCHECK_EQ(slow_path->GetSuccessor(), successor);
4136 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004137
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00004138 __ LoadFromOffset(
4139 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004140 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004141 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004142 __ Bind(slow_path->GetReturnLabel());
4143 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004144 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004145 __ b(slow_path->GetEntryLabel());
4146 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004147}
4148
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004149ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
4150 return codegen_->GetAssembler();
4151}
4152
4153void ParallelMoveResolverARM::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01004154 DCHECK_LT(index, moves_.size());
4155 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004156 Location source = move->GetSource();
4157 Location destination = move->GetDestination();
4158
4159 if (source.IsRegister()) {
4160 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004161 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004162 } else {
4163 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00004164 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004165 SP, destination.GetStackIndex());
4166 }
4167 } else if (source.IsStackSlot()) {
4168 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004169 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004170 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004171 } else if (destination.IsFpuRegister()) {
4172 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004173 } else {
4174 DCHECK(destination.IsStackSlot());
4175 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
4176 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4177 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004178 } else if (source.IsFpuRegister()) {
4179 if (destination.IsFpuRegister()) {
4180 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004181 } else {
4182 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004183 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
4184 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004185 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004186 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004187 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
4188 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004189 } else if (destination.IsRegisterPair()) {
4190 DCHECK(ExpectedPairLayout(destination));
4191 __ LoadFromOffset(
4192 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
4193 } else {
4194 DCHECK(destination.IsFpuRegisterPair()) << destination;
4195 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4196 SP,
4197 source.GetStackIndex());
4198 }
4199 } else if (source.IsRegisterPair()) {
4200 if (destination.IsRegisterPair()) {
4201 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
4202 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
4203 } else {
4204 DCHECK(destination.IsDoubleStackSlot()) << destination;
4205 DCHECK(ExpectedPairLayout(source));
4206 __ StoreToOffset(
4207 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
4208 }
4209 } else if (source.IsFpuRegisterPair()) {
4210 if (destination.IsFpuRegisterPair()) {
4211 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4212 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
4213 } else {
4214 DCHECK(destination.IsDoubleStackSlot()) << destination;
4215 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
4216 SP,
4217 destination.GetStackIndex());
4218 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004219 } else {
4220 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00004221 HConstant* constant = source.GetConstant();
4222 if (constant->IsIntConstant() || constant->IsNullConstant()) {
4223 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004224 if (destination.IsRegister()) {
4225 __ LoadImmediate(destination.AsRegister<Register>(), value);
4226 } else {
4227 DCHECK(destination.IsStackSlot());
4228 __ LoadImmediate(IP, value);
4229 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4230 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004231 } else if (constant->IsLongConstant()) {
4232 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004233 if (destination.IsRegisterPair()) {
4234 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
4235 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004236 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004237 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004238 __ LoadImmediate(IP, Low32Bits(value));
4239 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4240 __ LoadImmediate(IP, High32Bits(value));
4241 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4242 }
4243 } else if (constant->IsDoubleConstant()) {
4244 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004245 if (destination.IsFpuRegisterPair()) {
4246 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004247 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004248 DCHECK(destination.IsDoubleStackSlot()) << destination;
4249 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004250 __ LoadImmediate(IP, Low32Bits(int_value));
4251 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4252 __ LoadImmediate(IP, High32Bits(int_value));
4253 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4254 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004255 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004256 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004257 float value = constant->AsFloatConstant()->GetValue();
4258 if (destination.IsFpuRegister()) {
4259 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
4260 } else {
4261 DCHECK(destination.IsStackSlot());
4262 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
4263 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4264 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004265 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004266 }
4267}
4268
4269void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
4270 __ Mov(IP, reg);
4271 __ LoadFromOffset(kLoadWord, reg, SP, mem);
4272 __ StoreToOffset(kStoreWord, IP, SP, mem);
4273}
4274
4275void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
4276 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
4277 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
4278 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
4279 SP, mem1 + stack_offset);
4280 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
4281 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
4282 SP, mem2 + stack_offset);
4283 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
4284}
4285
4286void ParallelMoveResolverARM::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01004287 DCHECK_LT(index, moves_.size());
4288 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004289 Location source = move->GetSource();
4290 Location destination = move->GetDestination();
4291
4292 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004293 DCHECK_NE(source.AsRegister<Register>(), IP);
4294 DCHECK_NE(destination.AsRegister<Register>(), IP);
4295 __ Mov(IP, source.AsRegister<Register>());
4296 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
4297 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004298 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004299 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004300 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004301 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004302 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
4303 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004304 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004305 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004306 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004307 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004308 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004309 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004310 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004311 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004312 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
4313 destination.AsRegisterPairHigh<Register>(),
4314 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004315 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004316 Register low_reg = source.IsRegisterPair()
4317 ? source.AsRegisterPairLow<Register>()
4318 : destination.AsRegisterPairLow<Register>();
4319 int mem = source.IsRegisterPair()
4320 ? destination.GetStackIndex()
4321 : source.GetStackIndex();
4322 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004323 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004324 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004325 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004326 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004327 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
4328 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004329 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004330 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004331 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004332 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
4333 DRegister reg = source.IsFpuRegisterPair()
4334 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
4335 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
4336 int mem = source.IsFpuRegisterPair()
4337 ? destination.GetStackIndex()
4338 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004339 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004340 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004341 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004342 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
4343 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
4344 : destination.AsFpuRegister<SRegister>();
4345 int mem = source.IsFpuRegister()
4346 ? destination.GetStackIndex()
4347 : source.GetStackIndex();
4348
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004349 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004350 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004351 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004352 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004353 Exchange(source.GetStackIndex(), destination.GetStackIndex());
4354 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004355 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004356 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004357 }
4358}
4359
4360void ParallelMoveResolverARM::SpillScratch(int reg) {
4361 __ Push(static_cast<Register>(reg));
4362}
4363
4364void ParallelMoveResolverARM::RestoreScratch(int reg) {
4365 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004366}
4367
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004368void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004369 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
4370 ? LocationSummary::kCallOnSlowPath
4371 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004372 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004373 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004374 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004375 locations->SetOut(Location::RequiresRegister());
4376}
4377
4378void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004379 LocationSummary* locations = cls->GetLocations();
4380 Register out = locations->Out().AsRegister<Register>();
4381 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004382 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004383 DCHECK(!cls->CanCallRuntime());
4384 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004385 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004386 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004387 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004388 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004389 __ LoadFromOffset(kLoadWord,
4390 out,
4391 current_method,
Vladimir Marko05792b92015-08-03 11:56:49 +01004392 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004393 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01004394 // TODO: We will need a read barrier here.
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004395
Andreas Gampe85b62f22015-09-09 13:15:38 -07004396 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004397 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4398 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004399 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004400 if (cls->MustGenerateClinitCheck()) {
4401 GenerateClassInitializationCheck(slow_path, out);
4402 } else {
4403 __ Bind(slow_path->GetExitLabel());
4404 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004405 }
4406}
4407
4408void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
4409 LocationSummary* locations =
4410 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
4411 locations->SetInAt(0, Location::RequiresRegister());
4412 if (check->HasUses()) {
4413 locations->SetOut(Location::SameAsFirstInput());
4414 }
4415}
4416
4417void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004418 // We assume the class is not null.
Andreas Gampe85b62f22015-09-09 13:15:38 -07004419 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004420 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004421 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004422 GenerateClassInitializationCheck(slow_path,
4423 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004424}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004425
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004426void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
Andreas Gampe85b62f22015-09-09 13:15:38 -07004427 SlowPathCode* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004428 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4429 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4430 __ b(slow_path->GetEntryLabel(), LT);
4431 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4432 // properly. Therefore, we do a memory fence.
4433 __ dmb(ISH);
4434 __ Bind(slow_path->GetExitLabel());
4435}
4436
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004437void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4438 LocationSummary* locations =
4439 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004440 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004441 locations->SetOut(Location::RequiresRegister());
4442}
4443
4444void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07004445 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004446 codegen_->AddSlowPath(slow_path);
4447
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004448 LocationSummary* locations = load->GetLocations();
4449 Register out = locations->Out().AsRegister<Register>();
4450 Register current_method = locations->InAt(0).AsRegister<Register>();
4451 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004452 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004453 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004454 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01004455 // TODO: We will need a read barrier here.
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004456 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004457 __ Bind(slow_path->GetExitLabel());
4458}
4459
David Brazdilcb1c0552015-08-04 16:22:25 +01004460static int32_t GetExceptionTlsOffset() {
4461 return Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4462}
4463
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004464void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4465 LocationSummary* locations =
4466 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4467 locations->SetOut(Location::RequiresRegister());
4468}
4469
4470void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004471 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01004472 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4473}
4474
4475void LocationsBuilderARM::VisitClearException(HClearException* clear) {
4476 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4477}
4478
4479void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004480 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01004481 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004482}
4483
4484void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4485 LocationSummary* locations =
4486 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4487 InvokeRuntimeCallingConvention calling_convention;
4488 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4489}
4490
4491void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4492 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004493 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004494}
4495
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004496void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004497 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
4498 switch (instruction->GetTypeCheckKind()) {
4499 case TypeCheckKind::kExactCheck:
4500 case TypeCheckKind::kAbstractClassCheck:
4501 case TypeCheckKind::kClassHierarchyCheck:
4502 case TypeCheckKind::kArrayObjectCheck:
4503 call_kind = LocationSummary::kNoCall;
4504 break;
4505 case TypeCheckKind::kInterfaceCheck:
4506 call_kind = LocationSummary::kCall;
4507 break;
4508 case TypeCheckKind::kArrayCheck:
4509 call_kind = LocationSummary::kCallOnSlowPath;
4510 break;
4511 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004512 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004513 if (call_kind != LocationSummary::kCall) {
4514 locations->SetInAt(0, Location::RequiresRegister());
4515 locations->SetInAt(1, Location::RequiresRegister());
4516 // The out register is used as a temporary, so it overlaps with the inputs.
4517 // Note that TypeCheckSlowPathARM uses this register too.
4518 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
4519 } else {
4520 InvokeRuntimeCallingConvention calling_convention;
4521 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4522 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4523 locations->SetOut(Location::RegisterLocation(R0));
4524 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004525}
4526
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004527void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004528 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004529 Register obj = locations->InAt(0).AsRegister<Register>();
4530 Register cls = locations->InAt(1).AsRegister<Register>();
4531 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004532 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004533 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4534 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4535 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004536 Label done, zero;
Andreas Gampe85b62f22015-09-09 13:15:38 -07004537 SlowPathCode* slow_path = nullptr;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004538
4539 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004540 // avoid null check if we know obj is not null.
4541 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004542 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004543 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004544
4545 // In case of an interface check, we put the object class into the object register.
4546 // This is safe, as the register is caller-save, and the object must be in another
4547 // register if it survives the runtime call.
4548 Register target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck)
4549 ? obj
4550 : out;
4551 __ LoadFromOffset(kLoadWord, target, obj, class_offset);
4552 __ MaybeUnpoisonHeapReference(target);
4553
4554 switch (instruction->GetTypeCheckKind()) {
4555 case TypeCheckKind::kExactCheck: {
4556 __ cmp(out, ShifterOperand(cls));
4557 // Classes must be equal for the instanceof to succeed.
4558 __ b(&zero, NE);
4559 __ LoadImmediate(out, 1);
4560 __ b(&done);
4561 break;
4562 }
4563 case TypeCheckKind::kAbstractClassCheck: {
4564 // If the class is abstract, we eagerly fetch the super class of the
4565 // object to avoid doing a comparison we know will fail.
4566 Label loop;
4567 __ Bind(&loop);
4568 __ LoadFromOffset(kLoadWord, out, out, super_offset);
4569 __ MaybeUnpoisonHeapReference(out);
4570 // If `out` is null, we use it for the result, and jump to `done`.
4571 __ CompareAndBranchIfZero(out, &done);
4572 __ cmp(out, ShifterOperand(cls));
4573 __ b(&loop, NE);
4574 __ LoadImmediate(out, 1);
4575 if (zero.IsLinked()) {
4576 __ b(&done);
4577 }
4578 break;
4579 }
4580 case TypeCheckKind::kClassHierarchyCheck: {
4581 // Walk over the class hierarchy to find a match.
4582 Label loop, success;
4583 __ Bind(&loop);
4584 __ cmp(out, ShifterOperand(cls));
4585 __ b(&success, EQ);
4586 __ LoadFromOffset(kLoadWord, out, out, super_offset);
4587 __ MaybeUnpoisonHeapReference(out);
4588 __ CompareAndBranchIfNonZero(out, &loop);
4589 // If `out` is null, we use it for the result, and jump to `done`.
4590 __ b(&done);
4591 __ Bind(&success);
4592 __ LoadImmediate(out, 1);
4593 if (zero.IsLinked()) {
4594 __ b(&done);
4595 }
4596 break;
4597 }
4598 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01004599 // Do an exact check.
4600 Label exact_check;
4601 __ cmp(out, ShifterOperand(cls));
4602 __ b(&exact_check, EQ);
4603 // Otherwise, we need to check that the object's class is a non primitive array.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004604 __ LoadFromOffset(kLoadWord, out, out, component_offset);
4605 __ MaybeUnpoisonHeapReference(out);
4606 // If `out` is null, we use it for the result, and jump to `done`.
4607 __ CompareAndBranchIfZero(out, &done);
4608 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
4609 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
4610 __ CompareAndBranchIfNonZero(out, &zero);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01004611 __ Bind(&exact_check);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004612 __ LoadImmediate(out, 1);
4613 __ b(&done);
4614 break;
4615 }
4616 case TypeCheckKind::kArrayCheck: {
4617 __ cmp(out, ShifterOperand(cls));
4618 DCHECK(locations->OnlyCallsOnSlowPath());
4619 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4620 instruction, /* is_fatal */ false);
4621 codegen_->AddSlowPath(slow_path);
4622 __ b(slow_path->GetEntryLabel(), NE);
4623 __ LoadImmediate(out, 1);
4624 if (zero.IsLinked()) {
4625 __ b(&done);
4626 }
4627 break;
4628 }
4629
4630 case TypeCheckKind::kInterfaceCheck:
4631 default: {
4632 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
4633 instruction,
4634 instruction->GetDexPc(),
4635 nullptr);
4636 if (zero.IsLinked()) {
4637 __ b(&done);
4638 }
4639 break;
4640 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004641 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004642
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004643 if (zero.IsLinked()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004644 __ Bind(&zero);
4645 __ LoadImmediate(out, 0);
4646 }
4647
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004648 if (done.IsLinked()) {
4649 __ Bind(&done);
4650 }
4651
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004652 if (slow_path != nullptr) {
4653 __ Bind(slow_path->GetExitLabel());
4654 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004655}
4656
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004657void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004658 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
4659 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
4660
4661 switch (instruction->GetTypeCheckKind()) {
4662 case TypeCheckKind::kExactCheck:
4663 case TypeCheckKind::kAbstractClassCheck:
4664 case TypeCheckKind::kClassHierarchyCheck:
4665 case TypeCheckKind::kArrayObjectCheck:
4666 call_kind = throws_into_catch
4667 ? LocationSummary::kCallOnSlowPath
4668 : LocationSummary::kNoCall;
4669 break;
4670 case TypeCheckKind::kInterfaceCheck:
4671 call_kind = LocationSummary::kCall;
4672 break;
4673 case TypeCheckKind::kArrayCheck:
4674 call_kind = LocationSummary::kCallOnSlowPath;
4675 break;
4676 }
4677
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004678 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004679 instruction, call_kind);
4680 if (call_kind != LocationSummary::kCall) {
4681 locations->SetInAt(0, Location::RequiresRegister());
4682 locations->SetInAt(1, Location::RequiresRegister());
4683 // Note that TypeCheckSlowPathARM uses this register too.
4684 locations->AddTemp(Location::RequiresRegister());
4685 } else {
4686 InvokeRuntimeCallingConvention calling_convention;
4687 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4688 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4689 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004690}
4691
4692void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4693 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004694 Register obj = locations->InAt(0).AsRegister<Register>();
4695 Register cls = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004696 Register temp = locations->WillCall()
4697 ? Register(kNoRegister)
4698 : locations->GetTemp(0).AsRegister<Register>();
4699
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004700 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004701 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4702 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4703 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
4704 SlowPathCode* slow_path = nullptr;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004705
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004706 if (!locations->WillCall()) {
4707 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4708 instruction, !locations->CanCall());
4709 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004710 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004711
4712 Label done;
4713 // Avoid null check if we know obj is not null.
4714 if (instruction->MustDoNullCheck()) {
4715 __ CompareAndBranchIfZero(obj, &done);
4716 }
4717
4718 if (locations->WillCall()) {
4719 __ LoadFromOffset(kLoadWord, obj, obj, class_offset);
4720 __ MaybeUnpoisonHeapReference(obj);
4721 } else {
4722 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4723 __ MaybeUnpoisonHeapReference(temp);
4724 }
4725
4726 switch (instruction->GetTypeCheckKind()) {
4727 case TypeCheckKind::kExactCheck:
4728 case TypeCheckKind::kArrayCheck: {
4729 __ cmp(temp, ShifterOperand(cls));
4730 // Jump to slow path for throwing the exception or doing a
4731 // more involved array check.
4732 __ b(slow_path->GetEntryLabel(), NE);
4733 break;
4734 }
4735 case TypeCheckKind::kAbstractClassCheck: {
4736 // If the class is abstract, we eagerly fetch the super class of the
4737 // object to avoid doing a comparison we know will fail.
4738 Label loop;
4739 __ Bind(&loop);
4740 __ LoadFromOffset(kLoadWord, temp, temp, super_offset);
4741 __ MaybeUnpoisonHeapReference(temp);
4742 // Jump to the slow path to throw the exception.
4743 __ CompareAndBranchIfZero(temp, slow_path->GetEntryLabel());
4744 __ cmp(temp, ShifterOperand(cls));
4745 __ b(&loop, NE);
4746 break;
4747 }
4748 case TypeCheckKind::kClassHierarchyCheck: {
4749 // Walk over the class hierarchy to find a match.
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01004750 Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004751 __ Bind(&loop);
4752 __ cmp(temp, ShifterOperand(cls));
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01004753 __ b(&done, EQ);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004754 __ LoadFromOffset(kLoadWord, temp, temp, super_offset);
4755 __ MaybeUnpoisonHeapReference(temp);
4756 __ CompareAndBranchIfNonZero(temp, &loop);
4757 // Jump to the slow path to throw the exception.
4758 __ b(slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004759 break;
4760 }
4761 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01004762 // Do an exact check.
4763 __ cmp(temp, ShifterOperand(cls));
4764 __ b(&done, EQ);
4765 // Otherwise, we need to check that the object's class is a non primitive array.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004766 __ LoadFromOffset(kLoadWord, temp, temp, component_offset);
4767 __ MaybeUnpoisonHeapReference(temp);
4768 __ CompareAndBranchIfZero(temp, slow_path->GetEntryLabel());
4769 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
4770 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
4771 __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel());
4772 break;
4773 }
4774 case TypeCheckKind::kInterfaceCheck:
4775 default:
4776 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
4777 instruction,
4778 instruction->GetDexPc(),
4779 nullptr);
4780 break;
4781 }
4782 __ Bind(&done);
4783
4784 if (slow_path != nullptr) {
4785 __ Bind(slow_path->GetExitLabel());
4786 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004787}
4788
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004789void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4790 LocationSummary* locations =
4791 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4792 InvokeRuntimeCallingConvention calling_convention;
4793 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4794}
4795
4796void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4797 codegen_->InvokeRuntime(instruction->IsEnter()
4798 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4799 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004800 instruction->GetDexPc(),
4801 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004802}
4803
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004804void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4805void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4806void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4807
4808void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4809 LocationSummary* locations =
4810 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4811 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4812 || instruction->GetResultType() == Primitive::kPrimLong);
4813 locations->SetInAt(0, Location::RequiresRegister());
4814 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004815 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004816}
4817
4818void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4819 HandleBitwiseOperation(instruction);
4820}
4821
4822void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4823 HandleBitwiseOperation(instruction);
4824}
4825
4826void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4827 HandleBitwiseOperation(instruction);
4828}
4829
4830void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4831 LocationSummary* locations = instruction->GetLocations();
4832
4833 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004834 Register first = locations->InAt(0).AsRegister<Register>();
4835 Register second = locations->InAt(1).AsRegister<Register>();
4836 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004837 if (instruction->IsAnd()) {
4838 __ and_(out, first, ShifterOperand(second));
4839 } else if (instruction->IsOr()) {
4840 __ orr(out, first, ShifterOperand(second));
4841 } else {
4842 DCHECK(instruction->IsXor());
4843 __ eor(out, first, ShifterOperand(second));
4844 }
4845 } else {
4846 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4847 Location first = locations->InAt(0);
4848 Location second = locations->InAt(1);
4849 Location out = locations->Out();
4850 if (instruction->IsAnd()) {
4851 __ and_(out.AsRegisterPairLow<Register>(),
4852 first.AsRegisterPairLow<Register>(),
4853 ShifterOperand(second.AsRegisterPairLow<Register>()));
4854 __ and_(out.AsRegisterPairHigh<Register>(),
4855 first.AsRegisterPairHigh<Register>(),
4856 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4857 } else if (instruction->IsOr()) {
4858 __ orr(out.AsRegisterPairLow<Register>(),
4859 first.AsRegisterPairLow<Register>(),
4860 ShifterOperand(second.AsRegisterPairLow<Register>()));
4861 __ orr(out.AsRegisterPairHigh<Register>(),
4862 first.AsRegisterPairHigh<Register>(),
4863 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4864 } else {
4865 DCHECK(instruction->IsXor());
4866 __ eor(out.AsRegisterPairLow<Register>(),
4867 first.AsRegisterPairLow<Register>(),
4868 ShifterOperand(second.AsRegisterPairLow<Register>()));
4869 __ eor(out.AsRegisterPairHigh<Register>(),
4870 first.AsRegisterPairHigh<Register>(),
4871 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4872 }
4873 }
4874}
4875
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004876void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00004877 // For better instruction scheduling we load the direct code pointer before the method pointer.
4878 bool direct_code_loaded = false;
4879 switch (invoke->GetCodePtrLocation()) {
4880 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
4881 if (IsSameDexFile(*invoke->GetTargetMethod().dex_file, GetGraph()->GetDexFile())) {
4882 break;
4883 }
4884 // Calls across dex files are more likely to exceed the available BL range,
4885 // so use absolute patch by falling through to kDirectCodeFixup.
4886 FALLTHROUGH_INTENDED;
4887 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4888 // LR = code address from literal pool with link-time patch.
4889 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
4890 direct_code_loaded = true;
4891 break;
4892 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4893 // LR = invoke->GetDirectCodePtr();
4894 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
4895 direct_code_loaded = true;
4896 break;
4897 default:
4898 break;
4899 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004900
Vladimir Marko58155012015-08-19 12:49:41 +00004901 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
4902 switch (invoke->GetMethodLoadKind()) {
4903 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
4904 // temp = thread->string_init_entrypoint
4905 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
4906 break;
4907 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
4908 callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4909 break;
4910 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
4911 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
4912 break;
4913 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
4914 __ LoadLiteral(temp.AsRegister<Register>(),
4915 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
4916 break;
4917 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
4918 // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod.
4919 FALLTHROUGH_INTENDED;
4920 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
4921 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4922 Register method_reg;
4923 Register reg = temp.AsRegister<Register>();
4924 if (current_method.IsRegister()) {
4925 method_reg = current_method.AsRegister<Register>();
4926 } else {
4927 DCHECK(invoke->GetLocations()->Intrinsified());
4928 DCHECK(!current_method.IsValid());
4929 method_reg = reg;
4930 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4931 }
4932 // temp = current_method->dex_cache_resolved_methods_;
4933 __ LoadFromOffset(
Vladimir Marko05792b92015-08-03 11:56:49 +01004934 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset(
4935 kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00004936 // temp = temp[index_in_cache]
4937 uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index;
4938 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
4939 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004940 }
Vladimir Marko58155012015-08-19 12:49:41 +00004941 }
4942
4943 switch (invoke->GetCodePtrLocation()) {
4944 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
4945 __ bl(GetFrameEntryLabel());
4946 break;
4947 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
4948 if (!direct_code_loaded) {
4949 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
4950 __ Bind(&relative_call_patches_.back().label);
4951 Label label;
4952 __ bl(&label); // Arbitrarily branch to the instruction after BL, override at link time.
4953 __ Bind(&label);
4954 break;
4955 }
4956 // If we loaded the direct code above, fall through.
4957 FALLTHROUGH_INTENDED;
4958 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4959 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4960 // LR prepared above for better instruction scheduling.
4961 DCHECK(direct_code_loaded);
4962 // LR()
4963 __ blx(LR);
4964 break;
4965 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
4966 // LR = callee_method->entry_point_from_quick_compiled_code_
4967 __ LoadFromOffset(
4968 kLoadWord, LR, callee_method.AsRegister<Register>(),
4969 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value());
4970 // LR()
4971 __ blx(LR);
4972 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004973 }
4974
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004975 DCHECK(!IsLeafMethod());
4976}
4977
Andreas Gampebfb5ba92015-09-01 15:45:02 +00004978void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
4979 Register temp = temp_location.AsRegister<Register>();
4980 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
4981 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
4982 LocationSummary* locations = invoke->GetLocations();
4983 Location receiver = locations->InAt(0);
4984 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4985 // temp = object->GetClass();
4986 DCHECK(receiver.IsRegister());
4987 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
4988 MaybeRecordImplicitNullCheck(invoke);
4989 __ MaybeUnpoisonHeapReference(temp);
4990 // temp = temp->GetMethodAt(method_offset);
4991 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4992 kArmWordSize).Int32Value();
4993 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
4994 // LR = temp->GetEntryPoint();
4995 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
4996 // LR();
4997 __ blx(LR);
4998}
4999
Vladimir Marko58155012015-08-19 12:49:41 +00005000void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
5001 DCHECK(linker_patches->empty());
5002 size_t size = method_patches_.size() + call_patches_.size() + relative_call_patches_.size();
5003 linker_patches->reserve(size);
5004 for (const auto& entry : method_patches_) {
5005 const MethodReference& target_method = entry.first;
5006 Literal* literal = entry.second;
5007 DCHECK(literal->GetLabel()->IsBound());
5008 uint32_t literal_offset = literal->GetLabel()->Position();
5009 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
5010 target_method.dex_file,
5011 target_method.dex_method_index));
5012 }
5013 for (const auto& entry : call_patches_) {
5014 const MethodReference& target_method = entry.first;
5015 Literal* literal = entry.second;
5016 DCHECK(literal->GetLabel()->IsBound());
5017 uint32_t literal_offset = literal->GetLabel()->Position();
5018 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
5019 target_method.dex_file,
5020 target_method.dex_method_index));
5021 }
5022 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
5023 uint32_t literal_offset = info.label.Position();
5024 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
5025 info.target_method.dex_file,
5026 info.target_method.dex_method_index));
5027 }
5028}
5029
5030Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
5031 MethodToLiteralMap* map) {
5032 // Look up the literal for target_method.
5033 auto lb = map->lower_bound(target_method);
5034 if (lb != map->end() && !map->key_comp()(target_method, lb->first)) {
5035 return lb->second;
5036 }
5037 // We don't have a literal for this method yet, insert a new one.
5038 Literal* literal = __ NewLiteral<uint32_t>(0u);
5039 map->PutBefore(lb, target_method, literal);
5040 return literal;
5041}
5042
5043Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
5044 return DeduplicateMethodLiteral(target_method, &method_patches_);
5045}
5046
5047Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
5048 return DeduplicateMethodLiteral(target_method, &call_patches_);
5049}
5050
Calin Juravleb1498f62015-02-16 13:13:29 +00005051void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
5052 // Nothing to do, this should be removed during prepare for register allocator.
5053 UNUSED(instruction);
5054 LOG(FATAL) << "Unreachable";
5055}
5056
5057void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
5058 // Nothing to do, this should be removed during prepare for register allocator.
5059 UNUSED(instruction);
5060 LOG(FATAL) << "Unreachable";
5061}
5062
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01005063void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) {
5064 DCHECK(codegen_->IsBaseline());
5065 LocationSummary* locations =
5066 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5067 locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
5068}
5069
5070void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
5071 DCHECK(codegen_->IsBaseline());
5072 // Will be generated at use site.
5073}
5074
Mark Mendellfe57faa2015-09-18 09:26:15 -04005075// Simple implementation of packed switch - generate cascaded compare/jumps.
5076void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5077 LocationSummary* locations =
5078 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
5079 locations->SetInAt(0, Location::RequiresRegister());
5080}
5081
5082void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5083 int32_t lower_bound = switch_instr->GetStartValue();
5084 int32_t num_entries = switch_instr->GetNumEntries();
5085 LocationSummary* locations = switch_instr->GetLocations();
5086 Register value_reg = locations->InAt(0).AsRegister<Register>();
5087 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
5088
5089 // Create a series of compare/jumps.
5090 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
5091 for (int32_t i = 0; i < num_entries; i++) {
5092 GenerateCompareWithImmediate(value_reg, lower_bound + i);
5093 __ b(codegen_->GetLabelOf(successors.at(i)), EQ);
5094 }
5095
5096 // And the default for any other value.
5097 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
5098 __ b(codegen_->GetLabelOf(default_block));
5099 }
5100}
5101
Andreas Gampe85b62f22015-09-09 13:15:38 -07005102void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) {
5103 if (!trg.IsValid()) {
5104 DCHECK(type == Primitive::kPrimVoid);
5105 return;
5106 }
5107
5108 DCHECK_NE(type, Primitive::kPrimVoid);
5109
5110 Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type);
5111 if (return_loc.Equals(trg)) {
5112 return;
5113 }
5114
5115 // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged
5116 // with the last branch.
5117 if (type == Primitive::kPrimLong) {
5118 HParallelMove parallel_move(GetGraph()->GetArena());
5119 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr);
5120 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr);
5121 GetMoveResolver()->EmitNativeCode(&parallel_move);
5122 } else if (type == Primitive::kPrimDouble) {
5123 HParallelMove parallel_move(GetGraph()->GetArena());
5124 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr);
5125 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr);
5126 GetMoveResolver()->EmitNativeCode(&parallel_move);
5127 } else {
5128 // Let the parallel move resolver take care of all of this.
5129 HParallelMove parallel_move(GetGraph()->GetArena());
5130 parallel_move.AddMove(return_loc, trg, type, nullptr);
5131 GetMoveResolver()->EmitNativeCode(&parallel_move);
5132 }
5133}
5134
Roland Levillain4d027112015-07-01 15:41:14 +01005135#undef __
5136#undef QUICK_ENTRY_POINT
5137
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00005138} // namespace arm
5139} // namespace art