blob: 8d9794bd793fe3eaf909ba6539b6531093c599ff [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
Aart Bike9f37602015-10-09 11:15:55 -0700412inline Condition ARMCondition(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;
Aart Bike9f37602015-10-09 11:15:55 -0700420 case kCondB: return LO;
421 case kCondBE: return LS;
422 case kCondA: return HI;
423 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700424 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100425 LOG(FATAL) << "Unreachable";
426 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700427}
428
Aart Bike9f37602015-10-09 11:15:55 -0700429// Maps signed condition to unsigned condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100430inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700431 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100432 case kCondEQ: return EQ;
433 case kCondNE: return NE;
Aart Bike9f37602015-10-09 11:15:55 -0700434 // Signed to unsigned.
Roland Levillain4fa13f62015-07-06 18:11:54 +0100435 case kCondLT: return LO;
436 case kCondLE: return LS;
437 case kCondGT: return HI;
438 case kCondGE: return HS;
Aart Bike9f37602015-10-09 11:15:55 -0700439 // Unsigned remain unchanged.
440 case kCondB: return LO;
441 case kCondBE: return LS;
442 case kCondA: return HI;
443 case kCondAE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700444 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100445 LOG(FATAL) << "Unreachable";
446 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700447}
448
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100449void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100450 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100451}
452
453void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100454 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100455}
456
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100457size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
458 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
459 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100460}
461
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100462size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
463 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
464 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100465}
466
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000467size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
468 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
469 return kArmWordSize;
470}
471
472size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
473 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
474 return kArmWordSize;
475}
476
Calin Juravle34166012014-12-19 17:22:29 +0000477CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000478 const ArmInstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100479 const CompilerOptions& compiler_options,
480 OptimizingCompilerStats* stats)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000481 : CodeGenerator(graph,
482 kNumberOfCoreRegisters,
483 kNumberOfSRegisters,
484 kNumberOfRegisterPairs,
485 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
486 arraysize(kCoreCalleeSaves)),
Nicolas Geoffray75d5b9b2015-10-05 07:40:35 +0000487 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
488 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100489 compiler_options,
490 stats),
Vladimir Marko225b6462015-09-28 12:17:40 +0100491 block_labels_(nullptr),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100492 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100493 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100494 move_resolver_(graph->GetArena(), this),
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000495 assembler_(),
Vladimir Marko58155012015-08-19 12:49:41 +0000496 isa_features_(isa_features),
Vladimir Marko5233f932015-09-29 19:01:15 +0100497 method_patches_(MethodReferenceComparator(),
498 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
499 call_patches_(MethodReferenceComparator(),
500 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
501 relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) {
Andreas Gampe501fd632015-09-10 16:11:06 -0700502 // Always save the LR register to mimic Quick.
503 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100504}
505
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000506void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
507 // Ensure that we fix up branches and literal loads and emit the literal pool.
508 __ FinalizeCode();
509
510 // Adjust native pc offsets in stack maps.
511 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
512 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
513 uint32_t new_position = __ GetAdjustedPosition(old_position);
514 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
515 }
516 // Adjust native pc offsets of block labels.
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100517 for (HBasicBlock* block : *block_order_) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000518 // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid
519 // FirstNonEmptyBlock() which could lead to adjusting a label more than once.
Vladimir Marko225b6462015-09-28 12:17:40 +0100520 DCHECK_LT(block->GetBlockId(), GetGraph()->GetBlocks().size());
521 Label* block_label = &block_labels_[block->GetBlockId()];
David Brazdilfc6a86a2015-06-26 10:33:45 +0000522 DCHECK_EQ(block_label->IsBound(), !block->IsSingleJump());
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000523 if (block_label->IsBound()) {
524 __ AdjustLabelPosition(block_label);
525 }
526 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100527 // Adjust pc offsets for the disassembly information.
528 if (disasm_info_ != nullptr) {
529 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
530 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
531 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
532 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
533 it.second.start = __ GetAdjustedPosition(it.second.start);
534 it.second.end = __ GetAdjustedPosition(it.second.end);
535 }
536 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
537 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
538 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
539 }
540 }
Vladimir Marko58155012015-08-19 12:49:41 +0000541 // Adjust pc offsets for relative call patches.
542 for (MethodPatchInfo<Label>& info : relative_call_patches_) {
543 __ AdjustLabelPosition(&info.label);
544 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000545
546 CodeGenerator::Finalize(allocator);
547}
548
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100549Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100550 switch (type) {
551 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100552 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100553 ArmManagedRegister pair =
554 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100555 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
556 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
557
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100558 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
559 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100560 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100561 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100562 }
563
564 case Primitive::kPrimByte:
565 case Primitive::kPrimBoolean:
566 case Primitive::kPrimChar:
567 case Primitive::kPrimShort:
568 case Primitive::kPrimInt:
569 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100570 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100571 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100572 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
573 ArmManagedRegister current =
574 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
575 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100576 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100577 }
578 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100579 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100580 }
581
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000582 case Primitive::kPrimFloat: {
583 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100584 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100585 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100586
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000587 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000588 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
589 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000590 return Location::FpuRegisterPairLocation(reg, reg + 1);
591 }
592
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100593 case Primitive::kPrimVoid:
594 LOG(FATAL) << "Unreachable type " << type;
595 }
596
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100597 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100598}
599
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000600void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100601 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100602 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100603
604 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100605 blocked_core_registers_[SP] = true;
606 blocked_core_registers_[LR] = true;
607 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100608
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100609 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100610 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100611
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100612 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100613 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100614
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000615 if (is_baseline) {
616 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
617 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
618 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000619
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000620 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
Nicolas Geoffrayecf680d2015-10-05 11:15:37 +0100621 }
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000622
Nicolas Geoffrayecf680d2015-10-05 11:15:37 +0100623 if (is_baseline || GetGraph()->IsDebuggable()) {
624 // Stubs do not save callee-save floating point registers. If the graph
625 // is debuggable, we need to deal with these registers differently. For
626 // now, just block them.
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000627 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
628 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
629 }
630 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100631
632 UpdateBlockedPairRegisters();
633}
634
635void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
636 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
637 ArmManagedRegister current =
638 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
639 if (blocked_core_registers_[current.AsRegisterPairLow()]
640 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
641 blocked_register_pairs_[i] = true;
642 }
643 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100644}
645
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100646InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
647 : HGraphVisitor(graph),
648 assembler_(codegen->GetAssembler()),
649 codegen_(codegen) {}
650
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000651void CodeGeneratorARM::ComputeSpillMask() {
652 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000653 // Save one extra register for baseline. Note that on thumb2, there is no easy
654 // instruction to restore just the PC, so this actually helps both baseline
655 // and non-baseline to save and restore at least two registers at entry and exit.
656 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000657 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
658 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
659 // We use vpush and vpop for saving and restoring floating point registers, which take
660 // a SRegister and the number of registers to save/restore after that SRegister. We
661 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
662 // but in the range.
663 if (fpu_spill_mask_ != 0) {
664 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
665 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
666 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
667 fpu_spill_mask_ |= (1 << i);
668 }
669 }
670}
671
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100672static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100673 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100674}
675
676static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100677 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100678}
679
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000680void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000681 bool skip_overflow_check =
682 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000683 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000684 __ Bind(&frame_entry_label_);
685
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000686 if (HasEmptyFrame()) {
687 return;
688 }
689
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100690 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000691 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
692 __ LoadFromOffset(kLoadWord, IP, IP, 0);
693 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100694 }
695
Andreas Gampe501fd632015-09-10 16:11:06 -0700696 __ PushList(core_spill_mask_);
697 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_));
698 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000699 if (fpu_spill_mask_ != 0) {
700 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
701 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100702 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100703 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000704 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100705 int adjust = GetFrameSize() - FrameEntrySpillSize();
706 __ AddConstant(SP, -adjust);
707 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100708 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000709}
710
711void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000712 if (HasEmptyFrame()) {
713 __ bx(LR);
714 return;
715 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100716 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100717 int adjust = GetFrameSize() - FrameEntrySpillSize();
718 __ AddConstant(SP, adjust);
719 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000720 if (fpu_spill_mask_ != 0) {
721 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
722 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100723 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
724 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000725 }
Andreas Gampe501fd632015-09-10 16:11:06 -0700726 // Pop LR into PC to return.
727 DCHECK_NE(core_spill_mask_ & (1 << LR), 0U);
728 uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC;
729 __ PopList(pop_mask);
David Srbeckyc34dc932015-04-12 09:27:43 +0100730 __ cfi().RestoreState();
731 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000732}
733
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100734void CodeGeneratorARM::Bind(HBasicBlock* block) {
735 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000736}
737
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100738Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
739 switch (load->GetType()) {
740 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100741 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100742 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100743
744 case Primitive::kPrimInt:
745 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100746 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100747 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100748
749 case Primitive::kPrimBoolean:
750 case Primitive::kPrimByte:
751 case Primitive::kPrimChar:
752 case Primitive::kPrimShort:
753 case Primitive::kPrimVoid:
754 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700755 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100756 }
757
758 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700759 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100760}
761
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100762Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100763 switch (type) {
764 case Primitive::kPrimBoolean:
765 case Primitive::kPrimByte:
766 case Primitive::kPrimChar:
767 case Primitive::kPrimShort:
768 case Primitive::kPrimInt:
769 case Primitive::kPrimNot: {
770 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000771 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100772 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100773 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100774 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000775 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100776 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100777 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100778
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000779 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100780 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000781 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100782 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000783 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100784 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000785 if (calling_convention.GetRegisterAt(index) == R1) {
786 // Skip R1, and use R2_R3 instead.
787 gp_index_++;
788 index++;
789 }
790 }
791 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
792 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000793 calling_convention.GetRegisterAt(index + 1));
Calin Juravle175dc732015-08-25 15:42:32 +0100794
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000795 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000796 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100797 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000798 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
799 }
800 }
801
802 case Primitive::kPrimFloat: {
803 uint32_t stack_index = stack_index_++;
804 if (float_index_ % 2 == 0) {
805 float_index_ = std::max(double_index_, float_index_);
806 }
807 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
808 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
809 } else {
810 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
811 }
812 }
813
814 case Primitive::kPrimDouble: {
815 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
816 uint32_t stack_index = stack_index_;
817 stack_index_ += 2;
818 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
819 uint32_t index = double_index_;
820 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000821 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000822 calling_convention.GetFpuRegisterAt(index),
823 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000824 DCHECK(ExpectedPairLayout(result));
825 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000826 } else {
827 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100828 }
829 }
830
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100831 case Primitive::kPrimVoid:
832 LOG(FATAL) << "Unexpected parameter type " << type;
833 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100834 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100835 return Location();
836}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100837
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100838Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000839 switch (type) {
840 case Primitive::kPrimBoolean:
841 case Primitive::kPrimByte:
842 case Primitive::kPrimChar:
843 case Primitive::kPrimShort:
844 case Primitive::kPrimInt:
845 case Primitive::kPrimNot: {
846 return Location::RegisterLocation(R0);
847 }
848
849 case Primitive::kPrimFloat: {
850 return Location::FpuRegisterLocation(S0);
851 }
852
853 case Primitive::kPrimLong: {
854 return Location::RegisterPairLocation(R0, R1);
855 }
856
857 case Primitive::kPrimDouble: {
858 return Location::FpuRegisterPairLocation(S0, S1);
859 }
860
861 case Primitive::kPrimVoid:
862 return Location();
863 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100864
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000865 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000866}
867
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100868Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
869 return Location::RegisterLocation(kMethodRegisterArgument);
870}
871
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100872void CodeGeneratorARM::Move32(Location destination, Location source) {
873 if (source.Equals(destination)) {
874 return;
875 }
876 if (destination.IsRegister()) {
877 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000878 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100879 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000880 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100881 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000882 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100883 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100884 } else if (destination.IsFpuRegister()) {
885 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000886 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100887 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000888 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100889 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000890 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100891 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100892 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000893 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100894 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000895 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100896 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000897 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100898 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000899 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100900 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
901 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100902 }
903 }
904}
905
906void CodeGeneratorARM::Move64(Location destination, Location source) {
907 if (source.Equals(destination)) {
908 return;
909 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100910 if (destination.IsRegisterPair()) {
911 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000912 EmitParallelMoves(
913 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
914 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100915 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000916 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100917 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
918 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100919 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000920 UNIMPLEMENTED(FATAL);
Calin Juravlee460d1d2015-09-29 04:52:17 +0100921 } else if (source.IsFpuRegisterPair()) {
922 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
923 destination.AsRegisterPairHigh<Register>(),
924 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100925 } else {
926 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000927 DCHECK(ExpectedPairLayout(destination));
928 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
929 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100930 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000931 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100932 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000933 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
934 SP,
935 source.GetStackIndex());
Calin Juravlee460d1d2015-09-29 04:52:17 +0100936 } else if (source.IsRegisterPair()) {
937 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
938 source.AsRegisterPairLow<Register>(),
939 source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100940 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000941 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100942 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100943 } else {
944 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100945 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000946 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100947 if (source.AsRegisterPairLow<Register>() == R1) {
948 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100949 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
950 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100951 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100952 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100953 SP, destination.GetStackIndex());
954 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000955 } else if (source.IsFpuRegisterPair()) {
956 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
957 SP,
958 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100959 } else {
960 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000961 EmitParallelMoves(
962 Location::StackSlot(source.GetStackIndex()),
963 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100964 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000965 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100966 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
967 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100968 }
969 }
970}
971
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100972void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100973 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100974 if (instruction->IsCurrentMethod()) {
975 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
976 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100977 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100978 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000979 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000980 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
981 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000982 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000983 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000984 } else {
985 DCHECK(location.IsStackSlot());
986 __ LoadImmediate(IP, value);
987 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
988 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000989 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000990 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000991 int64_t value = const_to_move->AsLongConstant()->GetValue();
992 if (location.IsRegisterPair()) {
993 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
994 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
995 } else {
996 DCHECK(location.IsDoubleStackSlot());
997 __ LoadImmediate(IP, Low32Bits(value));
998 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
999 __ LoadImmediate(IP, High32Bits(value));
1000 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
1001 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001002 }
Roland Levillain476df552014-10-09 17:51:36 +01001003 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001004 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
1005 switch (instruction->GetType()) {
1006 case Primitive::kPrimBoolean:
1007 case Primitive::kPrimByte:
1008 case Primitive::kPrimChar:
1009 case Primitive::kPrimShort:
1010 case Primitive::kPrimInt:
1011 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001012 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001013 Move32(location, Location::StackSlot(stack_slot));
1014 break;
1015
1016 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001017 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001018 Move64(location, Location::DoubleStackSlot(stack_slot));
1019 break;
1020
1021 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001022 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001023 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +00001024 } else if (instruction->IsTemporary()) {
1025 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +00001026 if (temp_location.IsStackSlot()) {
1027 Move32(location, temp_location);
1028 } else {
1029 DCHECK(temp_location.IsDoubleStackSlot());
1030 Move64(location, temp_location);
1031 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001032 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001033 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001034 switch (instruction->GetType()) {
1035 case Primitive::kPrimBoolean:
1036 case Primitive::kPrimByte:
1037 case Primitive::kPrimChar:
1038 case Primitive::kPrimShort:
1039 case Primitive::kPrimNot:
1040 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001041 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001042 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001043 break;
1044
1045 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001046 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001047 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001048 break;
1049
1050 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001051 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001052 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001053 }
1054}
1055
Calin Juravle175dc732015-08-25 15:42:32 +01001056void CodeGeneratorARM::MoveConstant(Location location, int32_t value) {
1057 DCHECK(location.IsRegister());
1058 __ LoadImmediate(location.AsRegister<Register>(), value);
1059}
1060
Calin Juravlee460d1d2015-09-29 04:52:17 +01001061void CodeGeneratorARM::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
1062 if (Primitive::Is64BitType(dst_type)) {
1063 Move64(dst, src);
1064 } else {
1065 Move32(dst, src);
1066 }
1067}
1068
1069void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) {
1070 if (location.IsRegister()) {
1071 locations->AddTemp(location);
1072 } else if (location.IsRegisterPair()) {
1073 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
1074 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
1075 } else {
1076 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1077 }
1078}
1079
Calin Juravle175dc732015-08-25 15:42:32 +01001080void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint,
1081 HInstruction* instruction,
1082 uint32_t dex_pc,
1083 SlowPathCode* slow_path) {
1084 InvokeRuntime(GetThreadOffset<kArmWordSize>(entrypoint).Int32Value(),
1085 instruction,
1086 dex_pc,
1087 slow_path);
1088}
1089
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001090void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
1091 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001092 uint32_t dex_pc,
1093 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001094 ValidateInvokeRuntime(instruction, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001095 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1096 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001097 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001098}
1099
David Brazdilfc6a86a2015-06-26 10:33:45 +00001100void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001101 DCHECK(!successor->IsExitBlock());
1102
1103 HBasicBlock* block = got->GetBlock();
1104 HInstruction* previous = got->GetPrevious();
1105
1106 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +00001107 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001108 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1109 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1110 return;
1111 }
1112
1113 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1114 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1115 }
1116 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001117 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001118 }
1119}
1120
David Brazdilfc6a86a2015-06-26 10:33:45 +00001121void LocationsBuilderARM::VisitGoto(HGoto* got) {
1122 got->SetLocations(nullptr);
1123}
1124
1125void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1126 HandleGoto(got, got->GetSuccessor());
1127}
1128
1129void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1130 try_boundary->SetLocations(nullptr);
1131}
1132
1133void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1134 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1135 if (!successor->IsExitBlock()) {
1136 HandleGoto(try_boundary, successor);
1137 }
1138}
1139
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001140void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001141 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001142}
1143
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001144void InstructionCodeGeneratorARM::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001145}
1146
Roland Levillain4fa13f62015-07-06 18:11:54 +01001147void InstructionCodeGeneratorARM::GenerateCompareWithImmediate(Register left, int32_t right) {
1148 ShifterOperand operand;
1149 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, right, &operand)) {
1150 __ cmp(left, operand);
1151 } else {
1152 Register temp = IP;
1153 __ LoadImmediate(temp, right);
1154 __ cmp(left, ShifterOperand(temp));
1155 }
1156}
1157
1158void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1159 Label* true_label,
1160 Label* false_label) {
1161 __ vmstat(); // transfer FP status register to ARM APSR.
Aart Bike9f37602015-10-09 11:15:55 -07001162 // TODO: merge into a single branch (except "equal or unordered" and "not equal")
Roland Levillain4fa13f62015-07-06 18:11:54 +01001163 if (cond->IsFPConditionTrueIfNaN()) {
1164 __ b(true_label, VS); // VS for unordered.
1165 } else if (cond->IsFPConditionFalseIfNaN()) {
1166 __ b(false_label, VS); // VS for unordered.
1167 }
Aart Bike9f37602015-10-09 11:15:55 -07001168 __ b(true_label, ARMCondition(cond->GetCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001169}
1170
1171void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1172 Label* true_label,
1173 Label* false_label) {
1174 LocationSummary* locations = cond->GetLocations();
1175 Location left = locations->InAt(0);
1176 Location right = locations->InAt(1);
1177 IfCondition if_cond = cond->GetCondition();
1178
1179 Register left_high = left.AsRegisterPairHigh<Register>();
1180 Register left_low = left.AsRegisterPairLow<Register>();
1181 IfCondition true_high_cond = if_cond;
1182 IfCondition false_high_cond = cond->GetOppositeCondition();
Aart Bike9f37602015-10-09 11:15:55 -07001183 Condition final_condition = ARMUnsignedCondition(if_cond); // unsigned on lower part
Roland Levillain4fa13f62015-07-06 18:11:54 +01001184
1185 // Set the conditions for the test, remembering that == needs to be
1186 // decided using the low words.
Aart Bike9f37602015-10-09 11:15:55 -07001187 // TODO: consider avoiding jumps with temporary and CMP low+SBC high
Roland Levillain4fa13f62015-07-06 18:11:54 +01001188 switch (if_cond) {
1189 case kCondEQ:
1190 case kCondNE:
1191 // Nothing to do.
1192 break;
1193 case kCondLT:
1194 false_high_cond = kCondGT;
1195 break;
1196 case kCondLE:
1197 true_high_cond = kCondLT;
1198 break;
1199 case kCondGT:
1200 false_high_cond = kCondLT;
1201 break;
1202 case kCondGE:
1203 true_high_cond = kCondGT;
1204 break;
Aart Bike9f37602015-10-09 11:15:55 -07001205 case kCondB:
1206 false_high_cond = kCondA;
1207 break;
1208 case kCondBE:
1209 true_high_cond = kCondB;
1210 break;
1211 case kCondA:
1212 false_high_cond = kCondB;
1213 break;
1214 case kCondAE:
1215 true_high_cond = kCondA;
1216 break;
Roland Levillain4fa13f62015-07-06 18:11:54 +01001217 }
1218 if (right.IsConstant()) {
1219 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1220 int32_t val_low = Low32Bits(value);
1221 int32_t val_high = High32Bits(value);
1222
1223 GenerateCompareWithImmediate(left_high, val_high);
1224 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001225 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001226 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001227 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001228 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001229 __ b(true_label, ARMCondition(true_high_cond));
1230 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001231 }
1232 // Must be equal high, so compare the lows.
1233 GenerateCompareWithImmediate(left_low, val_low);
1234 } else {
1235 Register right_high = right.AsRegisterPairHigh<Register>();
1236 Register right_low = right.AsRegisterPairLow<Register>();
1237
1238 __ cmp(left_high, ShifterOperand(right_high));
1239 if (if_cond == kCondNE) {
Aart Bike9f37602015-10-09 11:15:55 -07001240 __ b(true_label, ARMCondition(true_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001241 } else if (if_cond == kCondEQ) {
Aart Bike9f37602015-10-09 11:15:55 -07001242 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001243 } else {
Aart Bike9f37602015-10-09 11:15:55 -07001244 __ b(true_label, ARMCondition(true_high_cond));
1245 __ b(false_label, ARMCondition(false_high_cond));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001246 }
1247 // Must be equal high, so compare the lows.
1248 __ cmp(left_low, ShifterOperand(right_low));
1249 }
1250 // The last comparison might be unsigned.
Aart Bike9f37602015-10-09 11:15:55 -07001251 // TODO: optimize cases where this is always true/false
Roland Levillain4fa13f62015-07-06 18:11:54 +01001252 __ b(true_label, final_condition);
1253}
1254
1255void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HIf* if_instr,
1256 HCondition* condition,
1257 Label* true_target,
1258 Label* false_target,
1259 Label* always_true_target) {
1260 LocationSummary* locations = condition->GetLocations();
1261 Location left = locations->InAt(0);
1262 Location right = locations->InAt(1);
1263
1264 // We don't want true_target as a nullptr.
1265 if (true_target == nullptr) {
1266 true_target = always_true_target;
1267 }
1268 bool falls_through = (false_target == nullptr);
1269
1270 // FP compares don't like null false_targets.
1271 if (false_target == nullptr) {
1272 false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1273 }
1274
1275 Primitive::Type type = condition->InputAt(0)->GetType();
1276 switch (type) {
1277 case Primitive::kPrimLong:
1278 GenerateLongComparesAndJumps(condition, true_target, false_target);
1279 break;
1280 case Primitive::kPrimFloat:
1281 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1282 GenerateFPJumps(condition, true_target, false_target);
1283 break;
1284 case Primitive::kPrimDouble:
1285 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1286 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1287 GenerateFPJumps(condition, true_target, false_target);
1288 break;
1289 default:
1290 LOG(FATAL) << "Unexpected compare type " << type;
1291 }
1292
1293 if (!falls_through) {
1294 __ b(false_target);
1295 }
1296}
1297
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001298void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
1299 Label* true_target,
1300 Label* false_target,
1301 Label* always_true_target) {
1302 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001303 if (cond->IsIntConstant()) {
1304 // Constant condition, statically compared against 1.
1305 int32_t cond_value = cond->AsIntConstant()->GetValue();
1306 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001307 if (always_true_target != nullptr) {
1308 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001309 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001310 return;
1311 } else {
1312 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001313 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001314 } else {
1315 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1316 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001317 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01001318 __ CompareAndBranchIfNonZero(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
1319 true_target);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001320 } else {
1321 // Condition has not been materialized, use its inputs as the
1322 // comparison and its condition as the branch condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +01001323 Primitive::Type type =
1324 cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt;
1325 // Is this a long or FP comparison that has been folded into the HCondition?
1326 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1327 // Generate the comparison directly.
1328 GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(),
1329 true_target, false_target, always_true_target);
1330 return;
1331 }
1332
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001333 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001334 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001335 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain4fa13f62015-07-06 18:11:54 +01001336 Location right = locations->InAt(1);
1337 if (right.IsRegister()) {
1338 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001339 } else {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001340 DCHECK(right.IsConstant());
1341 GenerateCompareWithImmediate(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001342 }
Aart Bike9f37602015-10-09 11:15:55 -07001343 __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001344 }
Dave Allison20dfc792014-06-16 20:44:29 -07001345 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001346 if (false_target != nullptr) {
1347 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001348 }
1349}
1350
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001351void LocationsBuilderARM::VisitIf(HIf* if_instr) {
1352 LocationSummary* locations =
1353 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
1354 HInstruction* cond = if_instr->InputAt(0);
1355 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1356 locations->SetInAt(0, Location::RequiresRegister());
1357 }
1358}
1359
1360void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1361 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1362 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1363 Label* always_true_target = true_target;
1364 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1365 if_instr->IfTrueSuccessor())) {
1366 always_true_target = nullptr;
1367 }
1368 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1369 if_instr->IfFalseSuccessor())) {
1370 false_target = nullptr;
1371 }
1372 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1373}
1374
1375void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1376 LocationSummary* locations = new (GetGraph()->GetArena())
1377 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1378 HInstruction* cond = deoptimize->InputAt(0);
Aart Bikbb245d12015-10-19 11:05:03 -07001379 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001380 locations->SetInAt(0, Location::RequiresRegister());
1381 }
1382}
1383
1384void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07001385 SlowPathCode* slow_path = new (GetGraph()->GetArena())
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001386 DeoptimizationSlowPathARM(deoptimize);
1387 codegen_->AddSlowPath(slow_path);
1388 Label* slow_path_entry = slow_path->GetEntryLabel();
1389 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1390}
Dave Allison20dfc792014-06-16 20:44:29 -07001391
Roland Levillain0d37cd02015-05-27 16:39:19 +01001392void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001393 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001394 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001395 // Handle the long/FP comparisons made in instruction simplification.
1396 switch (cond->InputAt(0)->GetType()) {
1397 case Primitive::kPrimLong:
1398 locations->SetInAt(0, Location::RequiresRegister());
1399 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1400 if (cond->NeedsMaterialization()) {
1401 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1402 }
1403 break;
1404
1405 case Primitive::kPrimFloat:
1406 case Primitive::kPrimDouble:
1407 locations->SetInAt(0, Location::RequiresFpuRegister());
1408 locations->SetInAt(1, Location::RequiresFpuRegister());
1409 if (cond->NeedsMaterialization()) {
1410 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1411 }
1412 break;
1413
1414 default:
1415 locations->SetInAt(0, Location::RequiresRegister());
1416 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1417 if (cond->NeedsMaterialization()) {
1418 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1419 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001420 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001421}
1422
Roland Levillain0d37cd02015-05-27 16:39:19 +01001423void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001424 if (!cond->NeedsMaterialization()) {
1425 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001426 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001427
1428 LocationSummary* locations = cond->GetLocations();
1429 Location left = locations->InAt(0);
1430 Location right = locations->InAt(1);
1431 Register out = locations->Out().AsRegister<Register>();
1432 Label true_label, false_label;
1433
1434 switch (cond->InputAt(0)->GetType()) {
1435 default: {
1436 // Integer case.
1437 if (right.IsRegister()) {
1438 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1439 } else {
1440 DCHECK(right.IsConstant());
1441 GenerateCompareWithImmediate(left.AsRegister<Register>(),
1442 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
1443 }
Aart Bike9f37602015-10-09 11:15:55 -07001444 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001445 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Aart Bike9f37602015-10-09 11:15:55 -07001446 ARMCondition(cond->GetCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001447 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Aart Bike9f37602015-10-09 11:15:55 -07001448 ARMCondition(cond->GetOppositeCondition()));
Roland Levillain4fa13f62015-07-06 18:11:54 +01001449 return;
1450 }
1451 case Primitive::kPrimLong:
1452 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1453 break;
1454 case Primitive::kPrimFloat:
1455 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1456 GenerateFPJumps(cond, &true_label, &false_label);
1457 break;
1458 case Primitive::kPrimDouble:
1459 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1460 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1461 GenerateFPJumps(cond, &true_label, &false_label);
1462 break;
1463 }
1464
1465 // Convert the jumps into the result.
1466 Label done_label;
1467
1468 // False case: result = 0.
1469 __ Bind(&false_label);
1470 __ LoadImmediate(out, 0);
1471 __ b(&done_label);
1472
1473 // True case: result = 1.
1474 __ Bind(&true_label);
1475 __ LoadImmediate(out, 1);
1476 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001477}
1478
1479void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1480 VisitCondition(comp);
1481}
1482
1483void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1484 VisitCondition(comp);
1485}
1486
1487void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1488 VisitCondition(comp);
1489}
1490
1491void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1492 VisitCondition(comp);
1493}
1494
1495void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1496 VisitCondition(comp);
1497}
1498
1499void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1500 VisitCondition(comp);
1501}
1502
1503void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1504 VisitCondition(comp);
1505}
1506
1507void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1508 VisitCondition(comp);
1509}
1510
1511void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1512 VisitCondition(comp);
1513}
1514
1515void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1516 VisitCondition(comp);
1517}
1518
1519void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1520 VisitCondition(comp);
1521}
1522
1523void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1524 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001525}
1526
Aart Bike9f37602015-10-09 11:15:55 -07001527void LocationsBuilderARM::VisitBelow(HBelow* comp) {
1528 VisitCondition(comp);
1529}
1530
1531void InstructionCodeGeneratorARM::VisitBelow(HBelow* comp) {
1532 VisitCondition(comp);
1533}
1534
1535void LocationsBuilderARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
1536 VisitCondition(comp);
1537}
1538
1539void InstructionCodeGeneratorARM::VisitBelowOrEqual(HBelowOrEqual* comp) {
1540 VisitCondition(comp);
1541}
1542
1543void LocationsBuilderARM::VisitAbove(HAbove* comp) {
1544 VisitCondition(comp);
1545}
1546
1547void InstructionCodeGeneratorARM::VisitAbove(HAbove* comp) {
1548 VisitCondition(comp);
1549}
1550
1551void LocationsBuilderARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
1552 VisitCondition(comp);
1553}
1554
1555void InstructionCodeGeneratorARM::VisitAboveOrEqual(HAboveOrEqual* comp) {
1556 VisitCondition(comp);
1557}
1558
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001559void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001560 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001561}
1562
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001563void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1564 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001565}
1566
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001567void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001568 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001569}
1570
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001571void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001572 // Nothing to do, this is driven by the code generator.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001573}
1574
1575void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001576 LocationSummary* locations =
1577 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001578 switch (store->InputAt(1)->GetType()) {
1579 case Primitive::kPrimBoolean:
1580 case Primitive::kPrimByte:
1581 case Primitive::kPrimChar:
1582 case Primitive::kPrimShort:
1583 case Primitive::kPrimInt:
1584 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001585 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001586 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1587 break;
1588
1589 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001590 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001591 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1592 break;
1593
1594 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001595 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001596 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001597}
1598
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001599void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001600}
1601
1602void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001603 LocationSummary* locations =
1604 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001605 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001606}
1607
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001608void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001609 // Will be generated at use site.
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001610}
1611
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001612void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1613 LocationSummary* locations =
1614 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1615 locations->SetOut(Location::ConstantLocation(constant));
1616}
1617
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001618void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001619 // Will be generated at use site.
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001620}
1621
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001622void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001623 LocationSummary* locations =
1624 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001625 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001626}
1627
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001628void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001629 // Will be generated at use site.
1630}
1631
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001632void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1633 LocationSummary* locations =
1634 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1635 locations->SetOut(Location::ConstantLocation(constant));
1636}
1637
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001638void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001639 // Will be generated at use site.
1640}
1641
1642void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1643 LocationSummary* locations =
1644 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1645 locations->SetOut(Location::ConstantLocation(constant));
1646}
1647
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001648void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001649 // Will be generated at use site.
1650}
1651
Calin Juravle27df7582015-04-17 19:12:31 +01001652void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1653 memory_barrier->SetLocations(nullptr);
1654}
1655
1656void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1657 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1658}
1659
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001660void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001661 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001662}
1663
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001664void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001665 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001666}
1667
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001668void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001669 LocationSummary* locations =
1670 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001671 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001672}
1673
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001674void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001675 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001676}
1677
Calin Juravle175dc732015-08-25 15:42:32 +01001678void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1679 // The trampoline uses the same calling convention as dex calling conventions,
1680 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
1681 // the method_idx.
1682 HandleInvoke(invoke);
1683}
1684
1685void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1686 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
1687}
1688
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001689void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001690 // When we do not run baseline, explicit clinit checks triggered by static
1691 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1692 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001693
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001694 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001695 codegen_->GetAssembler(),
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001696 codegen_->GetInstructionSetFeatures());
1697 if (intrinsic.TryDispatch(invoke)) {
1698 return;
1699 }
1700
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001701 HandleInvoke(invoke);
1702}
1703
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001704static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1705 if (invoke->GetLocations()->Intrinsified()) {
1706 IntrinsicCodeGeneratorARM intrinsic(codegen);
1707 intrinsic.Dispatch(invoke);
1708 return true;
1709 }
1710 return false;
1711}
1712
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001713void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001714 // When we do not run baseline, explicit clinit checks triggered by static
1715 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1716 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001717
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001718 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1719 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001720 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001721
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001722 LocationSummary* locations = invoke->GetLocations();
1723 codegen_->GenerateStaticOrDirectCall(
1724 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001725 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001726}
1727
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001728void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001729 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001730 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001731}
1732
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001733void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001734 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001735 codegen_->GetAssembler(),
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001736 codegen_->GetInstructionSetFeatures());
1737 if (intrinsic.TryDispatch(invoke)) {
1738 return;
1739 }
1740
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001741 HandleInvoke(invoke);
1742}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001743
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001744void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001745 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1746 return;
1747 }
1748
Andreas Gampebfb5ba92015-09-01 15:45:02 +00001749 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001750 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001751 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001752}
1753
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001754void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1755 HandleInvoke(invoke);
1756 // Add the hidden argument.
1757 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1758}
1759
1760void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1761 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001762 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001763 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1764 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001765 LocationSummary* locations = invoke->GetLocations();
1766 Location receiver = locations->InAt(0);
1767 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1768
1769 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001770 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1771 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001772
1773 // temp = object->GetClass();
1774 if (receiver.IsStackSlot()) {
1775 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1776 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1777 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001778 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001779 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001780 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001781 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001782 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001783 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001784 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001785 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1786 // LR = temp->GetEntryPoint();
1787 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1788 // LR();
1789 __ blx(LR);
1790 DCHECK(!codegen_->IsLeafMethod());
1791 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1792}
1793
Roland Levillain88cb1752014-10-20 16:36:47 +01001794void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1795 LocationSummary* locations =
1796 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1797 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001798 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001799 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001800 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1801 break;
1802 }
1803 case Primitive::kPrimLong: {
1804 locations->SetInAt(0, Location::RequiresRegister());
1805 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001806 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001807 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001808
Roland Levillain88cb1752014-10-20 16:36:47 +01001809 case Primitive::kPrimFloat:
1810 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001811 locations->SetInAt(0, Location::RequiresFpuRegister());
1812 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001813 break;
1814
1815 default:
1816 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1817 }
1818}
1819
1820void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1821 LocationSummary* locations = neg->GetLocations();
1822 Location out = locations->Out();
1823 Location in = locations->InAt(0);
1824 switch (neg->GetResultType()) {
1825 case Primitive::kPrimInt:
1826 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001827 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001828 break;
1829
1830 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001831 DCHECK(in.IsRegisterPair());
1832 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1833 __ rsbs(out.AsRegisterPairLow<Register>(),
1834 in.AsRegisterPairLow<Register>(),
1835 ShifterOperand(0));
1836 // We cannot emit an RSC (Reverse Subtract with Carry)
1837 // instruction here, as it does not exist in the Thumb-2
1838 // instruction set. We use the following approach
1839 // using SBC and SUB instead.
1840 //
1841 // out.hi = -C
1842 __ sbc(out.AsRegisterPairHigh<Register>(),
1843 out.AsRegisterPairHigh<Register>(),
1844 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1845 // out.hi = out.hi - in.hi
1846 __ sub(out.AsRegisterPairHigh<Register>(),
1847 out.AsRegisterPairHigh<Register>(),
1848 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1849 break;
1850
Roland Levillain88cb1752014-10-20 16:36:47 +01001851 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001852 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001853 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001854 break;
1855
Roland Levillain88cb1752014-10-20 16:36:47 +01001856 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001857 DCHECK(in.IsFpuRegisterPair());
1858 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1859 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001860 break;
1861
1862 default:
1863 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1864 }
1865}
1866
Roland Levillaindff1f282014-11-05 14:15:05 +00001867void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001868 Primitive::Type result_type = conversion->GetResultType();
1869 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001870 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001871
Roland Levillain5b3ee562015-04-14 16:02:41 +01001872 // The float-to-long, double-to-long and long-to-float type conversions
1873 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001874 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001875 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1876 && result_type == Primitive::kPrimLong)
1877 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001878 ? LocationSummary::kCall
1879 : LocationSummary::kNoCall;
1880 LocationSummary* locations =
1881 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1882
David Brazdilb2bd1c52015-03-25 11:17:37 +00001883 // The Java language does not allow treating boolean as an integral type but
1884 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001885
Roland Levillaindff1f282014-11-05 14:15:05 +00001886 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001887 case Primitive::kPrimByte:
1888 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001889 case Primitive::kPrimBoolean:
1890 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001891 case Primitive::kPrimShort:
1892 case Primitive::kPrimInt:
1893 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001894 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001895 locations->SetInAt(0, Location::RequiresRegister());
1896 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1897 break;
1898
1899 default:
1900 LOG(FATAL) << "Unexpected type conversion from " << input_type
1901 << " to " << result_type;
1902 }
1903 break;
1904
Roland Levillain01a8d712014-11-14 16:27:39 +00001905 case Primitive::kPrimShort:
1906 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001907 case Primitive::kPrimBoolean:
1908 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001909 case Primitive::kPrimByte:
1910 case Primitive::kPrimInt:
1911 case Primitive::kPrimChar:
1912 // Processing a Dex `int-to-short' instruction.
1913 locations->SetInAt(0, Location::RequiresRegister());
1914 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1915 break;
1916
1917 default:
1918 LOG(FATAL) << "Unexpected type conversion from " << input_type
1919 << " to " << result_type;
1920 }
1921 break;
1922
Roland Levillain946e1432014-11-11 17:35:19 +00001923 case Primitive::kPrimInt:
1924 switch (input_type) {
1925 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001926 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001927 locations->SetInAt(0, Location::Any());
1928 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1929 break;
1930
1931 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001932 // Processing a Dex `float-to-int' instruction.
1933 locations->SetInAt(0, Location::RequiresFpuRegister());
1934 locations->SetOut(Location::RequiresRegister());
1935 locations->AddTemp(Location::RequiresFpuRegister());
1936 break;
1937
Roland Levillain946e1432014-11-11 17:35:19 +00001938 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001939 // Processing a Dex `double-to-int' instruction.
1940 locations->SetInAt(0, Location::RequiresFpuRegister());
1941 locations->SetOut(Location::RequiresRegister());
1942 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001943 break;
1944
1945 default:
1946 LOG(FATAL) << "Unexpected type conversion from " << input_type
1947 << " to " << result_type;
1948 }
1949 break;
1950
Roland Levillaindff1f282014-11-05 14:15:05 +00001951 case Primitive::kPrimLong:
1952 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001953 case Primitive::kPrimBoolean:
1954 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001955 case Primitive::kPrimByte:
1956 case Primitive::kPrimShort:
1957 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001958 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001959 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001960 locations->SetInAt(0, Location::RequiresRegister());
1961 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1962 break;
1963
Roland Levillain624279f2014-12-04 11:54:28 +00001964 case Primitive::kPrimFloat: {
1965 // Processing a Dex `float-to-long' instruction.
1966 InvokeRuntimeCallingConvention calling_convention;
1967 locations->SetInAt(0, Location::FpuRegisterLocation(
1968 calling_convention.GetFpuRegisterAt(0)));
1969 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1970 break;
1971 }
1972
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001973 case Primitive::kPrimDouble: {
1974 // Processing a Dex `double-to-long' instruction.
1975 InvokeRuntimeCallingConvention calling_convention;
1976 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1977 calling_convention.GetFpuRegisterAt(0),
1978 calling_convention.GetFpuRegisterAt(1)));
1979 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001980 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001981 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001982
1983 default:
1984 LOG(FATAL) << "Unexpected type conversion from " << input_type
1985 << " to " << result_type;
1986 }
1987 break;
1988
Roland Levillain981e4542014-11-14 11:47:14 +00001989 case Primitive::kPrimChar:
1990 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001991 case Primitive::kPrimBoolean:
1992 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001993 case Primitive::kPrimByte:
1994 case Primitive::kPrimShort:
1995 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001996 // Processing a Dex `int-to-char' instruction.
1997 locations->SetInAt(0, Location::RequiresRegister());
1998 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1999 break;
2000
2001 default:
2002 LOG(FATAL) << "Unexpected type conversion from " << input_type
2003 << " to " << result_type;
2004 }
2005 break;
2006
Roland Levillaindff1f282014-11-05 14:15:05 +00002007 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002008 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002009 case Primitive::kPrimBoolean:
2010 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002011 case Primitive::kPrimByte:
2012 case Primitive::kPrimShort:
2013 case Primitive::kPrimInt:
2014 case Primitive::kPrimChar:
2015 // Processing a Dex `int-to-float' instruction.
2016 locations->SetInAt(0, Location::RequiresRegister());
2017 locations->SetOut(Location::RequiresFpuRegister());
2018 break;
2019
Roland Levillain5b3ee562015-04-14 16:02:41 +01002020 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00002021 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002022 InvokeRuntimeCallingConvention calling_convention;
2023 locations->SetInAt(0, Location::RegisterPairLocation(
2024 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2025 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00002026 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01002027 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00002028
Roland Levillaincff13742014-11-17 14:32:17 +00002029 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002030 // Processing a Dex `double-to-float' instruction.
2031 locations->SetInAt(0, Location::RequiresFpuRegister());
2032 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002033 break;
2034
2035 default:
2036 LOG(FATAL) << "Unexpected type conversion from " << input_type
2037 << " to " << result_type;
2038 };
2039 break;
2040
Roland Levillaindff1f282014-11-05 14:15:05 +00002041 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002042 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002043 case Primitive::kPrimBoolean:
2044 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002045 case Primitive::kPrimByte:
2046 case Primitive::kPrimShort:
2047 case Primitive::kPrimInt:
2048 case Primitive::kPrimChar:
2049 // Processing a Dex `int-to-double' instruction.
2050 locations->SetInAt(0, Location::RequiresRegister());
2051 locations->SetOut(Location::RequiresFpuRegister());
2052 break;
2053
2054 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00002055 // Processing a Dex `long-to-double' instruction.
2056 locations->SetInAt(0, Location::RequiresRegister());
2057 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01002058 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00002059 locations->AddTemp(Location::RequiresFpuRegister());
2060 break;
2061
Roland Levillaincff13742014-11-17 14:32:17 +00002062 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002063 // Processing a Dex `float-to-double' instruction.
2064 locations->SetInAt(0, Location::RequiresFpuRegister());
2065 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00002066 break;
2067
2068 default:
2069 LOG(FATAL) << "Unexpected type conversion from " << input_type
2070 << " to " << result_type;
2071 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002072 break;
2073
2074 default:
2075 LOG(FATAL) << "Unexpected type conversion from " << input_type
2076 << " to " << result_type;
2077 }
2078}
2079
2080void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
2081 LocationSummary* locations = conversion->GetLocations();
2082 Location out = locations->Out();
2083 Location in = locations->InAt(0);
2084 Primitive::Type result_type = conversion->GetResultType();
2085 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002086 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00002087 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002088 case Primitive::kPrimByte:
2089 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002090 case Primitive::kPrimBoolean:
2091 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002092 case Primitive::kPrimShort:
2093 case Primitive::kPrimInt:
2094 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002095 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002096 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002097 break;
2098
2099 default:
2100 LOG(FATAL) << "Unexpected type conversion from " << input_type
2101 << " to " << result_type;
2102 }
2103 break;
2104
Roland Levillain01a8d712014-11-14 16:27:39 +00002105 case Primitive::kPrimShort:
2106 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002107 case Primitive::kPrimBoolean:
2108 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002109 case Primitive::kPrimByte:
2110 case Primitive::kPrimInt:
2111 case Primitive::kPrimChar:
2112 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002113 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00002114 break;
2115
2116 default:
2117 LOG(FATAL) << "Unexpected type conversion from " << input_type
2118 << " to " << result_type;
2119 }
2120 break;
2121
Roland Levillain946e1432014-11-11 17:35:19 +00002122 case Primitive::kPrimInt:
2123 switch (input_type) {
2124 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002125 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002126 DCHECK(out.IsRegister());
2127 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002128 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00002129 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002130 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00002131 } else {
2132 DCHECK(in.IsConstant());
2133 DCHECK(in.GetConstant()->IsLongConstant());
2134 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002135 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00002136 }
2137 break;
2138
Roland Levillain3f8f9362014-12-02 17:45:01 +00002139 case Primitive::kPrimFloat: {
2140 // Processing a Dex `float-to-int' instruction.
2141 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
2142 __ vmovs(temp, in.AsFpuRegister<SRegister>());
2143 __ vcvtis(temp, temp);
2144 __ vmovrs(out.AsRegister<Register>(), temp);
2145 break;
2146 }
2147
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002148 case Primitive::kPrimDouble: {
2149 // Processing a Dex `double-to-int' instruction.
2150 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
2151 DRegister temp_d = FromLowSToD(temp_s);
2152 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
2153 __ vcvtid(temp_s, temp_d);
2154 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002155 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002156 }
Roland Levillain946e1432014-11-11 17:35:19 +00002157
2158 default:
2159 LOG(FATAL) << "Unexpected type conversion from " << input_type
2160 << " to " << result_type;
2161 }
2162 break;
2163
Roland Levillaindff1f282014-11-05 14:15:05 +00002164 case Primitive::kPrimLong:
2165 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002166 case Primitive::kPrimBoolean:
2167 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002168 case Primitive::kPrimByte:
2169 case Primitive::kPrimShort:
2170 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002171 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002172 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002173 DCHECK(out.IsRegisterPair());
2174 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002175 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002176 // Sign extension.
2177 __ Asr(out.AsRegisterPairHigh<Register>(),
2178 out.AsRegisterPairLow<Register>(),
2179 31);
2180 break;
2181
2182 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002183 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00002184 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
2185 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002186 conversion->GetDexPc(),
2187 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00002188 break;
2189
Roland Levillaindff1f282014-11-05 14:15:05 +00002190 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002191 // Processing a Dex `double-to-long' instruction.
2192 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
2193 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002194 conversion->GetDexPc(),
2195 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00002196 break;
2197
2198 default:
2199 LOG(FATAL) << "Unexpected type conversion from " << input_type
2200 << " to " << result_type;
2201 }
2202 break;
2203
Roland Levillain981e4542014-11-14 11:47:14 +00002204 case Primitive::kPrimChar:
2205 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002206 case Primitive::kPrimBoolean:
2207 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002208 case Primitive::kPrimByte:
2209 case Primitive::kPrimShort:
2210 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002211 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002212 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002213 break;
2214
2215 default:
2216 LOG(FATAL) << "Unexpected type conversion from " << input_type
2217 << " to " << result_type;
2218 }
2219 break;
2220
Roland Levillaindff1f282014-11-05 14:15:05 +00002221 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002222 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002223 case Primitive::kPrimBoolean:
2224 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002225 case Primitive::kPrimByte:
2226 case Primitive::kPrimShort:
2227 case Primitive::kPrimInt:
2228 case Primitive::kPrimChar: {
2229 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002230 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2231 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002232 break;
2233 }
2234
Roland Levillain5b3ee562015-04-14 16:02:41 +01002235 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002236 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002237 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
2238 conversion,
2239 conversion->GetDexPc(),
2240 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00002241 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002242
Roland Levillaincff13742014-11-17 14:32:17 +00002243 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002244 // Processing a Dex `double-to-float' instruction.
2245 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2246 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002247 break;
2248
2249 default:
2250 LOG(FATAL) << "Unexpected type conversion from " << input_type
2251 << " to " << result_type;
2252 };
2253 break;
2254
Roland Levillaindff1f282014-11-05 14:15:05 +00002255 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002256 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002257 case Primitive::kPrimBoolean:
2258 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002259 case Primitive::kPrimByte:
2260 case Primitive::kPrimShort:
2261 case Primitive::kPrimInt:
2262 case Primitive::kPrimChar: {
2263 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002264 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002265 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2266 out.AsFpuRegisterPairLow<SRegister>());
2267 break;
2268 }
2269
Roland Levillain647b9ed2014-11-27 12:06:00 +00002270 case Primitive::kPrimLong: {
2271 // Processing a Dex `long-to-double' instruction.
2272 Register low = in.AsRegisterPairLow<Register>();
2273 Register high = in.AsRegisterPairHigh<Register>();
2274 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2275 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002276 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002277 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002278 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2279 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002280
Roland Levillain682393c2015-04-14 15:57:52 +01002281 // temp_d = int-to-double(high)
2282 __ vmovsr(temp_s, high);
2283 __ vcvtdi(temp_d, temp_s);
2284 // constant_d = k2Pow32EncodingForDouble
2285 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2286 // out_d = unsigned-to-double(low)
2287 __ vmovsr(out_s, low);
2288 __ vcvtdu(out_d, out_s);
2289 // out_d += temp_d * constant_d
2290 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002291 break;
2292 }
2293
Roland Levillaincff13742014-11-17 14:32:17 +00002294 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002295 // Processing a Dex `float-to-double' instruction.
2296 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2297 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002298 break;
2299
2300 default:
2301 LOG(FATAL) << "Unexpected type conversion from " << input_type
2302 << " to " << result_type;
2303 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002304 break;
2305
2306 default:
2307 LOG(FATAL) << "Unexpected type conversion from " << input_type
2308 << " to " << result_type;
2309 }
2310}
2311
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002312void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002313 LocationSummary* locations =
2314 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002315 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002316 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002317 locations->SetInAt(0, Location::RequiresRegister());
2318 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002319 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2320 break;
2321 }
2322
2323 case Primitive::kPrimLong: {
2324 locations->SetInAt(0, Location::RequiresRegister());
2325 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002326 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002327 break;
2328 }
2329
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002330 case Primitive::kPrimFloat:
2331 case Primitive::kPrimDouble: {
2332 locations->SetInAt(0, Location::RequiresFpuRegister());
2333 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002334 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002335 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002336 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002337
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002338 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002339 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002340 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002341}
2342
2343void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2344 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002345 Location out = locations->Out();
2346 Location first = locations->InAt(0);
2347 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002348 switch (add->GetResultType()) {
2349 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002350 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002351 __ add(out.AsRegister<Register>(),
2352 first.AsRegister<Register>(),
2353 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002354 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002355 __ AddConstant(out.AsRegister<Register>(),
2356 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002357 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002358 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002359 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002360
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002361 case Primitive::kPrimLong: {
2362 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002363 __ adds(out.AsRegisterPairLow<Register>(),
2364 first.AsRegisterPairLow<Register>(),
2365 ShifterOperand(second.AsRegisterPairLow<Register>()));
2366 __ adc(out.AsRegisterPairHigh<Register>(),
2367 first.AsRegisterPairHigh<Register>(),
2368 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002369 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002370 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002371
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002372 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002373 __ vadds(out.AsFpuRegister<SRegister>(),
2374 first.AsFpuRegister<SRegister>(),
2375 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002376 break;
2377
2378 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002379 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2380 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2381 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002382 break;
2383
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002384 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002385 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002386 }
2387}
2388
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002389void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002390 LocationSummary* locations =
2391 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002392 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002393 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002394 locations->SetInAt(0, Location::RequiresRegister());
2395 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002396 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2397 break;
2398 }
2399
2400 case Primitive::kPrimLong: {
2401 locations->SetInAt(0, Location::RequiresRegister());
2402 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002403 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002404 break;
2405 }
Calin Juravle11351682014-10-23 15:38:15 +01002406 case Primitive::kPrimFloat:
2407 case Primitive::kPrimDouble: {
2408 locations->SetInAt(0, Location::RequiresFpuRegister());
2409 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002410 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002411 break;
Calin Juravle11351682014-10-23 15:38:15 +01002412 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002413 default:
Calin Juravle11351682014-10-23 15:38:15 +01002414 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002415 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002416}
2417
2418void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2419 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002420 Location out = locations->Out();
2421 Location first = locations->InAt(0);
2422 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002423 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002424 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002425 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002426 __ sub(out.AsRegister<Register>(),
2427 first.AsRegister<Register>(),
2428 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002429 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002430 __ AddConstant(out.AsRegister<Register>(),
2431 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002432 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002433 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002434 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002435 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002436
Calin Juravle11351682014-10-23 15:38:15 +01002437 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002438 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002439 __ subs(out.AsRegisterPairLow<Register>(),
2440 first.AsRegisterPairLow<Register>(),
2441 ShifterOperand(second.AsRegisterPairLow<Register>()));
2442 __ sbc(out.AsRegisterPairHigh<Register>(),
2443 first.AsRegisterPairHigh<Register>(),
2444 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002445 break;
Calin Juravle11351682014-10-23 15:38:15 +01002446 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002447
Calin Juravle11351682014-10-23 15:38:15 +01002448 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002449 __ vsubs(out.AsFpuRegister<SRegister>(),
2450 first.AsFpuRegister<SRegister>(),
2451 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002452 break;
Calin Juravle11351682014-10-23 15:38:15 +01002453 }
2454
2455 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002456 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2457 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2458 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002459 break;
2460 }
2461
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002462
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002463 default:
Calin Juravle11351682014-10-23 15:38:15 +01002464 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002465 }
2466}
2467
Calin Juravle34bacdf2014-10-07 20:23:36 +01002468void LocationsBuilderARM::VisitMul(HMul* mul) {
2469 LocationSummary* locations =
2470 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2471 switch (mul->GetResultType()) {
2472 case Primitive::kPrimInt:
2473 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002474 locations->SetInAt(0, Location::RequiresRegister());
2475 locations->SetInAt(1, Location::RequiresRegister());
2476 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002477 break;
2478 }
2479
Calin Juravleb5bfa962014-10-21 18:02:24 +01002480 case Primitive::kPrimFloat:
2481 case Primitive::kPrimDouble: {
2482 locations->SetInAt(0, Location::RequiresFpuRegister());
2483 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002484 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002485 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002486 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002487
2488 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002489 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002490 }
2491}
2492
2493void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2494 LocationSummary* locations = mul->GetLocations();
2495 Location out = locations->Out();
2496 Location first = locations->InAt(0);
2497 Location second = locations->InAt(1);
2498 switch (mul->GetResultType()) {
2499 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002500 __ mul(out.AsRegister<Register>(),
2501 first.AsRegister<Register>(),
2502 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002503 break;
2504 }
2505 case Primitive::kPrimLong: {
2506 Register out_hi = out.AsRegisterPairHigh<Register>();
2507 Register out_lo = out.AsRegisterPairLow<Register>();
2508 Register in1_hi = first.AsRegisterPairHigh<Register>();
2509 Register in1_lo = first.AsRegisterPairLow<Register>();
2510 Register in2_hi = second.AsRegisterPairHigh<Register>();
2511 Register in2_lo = second.AsRegisterPairLow<Register>();
2512
2513 // Extra checks to protect caused by the existence of R1_R2.
2514 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2515 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2516 DCHECK_NE(out_hi, in1_lo);
2517 DCHECK_NE(out_hi, in2_lo);
2518
2519 // input: in1 - 64 bits, in2 - 64 bits
2520 // output: out
2521 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2522 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2523 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2524
2525 // IP <- in1.lo * in2.hi
2526 __ mul(IP, in1_lo, in2_hi);
2527 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2528 __ mla(out_hi, in1_hi, in2_lo, IP);
2529 // out.lo <- (in1.lo * in2.lo)[31:0];
2530 __ umull(out_lo, IP, in1_lo, in2_lo);
2531 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2532 __ add(out_hi, out_hi, ShifterOperand(IP));
2533 break;
2534 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002535
2536 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002537 __ vmuls(out.AsFpuRegister<SRegister>(),
2538 first.AsFpuRegister<SRegister>(),
2539 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002540 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002541 }
2542
2543 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002544 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2545 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2546 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002547 break;
2548 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002549
2550 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002551 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002552 }
2553}
2554
Zheng Xuc6667102015-05-15 16:08:45 +08002555void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2556 DCHECK(instruction->IsDiv() || instruction->IsRem());
2557 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2558
2559 LocationSummary* locations = instruction->GetLocations();
2560 Location second = locations->InAt(1);
2561 DCHECK(second.IsConstant());
2562
2563 Register out = locations->Out().AsRegister<Register>();
2564 Register dividend = locations->InAt(0).AsRegister<Register>();
2565 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2566 DCHECK(imm == 1 || imm == -1);
2567
2568 if (instruction->IsRem()) {
2569 __ LoadImmediate(out, 0);
2570 } else {
2571 if (imm == 1) {
2572 __ Mov(out, dividend);
2573 } else {
2574 __ rsb(out, dividend, ShifterOperand(0));
2575 }
2576 }
2577}
2578
2579void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2580 DCHECK(instruction->IsDiv() || instruction->IsRem());
2581 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2582
2583 LocationSummary* locations = instruction->GetLocations();
2584 Location second = locations->InAt(1);
2585 DCHECK(second.IsConstant());
2586
2587 Register out = locations->Out().AsRegister<Register>();
2588 Register dividend = locations->InAt(0).AsRegister<Register>();
2589 Register temp = locations->GetTemp(0).AsRegister<Register>();
2590 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002591 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002592 DCHECK(IsPowerOfTwo(abs_imm));
2593 int ctz_imm = CTZ(abs_imm);
2594
2595 if (ctz_imm == 1) {
2596 __ Lsr(temp, dividend, 32 - ctz_imm);
2597 } else {
2598 __ Asr(temp, dividend, 31);
2599 __ Lsr(temp, temp, 32 - ctz_imm);
2600 }
2601 __ add(out, temp, ShifterOperand(dividend));
2602
2603 if (instruction->IsDiv()) {
2604 __ Asr(out, out, ctz_imm);
2605 if (imm < 0) {
2606 __ rsb(out, out, ShifterOperand(0));
2607 }
2608 } else {
2609 __ ubfx(out, out, 0, ctz_imm);
2610 __ sub(out, out, ShifterOperand(temp));
2611 }
2612}
2613
2614void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2615 DCHECK(instruction->IsDiv() || instruction->IsRem());
2616 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2617
2618 LocationSummary* locations = instruction->GetLocations();
2619 Location second = locations->InAt(1);
2620 DCHECK(second.IsConstant());
2621
2622 Register out = locations->Out().AsRegister<Register>();
2623 Register dividend = locations->InAt(0).AsRegister<Register>();
2624 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2625 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2626 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2627
2628 int64_t magic;
2629 int shift;
2630 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2631
2632 __ LoadImmediate(temp1, magic);
2633 __ smull(temp2, temp1, dividend, temp1);
2634
2635 if (imm > 0 && magic < 0) {
2636 __ add(temp1, temp1, ShifterOperand(dividend));
2637 } else if (imm < 0 && magic > 0) {
2638 __ sub(temp1, temp1, ShifterOperand(dividend));
2639 }
2640
2641 if (shift != 0) {
2642 __ Asr(temp1, temp1, shift);
2643 }
2644
2645 if (instruction->IsDiv()) {
2646 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2647 } else {
2648 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2649 // TODO: Strength reduction for mls.
2650 __ LoadImmediate(temp2, imm);
2651 __ mls(out, temp1, temp2, dividend);
2652 }
2653}
2654
2655void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2656 DCHECK(instruction->IsDiv() || instruction->IsRem());
2657 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2658
2659 LocationSummary* locations = instruction->GetLocations();
2660 Location second = locations->InAt(1);
2661 DCHECK(second.IsConstant());
2662
2663 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2664 if (imm == 0) {
2665 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2666 } else if (imm == 1 || imm == -1) {
2667 DivRemOneOrMinusOne(instruction);
2668 } else if (IsPowerOfTwo(std::abs(imm))) {
2669 DivRemByPowerOfTwo(instruction);
2670 } else {
2671 DCHECK(imm <= -2 || imm >= 2);
2672 GenerateDivRemWithAnyConstant(instruction);
2673 }
2674}
2675
Calin Juravle7c4954d2014-10-28 16:57:40 +00002676void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002677 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2678 if (div->GetResultType() == Primitive::kPrimLong) {
2679 // pLdiv runtime call.
2680 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002681 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2682 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002683 } else if (div->GetResultType() == Primitive::kPrimInt &&
2684 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2685 // pIdivmod runtime call.
2686 call_kind = LocationSummary::kCall;
2687 }
2688
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002689 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2690
Calin Juravle7c4954d2014-10-28 16:57:40 +00002691 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002692 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002693 if (div->InputAt(1)->IsConstant()) {
2694 locations->SetInAt(0, Location::RequiresRegister());
2695 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2696 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2697 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2698 if (abs_imm <= 1) {
2699 // No temp register required.
2700 } else {
2701 locations->AddTemp(Location::RequiresRegister());
2702 if (!IsPowerOfTwo(abs_imm)) {
2703 locations->AddTemp(Location::RequiresRegister());
2704 }
2705 }
2706 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002707 locations->SetInAt(0, Location::RequiresRegister());
2708 locations->SetInAt(1, Location::RequiresRegister());
2709 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2710 } else {
2711 InvokeRuntimeCallingConvention calling_convention;
2712 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2713 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2714 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2715 // we only need the former.
2716 locations->SetOut(Location::RegisterLocation(R0));
2717 }
Calin Juravled0d48522014-11-04 16:40:20 +00002718 break;
2719 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002720 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002721 InvokeRuntimeCallingConvention calling_convention;
2722 locations->SetInAt(0, Location::RegisterPairLocation(
2723 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2724 locations->SetInAt(1, Location::RegisterPairLocation(
2725 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002726 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002727 break;
2728 }
2729 case Primitive::kPrimFloat:
2730 case Primitive::kPrimDouble: {
2731 locations->SetInAt(0, Location::RequiresFpuRegister());
2732 locations->SetInAt(1, Location::RequiresFpuRegister());
2733 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2734 break;
2735 }
2736
2737 default:
2738 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2739 }
2740}
2741
2742void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2743 LocationSummary* locations = div->GetLocations();
2744 Location out = locations->Out();
2745 Location first = locations->InAt(0);
2746 Location second = locations->InAt(1);
2747
2748 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002749 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002750 if (second.IsConstant()) {
2751 GenerateDivRemConstantIntegral(div);
2752 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002753 __ sdiv(out.AsRegister<Register>(),
2754 first.AsRegister<Register>(),
2755 second.AsRegister<Register>());
2756 } else {
2757 InvokeRuntimeCallingConvention calling_convention;
2758 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2759 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2760 DCHECK_EQ(R0, out.AsRegister<Register>());
2761
2762 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2763 }
Calin Juravled0d48522014-11-04 16:40:20 +00002764 break;
2765 }
2766
Calin Juravle7c4954d2014-10-28 16:57:40 +00002767 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002768 InvokeRuntimeCallingConvention calling_convention;
2769 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2770 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2771 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2772 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2773 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002774 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002775
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002776 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002777 break;
2778 }
2779
2780 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002781 __ vdivs(out.AsFpuRegister<SRegister>(),
2782 first.AsFpuRegister<SRegister>(),
2783 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002784 break;
2785 }
2786
2787 case Primitive::kPrimDouble: {
2788 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2789 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2790 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2791 break;
2792 }
2793
2794 default:
2795 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2796 }
2797}
2798
Calin Juravlebacfec32014-11-14 15:54:36 +00002799void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002800 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002801
2802 // Most remainders are implemented in the runtime.
2803 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002804 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2805 // sdiv will be replaced by other instruction sequence.
2806 call_kind = LocationSummary::kNoCall;
2807 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2808 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002809 // Have hardware divide instruction for int, do it with three instructions.
2810 call_kind = LocationSummary::kNoCall;
2811 }
2812
Calin Juravlebacfec32014-11-14 15:54:36 +00002813 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2814
Calin Juravled2ec87d2014-12-08 14:24:46 +00002815 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002816 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002817 if (rem->InputAt(1)->IsConstant()) {
2818 locations->SetInAt(0, Location::RequiresRegister());
2819 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2820 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2821 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2822 if (abs_imm <= 1) {
2823 // No temp register required.
2824 } else {
2825 locations->AddTemp(Location::RequiresRegister());
2826 if (!IsPowerOfTwo(abs_imm)) {
2827 locations->AddTemp(Location::RequiresRegister());
2828 }
2829 }
2830 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002831 locations->SetInAt(0, Location::RequiresRegister());
2832 locations->SetInAt(1, Location::RequiresRegister());
2833 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2834 locations->AddTemp(Location::RequiresRegister());
2835 } else {
2836 InvokeRuntimeCallingConvention calling_convention;
2837 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2838 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2839 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2840 // we only need the latter.
2841 locations->SetOut(Location::RegisterLocation(R1));
2842 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002843 break;
2844 }
2845 case Primitive::kPrimLong: {
2846 InvokeRuntimeCallingConvention calling_convention;
2847 locations->SetInAt(0, Location::RegisterPairLocation(
2848 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2849 locations->SetInAt(1, Location::RegisterPairLocation(
2850 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2851 // The runtime helper puts the output in R2,R3.
2852 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2853 break;
2854 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002855 case Primitive::kPrimFloat: {
2856 InvokeRuntimeCallingConvention calling_convention;
2857 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2858 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2859 locations->SetOut(Location::FpuRegisterLocation(S0));
2860 break;
2861 }
2862
Calin Juravlebacfec32014-11-14 15:54:36 +00002863 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002864 InvokeRuntimeCallingConvention calling_convention;
2865 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2866 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2867 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2868 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2869 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002870 break;
2871 }
2872
2873 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002874 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002875 }
2876}
2877
2878void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2879 LocationSummary* locations = rem->GetLocations();
2880 Location out = locations->Out();
2881 Location first = locations->InAt(0);
2882 Location second = locations->InAt(1);
2883
Calin Juravled2ec87d2014-12-08 14:24:46 +00002884 Primitive::Type type = rem->GetResultType();
2885 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002886 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002887 if (second.IsConstant()) {
2888 GenerateDivRemConstantIntegral(rem);
2889 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002890 Register reg1 = first.AsRegister<Register>();
2891 Register reg2 = second.AsRegister<Register>();
2892 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002893
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002894 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002895 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002896 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002897 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002898 } else {
2899 InvokeRuntimeCallingConvention calling_convention;
2900 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2901 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2902 DCHECK_EQ(R1, out.AsRegister<Register>());
2903
2904 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2905 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002906 break;
2907 }
2908
2909 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002910 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002911 break;
2912 }
2913
Calin Juravled2ec87d2014-12-08 14:24:46 +00002914 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002915 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002916 break;
2917 }
2918
Calin Juravlebacfec32014-11-14 15:54:36 +00002919 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002920 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002921 break;
2922 }
2923
2924 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002925 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002926 }
2927}
2928
Calin Juravled0d48522014-11-04 16:40:20 +00002929void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00002930 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2931 ? LocationSummary::kCallOnSlowPath
2932 : LocationSummary::kNoCall;
2933 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002934 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002935 if (instruction->HasUses()) {
2936 locations->SetOut(Location::SameAsFirstInput());
2937 }
2938}
2939
2940void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07002941 SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
Calin Juravled0d48522014-11-04 16:40:20 +00002942 codegen_->AddSlowPath(slow_path);
2943
2944 LocationSummary* locations = instruction->GetLocations();
2945 Location value = locations->InAt(0);
2946
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002947 switch (instruction->GetType()) {
Serguei Katkov8c0676c2015-08-03 13:55:33 +06002948 case Primitive::kPrimByte:
2949 case Primitive::kPrimChar:
2950 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002951 case Primitive::kPrimInt: {
2952 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01002953 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002954 } else {
2955 DCHECK(value.IsConstant()) << value;
2956 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2957 __ b(slow_path->GetEntryLabel());
2958 }
2959 }
2960 break;
2961 }
2962 case Primitive::kPrimLong: {
2963 if (value.IsRegisterPair()) {
2964 __ orrs(IP,
2965 value.AsRegisterPairLow<Register>(),
2966 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2967 __ b(slow_path->GetEntryLabel(), EQ);
2968 } else {
2969 DCHECK(value.IsConstant()) << value;
2970 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2971 __ b(slow_path->GetEntryLabel());
2972 }
2973 }
2974 break;
2975 default:
2976 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2977 }
2978 }
Calin Juravled0d48522014-11-04 16:40:20 +00002979}
2980
Calin Juravle9aec02f2014-11-18 23:06:35 +00002981void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2982 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2983
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002984 LocationSummary* locations =
2985 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002986
2987 switch (op->GetResultType()) {
2988 case Primitive::kPrimInt: {
2989 locations->SetInAt(0, Location::RequiresRegister());
2990 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002991 // Make the output overlap, as it will be used to hold the masked
2992 // second input.
2993 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002994 break;
2995 }
2996 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002997 locations->SetInAt(0, Location::RequiresRegister());
2998 locations->SetInAt(1, Location::RequiresRegister());
2999 locations->AddTemp(Location::RequiresRegister());
3000 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00003001 break;
3002 }
3003 default:
3004 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
3005 }
3006}
3007
3008void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
3009 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
3010
3011 LocationSummary* locations = op->GetLocations();
3012 Location out = locations->Out();
3013 Location first = locations->InAt(0);
3014 Location second = locations->InAt(1);
3015
3016 Primitive::Type type = op->GetResultType();
3017 switch (type) {
3018 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003019 Register out_reg = out.AsRegister<Register>();
3020 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003021 // Arm doesn't mask the shift count so we need to do it ourselves.
3022 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003023 Register second_reg = second.AsRegister<Register>();
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003024 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
Calin Juravle9aec02f2014-11-18 23:06:35 +00003025 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003026 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003027 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003028 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003029 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003030 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003031 }
3032 } else {
3033 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
3034 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
3035 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
3036 __ Mov(out_reg, first_reg);
3037 } else if (op->IsShl()) {
3038 __ Lsl(out_reg, first_reg, shift_value);
3039 } else if (op->IsShr()) {
3040 __ Asr(out_reg, first_reg, shift_value);
3041 } else {
3042 __ Lsr(out_reg, first_reg, shift_value);
3043 }
3044 }
3045 break;
3046 }
3047 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003048 Register o_h = out.AsRegisterPairHigh<Register>();
3049 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00003050
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003051 Register temp = locations->GetTemp(0).AsRegister<Register>();
3052
3053 Register high = first.AsRegisterPairHigh<Register>();
3054 Register low = first.AsRegisterPairLow<Register>();
3055
3056 Register second_reg = second.AsRegister<Register>();
3057
Calin Juravle9aec02f2014-11-18 23:06:35 +00003058 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003059 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003060 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003061 __ Lsl(o_h, high, o_l);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003062 // Shift the low part and `or` what overflew on the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003063 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003064 __ Lsr(temp, low, temp);
3065 __ orr(o_h, o_h, ShifterOperand(temp));
3066 // If the shift is > 32 bits, override the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003067 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003068 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003069 __ Lsl(o_h, low, temp, PL);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003070 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003071 __ Lsl(o_l, low, o_l);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003072 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003073 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003074 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003075 __ Lsr(o_l, low, o_h);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003076 // Shift the high part and `or` what underflew on the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003077 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003078 __ Lsl(temp, high, temp);
3079 __ orr(o_l, o_l, ShifterOperand(temp));
3080 // If the shift is > 32 bits, override the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003081 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003082 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003083 __ Asr(o_l, high, temp, PL);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003084 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003085 __ Asr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003086 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003087 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003088 // same as Shr except we use `Lsr`s and not `Asr`s
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003089 __ Lsr(o_l, low, o_h);
3090 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003091 __ Lsl(temp, high, temp);
3092 __ orr(o_l, o_l, ShifterOperand(temp));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003093 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003094 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003095 __ Lsr(o_l, high, temp, PL);
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003096 __ Lsr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003097 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003098 break;
3099 }
3100 default:
3101 LOG(FATAL) << "Unexpected operation type " << type;
3102 }
3103}
3104
3105void LocationsBuilderARM::VisitShl(HShl* shl) {
3106 HandleShift(shl);
3107}
3108
3109void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
3110 HandleShift(shl);
3111}
3112
3113void LocationsBuilderARM::VisitShr(HShr* shr) {
3114 HandleShift(shr);
3115}
3116
3117void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
3118 HandleShift(shr);
3119}
3120
3121void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
3122 HandleShift(ushr);
3123}
3124
3125void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
3126 HandleShift(ushr);
3127}
3128
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003129void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003130 LocationSummary* locations =
3131 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01003132 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003133 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003134 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003135 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003136}
3137
3138void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
3139 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003140 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003141 // Note: if heap poisoning is enabled, the entry point takes cares
3142 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01003143 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003144 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003145 instruction->GetDexPc(),
3146 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003147}
3148
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003149void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3150 LocationSummary* locations =
3151 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3152 InvokeRuntimeCallingConvention calling_convention;
3153 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003154 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003155 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003156 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003157}
3158
3159void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3160 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003161 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003162 // Note: if heap poisoning is enabled, the entry point takes cares
3163 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01003164 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003165 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003166 instruction->GetDexPc(),
3167 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003168}
3169
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003170void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003171 LocationSummary* locations =
3172 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003173 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3174 if (location.IsStackSlot()) {
3175 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3176 } else if (location.IsDoubleStackSlot()) {
3177 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003178 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003179 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003180}
3181
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003182void InstructionCodeGeneratorARM::VisitParameterValue(
3183 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003184 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003185}
3186
3187void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3188 LocationSummary* locations =
3189 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3190 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3191}
3192
3193void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3194 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003195}
3196
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003197void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003198 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003199 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003200 locations->SetInAt(0, Location::RequiresRegister());
3201 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003202}
3203
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003204void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3205 LocationSummary* locations = not_->GetLocations();
3206 Location out = locations->Out();
3207 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003208 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003209 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003210 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003211 break;
3212
3213 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003214 __ mvn(out.AsRegisterPairLow<Register>(),
3215 ShifterOperand(in.AsRegisterPairLow<Register>()));
3216 __ mvn(out.AsRegisterPairHigh<Register>(),
3217 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003218 break;
3219
3220 default:
3221 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3222 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003223}
3224
David Brazdil66d126e2015-04-03 16:02:44 +01003225void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3226 LocationSummary* locations =
3227 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3228 locations->SetInAt(0, Location::RequiresRegister());
3229 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3230}
3231
3232void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003233 LocationSummary* locations = bool_not->GetLocations();
3234 Location out = locations->Out();
3235 Location in = locations->InAt(0);
3236 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3237}
3238
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003239void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003240 LocationSummary* locations =
3241 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003242 switch (compare->InputAt(0)->GetType()) {
3243 case Primitive::kPrimLong: {
3244 locations->SetInAt(0, Location::RequiresRegister());
3245 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003246 // Output overlaps because it is written before doing the low comparison.
3247 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003248 break;
3249 }
3250 case Primitive::kPrimFloat:
3251 case Primitive::kPrimDouble: {
3252 locations->SetInAt(0, Location::RequiresFpuRegister());
3253 locations->SetInAt(1, Location::RequiresFpuRegister());
3254 locations->SetOut(Location::RequiresRegister());
3255 break;
3256 }
3257 default:
3258 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3259 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003260}
3261
3262void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003263 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003264 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003265 Location left = locations->InAt(0);
3266 Location right = locations->InAt(1);
3267
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003268 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003269 Primitive::Type type = compare->InputAt(0)->GetType();
3270 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003271 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003272 __ cmp(left.AsRegisterPairHigh<Register>(),
3273 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003274 __ b(&less, LT);
3275 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003276 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003277 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003278 __ cmp(left.AsRegisterPairLow<Register>(),
3279 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00003280 break;
3281 }
3282 case Primitive::kPrimFloat:
3283 case Primitive::kPrimDouble: {
3284 __ LoadImmediate(out, 0);
3285 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003286 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00003287 } else {
3288 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
3289 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
3290 }
3291 __ vmstat(); // transfer FP status register to ARM APSR.
3292 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003293 break;
3294 }
3295 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003296 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003297 }
Calin Juravleddb7df22014-11-25 20:56:51 +00003298 __ b(&done, EQ);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003299 __ b(&less, LO); // LO is for both: unsigned compare for longs and 'less than' for floats.
Calin Juravleddb7df22014-11-25 20:56:51 +00003300
3301 __ Bind(&greater);
3302 __ LoadImmediate(out, 1);
3303 __ b(&done);
3304
3305 __ Bind(&less);
3306 __ LoadImmediate(out, -1);
3307
3308 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003309}
3310
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003311void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003312 LocationSummary* locations =
3313 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003314 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
3315 locations->SetInAt(i, Location::Any());
3316 }
3317 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003318}
3319
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003320void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003321 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003322}
3323
Calin Juravle52c48962014-12-16 17:02:57 +00003324void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3325 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07003326 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00003327 switch (kind) {
3328 case MemBarrierKind::kAnyStore:
3329 case MemBarrierKind::kLoadAny:
3330 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003331 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003332 break;
3333 }
3334 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003335 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003336 break;
3337 }
3338 default:
3339 LOG(FATAL) << "Unexpected memory barrier " << kind;
3340 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003341 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003342}
3343
3344void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3345 uint32_t offset,
3346 Register out_lo,
3347 Register out_hi) {
3348 if (offset != 0) {
3349 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003350 __ add(IP, addr, ShifterOperand(out_lo));
3351 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003352 }
3353 __ ldrexd(out_lo, out_hi, addr);
3354}
3355
3356void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3357 uint32_t offset,
3358 Register value_lo,
3359 Register value_hi,
3360 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003361 Register temp2,
3362 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003363 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003364 if (offset != 0) {
3365 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003366 __ add(IP, addr, ShifterOperand(temp1));
3367 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003368 }
3369 __ Bind(&fail);
3370 // We need a load followed by store. (The address used in a STREX instruction must
3371 // be the same as the address in the most recently executed LDREX instruction.)
3372 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003373 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003374 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003375 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003376}
3377
3378void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3379 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3380
Nicolas Geoffray39468442014-09-02 15:17:15 +01003381 LocationSummary* locations =
3382 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003383 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003384
Calin Juravle52c48962014-12-16 17:02:57 +00003385 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003386 if (Primitive::IsFloatingPointType(field_type)) {
3387 locations->SetInAt(1, Location::RequiresFpuRegister());
3388 } else {
3389 locations->SetInAt(1, Location::RequiresRegister());
3390 }
3391
Calin Juravle52c48962014-12-16 17:02:57 +00003392 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003393 bool generate_volatile = field_info.IsVolatile()
3394 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003395 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003396 bool needs_write_barrier =
3397 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003398 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003399 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003400 if (needs_write_barrier) {
3401 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003402 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003403 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003404 // Arm encoding have some additional constraints for ldrexd/strexd:
3405 // - registers need to be consecutive
3406 // - the first register should be even but not R14.
3407 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3408 // enable Arm encoding.
3409 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3410
3411 locations->AddTemp(Location::RequiresRegister());
3412 locations->AddTemp(Location::RequiresRegister());
3413 if (field_type == Primitive::kPrimDouble) {
3414 // For doubles we need two more registers to copy the value.
3415 locations->AddTemp(Location::RegisterLocation(R2));
3416 locations->AddTemp(Location::RegisterLocation(R3));
3417 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003418 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003419}
3420
Calin Juravle52c48962014-12-16 17:02:57 +00003421void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003422 const FieldInfo& field_info,
3423 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003424 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3425
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003426 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003427 Register base = locations->InAt(0).AsRegister<Register>();
3428 Location value = locations->InAt(1);
3429
3430 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003431 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003432 Primitive::Type field_type = field_info.GetFieldType();
3433 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003434 bool needs_write_barrier =
3435 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003436
3437 if (is_volatile) {
3438 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3439 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003440
3441 switch (field_type) {
3442 case Primitive::kPrimBoolean:
3443 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003444 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003445 break;
3446 }
3447
3448 case Primitive::kPrimShort:
3449 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003450 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003451 break;
3452 }
3453
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003454 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003455 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003456 if (kPoisonHeapReferences && needs_write_barrier) {
3457 // Note that in the case where `value` is a null reference,
3458 // we do not enter this block, as a null reference does not
3459 // need poisoning.
3460 DCHECK_EQ(field_type, Primitive::kPrimNot);
3461 Register temp = locations->GetTemp(0).AsRegister<Register>();
3462 __ Mov(temp, value.AsRegister<Register>());
3463 __ PoisonHeapReference(temp);
3464 __ StoreToOffset(kStoreWord, temp, base, offset);
3465 } else {
3466 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3467 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003468 break;
3469 }
3470
3471 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003472 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003473 GenerateWideAtomicStore(base, offset,
3474 value.AsRegisterPairLow<Register>(),
3475 value.AsRegisterPairHigh<Register>(),
3476 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003477 locations->GetTemp(1).AsRegister<Register>(),
3478 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003479 } else {
3480 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003481 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003482 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003483 break;
3484 }
3485
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003486 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003487 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003488 break;
3489 }
3490
3491 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003492 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003493 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003494 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3495 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3496
3497 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3498
3499 GenerateWideAtomicStore(base, offset,
3500 value_reg_lo,
3501 value_reg_hi,
3502 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003503 locations->GetTemp(3).AsRegister<Register>(),
3504 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003505 } else {
3506 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003507 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003508 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003509 break;
3510 }
3511
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003512 case Primitive::kPrimVoid:
3513 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003514 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003515 }
Calin Juravle52c48962014-12-16 17:02:57 +00003516
Calin Juravle77520bc2015-01-12 18:45:46 +00003517 // Longs and doubles are handled in the switch.
3518 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3519 codegen_->MaybeRecordImplicitNullCheck(instruction);
3520 }
3521
3522 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3523 Register temp = locations->GetTemp(0).AsRegister<Register>();
3524 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003525 codegen_->MarkGCCard(
3526 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003527 }
3528
Calin Juravle52c48962014-12-16 17:02:57 +00003529 if (is_volatile) {
3530 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3531 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003532}
3533
Calin Juravle52c48962014-12-16 17:02:57 +00003534void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3535 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003536 LocationSummary* locations =
3537 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003538 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003539
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003540 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003541 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003542 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003543 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003544
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003545 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3546 locations->SetOut(Location::RequiresFpuRegister());
3547 } else {
3548 locations->SetOut(Location::RequiresRegister(),
3549 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3550 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003551 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003552 // Arm encoding have some additional constraints for ldrexd/strexd:
3553 // - registers need to be consecutive
3554 // - the first register should be even but not R14.
3555 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3556 // enable Arm encoding.
3557 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3558 locations->AddTemp(Location::RequiresRegister());
3559 locations->AddTemp(Location::RequiresRegister());
3560 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003561}
3562
Vladimir Markod2b4ca22015-09-14 15:13:26 +01003563Location LocationsBuilderARM::ArmEncodableConstantOrRegister(HInstruction* constant,
3564 Opcode opcode) {
3565 DCHECK(!Primitive::IsFloatingPointType(constant->GetType()));
3566 if (constant->IsConstant() &&
3567 CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) {
3568 return Location::ConstantLocation(constant->AsConstant());
3569 }
3570 return Location::RequiresRegister();
3571}
3572
3573bool LocationsBuilderARM::CanEncodeConstantAsImmediate(HConstant* input_cst,
3574 Opcode opcode) {
3575 uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst));
3576 if (Primitive::Is64BitType(input_cst->GetType())) {
3577 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode) &&
3578 CanEncodeConstantAsImmediate(High32Bits(value), opcode);
3579 } else {
3580 return CanEncodeConstantAsImmediate(Low32Bits(value), opcode);
3581 }
3582}
3583
3584bool LocationsBuilderARM::CanEncodeConstantAsImmediate(uint32_t value, Opcode opcode) {
3585 ShifterOperand so;
3586 ArmAssembler* assembler = codegen_->GetAssembler();
3587 if (assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, opcode, value, &so)) {
3588 return true;
3589 }
3590 Opcode neg_opcode = kNoOperand;
3591 switch (opcode) {
3592 case AND:
3593 neg_opcode = BIC;
3594 break;
3595 case ORR:
3596 neg_opcode = ORN;
3597 break;
3598 default:
3599 return false;
3600 }
3601 return assembler->ShifterOperandCanHold(kNoRegister, kNoRegister, neg_opcode, ~value, &so);
3602}
3603
Calin Juravle52c48962014-12-16 17:02:57 +00003604void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3605 const FieldInfo& field_info) {
3606 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003607
Calin Juravle52c48962014-12-16 17:02:57 +00003608 LocationSummary* locations = instruction->GetLocations();
3609 Register base = locations->InAt(0).AsRegister<Register>();
3610 Location out = locations->Out();
3611 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003612 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003613 Primitive::Type field_type = field_info.GetFieldType();
3614 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3615
3616 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003617 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003618 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003619 break;
3620 }
3621
3622 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003623 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003624 break;
3625 }
3626
3627 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003628 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003629 break;
3630 }
3631
3632 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003633 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003634 break;
3635 }
3636
3637 case Primitive::kPrimInt:
3638 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003639 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003640 break;
3641 }
3642
3643 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003644 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003645 GenerateWideAtomicLoad(base, offset,
3646 out.AsRegisterPairLow<Register>(),
3647 out.AsRegisterPairHigh<Register>());
3648 } else {
3649 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3650 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003651 break;
3652 }
3653
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003654 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003655 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003656 break;
3657 }
3658
3659 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003660 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003661 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003662 Register lo = locations->GetTemp(0).AsRegister<Register>();
3663 Register hi = locations->GetTemp(1).AsRegister<Register>();
3664 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003665 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003666 __ vmovdrr(out_reg, lo, hi);
3667 } else {
3668 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003669 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003670 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003671 break;
3672 }
3673
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003674 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003675 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003676 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003677 }
Calin Juravle52c48962014-12-16 17:02:57 +00003678
Calin Juravle77520bc2015-01-12 18:45:46 +00003679 // Doubles are handled in the switch.
3680 if (field_type != Primitive::kPrimDouble) {
3681 codegen_->MaybeRecordImplicitNullCheck(instruction);
3682 }
3683
Calin Juravle52c48962014-12-16 17:02:57 +00003684 if (is_volatile) {
3685 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3686 }
Roland Levillain4d027112015-07-01 15:41:14 +01003687
3688 if (field_type == Primitive::kPrimNot) {
3689 __ MaybeUnpoisonHeapReference(out.AsRegister<Register>());
3690 }
Calin Juravle52c48962014-12-16 17:02:57 +00003691}
3692
3693void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3694 HandleFieldSet(instruction, instruction->GetFieldInfo());
3695}
3696
3697void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003698 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003699}
3700
3701void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3702 HandleFieldGet(instruction, instruction->GetFieldInfo());
3703}
3704
3705void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3706 HandleFieldGet(instruction, instruction->GetFieldInfo());
3707}
3708
3709void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3710 HandleFieldGet(instruction, instruction->GetFieldInfo());
3711}
3712
3713void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3714 HandleFieldGet(instruction, instruction->GetFieldInfo());
3715}
3716
3717void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3718 HandleFieldSet(instruction, instruction->GetFieldInfo());
3719}
3720
3721void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003722 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003723}
3724
Calin Juravlee460d1d2015-09-29 04:52:17 +01003725void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet(
3726 HUnresolvedInstanceFieldGet* instruction) {
3727 FieldAccessCallingConventionARM calling_convention;
3728 codegen_->CreateUnresolvedFieldLocationSummary(
3729 instruction, instruction->GetFieldType(), calling_convention);
3730}
3731
3732void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet(
3733 HUnresolvedInstanceFieldGet* instruction) {
3734 FieldAccessCallingConventionARM calling_convention;
3735 codegen_->GenerateUnresolvedFieldAccess(instruction,
3736 instruction->GetFieldType(),
3737 instruction->GetFieldIndex(),
3738 instruction->GetDexPc(),
3739 calling_convention);
3740}
3741
3742void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet(
3743 HUnresolvedInstanceFieldSet* instruction) {
3744 FieldAccessCallingConventionARM calling_convention;
3745 codegen_->CreateUnresolvedFieldLocationSummary(
3746 instruction, instruction->GetFieldType(), calling_convention);
3747}
3748
3749void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet(
3750 HUnresolvedInstanceFieldSet* instruction) {
3751 FieldAccessCallingConventionARM calling_convention;
3752 codegen_->GenerateUnresolvedFieldAccess(instruction,
3753 instruction->GetFieldType(),
3754 instruction->GetFieldIndex(),
3755 instruction->GetDexPc(),
3756 calling_convention);
3757}
3758
3759void LocationsBuilderARM::VisitUnresolvedStaticFieldGet(
3760 HUnresolvedStaticFieldGet* instruction) {
3761 FieldAccessCallingConventionARM calling_convention;
3762 codegen_->CreateUnresolvedFieldLocationSummary(
3763 instruction, instruction->GetFieldType(), calling_convention);
3764}
3765
3766void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet(
3767 HUnresolvedStaticFieldGet* instruction) {
3768 FieldAccessCallingConventionARM calling_convention;
3769 codegen_->GenerateUnresolvedFieldAccess(instruction,
3770 instruction->GetFieldType(),
3771 instruction->GetFieldIndex(),
3772 instruction->GetDexPc(),
3773 calling_convention);
3774}
3775
3776void LocationsBuilderARM::VisitUnresolvedStaticFieldSet(
3777 HUnresolvedStaticFieldSet* instruction) {
3778 FieldAccessCallingConventionARM calling_convention;
3779 codegen_->CreateUnresolvedFieldLocationSummary(
3780 instruction, instruction->GetFieldType(), calling_convention);
3781}
3782
3783void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet(
3784 HUnresolvedStaticFieldSet* instruction) {
3785 FieldAccessCallingConventionARM calling_convention;
3786 codegen_->GenerateUnresolvedFieldAccess(instruction,
3787 instruction->GetFieldType(),
3788 instruction->GetFieldIndex(),
3789 instruction->GetDexPc(),
3790 calling_convention);
3791}
3792
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003793void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003794 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3795 ? LocationSummary::kCallOnSlowPath
3796 : LocationSummary::kNoCall;
3797 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravle77520bc2015-01-12 18:45:46 +00003798 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003799 if (instruction->HasUses()) {
3800 locations->SetOut(Location::SameAsFirstInput());
3801 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003802}
3803
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003804void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003805 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3806 return;
3807 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003808 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003809
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003810 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3811 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3812}
3813
3814void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07003815 SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003816 codegen_->AddSlowPath(slow_path);
3817
3818 LocationSummary* locations = instruction->GetLocations();
3819 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003820
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003821 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003822}
3823
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003824void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003825 if (codegen_->IsImplicitNullCheckAllowed(instruction)) {
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003826 GenerateImplicitNullCheck(instruction);
3827 } else {
3828 GenerateExplicitNullCheck(instruction);
3829 }
3830}
3831
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003832void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003833 LocationSummary* locations =
3834 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003835 locations->SetInAt(0, Location::RequiresRegister());
3836 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003837 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3838 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3839 } else {
3840 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3841 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003842}
3843
3844void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3845 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003846 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003847 Location index = locations->InAt(1);
Roland Levillain4d027112015-07-01 15:41:14 +01003848 Primitive::Type type = instruction->GetType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003849
Roland Levillain4d027112015-07-01 15:41:14 +01003850 switch (type) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003851 case Primitive::kPrimBoolean: {
3852 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003853 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003854 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003855 size_t offset =
3856 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003857 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3858 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003859 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003860 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3861 }
3862 break;
3863 }
3864
3865 case Primitive::kPrimByte: {
3866 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003867 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003868 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003869 size_t offset =
3870 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003871 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3872 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003873 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003874 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3875 }
3876 break;
3877 }
3878
3879 case Primitive::kPrimShort: {
3880 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003881 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003882 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003883 size_t offset =
3884 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003885 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3886 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003887 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003888 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3889 }
3890 break;
3891 }
3892
3893 case Primitive::kPrimChar: {
3894 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003895 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003896 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003897 size_t offset =
3898 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003899 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3900 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003901 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003902 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3903 }
3904 break;
3905 }
3906
3907 case Primitive::kPrimInt:
3908 case Primitive::kPrimNot: {
Roland Levillain33d69032015-06-18 18:20:59 +01003909 static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
3910 "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003911 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003912 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003913 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003914 size_t offset =
3915 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003916 __ LoadFromOffset(kLoadWord, out, obj, offset);
3917 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003918 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003919 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3920 }
3921 break;
3922 }
3923
3924 case Primitive::kPrimLong: {
3925 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003926 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003927 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003928 size_t offset =
3929 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003930 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003931 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003932 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003933 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003934 }
3935 break;
3936 }
3937
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003938 case Primitive::kPrimFloat: {
3939 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3940 Location out = locations->Out();
3941 DCHECK(out.IsFpuRegister());
3942 if (index.IsConstant()) {
3943 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3944 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3945 } else {
3946 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3947 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3948 }
3949 break;
3950 }
3951
3952 case Primitive::kPrimDouble: {
3953 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3954 Location out = locations->Out();
3955 DCHECK(out.IsFpuRegisterPair());
3956 if (index.IsConstant()) {
3957 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3958 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3959 } else {
3960 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3961 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3962 }
3963 break;
3964 }
3965
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003966 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01003967 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003968 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003969 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003970 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01003971
3972 if (type == Primitive::kPrimNot) {
3973 Register out = locations->Out().AsRegister<Register>();
3974 __ MaybeUnpoisonHeapReference(out);
3975 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003976}
3977
3978void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003979 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003980
3981 bool needs_write_barrier =
3982 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003983 bool may_need_runtime_call = instruction->NeedsTypeCheck();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003984
Nicolas Geoffray39468442014-09-02 15:17:15 +01003985 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003986 instruction,
3987 may_need_runtime_call ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall);
3988 locations->SetInAt(0, Location::RequiresRegister());
3989 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3990 if (Primitive::IsFloatingPointType(value_type)) {
3991 locations->SetInAt(2, Location::RequiresFpuRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003992 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003993 locations->SetInAt(2, Location::RequiresRegister());
3994 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003995
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01003996 if (needs_write_barrier) {
3997 // Temporary registers for the write barrier.
3998 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
3999 locations->AddTemp(Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004000 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004001}
4002
4003void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
4004 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004005 Register array = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004006 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01004007 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004008 bool may_need_runtime_call = locations->CanCall();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004009 bool needs_write_barrier =
4010 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004011
4012 switch (value_type) {
4013 case Primitive::kPrimBoolean:
4014 case Primitive::kPrimByte: {
4015 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004016 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004017 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004018 size_t offset =
4019 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004020 __ StoreToOffset(kStoreByte, value, array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004021 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004022 __ add(IP, array, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004023 __ StoreToOffset(kStoreByte, value, IP, data_offset);
4024 }
4025 break;
4026 }
4027
4028 case Primitive::kPrimShort:
4029 case Primitive::kPrimChar: {
4030 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004031 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004032 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004033 size_t offset =
4034 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004035 __ StoreToOffset(kStoreHalfword, value, array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004036 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004037 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004038 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
4039 }
4040 break;
4041 }
4042
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004043 case Primitive::kPrimNot: {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004044 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
4045 Register value = locations->InAt(2).AsRegister<Register>();
4046 Register source = value;
4047
4048 if (instruction->InputAt(2)->IsNullConstant()) {
4049 // Just setting null.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004050 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004051 size_t offset =
4052 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004053 __ StoreToOffset(kStoreWord, source, array, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004054 } else {
4055 DCHECK(index.IsRegister()) << index;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004056 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillain4d027112015-07-01 15:41:14 +01004057 __ StoreToOffset(kStoreWord, source, IP, data_offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004058 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004059 break;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00004060 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004061
4062 DCHECK(needs_write_barrier);
4063 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
4064 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
4065 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4066 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4067 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4068 Label done;
4069 SlowPathCode* slow_path = nullptr;
4070
4071 if (may_need_runtime_call) {
4072 slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM(instruction);
4073 codegen_->AddSlowPath(slow_path);
4074 if (instruction->GetValueCanBeNull()) {
4075 Label non_zero;
4076 __ CompareAndBranchIfNonZero(value, &non_zero);
4077 if (index.IsConstant()) {
4078 size_t offset =
4079 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4080 __ StoreToOffset(kStoreWord, value, array, offset);
4081 } else {
4082 DCHECK(index.IsRegister()) << index;
4083 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
4084 __ StoreToOffset(kStoreWord, value, IP, data_offset);
4085 }
4086 codegen_->MaybeRecordImplicitNullCheck(instruction);
4087 __ b(&done);
4088 __ Bind(&non_zero);
4089 }
4090
4091 __ LoadFromOffset(kLoadWord, temp1, array, class_offset);
4092 codegen_->MaybeRecordImplicitNullCheck(instruction);
4093 __ MaybeUnpoisonHeapReference(temp1);
4094 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
4095 __ LoadFromOffset(kLoadWord, temp2, value, class_offset);
4096 // No need to poison/unpoison, we're comparing two poisoined references.
4097 __ cmp(temp1, ShifterOperand(temp2));
4098 if (instruction->StaticTypeOfArrayIsObjectArray()) {
4099 Label do_put;
4100 __ b(&do_put, EQ);
4101 __ MaybeUnpoisonHeapReference(temp1);
4102 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
4103 // No need to poison/unpoison, we're comparing against null.
4104 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
4105 __ Bind(&do_put);
4106 } else {
4107 __ b(slow_path->GetEntryLabel(), NE);
4108 }
4109 }
4110
4111 if (kPoisonHeapReferences) {
4112 // Note that in the case where `value` is a null reference,
4113 // we do not enter this block, as a null reference does not
4114 // need poisoning.
4115 DCHECK_EQ(value_type, Primitive::kPrimNot);
4116 __ Mov(temp1, value);
4117 __ PoisonHeapReference(temp1);
4118 source = temp1;
4119 }
4120
4121 if (index.IsConstant()) {
4122 size_t offset =
4123 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4124 __ StoreToOffset(kStoreWord, source, array, offset);
4125 } else {
4126 DCHECK(index.IsRegister()) << index;
4127 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
4128 __ StoreToOffset(kStoreWord, source, IP, data_offset);
4129 }
4130
4131 if (!may_need_runtime_call) {
4132 codegen_->MaybeRecordImplicitNullCheck(instruction);
4133 }
4134
4135 codegen_->MarkGCCard(temp1, temp2, array, value, instruction->GetValueCanBeNull());
4136
4137 if (done.IsLinked()) {
4138 __ Bind(&done);
4139 }
4140
4141 if (slow_path != nullptr) {
4142 __ Bind(slow_path->GetExitLabel());
4143 }
4144
4145 break;
4146 }
4147
4148 case Primitive::kPrimInt: {
4149 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
4150 Register value = locations->InAt(2).AsRegister<Register>();
4151 if (index.IsConstant()) {
4152 size_t offset =
4153 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
4154 __ StoreToOffset(kStoreWord, value, array, offset);
4155 } else {
4156 DCHECK(index.IsRegister()) << index;
4157 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
4158 __ StoreToOffset(kStoreWord, value, IP, data_offset);
4159 }
4160
4161 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004162 break;
4163 }
4164
4165 case Primitive::kPrimLong: {
4166 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004167 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004168 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00004169 size_t offset =
4170 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004171 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), array, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004172 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004173 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01004174 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004175 }
4176 break;
4177 }
4178
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004179 case Primitive::kPrimFloat: {
4180 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
4181 Location value = locations->InAt(2);
4182 DCHECK(value.IsFpuRegister());
4183 if (index.IsConstant()) {
4184 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004185 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004186 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004187 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004188 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
4189 }
4190 break;
4191 }
4192
4193 case Primitive::kPrimDouble: {
4194 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
4195 Location value = locations->InAt(2);
4196 DCHECK(value.IsFpuRegisterPair());
4197 if (index.IsConstant()) {
4198 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004199 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), array, offset);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004200 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01004201 __ add(IP, array, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004202 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
4203 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004204
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004205 break;
4206 }
4207
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004208 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004209 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004210 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004211 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004212
4213 // Ints and objects are handled in the switch.
4214 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
4215 codegen_->MaybeRecordImplicitNullCheck(instruction);
4216 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004217}
4218
4219void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004220 LocationSummary* locations =
4221 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004222 locations->SetInAt(0, Location::RequiresRegister());
4223 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004224}
4225
4226void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
4227 LocationSummary* locations = instruction->GetLocations();
4228 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004229 Register obj = locations->InAt(0).AsRegister<Register>();
4230 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004231 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004232 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004233}
4234
4235void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004236 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4237 ? LocationSummary::kCallOnSlowPath
4238 : LocationSummary::kNoCall;
4239 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004240 locations->SetInAt(0, Location::RequiresRegister());
4241 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004242 if (instruction->HasUses()) {
4243 locations->SetOut(Location::SameAsFirstInput());
4244 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004245}
4246
4247void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
4248 LocationSummary* locations = instruction->GetLocations();
Andreas Gampe85b62f22015-09-09 13:15:38 -07004249 SlowPathCode* slow_path =
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004250 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004251 codegen_->AddSlowPath(slow_path);
4252
Roland Levillain271ab9c2014-11-27 15:23:57 +00004253 Register index = locations->InAt(0).AsRegister<Register>();
4254 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004255
4256 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01004257 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004258}
4259
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004260void CodeGeneratorARM::MarkGCCard(Register temp,
4261 Register card,
4262 Register object,
4263 Register value,
4264 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004265 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004266 if (can_be_null) {
4267 __ CompareAndBranchIfZero(value, &is_null);
4268 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004269 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
4270 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
4271 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004272 if (can_be_null) {
4273 __ Bind(&is_null);
4274 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004275}
4276
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004277void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
4278 temp->SetLocations(nullptr);
4279}
4280
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01004281void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004282 // Nothing to do, this is driven by the code generator.
4283}
4284
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01004285void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004286 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004287}
4288
4289void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004290 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
4291}
4292
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004293void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
4294 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
4295}
4296
4297void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004298 HBasicBlock* block = instruction->GetBlock();
4299 if (block->GetLoopInformation() != nullptr) {
4300 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
4301 // The back edge will generate the suspend check.
4302 return;
4303 }
4304 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
4305 // The goto will generate the suspend check.
4306 return;
4307 }
4308 GenerateSuspendCheck(instruction, nullptr);
4309}
4310
4311void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
4312 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004313 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01004314 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
4315 if (slow_path == nullptr) {
4316 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
4317 instruction->SetSlowPath(slow_path);
4318 codegen_->AddSlowPath(slow_path);
4319 if (successor != nullptr) {
4320 DCHECK(successor->IsLoopHeader());
4321 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
4322 }
4323 } else {
4324 DCHECK_EQ(slow_path->GetSuccessor(), successor);
4325 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004326
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00004327 __ LoadFromOffset(
4328 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004329 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004330 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004331 __ Bind(slow_path->GetReturnLabel());
4332 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004333 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004334 __ b(slow_path->GetEntryLabel());
4335 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004336}
4337
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004338ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
4339 return codegen_->GetAssembler();
4340}
4341
4342void ParallelMoveResolverARM::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01004343 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004344 Location source = move->GetSource();
4345 Location destination = move->GetDestination();
4346
4347 if (source.IsRegister()) {
4348 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004349 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004350 } else {
4351 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00004352 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004353 SP, destination.GetStackIndex());
4354 }
4355 } else if (source.IsStackSlot()) {
4356 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004357 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004358 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004359 } else if (destination.IsFpuRegister()) {
4360 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004361 } else {
4362 DCHECK(destination.IsStackSlot());
4363 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
4364 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4365 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004366 } else if (source.IsFpuRegister()) {
4367 if (destination.IsFpuRegister()) {
4368 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004369 } else {
4370 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004371 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
4372 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004373 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004374 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004375 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
4376 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004377 } else if (destination.IsRegisterPair()) {
4378 DCHECK(ExpectedPairLayout(destination));
4379 __ LoadFromOffset(
4380 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
4381 } else {
4382 DCHECK(destination.IsFpuRegisterPair()) << destination;
4383 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4384 SP,
4385 source.GetStackIndex());
4386 }
4387 } else if (source.IsRegisterPair()) {
4388 if (destination.IsRegisterPair()) {
4389 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
4390 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
4391 } else {
4392 DCHECK(destination.IsDoubleStackSlot()) << destination;
4393 DCHECK(ExpectedPairLayout(source));
4394 __ StoreToOffset(
4395 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
4396 }
4397 } else if (source.IsFpuRegisterPair()) {
4398 if (destination.IsFpuRegisterPair()) {
4399 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4400 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
4401 } else {
4402 DCHECK(destination.IsDoubleStackSlot()) << destination;
4403 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
4404 SP,
4405 destination.GetStackIndex());
4406 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004407 } else {
4408 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00004409 HConstant* constant = source.GetConstant();
4410 if (constant->IsIntConstant() || constant->IsNullConstant()) {
4411 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004412 if (destination.IsRegister()) {
4413 __ LoadImmediate(destination.AsRegister<Register>(), value);
4414 } else {
4415 DCHECK(destination.IsStackSlot());
4416 __ LoadImmediate(IP, value);
4417 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4418 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004419 } else if (constant->IsLongConstant()) {
4420 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004421 if (destination.IsRegisterPair()) {
4422 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
4423 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004424 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004425 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004426 __ LoadImmediate(IP, Low32Bits(value));
4427 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4428 __ LoadImmediate(IP, High32Bits(value));
4429 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4430 }
4431 } else if (constant->IsDoubleConstant()) {
4432 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004433 if (destination.IsFpuRegisterPair()) {
4434 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004435 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004436 DCHECK(destination.IsDoubleStackSlot()) << destination;
4437 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004438 __ LoadImmediate(IP, Low32Bits(int_value));
4439 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4440 __ LoadImmediate(IP, High32Bits(int_value));
4441 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4442 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004443 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004444 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004445 float value = constant->AsFloatConstant()->GetValue();
4446 if (destination.IsFpuRegister()) {
4447 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
4448 } else {
4449 DCHECK(destination.IsStackSlot());
4450 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
4451 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4452 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004453 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004454 }
4455}
4456
4457void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
4458 __ Mov(IP, reg);
4459 __ LoadFromOffset(kLoadWord, reg, SP, mem);
4460 __ StoreToOffset(kStoreWord, IP, SP, mem);
4461}
4462
4463void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
4464 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
4465 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
4466 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
4467 SP, mem1 + stack_offset);
4468 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
4469 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
4470 SP, mem2 + stack_offset);
4471 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
4472}
4473
4474void ParallelMoveResolverARM::EmitSwap(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01004475 MoveOperands* move = moves_[index];
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004476 Location source = move->GetSource();
4477 Location destination = move->GetDestination();
4478
4479 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004480 DCHECK_NE(source.AsRegister<Register>(), IP);
4481 DCHECK_NE(destination.AsRegister<Register>(), IP);
4482 __ Mov(IP, source.AsRegister<Register>());
4483 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
4484 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004485 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004486 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004487 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004488 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004489 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
4490 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004491 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004492 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004493 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004494 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004495 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004496 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004497 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004498 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004499 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
4500 destination.AsRegisterPairHigh<Register>(),
4501 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004502 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004503 Register low_reg = source.IsRegisterPair()
4504 ? source.AsRegisterPairLow<Register>()
4505 : destination.AsRegisterPairLow<Register>();
4506 int mem = source.IsRegisterPair()
4507 ? destination.GetStackIndex()
4508 : source.GetStackIndex();
4509 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004510 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004511 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004512 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004513 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004514 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
4515 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004516 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004517 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004518 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004519 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
4520 DRegister reg = source.IsFpuRegisterPair()
4521 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
4522 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
4523 int mem = source.IsFpuRegisterPair()
4524 ? destination.GetStackIndex()
4525 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004526 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004527 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004528 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004529 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
4530 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
4531 : destination.AsFpuRegister<SRegister>();
4532 int mem = source.IsFpuRegister()
4533 ? destination.GetStackIndex()
4534 : source.GetStackIndex();
4535
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004536 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004537 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004538 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004539 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004540 Exchange(source.GetStackIndex(), destination.GetStackIndex());
4541 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004542 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004543 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004544 }
4545}
4546
4547void ParallelMoveResolverARM::SpillScratch(int reg) {
4548 __ Push(static_cast<Register>(reg));
4549}
4550
4551void ParallelMoveResolverARM::RestoreScratch(int reg) {
4552 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004553}
4554
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004555void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Calin Juravle98893e12015-10-02 21:05:03 +01004556 InvokeRuntimeCallingConvention calling_convention;
4557 CodeGenerator::CreateLoadClassLocationSummary(
4558 cls,
4559 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
4560 Location::RegisterLocation(R0));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004561}
4562
4563void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004564 LocationSummary* locations = cls->GetLocations();
Calin Juravle98893e12015-10-02 21:05:03 +01004565 if (cls->NeedsAccessCheck()) {
4566 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
4567 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess),
4568 cls,
4569 cls->GetDexPc(),
4570 nullptr);
Calin Juravle580b6092015-10-06 17:35:58 +01004571 return;
4572 }
4573
4574 Register out = locations->Out().AsRegister<Register>();
4575 Register current_method = locations->InAt(0).AsRegister<Register>();
4576 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004577 DCHECK(!cls->CanCallRuntime());
4578 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004579 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004580 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004581 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004582 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004583 __ LoadFromOffset(kLoadWord,
4584 out,
4585 current_method,
Vladimir Marko05792b92015-08-03 11:56:49 +01004586 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004587 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01004588 // TODO: We will need a read barrier here.
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004589
Andreas Gampe85b62f22015-09-09 13:15:38 -07004590 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004591 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4592 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004593 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004594 if (cls->MustGenerateClinitCheck()) {
4595 GenerateClassInitializationCheck(slow_path, out);
4596 } else {
4597 __ Bind(slow_path->GetExitLabel());
4598 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004599 }
4600}
4601
4602void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
4603 LocationSummary* locations =
4604 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
4605 locations->SetInAt(0, Location::RequiresRegister());
4606 if (check->HasUses()) {
4607 locations->SetOut(Location::SameAsFirstInput());
4608 }
4609}
4610
4611void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004612 // We assume the class is not null.
Andreas Gampe85b62f22015-09-09 13:15:38 -07004613 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004614 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004615 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004616 GenerateClassInitializationCheck(slow_path,
4617 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004618}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004619
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004620void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
Andreas Gampe85b62f22015-09-09 13:15:38 -07004621 SlowPathCode* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004622 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4623 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4624 __ b(slow_path->GetEntryLabel(), LT);
4625 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4626 // properly. Therefore, we do a memory fence.
4627 __ dmb(ISH);
4628 __ Bind(slow_path->GetExitLabel());
4629}
4630
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004631void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4632 LocationSummary* locations =
4633 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004634 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004635 locations->SetOut(Location::RequiresRegister());
4636}
4637
4638void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
Andreas Gampe85b62f22015-09-09 13:15:38 -07004639 SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004640 codegen_->AddSlowPath(slow_path);
4641
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004642 LocationSummary* locations = load->GetLocations();
4643 Register out = locations->Out().AsRegister<Register>();
4644 Register current_method = locations->InAt(0).AsRegister<Register>();
4645 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004646 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004647 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004648 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01004649 // TODO: We will need a read barrier here.
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004650 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004651 __ Bind(slow_path->GetExitLabel());
4652}
4653
David Brazdilcb1c0552015-08-04 16:22:25 +01004654static int32_t GetExceptionTlsOffset() {
4655 return Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4656}
4657
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004658void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4659 LocationSummary* locations =
4660 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4661 locations->SetOut(Location::RequiresRegister());
4662}
4663
4664void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004665 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01004666 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4667}
4668
4669void LocationsBuilderARM::VisitClearException(HClearException* clear) {
4670 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4671}
4672
4673void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004674 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01004675 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004676}
4677
4678void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4679 LocationSummary* locations =
4680 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4681 InvokeRuntimeCallingConvention calling_convention;
4682 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4683}
4684
4685void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4686 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004687 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004688}
4689
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004690void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004691 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
4692 switch (instruction->GetTypeCheckKind()) {
4693 case TypeCheckKind::kExactCheck:
4694 case TypeCheckKind::kAbstractClassCheck:
4695 case TypeCheckKind::kClassHierarchyCheck:
4696 case TypeCheckKind::kArrayObjectCheck:
4697 call_kind = LocationSummary::kNoCall;
4698 break;
Calin Juravle98893e12015-10-02 21:05:03 +01004699 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004700 case TypeCheckKind::kInterfaceCheck:
4701 call_kind = LocationSummary::kCall;
4702 break;
4703 case TypeCheckKind::kArrayCheck:
4704 call_kind = LocationSummary::kCallOnSlowPath;
4705 break;
4706 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004707 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004708 if (call_kind != LocationSummary::kCall) {
4709 locations->SetInAt(0, Location::RequiresRegister());
4710 locations->SetInAt(1, Location::RequiresRegister());
4711 // The out register is used as a temporary, so it overlaps with the inputs.
4712 // Note that TypeCheckSlowPathARM uses this register too.
4713 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
4714 } else {
4715 InvokeRuntimeCallingConvention calling_convention;
4716 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4717 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4718 locations->SetOut(Location::RegisterLocation(R0));
4719 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004720}
4721
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004722void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004723 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004724 Register obj = locations->InAt(0).AsRegister<Register>();
4725 Register cls = locations->InAt(1).AsRegister<Register>();
4726 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004727 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004728 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4729 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4730 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004731 Label done, zero;
Andreas Gampe85b62f22015-09-09 13:15:38 -07004732 SlowPathCode* slow_path = nullptr;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004733
4734 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004735 // avoid null check if we know obj is not null.
4736 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004737 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004738 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004739
Calin Juravle98893e12015-10-02 21:05:03 +01004740 // In case of an interface/unresolved check, we put the object class into the object register.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004741 // This is safe, as the register is caller-save, and the object must be in another
4742 // register if it survives the runtime call.
Calin Juravle98893e12015-10-02 21:05:03 +01004743 Register target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) ||
4744 (instruction->GetTypeCheckKind() == TypeCheckKind::kUnresolvedCheck)
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004745 ? obj
4746 : out;
4747 __ LoadFromOffset(kLoadWord, target, obj, class_offset);
4748 __ MaybeUnpoisonHeapReference(target);
4749
4750 switch (instruction->GetTypeCheckKind()) {
4751 case TypeCheckKind::kExactCheck: {
4752 __ cmp(out, ShifterOperand(cls));
4753 // Classes must be equal for the instanceof to succeed.
4754 __ b(&zero, NE);
4755 __ LoadImmediate(out, 1);
4756 __ b(&done);
4757 break;
4758 }
4759 case TypeCheckKind::kAbstractClassCheck: {
4760 // If the class is abstract, we eagerly fetch the super class of the
4761 // object to avoid doing a comparison we know will fail.
4762 Label loop;
4763 __ Bind(&loop);
4764 __ LoadFromOffset(kLoadWord, out, out, super_offset);
4765 __ MaybeUnpoisonHeapReference(out);
4766 // If `out` is null, we use it for the result, and jump to `done`.
4767 __ CompareAndBranchIfZero(out, &done);
4768 __ cmp(out, ShifterOperand(cls));
4769 __ b(&loop, NE);
4770 __ LoadImmediate(out, 1);
4771 if (zero.IsLinked()) {
4772 __ b(&done);
4773 }
4774 break;
4775 }
4776 case TypeCheckKind::kClassHierarchyCheck: {
4777 // Walk over the class hierarchy to find a match.
4778 Label loop, success;
4779 __ Bind(&loop);
4780 __ cmp(out, ShifterOperand(cls));
4781 __ b(&success, EQ);
4782 __ LoadFromOffset(kLoadWord, out, out, super_offset);
4783 __ MaybeUnpoisonHeapReference(out);
4784 __ CompareAndBranchIfNonZero(out, &loop);
4785 // If `out` is null, we use it for the result, and jump to `done`.
4786 __ b(&done);
4787 __ Bind(&success);
4788 __ LoadImmediate(out, 1);
4789 if (zero.IsLinked()) {
4790 __ b(&done);
4791 }
4792 break;
4793 }
4794 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01004795 // Do an exact check.
4796 Label exact_check;
4797 __ cmp(out, ShifterOperand(cls));
4798 __ b(&exact_check, EQ);
4799 // Otherwise, we need to check that the object's class is a non primitive array.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004800 __ LoadFromOffset(kLoadWord, out, out, component_offset);
4801 __ MaybeUnpoisonHeapReference(out);
4802 // If `out` is null, we use it for the result, and jump to `done`.
4803 __ CompareAndBranchIfZero(out, &done);
4804 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
4805 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
4806 __ CompareAndBranchIfNonZero(out, &zero);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01004807 __ Bind(&exact_check);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004808 __ LoadImmediate(out, 1);
4809 __ b(&done);
4810 break;
4811 }
4812 case TypeCheckKind::kArrayCheck: {
4813 __ cmp(out, ShifterOperand(cls));
4814 DCHECK(locations->OnlyCallsOnSlowPath());
4815 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4816 instruction, /* is_fatal */ false);
4817 codegen_->AddSlowPath(slow_path);
4818 __ b(slow_path->GetEntryLabel(), NE);
4819 __ LoadImmediate(out, 1);
4820 if (zero.IsLinked()) {
4821 __ b(&done);
4822 }
4823 break;
4824 }
Calin Juravle98893e12015-10-02 21:05:03 +01004825 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004826 case TypeCheckKind::kInterfaceCheck:
4827 default: {
4828 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
4829 instruction,
4830 instruction->GetDexPc(),
4831 nullptr);
4832 if (zero.IsLinked()) {
4833 __ b(&done);
4834 }
4835 break;
4836 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004837 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004838
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004839 if (zero.IsLinked()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004840 __ Bind(&zero);
4841 __ LoadImmediate(out, 0);
4842 }
4843
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004844 if (done.IsLinked()) {
4845 __ Bind(&done);
4846 }
4847
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004848 if (slow_path != nullptr) {
4849 __ Bind(slow_path->GetExitLabel());
4850 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004851}
4852
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004853void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004854 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
4855 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
4856
4857 switch (instruction->GetTypeCheckKind()) {
4858 case TypeCheckKind::kExactCheck:
4859 case TypeCheckKind::kAbstractClassCheck:
4860 case TypeCheckKind::kClassHierarchyCheck:
4861 case TypeCheckKind::kArrayObjectCheck:
4862 call_kind = throws_into_catch
4863 ? LocationSummary::kCallOnSlowPath
4864 : LocationSummary::kNoCall;
4865 break;
Calin Juravle98893e12015-10-02 21:05:03 +01004866 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004867 case TypeCheckKind::kInterfaceCheck:
4868 call_kind = LocationSummary::kCall;
4869 break;
4870 case TypeCheckKind::kArrayCheck:
4871 call_kind = LocationSummary::kCallOnSlowPath;
4872 break;
4873 }
4874
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004875 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004876 instruction, call_kind);
4877 if (call_kind != LocationSummary::kCall) {
4878 locations->SetInAt(0, Location::RequiresRegister());
4879 locations->SetInAt(1, Location::RequiresRegister());
4880 // Note that TypeCheckSlowPathARM uses this register too.
4881 locations->AddTemp(Location::RequiresRegister());
4882 } else {
4883 InvokeRuntimeCallingConvention calling_convention;
4884 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4885 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4886 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004887}
4888
4889void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4890 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004891 Register obj = locations->InAt(0).AsRegister<Register>();
4892 Register cls = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004893 Register temp = locations->WillCall()
4894 ? Register(kNoRegister)
4895 : locations->GetTemp(0).AsRegister<Register>();
4896
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004897 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004898 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4899 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4900 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
4901 SlowPathCode* slow_path = nullptr;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004902
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004903 if (!locations->WillCall()) {
4904 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4905 instruction, !locations->CanCall());
4906 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004907 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004908
4909 Label done;
4910 // Avoid null check if we know obj is not null.
4911 if (instruction->MustDoNullCheck()) {
4912 __ CompareAndBranchIfZero(obj, &done);
4913 }
4914
4915 if (locations->WillCall()) {
4916 __ LoadFromOffset(kLoadWord, obj, obj, class_offset);
4917 __ MaybeUnpoisonHeapReference(obj);
4918 } else {
4919 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4920 __ MaybeUnpoisonHeapReference(temp);
4921 }
4922
4923 switch (instruction->GetTypeCheckKind()) {
4924 case TypeCheckKind::kExactCheck:
4925 case TypeCheckKind::kArrayCheck: {
4926 __ cmp(temp, ShifterOperand(cls));
4927 // Jump to slow path for throwing the exception or doing a
4928 // more involved array check.
4929 __ b(slow_path->GetEntryLabel(), NE);
4930 break;
4931 }
4932 case TypeCheckKind::kAbstractClassCheck: {
4933 // If the class is abstract, we eagerly fetch the super class of the
4934 // object to avoid doing a comparison we know will fail.
4935 Label loop;
4936 __ Bind(&loop);
4937 __ LoadFromOffset(kLoadWord, temp, temp, super_offset);
4938 __ MaybeUnpoisonHeapReference(temp);
4939 // Jump to the slow path to throw the exception.
4940 __ CompareAndBranchIfZero(temp, slow_path->GetEntryLabel());
4941 __ cmp(temp, ShifterOperand(cls));
4942 __ b(&loop, NE);
4943 break;
4944 }
4945 case TypeCheckKind::kClassHierarchyCheck: {
4946 // Walk over the class hierarchy to find a match.
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01004947 Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004948 __ Bind(&loop);
4949 __ cmp(temp, ShifterOperand(cls));
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01004950 __ b(&done, EQ);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004951 __ LoadFromOffset(kLoadWord, temp, temp, super_offset);
4952 __ MaybeUnpoisonHeapReference(temp);
4953 __ CompareAndBranchIfNonZero(temp, &loop);
4954 // Jump to the slow path to throw the exception.
4955 __ b(slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004956 break;
4957 }
4958 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01004959 // Do an exact check.
4960 __ cmp(temp, ShifterOperand(cls));
4961 __ b(&done, EQ);
4962 // Otherwise, we need to check that the object's class is a non primitive array.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004963 __ LoadFromOffset(kLoadWord, temp, temp, component_offset);
4964 __ MaybeUnpoisonHeapReference(temp);
4965 __ CompareAndBranchIfZero(temp, slow_path->GetEntryLabel());
4966 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
4967 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
4968 __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel());
4969 break;
4970 }
Calin Juravle98893e12015-10-02 21:05:03 +01004971 case TypeCheckKind::kUnresolvedCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00004972 case TypeCheckKind::kInterfaceCheck:
4973 default:
4974 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
4975 instruction,
4976 instruction->GetDexPc(),
4977 nullptr);
4978 break;
4979 }
4980 __ Bind(&done);
4981
4982 if (slow_path != nullptr) {
4983 __ Bind(slow_path->GetExitLabel());
4984 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004985}
4986
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004987void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4988 LocationSummary* locations =
4989 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4990 InvokeRuntimeCallingConvention calling_convention;
4991 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4992}
4993
4994void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4995 codegen_->InvokeRuntime(instruction->IsEnter()
4996 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4997 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004998 instruction->GetDexPc(),
4999 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00005000}
5001
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005002void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction, AND); }
5003void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction, ORR); }
5004void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction, EOR); }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005005
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005006void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) {
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005007 LocationSummary* locations =
5008 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5009 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
5010 || instruction->GetResultType() == Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005011 // Note: GVN reorders commutative operations to have the constant on the right hand side.
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005012 locations->SetInAt(0, Location::RequiresRegister());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005013 locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00005014 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005015}
5016
5017void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
5018 HandleBitwiseOperation(instruction);
5019}
5020
5021void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
5022 HandleBitwiseOperation(instruction);
5023}
5024
5025void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
5026 HandleBitwiseOperation(instruction);
5027}
5028
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005029void InstructionCodeGeneratorARM::GenerateAndConst(Register out, Register first, uint32_t value) {
5030 // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier).
5031 if (value == 0xffffffffu) {
5032 if (out != first) {
5033 __ mov(out, ShifterOperand(first));
5034 }
5035 return;
5036 }
5037 if (value == 0u) {
5038 __ mov(out, ShifterOperand(0));
5039 return;
5040 }
5041 ShifterOperand so;
5042 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, AND, value, &so)) {
5043 __ and_(out, first, so);
5044 } else {
5045 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, BIC, ~value, &so));
5046 __ bic(out, first, ShifterOperand(~value));
5047 }
5048}
5049
5050void InstructionCodeGeneratorARM::GenerateOrrConst(Register out, Register first, uint32_t value) {
5051 // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier).
5052 if (value == 0u) {
5053 if (out != first) {
5054 __ mov(out, ShifterOperand(first));
5055 }
5056 return;
5057 }
5058 if (value == 0xffffffffu) {
5059 __ mvn(out, ShifterOperand(0));
5060 return;
5061 }
5062 ShifterOperand so;
5063 if (__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORR, value, &so)) {
5064 __ orr(out, first, so);
5065 } else {
5066 DCHECK(__ ShifterOperandCanHold(kNoRegister, kNoRegister, ORN, ~value, &so));
5067 __ orn(out, first, ShifterOperand(~value));
5068 }
5069}
5070
5071void InstructionCodeGeneratorARM::GenerateEorConst(Register out, Register first, uint32_t value) {
5072 // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier).
5073 if (value == 0u) {
5074 if (out != first) {
5075 __ mov(out, ShifterOperand(first));
5076 }
5077 return;
5078 }
5079 __ eor(out, first, ShifterOperand(value));
5080}
5081
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005082void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
5083 LocationSummary* locations = instruction->GetLocations();
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005084 Location first = locations->InAt(0);
5085 Location second = locations->InAt(1);
5086 Location out = locations->Out();
5087
5088 if (second.IsConstant()) {
5089 uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant()));
5090 uint32_t value_low = Low32Bits(value);
5091 if (instruction->GetResultType() == Primitive::kPrimInt) {
5092 Register first_reg = first.AsRegister<Register>();
5093 Register out_reg = out.AsRegister<Register>();
5094 if (instruction->IsAnd()) {
5095 GenerateAndConst(out_reg, first_reg, value_low);
5096 } else if (instruction->IsOr()) {
5097 GenerateOrrConst(out_reg, first_reg, value_low);
5098 } else {
5099 DCHECK(instruction->IsXor());
5100 GenerateEorConst(out_reg, first_reg, value_low);
5101 }
5102 } else {
5103 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
5104 uint32_t value_high = High32Bits(value);
5105 Register first_low = first.AsRegisterPairLow<Register>();
5106 Register first_high = first.AsRegisterPairHigh<Register>();
5107 Register out_low = out.AsRegisterPairLow<Register>();
5108 Register out_high = out.AsRegisterPairHigh<Register>();
5109 if (instruction->IsAnd()) {
5110 GenerateAndConst(out_low, first_low, value_low);
5111 GenerateAndConst(out_high, first_high, value_high);
5112 } else if (instruction->IsOr()) {
5113 GenerateOrrConst(out_low, first_low, value_low);
5114 GenerateOrrConst(out_high, first_high, value_high);
5115 } else {
5116 DCHECK(instruction->IsXor());
5117 GenerateEorConst(out_low, first_low, value_low);
5118 GenerateEorConst(out_high, first_high, value_high);
5119 }
5120 }
5121 return;
5122 }
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005123
5124 if (instruction->GetResultType() == Primitive::kPrimInt) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005125 Register first_reg = first.AsRegister<Register>();
5126 ShifterOperand second_reg(second.AsRegister<Register>());
5127 Register out_reg = out.AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005128 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005129 __ and_(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005130 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005131 __ orr(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005132 } else {
5133 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005134 __ eor(out_reg, first_reg, second_reg);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005135 }
5136 } else {
5137 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005138 Register first_low = first.AsRegisterPairLow<Register>();
5139 Register first_high = first.AsRegisterPairHigh<Register>();
5140 ShifterOperand second_low(second.AsRegisterPairLow<Register>());
5141 ShifterOperand second_high(second.AsRegisterPairHigh<Register>());
5142 Register out_low = out.AsRegisterPairLow<Register>();
5143 Register out_high = out.AsRegisterPairHigh<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005144 if (instruction->IsAnd()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005145 __ and_(out_low, first_low, second_low);
5146 __ and_(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005147 } else if (instruction->IsOr()) {
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005148 __ orr(out_low, first_low, second_low);
5149 __ orr(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005150 } else {
5151 DCHECK(instruction->IsXor());
Vladimir Markod2b4ca22015-09-14 15:13:26 +01005152 __ eor(out_low, first_low, second_low);
5153 __ eor(out_high, first_high, second_high);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00005154 }
5155 }
5156}
5157
Vladimir Markodc151b22015-10-15 18:02:30 +01005158HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM::GetSupportedInvokeStaticOrDirectDispatch(
5159 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
5160 MethodReference target_method) {
5161 if (desired_dispatch_info.method_load_kind ==
5162 HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative) {
5163 // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod.
5164 return HInvokeStaticOrDirect::DispatchInfo {
5165 HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod,
5166 HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod,
5167 0u,
5168 0u
5169 };
5170 }
5171 if (desired_dispatch_info.code_ptr_location ==
5172 HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative) {
5173 const DexFile& outer_dex_file = GetGraph()->GetDexFile();
5174 if (&outer_dex_file != target_method.dex_file) {
5175 // Calls across dex files are more likely to exceed the available BL range,
5176 // so use absolute patch with fixup if available and kCallArtMethod otherwise.
5177 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location =
5178 (desired_dispatch_info.method_load_kind ==
5179 HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup)
5180 ? HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup
5181 : HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
5182 return HInvokeStaticOrDirect::DispatchInfo {
5183 desired_dispatch_info.method_load_kind,
5184 code_ptr_location,
5185 desired_dispatch_info.method_load_data,
5186 0u
5187 };
5188 }
5189 }
5190 return desired_dispatch_info;
5191}
5192
Nicolas Geoffray38207af2015-06-01 15:46:22 +01005193void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00005194 // For better instruction scheduling we load the direct code pointer before the method pointer.
Vladimir Marko58155012015-08-19 12:49:41 +00005195 switch (invoke->GetCodePtrLocation()) {
Vladimir Marko58155012015-08-19 12:49:41 +00005196 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
5197 // LR = code address from literal pool with link-time patch.
5198 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
Vladimir Marko58155012015-08-19 12:49:41 +00005199 break;
5200 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
5201 // LR = invoke->GetDirectCodePtr();
5202 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
Vladimir Marko58155012015-08-19 12:49:41 +00005203 break;
5204 default:
5205 break;
5206 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08005207
Vladimir Marko58155012015-08-19 12:49:41 +00005208 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
5209 switch (invoke->GetMethodLoadKind()) {
5210 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
5211 // temp = thread->string_init_entrypoint
5212 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
5213 break;
5214 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
5215 callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
5216 break;
5217 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
5218 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
5219 break;
5220 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
5221 __ LoadLiteral(temp.AsRegister<Register>(),
5222 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
5223 break;
5224 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01005225 // TODO: Implement this type.
5226 // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch().
5227 LOG(FATAL) << "Unsupported";
5228 UNREACHABLE();
Vladimir Marko58155012015-08-19 12:49:41 +00005229 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
5230 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
5231 Register method_reg;
5232 Register reg = temp.AsRegister<Register>();
5233 if (current_method.IsRegister()) {
5234 method_reg = current_method.AsRegister<Register>();
5235 } else {
5236 DCHECK(invoke->GetLocations()->Intrinsified());
5237 DCHECK(!current_method.IsValid());
5238 method_reg = reg;
5239 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
5240 }
5241 // temp = current_method->dex_cache_resolved_methods_;
5242 __ LoadFromOffset(
Vladimir Marko05792b92015-08-03 11:56:49 +01005243 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset(
5244 kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00005245 // temp = temp[index_in_cache]
5246 uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index;
5247 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
5248 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01005249 }
Vladimir Marko58155012015-08-19 12:49:41 +00005250 }
5251
5252 switch (invoke->GetCodePtrLocation()) {
5253 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
5254 __ bl(GetFrameEntryLabel());
5255 break;
5256 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Vladimir Markodc151b22015-10-15 18:02:30 +01005257 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
5258 __ Bind(&relative_call_patches_.back().label);
5259 // Arbitrarily branch to the BL itself, override at link time.
5260 __ bl(&relative_call_patches_.back().label);
5261 break;
Vladimir Marko58155012015-08-19 12:49:41 +00005262 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
5263 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
5264 // LR prepared above for better instruction scheduling.
Vladimir Marko58155012015-08-19 12:49:41 +00005265 // LR()
5266 __ blx(LR);
5267 break;
5268 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
5269 // LR = callee_method->entry_point_from_quick_compiled_code_
5270 __ LoadFromOffset(
5271 kLoadWord, LR, callee_method.AsRegister<Register>(),
5272 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value());
5273 // LR()
5274 __ blx(LR);
5275 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08005276 }
5277
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08005278 DCHECK(!IsLeafMethod());
5279}
5280
Andreas Gampebfb5ba92015-09-01 15:45:02 +00005281void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
5282 Register temp = temp_location.AsRegister<Register>();
5283 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
5284 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
5285 LocationSummary* locations = invoke->GetLocations();
5286 Location receiver = locations->InAt(0);
5287 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
5288 // temp = object->GetClass();
5289 DCHECK(receiver.IsRegister());
5290 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
5291 MaybeRecordImplicitNullCheck(invoke);
5292 __ MaybeUnpoisonHeapReference(temp);
5293 // temp = temp->GetMethodAt(method_offset);
5294 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
5295 kArmWordSize).Int32Value();
5296 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
5297 // LR = temp->GetEntryPoint();
5298 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
5299 // LR();
5300 __ blx(LR);
5301}
5302
Vladimir Marko58155012015-08-19 12:49:41 +00005303void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
5304 DCHECK(linker_patches->empty());
5305 size_t size = method_patches_.size() + call_patches_.size() + relative_call_patches_.size();
5306 linker_patches->reserve(size);
5307 for (const auto& entry : method_patches_) {
5308 const MethodReference& target_method = entry.first;
5309 Literal* literal = entry.second;
5310 DCHECK(literal->GetLabel()->IsBound());
5311 uint32_t literal_offset = literal->GetLabel()->Position();
5312 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
5313 target_method.dex_file,
5314 target_method.dex_method_index));
5315 }
5316 for (const auto& entry : call_patches_) {
5317 const MethodReference& target_method = entry.first;
5318 Literal* literal = entry.second;
5319 DCHECK(literal->GetLabel()->IsBound());
5320 uint32_t literal_offset = literal->GetLabel()->Position();
5321 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
5322 target_method.dex_file,
5323 target_method.dex_method_index));
5324 }
5325 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
5326 uint32_t literal_offset = info.label.Position();
5327 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
5328 info.target_method.dex_file,
5329 info.target_method.dex_method_index));
5330 }
5331}
5332
5333Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
5334 MethodToLiteralMap* map) {
5335 // Look up the literal for target_method.
5336 auto lb = map->lower_bound(target_method);
5337 if (lb != map->end() && !map->key_comp()(target_method, lb->first)) {
5338 return lb->second;
5339 }
5340 // We don't have a literal for this method yet, insert a new one.
5341 Literal* literal = __ NewLiteral<uint32_t>(0u);
5342 map->PutBefore(lb, target_method, literal);
5343 return literal;
5344}
5345
5346Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
5347 return DeduplicateMethodLiteral(target_method, &method_patches_);
5348}
5349
5350Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
5351 return DeduplicateMethodLiteral(target_method, &call_patches_);
5352}
5353
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005354void LocationsBuilderARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00005355 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00005356 LOG(FATAL) << "Unreachable";
5357}
5358
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005359void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00005360 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00005361 LOG(FATAL) << "Unreachable";
5362}
5363
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01005364void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) {
5365 DCHECK(codegen_->IsBaseline());
5366 LocationSummary* locations =
5367 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5368 locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
5369}
5370
5371void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
5372 DCHECK(codegen_->IsBaseline());
5373 // Will be generated at use site.
5374}
5375
Mark Mendellfe57faa2015-09-18 09:26:15 -04005376// Simple implementation of packed switch - generate cascaded compare/jumps.
5377void LocationsBuilderARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5378 LocationSummary* locations =
5379 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
5380 locations->SetInAt(0, Location::RequiresRegister());
5381}
5382
5383void InstructionCodeGeneratorARM::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5384 int32_t lower_bound = switch_instr->GetStartValue();
5385 int32_t num_entries = switch_instr->GetNumEntries();
5386 LocationSummary* locations = switch_instr->GetLocations();
5387 Register value_reg = locations->InAt(0).AsRegister<Register>();
5388 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
5389
5390 // Create a series of compare/jumps.
5391 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
5392 for (int32_t i = 0; i < num_entries; i++) {
5393 GenerateCompareWithImmediate(value_reg, lower_bound + i);
Vladimir Markoec7802a2015-10-01 20:57:57 +01005394 __ b(codegen_->GetLabelOf(successors[i]), EQ);
Mark Mendellfe57faa2015-09-18 09:26:15 -04005395 }
5396
5397 // And the default for any other value.
5398 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
5399 __ b(codegen_->GetLabelOf(default_block));
5400 }
5401}
5402
Andreas Gampe85b62f22015-09-09 13:15:38 -07005403void CodeGeneratorARM::MoveFromReturnRegister(Location trg, Primitive::Type type) {
5404 if (!trg.IsValid()) {
5405 DCHECK(type == Primitive::kPrimVoid);
5406 return;
5407 }
5408
5409 DCHECK_NE(type, Primitive::kPrimVoid);
5410
5411 Location return_loc = InvokeDexCallingConventionVisitorARM().GetReturnLocation(type);
5412 if (return_loc.Equals(trg)) {
5413 return;
5414 }
5415
5416 // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged
5417 // with the last branch.
5418 if (type == Primitive::kPrimLong) {
5419 HParallelMove parallel_move(GetGraph()->GetArena());
5420 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimInt, nullptr);
5421 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimInt, nullptr);
5422 GetMoveResolver()->EmitNativeCode(&parallel_move);
5423 } else if (type == Primitive::kPrimDouble) {
5424 HParallelMove parallel_move(GetGraph()->GetArena());
5425 parallel_move.AddMove(return_loc.ToLow(), trg.ToLow(), Primitive::kPrimFloat, nullptr);
5426 parallel_move.AddMove(return_loc.ToHigh(), trg.ToHigh(), Primitive::kPrimFloat, nullptr);
5427 GetMoveResolver()->EmitNativeCode(&parallel_move);
5428 } else {
5429 // Let the parallel move resolver take care of all of this.
5430 HParallelMove parallel_move(GetGraph()->GetArena());
5431 parallel_move.AddMove(return_loc, trg, type, nullptr);
5432 GetMoveResolver()->EmitNativeCode(&parallel_move);
5433 }
5434}
5435
Roland Levillain4d027112015-07-01 15:41:14 +01005436#undef __
5437#undef QUICK_ENTRY_POINT
5438
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00005439} // namespace arm
5440} // namespace art