blob: 815dc4b12096c8b85a1e4843fa1dde490608c09a [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_arm.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000018
Calin Juravle34166012014-12-19 17:22:29 +000019#include "arch/arm/instruction_set_features_arm.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "art_method.h"
Zheng Xuc6667102015-05-15 16:08:45 +080021#include "code_generator_utils.h"
Vladimir Marko58155012015-08-19 12:49:41 +000022#include "compiled_method.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070023#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010024#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080025#include "intrinsics.h"
26#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070027#include "mirror/array-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070028#include "mirror/class-inl.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070029#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010030#include "utils/arm/assembler_arm.h"
31#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000032#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010033#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000034
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000035namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010036
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000037namespace arm {
38
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000039static bool ExpectedPairLayout(Location location) {
40 // We expected this for both core and fpu register pairs.
41 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
42}
43
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010044static constexpr int kCurrentMethodStackOffset = 0;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +010045static constexpr Register kMethodRegisterArgument = R0;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010046
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000047// We unconditionally allocate R5 to ensure we can do long operations
48// with baseline.
49static constexpr Register kCoreSavedRegisterForBaseline = R5;
50static constexpr Register kCoreCalleeSaves[] =
Andreas Gampe501fd632015-09-10 16:11:06 -070051 { R5, R6, R7, R8, R10, R11, LR };
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000052static constexpr SRegister kFpuCalleeSaves[] =
53 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010054
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000055// D31 cannot be split into two S registers, and the register allocator only works on
56// S registers. Therefore there is no need to block it.
57static constexpr DRegister DTMP = D31;
58
Roland Levillain62a46b22015-06-01 18:24:13 +010059#define __ down_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010060#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010061
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010062class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010063 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010064 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010065
Alexandre Rames67555f72014-11-18 10:55:16 +000066 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010067 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010068 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +000069 if (instruction_->CanThrowIntoCatchBlock()) {
70 // Live registers will be restored in the catch block if caught.
71 SaveLiveRegisters(codegen, instruction_->GetLocations());
72 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010073 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000074 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010075 }
76
Alexandre Rames8158f282015-08-07 10:26:17 +010077 bool IsFatal() const OVERRIDE { return true; }
78
Alexandre Rames9931f312015-06-19 14:47:01 +010079 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
80
Nicolas Geoffraye5038322014-07-04 09:41:32 +010081 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010082 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010083 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
84};
85
Calin Juravled0d48522014-11-04 16:40:20 +000086class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
87 public:
88 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
89
Alexandre Rames67555f72014-11-18 10:55:16 +000090 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000091 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
92 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +000093 if (instruction_->CanThrowIntoCatchBlock()) {
94 // Live registers will be restored in the catch block if caught.
95 SaveLiveRegisters(codegen, instruction_->GetLocations());
96 }
Calin Juravled0d48522014-11-04 16:40:20 +000097 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000098 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +000099 }
100
Alexandre Rames8158f282015-08-07 10:26:17 +0100101 bool IsFatal() const OVERRIDE { return true; }
102
Alexandre Rames9931f312015-06-19 14:47:01 +0100103 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
104
Calin Juravled0d48522014-11-04 16:40:20 +0000105 private:
106 HDivZeroCheck* const instruction_;
107 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
108};
109
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100110class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000111 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000112 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100113 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000114
Alexandre Rames67555f72014-11-18 10:55:16 +0000115 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100116 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000117 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000118 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100119 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000120 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000121 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100122 if (successor_ == nullptr) {
123 __ b(GetReturnLabel());
124 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100125 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100126 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000127 }
128
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100129 Label* GetReturnLabel() {
130 DCHECK(successor_ == nullptr);
131 return &return_label_;
132 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000133
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100134 HBasicBlock* GetSuccessor() const {
135 return successor_;
136 }
137
Alexandre Rames9931f312015-06-19 14:47:01 +0100138 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; }
139
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000140 private:
141 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100142 // If not null, the block to branch to after the suspend check.
143 HBasicBlock* const successor_;
144
145 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000146 Label return_label_;
147
148 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
149};
150
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100151class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152 public:
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100153 explicit BoundsCheckSlowPathARM(HBoundsCheck* instruction)
154 : instruction_(instruction) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100155
Alexandre Rames67555f72014-11-18 10:55:16 +0000156 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100157 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100158 LocationSummary* locations = instruction_->GetLocations();
159
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100160 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000161 if (instruction_->CanThrowIntoCatchBlock()) {
162 // Live registers will be restored in the catch block if caught.
163 SaveLiveRegisters(codegen, instruction_->GetLocations());
164 }
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000165 // We're moving two locations to locations that could overlap, so we need a parallel
166 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100167 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000168 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100169 locations->InAt(0),
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000170 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100171 Primitive::kPrimInt,
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100172 locations->InAt(1),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100173 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
174 Primitive::kPrimInt);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100175 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000176 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100177 }
178
Alexandre Rames8158f282015-08-07 10:26:17 +0100179 bool IsFatal() const OVERRIDE { return true; }
180
Alexandre Rames9931f312015-06-19 14:47:01 +0100181 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; }
182
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100183 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100184 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100185
186 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
187};
188
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000189class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000191 LoadClassSlowPathARM(HLoadClass* cls,
192 HInstruction* at,
193 uint32_t dex_pc,
194 bool do_clinit)
195 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
196 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
197 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100198
Alexandre Rames67555f72014-11-18 10:55:16 +0000199 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200 LocationSummary* locations = at_->GetLocations();
201
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100202 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
203 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000204 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100205
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100206 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000207 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000208 int32_t entry_point_offset = do_clinit_
209 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
210 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000211 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000212
213 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000214 Location out = locations->Out();
215 if (out.IsValid()) {
216 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000217 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
218 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000219 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100220 __ b(GetExitLabel());
221 }
222
Alexandre Rames9931f312015-06-19 14:47:01 +0100223 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
224
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100225 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000226 // The class this slow path will load.
227 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100228
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000229 // The instruction where this slow path is happening.
230 // (Might be the load class or an initialization check).
231 HInstruction* const at_;
232
233 // The dex PC of `at_`.
234 const uint32_t dex_pc_;
235
236 // Whether to initialize the class.
237 const bool do_clinit_;
238
239 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100240};
241
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000242class LoadStringSlowPathARM : public SlowPathCodeARM {
243 public:
244 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
245
Alexandre Rames67555f72014-11-18 10:55:16 +0000246 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000247 LocationSummary* locations = instruction_->GetLocations();
248 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
249
250 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
251 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000252 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000253
254 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800255 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000256 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000257 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000258 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
259
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000260 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000261 __ b(GetExitLabel());
262 }
263
Alexandre Rames9931f312015-06-19 14:47:01 +0100264 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
265
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000266 private:
267 HLoadString* const instruction_;
268
269 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
270};
271
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000272class TypeCheckSlowPathARM : public SlowPathCodeARM {
273 public:
Nicolas Geoffray64acf302015-09-14 22:20:29 +0100274 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 Geoffray64acf302015-09-14 22:20:29 +0100286
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 Geoffray64acf302015-09-14 22:20:29 +0100325 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 Geoffray64acf302015-09-14 22:20:29 +0100333 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 Geoffray64acf302015-09-14 22:20:29 +0100337 const bool is_fatal_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000338
339 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
340};
341
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700342class DeoptimizationSlowPathARM : public SlowPathCodeARM {
343 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 Geoffrayb5f62b32014-10-30 10:58:41 +0000364#undef __
Roland Levillain62a46b22015-06-01 18:24:13 +0100365#define __ down_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700366
Roland Levillain4fa13f62015-07-06 18:11:54 +0100367inline Condition ARMSignedOrFPCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700368 switch (cond) {
369 case kCondEQ: return EQ;
370 case kCondNE: return NE;
371 case kCondLT: return LT;
372 case kCondLE: return LE;
373 case kCondGT: return GT;
374 case kCondGE: return GE;
Dave Allison20dfc792014-06-16 20:44:29 -0700375 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100376 LOG(FATAL) << "Unreachable";
377 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700378}
379
Roland Levillain4fa13f62015-07-06 18:11:54 +0100380inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700381 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100382 case kCondEQ: return EQ;
383 case kCondNE: return NE;
384 case kCondLT: return LO;
385 case kCondLE: return LS;
386 case kCondGT: return HI;
387 case kCondGE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700388 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100389 LOG(FATAL) << "Unreachable";
390 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700391}
392
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100393void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100394 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100395}
396
397void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100398 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100399}
400
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100401size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
402 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
403 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100404}
405
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100406size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
407 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
408 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100409}
410
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000411size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
412 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
413 return kArmWordSize;
414}
415
416size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
417 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
418 return kArmWordSize;
419}
420
Calin Juravle34166012014-12-19 17:22:29 +0000421CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000422 const ArmInstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100423 const CompilerOptions& compiler_options,
424 OptimizingCompilerStats* stats)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000425 : CodeGenerator(graph,
426 kNumberOfCoreRegisters,
427 kNumberOfSRegisters,
428 kNumberOfRegisterPairs,
429 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
430 arraysize(kCoreCalleeSaves)),
431 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
432 arraysize(kFpuCalleeSaves)),
Serban Constantinescuecc43662015-08-13 13:33:12 +0100433 compiler_options,
434 stats),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100435 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100436 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100437 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100438 move_resolver_(graph->GetArena(), this),
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000439 assembler_(),
Vladimir Marko58155012015-08-19 12:49:41 +0000440 isa_features_(isa_features),
441 method_patches_(MethodReferenceComparator(), graph->GetArena()->Adapter()),
442 call_patches_(MethodReferenceComparator(), graph->GetArena()->Adapter()),
443 relative_call_patches_(graph->GetArena()->Adapter()) {
Andreas Gampe501fd632015-09-10 16:11:06 -0700444 // Always save the LR register to mimic Quick.
445 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100446}
447
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000448void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
449 // Ensure that we fix up branches and literal loads and emit the literal pool.
450 __ FinalizeCode();
451
452 // Adjust native pc offsets in stack maps.
453 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
454 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
455 uint32_t new_position = __ GetAdjustedPosition(old_position);
456 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
457 }
458 // Adjust native pc offsets of block labels.
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100459 for (HBasicBlock* block : *block_order_) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000460 // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid
461 // FirstNonEmptyBlock() which could lead to adjusting a label more than once.
462 DCHECK_LT(static_cast<size_t>(block->GetBlockId()), block_labels_.Size());
463 Label* block_label = &block_labels_.GetRawStorage()[block->GetBlockId()];
David Brazdilfc6a86a2015-06-26 10:33:45 +0000464 DCHECK_EQ(block_label->IsBound(), !block->IsSingleJump());
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000465 if (block_label->IsBound()) {
466 __ AdjustLabelPosition(block_label);
467 }
468 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100469 // Adjust pc offsets for the disassembly information.
470 if (disasm_info_ != nullptr) {
471 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
472 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
473 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
474 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
475 it.second.start = __ GetAdjustedPosition(it.second.start);
476 it.second.end = __ GetAdjustedPosition(it.second.end);
477 }
478 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
479 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
480 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
481 }
482 }
Vladimir Marko58155012015-08-19 12:49:41 +0000483 // Adjust pc offsets for relative call patches.
484 for (MethodPatchInfo<Label>& info : relative_call_patches_) {
485 __ AdjustLabelPosition(&info.label);
486 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000487
488 CodeGenerator::Finalize(allocator);
489}
490
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100491Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100492 switch (type) {
493 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100494 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100495 ArmManagedRegister pair =
496 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100497 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
498 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
499
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100500 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
501 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100502 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100503 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100504 }
505
506 case Primitive::kPrimByte:
507 case Primitive::kPrimBoolean:
508 case Primitive::kPrimChar:
509 case Primitive::kPrimShort:
510 case Primitive::kPrimInt:
511 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100512 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100513 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100514 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
515 ArmManagedRegister current =
516 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
517 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100518 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100519 }
520 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100521 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100522 }
523
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000524 case Primitive::kPrimFloat: {
525 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100526 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100527 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100528
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000529 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000530 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
531 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000532 return Location::FpuRegisterPairLocation(reg, reg + 1);
533 }
534
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100535 case Primitive::kPrimVoid:
536 LOG(FATAL) << "Unreachable type " << type;
537 }
538
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100539 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100540}
541
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000542void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100543 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100544 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100545
546 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100547 blocked_core_registers_[SP] = true;
548 blocked_core_registers_[LR] = true;
549 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100550
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100551 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100552 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100553
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100554 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100555 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100556
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000557 if (is_baseline) {
558 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
559 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
560 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000561
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000562 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
563
564 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
565 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
566 }
567 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100568
569 UpdateBlockedPairRegisters();
570}
571
572void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
573 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
574 ArmManagedRegister current =
575 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
576 if (blocked_core_registers_[current.AsRegisterPairLow()]
577 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
578 blocked_register_pairs_[i] = true;
579 }
580 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100581}
582
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100583InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
584 : HGraphVisitor(graph),
585 assembler_(codegen->GetAssembler()),
586 codegen_(codegen) {}
587
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000588void CodeGeneratorARM::ComputeSpillMask() {
589 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000590 // Save one extra register for baseline. Note that on thumb2, there is no easy
591 // instruction to restore just the PC, so this actually helps both baseline
592 // and non-baseline to save and restore at least two registers at entry and exit.
593 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000594 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
595 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
596 // We use vpush and vpop for saving and restoring floating point registers, which take
597 // a SRegister and the number of registers to save/restore after that SRegister. We
598 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
599 // but in the range.
600 if (fpu_spill_mask_ != 0) {
601 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
602 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
603 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
604 fpu_spill_mask_ |= (1 << i);
605 }
606 }
607}
608
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100609static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100610 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100611}
612
613static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100614 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100615}
616
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000617void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000618 bool skip_overflow_check =
619 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000620 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000621 __ Bind(&frame_entry_label_);
622
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000623 if (HasEmptyFrame()) {
624 return;
625 }
626
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100627 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000628 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
629 __ LoadFromOffset(kLoadWord, IP, IP, 0);
630 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100631 }
632
Andreas Gampe501fd632015-09-10 16:11:06 -0700633 __ PushList(core_spill_mask_);
634 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_));
635 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, core_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000636 if (fpu_spill_mask_ != 0) {
637 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
638 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100639 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100640 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000641 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100642 int adjust = GetFrameSize() - FrameEntrySpillSize();
643 __ AddConstant(SP, -adjust);
644 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100645 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000646}
647
648void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000649 if (HasEmptyFrame()) {
650 __ bx(LR);
651 return;
652 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100653 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100654 int adjust = GetFrameSize() - FrameEntrySpillSize();
655 __ AddConstant(SP, adjust);
656 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000657 if (fpu_spill_mask_ != 0) {
658 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
659 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100660 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
661 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000662 }
Andreas Gampe501fd632015-09-10 16:11:06 -0700663 // Pop LR into PC to return.
664 DCHECK_NE(core_spill_mask_ & (1 << LR), 0U);
665 uint32_t pop_mask = (core_spill_mask_ & (~(1 << LR))) | 1 << PC;
666 __ PopList(pop_mask);
David Srbeckyc34dc932015-04-12 09:27:43 +0100667 __ cfi().RestoreState();
668 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000669}
670
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100671void CodeGeneratorARM::Bind(HBasicBlock* block) {
672 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000673}
674
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100675Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
676 switch (load->GetType()) {
677 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100678 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100679 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100680
681 case Primitive::kPrimInt:
682 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100683 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100684 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100685
686 case Primitive::kPrimBoolean:
687 case Primitive::kPrimByte:
688 case Primitive::kPrimChar:
689 case Primitive::kPrimShort:
690 case Primitive::kPrimVoid:
691 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700692 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100693 }
694
695 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700696 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100697}
698
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100699Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100700 switch (type) {
701 case Primitive::kPrimBoolean:
702 case Primitive::kPrimByte:
703 case Primitive::kPrimChar:
704 case Primitive::kPrimShort:
705 case Primitive::kPrimInt:
706 case Primitive::kPrimNot: {
707 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000708 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100709 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100710 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100711 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000712 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100713 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100714 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100715
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000716 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100717 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000718 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100719 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000720 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100721 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000722 if (calling_convention.GetRegisterAt(index) == R1) {
723 // Skip R1, and use R2_R3 instead.
724 gp_index_++;
725 index++;
726 }
727 }
728 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
729 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000730 calling_convention.GetRegisterAt(index + 1));
Calin Juravle175dc732015-08-25 15:42:32 +0100731
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000732 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000733 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100734 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000735 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
736 }
737 }
738
739 case Primitive::kPrimFloat: {
740 uint32_t stack_index = stack_index_++;
741 if (float_index_ % 2 == 0) {
742 float_index_ = std::max(double_index_, float_index_);
743 }
744 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
745 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
746 } else {
747 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
748 }
749 }
750
751 case Primitive::kPrimDouble: {
752 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
753 uint32_t stack_index = stack_index_;
754 stack_index_ += 2;
755 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
756 uint32_t index = double_index_;
757 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000758 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000759 calling_convention.GetFpuRegisterAt(index),
760 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000761 DCHECK(ExpectedPairLayout(result));
762 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000763 } else {
764 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100765 }
766 }
767
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100768 case Primitive::kPrimVoid:
769 LOG(FATAL) << "Unexpected parameter type " << type;
770 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100771 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100772 return Location();
773}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100774
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100775Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000776 switch (type) {
777 case Primitive::kPrimBoolean:
778 case Primitive::kPrimByte:
779 case Primitive::kPrimChar:
780 case Primitive::kPrimShort:
781 case Primitive::kPrimInt:
782 case Primitive::kPrimNot: {
783 return Location::RegisterLocation(R0);
784 }
785
786 case Primitive::kPrimFloat: {
787 return Location::FpuRegisterLocation(S0);
788 }
789
790 case Primitive::kPrimLong: {
791 return Location::RegisterPairLocation(R0, R1);
792 }
793
794 case Primitive::kPrimDouble: {
795 return Location::FpuRegisterPairLocation(S0, S1);
796 }
797
798 case Primitive::kPrimVoid:
799 return Location();
800 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100801
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000802 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000803}
804
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100805Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
806 return Location::RegisterLocation(kMethodRegisterArgument);
807}
808
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100809void CodeGeneratorARM::Move32(Location destination, Location source) {
810 if (source.Equals(destination)) {
811 return;
812 }
813 if (destination.IsRegister()) {
814 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000815 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100816 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000817 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100818 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000819 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100820 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100821 } else if (destination.IsFpuRegister()) {
822 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000823 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100824 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000825 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100826 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000827 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100828 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100829 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000830 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100831 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000832 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100833 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000834 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100835 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000836 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100837 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
838 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100839 }
840 }
841}
842
843void CodeGeneratorARM::Move64(Location destination, Location source) {
844 if (source.Equals(destination)) {
845 return;
846 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100847 if (destination.IsRegisterPair()) {
848 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000849 EmitParallelMoves(
850 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
851 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100852 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000853 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100854 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
855 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100856 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000857 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100858 } else {
859 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000860 DCHECK(ExpectedPairLayout(destination));
861 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
862 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100863 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000864 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100865 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000866 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
867 SP,
868 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100869 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000870 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100871 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100872 } else {
873 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100874 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000875 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100876 if (source.AsRegisterPairLow<Register>() == R1) {
877 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100878 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
879 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100880 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100881 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100882 SP, destination.GetStackIndex());
883 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000884 } else if (source.IsFpuRegisterPair()) {
885 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
886 SP,
887 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100888 } else {
889 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000890 EmitParallelMoves(
891 Location::StackSlot(source.GetStackIndex()),
892 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100893 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000894 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100895 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
896 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100897 }
898 }
899}
900
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100901void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100902 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100903 if (instruction->IsCurrentMethod()) {
904 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
905 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100906 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100907 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000908 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000909 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
910 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000911 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000912 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000913 } else {
914 DCHECK(location.IsStackSlot());
915 __ LoadImmediate(IP, value);
916 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
917 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000918 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000919 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000920 int64_t value = const_to_move->AsLongConstant()->GetValue();
921 if (location.IsRegisterPair()) {
922 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
923 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
924 } else {
925 DCHECK(location.IsDoubleStackSlot());
926 __ LoadImmediate(IP, Low32Bits(value));
927 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
928 __ LoadImmediate(IP, High32Bits(value));
929 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
930 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100931 }
Roland Levillain476df552014-10-09 17:51:36 +0100932 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100933 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
934 switch (instruction->GetType()) {
935 case Primitive::kPrimBoolean:
936 case Primitive::kPrimByte:
937 case Primitive::kPrimChar:
938 case Primitive::kPrimShort:
939 case Primitive::kPrimInt:
940 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100941 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100942 Move32(location, Location::StackSlot(stack_slot));
943 break;
944
945 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100946 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100947 Move64(location, Location::DoubleStackSlot(stack_slot));
948 break;
949
950 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100951 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100952 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000953 } else if (instruction->IsTemporary()) {
954 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000955 if (temp_location.IsStackSlot()) {
956 Move32(location, temp_location);
957 } else {
958 DCHECK(temp_location.IsDoubleStackSlot());
959 Move64(location, temp_location);
960 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000961 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100962 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100963 switch (instruction->GetType()) {
964 case Primitive::kPrimBoolean:
965 case Primitive::kPrimByte:
966 case Primitive::kPrimChar:
967 case Primitive::kPrimShort:
968 case Primitive::kPrimNot:
969 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100970 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100971 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100972 break;
973
974 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100975 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100976 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100977 break;
978
979 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100980 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100981 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000982 }
983}
984
Calin Juravle175dc732015-08-25 15:42:32 +0100985void CodeGeneratorARM::MoveConstant(Location location, int32_t value) {
986 DCHECK(location.IsRegister());
987 __ LoadImmediate(location.AsRegister<Register>(), value);
988}
989
Calin Juravle23a8e352015-09-08 19:56:31 +0100990void CodeGeneratorARM::AddLocationAsTemp(Location location, LocationSummary* locations) {
991 if (location.IsRegister()) {
992 locations->AddTemp(location);
993 } else if (location.IsRegisterPair()) {
994 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
995 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
996 } else {
997 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
998 }
999}
1000
1001void CodeGeneratorARM::MoveLocationToTemp(Location source,
1002 const LocationSummary& locations,
1003 int temp_index,
1004 Primitive::Type type) {
1005 if (!Primitive::IsFloatingPointType(type)) {
1006 UNIMPLEMENTED(FATAL) << "MoveLocationToTemp not implemented for type " << type;
1007 }
1008
1009 if (type == Primitive::kPrimFloat) {
1010 DCHECK(source.IsFpuRegister()) << source;
1011 __ vmovrs(locations.GetTemp(temp_index).AsRegister<Register>(),
1012 source.AsFpuRegister<SRegister>());
1013 } else {
1014 DCHECK_EQ(type, Primitive::kPrimDouble) << type;
1015 DCHECK(source.IsFpuRegisterPair()) << source;
1016 __ vmovrrd(locations.GetTemp(temp_index).AsRegister<Register>(),
1017 locations.GetTemp(temp_index + 1).AsRegister<Register>(),
1018 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
1019 }
1020}
1021
1022void CodeGeneratorARM::MoveTempToLocation(const LocationSummary& locations,
1023 int temp_index,
1024 Location destination,
1025 Primitive::Type type) {
1026 if (!Primitive::IsFloatingPointType(type)) {
1027 UNIMPLEMENTED(FATAL) << "MoveLocationToTemp not implemented for type " << type;
1028 }
1029
1030 if (type == Primitive::kPrimFloat) {
1031 DCHECK(destination.IsFpuRegister()) << destination;
1032 __ vmovsr(destination.AsFpuRegister<SRegister>(),
1033 locations.GetTemp(temp_index).AsRegister<Register>());
1034 } else {
1035 DCHECK(type == Primitive::kPrimDouble);
1036 DCHECK(destination.IsFpuRegisterPair()) << destination;
1037 __ vmovdrr(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
1038 locations.GetTemp(temp_index).AsRegister<Register>(),
1039 locations.GetTemp(temp_index + 1).AsRegister<Register>());
1040 }
1041}
1042
Calin Juravle175dc732015-08-25 15:42:32 +01001043void CodeGeneratorARM::InvokeRuntime(QuickEntrypointEnum entrypoint,
1044 HInstruction* instruction,
1045 uint32_t dex_pc,
1046 SlowPathCode* slow_path) {
1047 InvokeRuntime(GetThreadOffset<kArmWordSize>(entrypoint).Int32Value(),
1048 instruction,
1049 dex_pc,
1050 slow_path);
1051}
1052
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001053void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
1054 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001055 uint32_t dex_pc,
1056 SlowPathCode* slow_path) {
Alexandre Rames78e3ef62015-08-12 13:43:29 +01001057 ValidateInvokeRuntime(instruction, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001058 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
1059 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001060 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001061}
1062
David Brazdilfc6a86a2015-06-26 10:33:45 +00001063void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001064 DCHECK(!successor->IsExitBlock());
1065
1066 HBasicBlock* block = got->GetBlock();
1067 HInstruction* previous = got->GetPrevious();
1068
1069 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +00001070 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01001071 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1072 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1073 return;
1074 }
1075
1076 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1077 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1078 }
1079 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001080 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001081 }
1082}
1083
David Brazdilfc6a86a2015-06-26 10:33:45 +00001084void LocationsBuilderARM::VisitGoto(HGoto* got) {
1085 got->SetLocations(nullptr);
1086}
1087
1088void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1089 HandleGoto(got, got->GetSuccessor());
1090}
1091
1092void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1093 try_boundary->SetLocations(nullptr);
1094}
1095
1096void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1097 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1098 if (!successor->IsExitBlock()) {
1099 HandleGoto(try_boundary, successor);
1100 }
1101}
1102
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001103void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001104 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001105}
1106
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001107void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001108 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001109}
1110
Roland Levillain4fa13f62015-07-06 18:11:54 +01001111void InstructionCodeGeneratorARM::GenerateCompareWithImmediate(Register left, int32_t right) {
1112 ShifterOperand operand;
1113 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, right, &operand)) {
1114 __ cmp(left, operand);
1115 } else {
1116 Register temp = IP;
1117 __ LoadImmediate(temp, right);
1118 __ cmp(left, ShifterOperand(temp));
1119 }
1120}
1121
1122void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1123 Label* true_label,
1124 Label* false_label) {
1125 __ vmstat(); // transfer FP status register to ARM APSR.
1126 if (cond->IsFPConditionTrueIfNaN()) {
1127 __ b(true_label, VS); // VS for unordered.
1128 } else if (cond->IsFPConditionFalseIfNaN()) {
1129 __ b(false_label, VS); // VS for unordered.
1130 }
1131 __ b(true_label, ARMSignedOrFPCondition(cond->GetCondition()));
1132}
1133
1134void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1135 Label* true_label,
1136 Label* false_label) {
1137 LocationSummary* locations = cond->GetLocations();
1138 Location left = locations->InAt(0);
1139 Location right = locations->InAt(1);
1140 IfCondition if_cond = cond->GetCondition();
1141
1142 Register left_high = left.AsRegisterPairHigh<Register>();
1143 Register left_low = left.AsRegisterPairLow<Register>();
1144 IfCondition true_high_cond = if_cond;
1145 IfCondition false_high_cond = cond->GetOppositeCondition();
1146 Condition final_condition = ARMUnsignedCondition(if_cond);
1147
1148 // Set the conditions for the test, remembering that == needs to be
1149 // decided using the low words.
1150 switch (if_cond) {
1151 case kCondEQ:
1152 case kCondNE:
1153 // Nothing to do.
1154 break;
1155 case kCondLT:
1156 false_high_cond = kCondGT;
1157 break;
1158 case kCondLE:
1159 true_high_cond = kCondLT;
1160 break;
1161 case kCondGT:
1162 false_high_cond = kCondLT;
1163 break;
1164 case kCondGE:
1165 true_high_cond = kCondGT;
1166 break;
1167 }
1168 if (right.IsConstant()) {
1169 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1170 int32_t val_low = Low32Bits(value);
1171 int32_t val_high = High32Bits(value);
1172
1173 GenerateCompareWithImmediate(left_high, val_high);
1174 if (if_cond == kCondNE) {
1175 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1176 } else if (if_cond == kCondEQ) {
1177 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1178 } else {
1179 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1180 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1181 }
1182 // Must be equal high, so compare the lows.
1183 GenerateCompareWithImmediate(left_low, val_low);
1184 } else {
1185 Register right_high = right.AsRegisterPairHigh<Register>();
1186 Register right_low = right.AsRegisterPairLow<Register>();
1187
1188 __ cmp(left_high, ShifterOperand(right_high));
1189 if (if_cond == kCondNE) {
1190 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1191 } else if (if_cond == kCondEQ) {
1192 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1193 } else {
1194 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1195 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1196 }
1197 // Must be equal high, so compare the lows.
1198 __ cmp(left_low, ShifterOperand(right_low));
1199 }
1200 // The last comparison might be unsigned.
1201 __ b(true_label, final_condition);
1202}
1203
1204void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HIf* if_instr,
1205 HCondition* condition,
1206 Label* true_target,
1207 Label* false_target,
1208 Label* always_true_target) {
1209 LocationSummary* locations = condition->GetLocations();
1210 Location left = locations->InAt(0);
1211 Location right = locations->InAt(1);
1212
1213 // We don't want true_target as a nullptr.
1214 if (true_target == nullptr) {
1215 true_target = always_true_target;
1216 }
1217 bool falls_through = (false_target == nullptr);
1218
1219 // FP compares don't like null false_targets.
1220 if (false_target == nullptr) {
1221 false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1222 }
1223
1224 Primitive::Type type = condition->InputAt(0)->GetType();
1225 switch (type) {
1226 case Primitive::kPrimLong:
1227 GenerateLongComparesAndJumps(condition, true_target, false_target);
1228 break;
1229 case Primitive::kPrimFloat:
1230 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1231 GenerateFPJumps(condition, true_target, false_target);
1232 break;
1233 case Primitive::kPrimDouble:
1234 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1235 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1236 GenerateFPJumps(condition, true_target, false_target);
1237 break;
1238 default:
1239 LOG(FATAL) << "Unexpected compare type " << type;
1240 }
1241
1242 if (!falls_through) {
1243 __ b(false_target);
1244 }
1245}
1246
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001247void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
1248 Label* true_target,
1249 Label* false_target,
1250 Label* always_true_target) {
1251 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001252 if (cond->IsIntConstant()) {
1253 // Constant condition, statically compared against 1.
1254 int32_t cond_value = cond->AsIntConstant()->GetValue();
1255 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001256 if (always_true_target != nullptr) {
1257 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001258 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001259 return;
1260 } else {
1261 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001262 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001263 } else {
1264 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1265 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001266 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01001267 __ CompareAndBranchIfNonZero(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
1268 true_target);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001269 } else {
1270 // Condition has not been materialized, use its inputs as the
1271 // comparison and its condition as the branch condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +01001272 Primitive::Type type =
1273 cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt;
1274 // Is this a long or FP comparison that has been folded into the HCondition?
1275 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1276 // Generate the comparison directly.
1277 GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(),
1278 true_target, false_target, always_true_target);
1279 return;
1280 }
1281
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001282 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001283 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001284 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain4fa13f62015-07-06 18:11:54 +01001285 Location right = locations->InAt(1);
1286 if (right.IsRegister()) {
1287 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001288 } else {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001289 DCHECK(right.IsConstant());
1290 GenerateCompareWithImmediate(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001291 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001292 __ b(true_target, ARMSignedOrFPCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001293 }
Dave Allison20dfc792014-06-16 20:44:29 -07001294 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001295 if (false_target != nullptr) {
1296 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001297 }
1298}
1299
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001300void LocationsBuilderARM::VisitIf(HIf* if_instr) {
1301 LocationSummary* locations =
1302 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
1303 HInstruction* cond = if_instr->InputAt(0);
1304 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1305 locations->SetInAt(0, Location::RequiresRegister());
1306 }
1307}
1308
1309void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1310 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1311 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1312 Label* always_true_target = true_target;
1313 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1314 if_instr->IfTrueSuccessor())) {
1315 always_true_target = nullptr;
1316 }
1317 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1318 if_instr->IfFalseSuccessor())) {
1319 false_target = nullptr;
1320 }
1321 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1322}
1323
1324void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1325 LocationSummary* locations = new (GetGraph()->GetArena())
1326 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1327 HInstruction* cond = deoptimize->InputAt(0);
1328 DCHECK(cond->IsCondition());
1329 if (cond->AsCondition()->NeedsMaterialization()) {
1330 locations->SetInAt(0, Location::RequiresRegister());
1331 }
1332}
1333
1334void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1335 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1336 DeoptimizationSlowPathARM(deoptimize);
1337 codegen_->AddSlowPath(slow_path);
1338 Label* slow_path_entry = slow_path->GetEntryLabel();
1339 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1340}
Dave Allison20dfc792014-06-16 20:44:29 -07001341
Roland Levillain0d37cd02015-05-27 16:39:19 +01001342void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001343 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001344 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001345 // Handle the long/FP comparisons made in instruction simplification.
1346 switch (cond->InputAt(0)->GetType()) {
1347 case Primitive::kPrimLong:
1348 locations->SetInAt(0, Location::RequiresRegister());
1349 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1350 if (cond->NeedsMaterialization()) {
1351 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1352 }
1353 break;
1354
1355 case Primitive::kPrimFloat:
1356 case Primitive::kPrimDouble:
1357 locations->SetInAt(0, Location::RequiresFpuRegister());
1358 locations->SetInAt(1, Location::RequiresFpuRegister());
1359 if (cond->NeedsMaterialization()) {
1360 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1361 }
1362 break;
1363
1364 default:
1365 locations->SetInAt(0, Location::RequiresRegister());
1366 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1367 if (cond->NeedsMaterialization()) {
1368 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1369 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001370 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001371}
1372
Roland Levillain0d37cd02015-05-27 16:39:19 +01001373void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001374 if (!cond->NeedsMaterialization()) {
1375 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001376 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001377
1378 LocationSummary* locations = cond->GetLocations();
1379 Location left = locations->InAt(0);
1380 Location right = locations->InAt(1);
1381 Register out = locations->Out().AsRegister<Register>();
1382 Label true_label, false_label;
1383
1384 switch (cond->InputAt(0)->GetType()) {
1385 default: {
1386 // Integer case.
1387 if (right.IsRegister()) {
1388 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1389 } else {
1390 DCHECK(right.IsConstant());
1391 GenerateCompareWithImmediate(left.AsRegister<Register>(),
1392 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
1393 }
1394 __ it(ARMSignedOrFPCondition(cond->GetCondition()), kItElse);
1395 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
1396 ARMSignedOrFPCondition(cond->GetCondition()));
1397 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
1398 ARMSignedOrFPCondition(cond->GetOppositeCondition()));
1399 return;
1400 }
1401 case Primitive::kPrimLong:
1402 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1403 break;
1404 case Primitive::kPrimFloat:
1405 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1406 GenerateFPJumps(cond, &true_label, &false_label);
1407 break;
1408 case Primitive::kPrimDouble:
1409 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1410 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1411 GenerateFPJumps(cond, &true_label, &false_label);
1412 break;
1413 }
1414
1415 // Convert the jumps into the result.
1416 Label done_label;
1417
1418 // False case: result = 0.
1419 __ Bind(&false_label);
1420 __ LoadImmediate(out, 0);
1421 __ b(&done_label);
1422
1423 // True case: result = 1.
1424 __ Bind(&true_label);
1425 __ LoadImmediate(out, 1);
1426 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001427}
1428
1429void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1430 VisitCondition(comp);
1431}
1432
1433void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1434 VisitCondition(comp);
1435}
1436
1437void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1438 VisitCondition(comp);
1439}
1440
1441void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1442 VisitCondition(comp);
1443}
1444
1445void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1446 VisitCondition(comp);
1447}
1448
1449void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1450 VisitCondition(comp);
1451}
1452
1453void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1454 VisitCondition(comp);
1455}
1456
1457void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1458 VisitCondition(comp);
1459}
1460
1461void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1462 VisitCondition(comp);
1463}
1464
1465void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1466 VisitCondition(comp);
1467}
1468
1469void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1470 VisitCondition(comp);
1471}
1472
1473void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1474 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001475}
1476
1477void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001478 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001479}
1480
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001481void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1482 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001483}
1484
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001485void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001486 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001487}
1488
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001489void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001490 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001491 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001492}
1493
1494void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001495 LocationSummary* locations =
1496 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001497 switch (store->InputAt(1)->GetType()) {
1498 case Primitive::kPrimBoolean:
1499 case Primitive::kPrimByte:
1500 case Primitive::kPrimChar:
1501 case Primitive::kPrimShort:
1502 case Primitive::kPrimInt:
1503 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001504 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001505 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1506 break;
1507
1508 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001509 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001510 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1511 break;
1512
1513 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001514 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001515 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001516}
1517
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001518void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001519 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001520}
1521
1522void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001523 LocationSummary* locations =
1524 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001525 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001526}
1527
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001528void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001529 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001530 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001531}
1532
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001533void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1534 LocationSummary* locations =
1535 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1536 locations->SetOut(Location::ConstantLocation(constant));
1537}
1538
1539void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1540 // Will be generated at use site.
1541 UNUSED(constant);
1542}
1543
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001544void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001545 LocationSummary* locations =
1546 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001547 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001548}
1549
1550void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1551 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001552 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001553}
1554
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001555void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1556 LocationSummary* locations =
1557 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1558 locations->SetOut(Location::ConstantLocation(constant));
1559}
1560
1561void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1562 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001563 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001564}
1565
1566void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1567 LocationSummary* locations =
1568 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1569 locations->SetOut(Location::ConstantLocation(constant));
1570}
1571
1572void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1573 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001574 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001575}
1576
Calin Juravle27df7582015-04-17 19:12:31 +01001577void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1578 memory_barrier->SetLocations(nullptr);
1579}
1580
1581void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1582 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1583}
1584
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001585void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001586 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001587}
1588
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001589void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001590 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001591 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001592}
1593
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001594void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001595 LocationSummary* locations =
1596 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001597 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001598}
1599
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001600void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001601 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001602 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001603}
1604
Calin Juravle175dc732015-08-25 15:42:32 +01001605void LocationsBuilderARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1606 // The trampoline uses the same calling convention as dex calling conventions,
1607 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
1608 // the method_idx.
1609 HandleInvoke(invoke);
1610}
1611
1612void InstructionCodeGeneratorARM::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
1613 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
1614}
1615
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001616void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001617 // When we do not run baseline, explicit clinit checks triggered by static
1618 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1619 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001620
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001621 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1622 codegen_->GetInstructionSetFeatures());
1623 if (intrinsic.TryDispatch(invoke)) {
1624 return;
1625 }
1626
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001627 HandleInvoke(invoke);
1628}
1629
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001630static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1631 if (invoke->GetLocations()->Intrinsified()) {
1632 IntrinsicCodeGeneratorARM intrinsic(codegen);
1633 intrinsic.Dispatch(invoke);
1634 return true;
1635 }
1636 return false;
1637}
1638
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001639void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001640 // When we do not run baseline, explicit clinit checks triggered by static
1641 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1642 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001643
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001644 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1645 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001646 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001647
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001648 LocationSummary* locations = invoke->GetLocations();
1649 codegen_->GenerateStaticOrDirectCall(
1650 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001651 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001652}
1653
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001654void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001655 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001656 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001657}
1658
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001659void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001660 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1661 codegen_->GetInstructionSetFeatures());
1662 if (intrinsic.TryDispatch(invoke)) {
1663 return;
1664 }
1665
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001666 HandleInvoke(invoke);
1667}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001668
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001669void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001670 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1671 return;
1672 }
1673
Andreas Gampebfb5ba92015-09-01 15:45:02 +00001674 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001675 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001676 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001677}
1678
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001679void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1680 HandleInvoke(invoke);
1681 // Add the hidden argument.
1682 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1683}
1684
1685void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1686 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001687 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001688 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1689 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001690 LocationSummary* locations = invoke->GetLocations();
1691 Location receiver = locations->InAt(0);
1692 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1693
1694 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001695 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1696 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001697
1698 // temp = object->GetClass();
1699 if (receiver.IsStackSlot()) {
1700 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1701 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1702 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001703 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001704 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001705 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001706 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001707 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001708 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001709 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001710 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1711 // LR = temp->GetEntryPoint();
1712 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1713 // LR();
1714 __ blx(LR);
1715 DCHECK(!codegen_->IsLeafMethod());
1716 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1717}
1718
Roland Levillain88cb1752014-10-20 16:36:47 +01001719void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1720 LocationSummary* locations =
1721 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1722 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001723 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001724 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001725 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1726 break;
1727 }
1728 case Primitive::kPrimLong: {
1729 locations->SetInAt(0, Location::RequiresRegister());
1730 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001731 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001732 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001733
Roland Levillain88cb1752014-10-20 16:36:47 +01001734 case Primitive::kPrimFloat:
1735 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001736 locations->SetInAt(0, Location::RequiresFpuRegister());
1737 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001738 break;
1739
1740 default:
1741 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1742 }
1743}
1744
1745void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1746 LocationSummary* locations = neg->GetLocations();
1747 Location out = locations->Out();
1748 Location in = locations->InAt(0);
1749 switch (neg->GetResultType()) {
1750 case Primitive::kPrimInt:
1751 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001752 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001753 break;
1754
1755 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001756 DCHECK(in.IsRegisterPair());
1757 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1758 __ rsbs(out.AsRegisterPairLow<Register>(),
1759 in.AsRegisterPairLow<Register>(),
1760 ShifterOperand(0));
1761 // We cannot emit an RSC (Reverse Subtract with Carry)
1762 // instruction here, as it does not exist in the Thumb-2
1763 // instruction set. We use the following approach
1764 // using SBC and SUB instead.
1765 //
1766 // out.hi = -C
1767 __ sbc(out.AsRegisterPairHigh<Register>(),
1768 out.AsRegisterPairHigh<Register>(),
1769 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1770 // out.hi = out.hi - in.hi
1771 __ sub(out.AsRegisterPairHigh<Register>(),
1772 out.AsRegisterPairHigh<Register>(),
1773 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1774 break;
1775
Roland Levillain88cb1752014-10-20 16:36:47 +01001776 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001777 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001778 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001779 break;
1780
Roland Levillain88cb1752014-10-20 16:36:47 +01001781 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001782 DCHECK(in.IsFpuRegisterPair());
1783 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1784 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001785 break;
1786
1787 default:
1788 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1789 }
1790}
1791
Roland Levillaindff1f282014-11-05 14:15:05 +00001792void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001793 Primitive::Type result_type = conversion->GetResultType();
1794 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001795 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001796
Roland Levillain5b3ee562015-04-14 16:02:41 +01001797 // The float-to-long, double-to-long and long-to-float type conversions
1798 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001799 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001800 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1801 && result_type == Primitive::kPrimLong)
1802 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001803 ? LocationSummary::kCall
1804 : LocationSummary::kNoCall;
1805 LocationSummary* locations =
1806 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1807
David Brazdilb2bd1c52015-03-25 11:17:37 +00001808 // The Java language does not allow treating boolean as an integral type but
1809 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001810
Roland Levillaindff1f282014-11-05 14:15:05 +00001811 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001812 case Primitive::kPrimByte:
1813 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001814 case Primitive::kPrimBoolean:
1815 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001816 case Primitive::kPrimShort:
1817 case Primitive::kPrimInt:
1818 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001819 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001820 locations->SetInAt(0, Location::RequiresRegister());
1821 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1822 break;
1823
1824 default:
1825 LOG(FATAL) << "Unexpected type conversion from " << input_type
1826 << " to " << result_type;
1827 }
1828 break;
1829
Roland Levillain01a8d712014-11-14 16:27:39 +00001830 case Primitive::kPrimShort:
1831 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001832 case Primitive::kPrimBoolean:
1833 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001834 case Primitive::kPrimByte:
1835 case Primitive::kPrimInt:
1836 case Primitive::kPrimChar:
1837 // Processing a Dex `int-to-short' instruction.
1838 locations->SetInAt(0, Location::RequiresRegister());
1839 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1840 break;
1841
1842 default:
1843 LOG(FATAL) << "Unexpected type conversion from " << input_type
1844 << " to " << result_type;
1845 }
1846 break;
1847
Roland Levillain946e1432014-11-11 17:35:19 +00001848 case Primitive::kPrimInt:
1849 switch (input_type) {
1850 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001851 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001852 locations->SetInAt(0, Location::Any());
1853 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1854 break;
1855
1856 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001857 // Processing a Dex `float-to-int' instruction.
1858 locations->SetInAt(0, Location::RequiresFpuRegister());
1859 locations->SetOut(Location::RequiresRegister());
1860 locations->AddTemp(Location::RequiresFpuRegister());
1861 break;
1862
Roland Levillain946e1432014-11-11 17:35:19 +00001863 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001864 // Processing a Dex `double-to-int' instruction.
1865 locations->SetInAt(0, Location::RequiresFpuRegister());
1866 locations->SetOut(Location::RequiresRegister());
1867 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001868 break;
1869
1870 default:
1871 LOG(FATAL) << "Unexpected type conversion from " << input_type
1872 << " to " << result_type;
1873 }
1874 break;
1875
Roland Levillaindff1f282014-11-05 14:15:05 +00001876 case Primitive::kPrimLong:
1877 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001878 case Primitive::kPrimBoolean:
1879 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001880 case Primitive::kPrimByte:
1881 case Primitive::kPrimShort:
1882 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001883 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001884 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001885 locations->SetInAt(0, Location::RequiresRegister());
1886 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1887 break;
1888
Roland Levillain624279f2014-12-04 11:54:28 +00001889 case Primitive::kPrimFloat: {
1890 // Processing a Dex `float-to-long' instruction.
1891 InvokeRuntimeCallingConvention calling_convention;
1892 locations->SetInAt(0, Location::FpuRegisterLocation(
1893 calling_convention.GetFpuRegisterAt(0)));
1894 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1895 break;
1896 }
1897
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001898 case Primitive::kPrimDouble: {
1899 // Processing a Dex `double-to-long' instruction.
1900 InvokeRuntimeCallingConvention calling_convention;
1901 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1902 calling_convention.GetFpuRegisterAt(0),
1903 calling_convention.GetFpuRegisterAt(1)));
1904 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001905 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001906 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001907
1908 default:
1909 LOG(FATAL) << "Unexpected type conversion from " << input_type
1910 << " to " << result_type;
1911 }
1912 break;
1913
Roland Levillain981e4542014-11-14 11:47:14 +00001914 case Primitive::kPrimChar:
1915 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001916 case Primitive::kPrimBoolean:
1917 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001918 case Primitive::kPrimByte:
1919 case Primitive::kPrimShort:
1920 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001921 // Processing a Dex `int-to-char' instruction.
1922 locations->SetInAt(0, Location::RequiresRegister());
1923 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1924 break;
1925
1926 default:
1927 LOG(FATAL) << "Unexpected type conversion from " << input_type
1928 << " to " << result_type;
1929 }
1930 break;
1931
Roland Levillaindff1f282014-11-05 14:15:05 +00001932 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001933 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001934 case Primitive::kPrimBoolean:
1935 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001936 case Primitive::kPrimByte:
1937 case Primitive::kPrimShort:
1938 case Primitive::kPrimInt:
1939 case Primitive::kPrimChar:
1940 // Processing a Dex `int-to-float' instruction.
1941 locations->SetInAt(0, Location::RequiresRegister());
1942 locations->SetOut(Location::RequiresFpuRegister());
1943 break;
1944
Roland Levillain5b3ee562015-04-14 16:02:41 +01001945 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001946 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001947 InvokeRuntimeCallingConvention calling_convention;
1948 locations->SetInAt(0, Location::RegisterPairLocation(
1949 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1950 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001951 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001952 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001953
Roland Levillaincff13742014-11-17 14:32:17 +00001954 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001955 // Processing a Dex `double-to-float' instruction.
1956 locations->SetInAt(0, Location::RequiresFpuRegister());
1957 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001958 break;
1959
1960 default:
1961 LOG(FATAL) << "Unexpected type conversion from " << input_type
1962 << " to " << result_type;
1963 };
1964 break;
1965
Roland Levillaindff1f282014-11-05 14:15:05 +00001966 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001967 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001968 case Primitive::kPrimBoolean:
1969 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001970 case Primitive::kPrimByte:
1971 case Primitive::kPrimShort:
1972 case Primitive::kPrimInt:
1973 case Primitive::kPrimChar:
1974 // Processing a Dex `int-to-double' instruction.
1975 locations->SetInAt(0, Location::RequiresRegister());
1976 locations->SetOut(Location::RequiresFpuRegister());
1977 break;
1978
1979 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001980 // Processing a Dex `long-to-double' instruction.
1981 locations->SetInAt(0, Location::RequiresRegister());
1982 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001983 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001984 locations->AddTemp(Location::RequiresFpuRegister());
1985 break;
1986
Roland Levillaincff13742014-11-17 14:32:17 +00001987 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001988 // Processing a Dex `float-to-double' instruction.
1989 locations->SetInAt(0, Location::RequiresFpuRegister());
1990 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001991 break;
1992
1993 default:
1994 LOG(FATAL) << "Unexpected type conversion from " << input_type
1995 << " to " << result_type;
1996 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001997 break;
1998
1999 default:
2000 LOG(FATAL) << "Unexpected type conversion from " << input_type
2001 << " to " << result_type;
2002 }
2003}
2004
2005void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
2006 LocationSummary* locations = conversion->GetLocations();
2007 Location out = locations->Out();
2008 Location in = locations->InAt(0);
2009 Primitive::Type result_type = conversion->GetResultType();
2010 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002011 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00002012 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00002013 case Primitive::kPrimByte:
2014 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002015 case Primitive::kPrimBoolean:
2016 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00002017 case Primitive::kPrimShort:
2018 case Primitive::kPrimInt:
2019 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002020 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002021 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00002022 break;
2023
2024 default:
2025 LOG(FATAL) << "Unexpected type conversion from " << input_type
2026 << " to " << result_type;
2027 }
2028 break;
2029
Roland Levillain01a8d712014-11-14 16:27:39 +00002030 case Primitive::kPrimShort:
2031 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002032 case Primitive::kPrimBoolean:
2033 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00002034 case Primitive::kPrimByte:
2035 case Primitive::kPrimInt:
2036 case Primitive::kPrimChar:
2037 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002038 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00002039 break;
2040
2041 default:
2042 LOG(FATAL) << "Unexpected type conversion from " << input_type
2043 << " to " << result_type;
2044 }
2045 break;
2046
Roland Levillain946e1432014-11-11 17:35:19 +00002047 case Primitive::kPrimInt:
2048 switch (input_type) {
2049 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00002050 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00002051 DCHECK(out.IsRegister());
2052 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002053 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00002054 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002055 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00002056 } else {
2057 DCHECK(in.IsConstant());
2058 DCHECK(in.GetConstant()->IsLongConstant());
2059 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002060 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00002061 }
2062 break;
2063
Roland Levillain3f8f9362014-12-02 17:45:01 +00002064 case Primitive::kPrimFloat: {
2065 // Processing a Dex `float-to-int' instruction.
2066 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
2067 __ vmovs(temp, in.AsFpuRegister<SRegister>());
2068 __ vcvtis(temp, temp);
2069 __ vmovrs(out.AsRegister<Register>(), temp);
2070 break;
2071 }
2072
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002073 case Primitive::kPrimDouble: {
2074 // Processing a Dex `double-to-int' instruction.
2075 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
2076 DRegister temp_d = FromLowSToD(temp_s);
2077 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
2078 __ vcvtid(temp_s, temp_d);
2079 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00002080 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002081 }
Roland Levillain946e1432014-11-11 17:35:19 +00002082
2083 default:
2084 LOG(FATAL) << "Unexpected type conversion from " << input_type
2085 << " to " << result_type;
2086 }
2087 break;
2088
Roland Levillaindff1f282014-11-05 14:15:05 +00002089 case Primitive::kPrimLong:
2090 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002091 case Primitive::kPrimBoolean:
2092 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002093 case Primitive::kPrimByte:
2094 case Primitive::kPrimShort:
2095 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002096 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002097 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002098 DCHECK(out.IsRegisterPair());
2099 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002100 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002101 // Sign extension.
2102 __ Asr(out.AsRegisterPairHigh<Register>(),
2103 out.AsRegisterPairLow<Register>(),
2104 31);
2105 break;
2106
2107 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002108 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00002109 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
2110 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002111 conversion->GetDexPc(),
2112 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00002113 break;
2114
Roland Levillaindff1f282014-11-05 14:15:05 +00002115 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002116 // Processing a Dex `double-to-long' instruction.
2117 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
2118 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002119 conversion->GetDexPc(),
2120 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00002121 break;
2122
2123 default:
2124 LOG(FATAL) << "Unexpected type conversion from " << input_type
2125 << " to " << result_type;
2126 }
2127 break;
2128
Roland Levillain981e4542014-11-14 11:47:14 +00002129 case Primitive::kPrimChar:
2130 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002131 case Primitive::kPrimBoolean:
2132 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002133 case Primitive::kPrimByte:
2134 case Primitive::kPrimShort:
2135 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002136 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002137 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002138 break;
2139
2140 default:
2141 LOG(FATAL) << "Unexpected type conversion from " << input_type
2142 << " to " << result_type;
2143 }
2144 break;
2145
Roland Levillaindff1f282014-11-05 14:15:05 +00002146 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002147 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002148 case Primitive::kPrimBoolean:
2149 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002150 case Primitive::kPrimByte:
2151 case Primitive::kPrimShort:
2152 case Primitive::kPrimInt:
2153 case Primitive::kPrimChar: {
2154 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002155 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2156 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002157 break;
2158 }
2159
Roland Levillain5b3ee562015-04-14 16:02:41 +01002160 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002161 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002162 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
2163 conversion,
2164 conversion->GetDexPc(),
2165 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00002166 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002167
Roland Levillaincff13742014-11-17 14:32:17 +00002168 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002169 // Processing a Dex `double-to-float' instruction.
2170 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2171 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002172 break;
2173
2174 default:
2175 LOG(FATAL) << "Unexpected type conversion from " << input_type
2176 << " to " << result_type;
2177 };
2178 break;
2179
Roland Levillaindff1f282014-11-05 14:15:05 +00002180 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002181 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002182 case Primitive::kPrimBoolean:
2183 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002184 case Primitive::kPrimByte:
2185 case Primitive::kPrimShort:
2186 case Primitive::kPrimInt:
2187 case Primitive::kPrimChar: {
2188 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002189 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002190 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2191 out.AsFpuRegisterPairLow<SRegister>());
2192 break;
2193 }
2194
Roland Levillain647b9ed2014-11-27 12:06:00 +00002195 case Primitive::kPrimLong: {
2196 // Processing a Dex `long-to-double' instruction.
2197 Register low = in.AsRegisterPairLow<Register>();
2198 Register high = in.AsRegisterPairHigh<Register>();
2199 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2200 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002201 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002202 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002203 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2204 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002205
Roland Levillain682393c2015-04-14 15:57:52 +01002206 // temp_d = int-to-double(high)
2207 __ vmovsr(temp_s, high);
2208 __ vcvtdi(temp_d, temp_s);
2209 // constant_d = k2Pow32EncodingForDouble
2210 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2211 // out_d = unsigned-to-double(low)
2212 __ vmovsr(out_s, low);
2213 __ vcvtdu(out_d, out_s);
2214 // out_d += temp_d * constant_d
2215 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002216 break;
2217 }
2218
Roland Levillaincff13742014-11-17 14:32:17 +00002219 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002220 // Processing a Dex `float-to-double' instruction.
2221 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2222 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002223 break;
2224
2225 default:
2226 LOG(FATAL) << "Unexpected type conversion from " << input_type
2227 << " to " << result_type;
2228 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002229 break;
2230
2231 default:
2232 LOG(FATAL) << "Unexpected type conversion from " << input_type
2233 << " to " << result_type;
2234 }
2235}
2236
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002237void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002238 LocationSummary* locations =
2239 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002240 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002241 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002242 locations->SetInAt(0, Location::RequiresRegister());
2243 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002244 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2245 break;
2246 }
2247
2248 case Primitive::kPrimLong: {
2249 locations->SetInAt(0, Location::RequiresRegister());
2250 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002251 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002252 break;
2253 }
2254
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002255 case Primitive::kPrimFloat:
2256 case Primitive::kPrimDouble: {
2257 locations->SetInAt(0, Location::RequiresFpuRegister());
2258 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002259 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002260 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002261 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002262
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002263 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002264 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002265 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002266}
2267
2268void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2269 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002270 Location out = locations->Out();
2271 Location first = locations->InAt(0);
2272 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002273 switch (add->GetResultType()) {
2274 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002275 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002276 __ add(out.AsRegister<Register>(),
2277 first.AsRegister<Register>(),
2278 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002279 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002280 __ AddConstant(out.AsRegister<Register>(),
2281 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002282 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002283 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002284 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002285
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002286 case Primitive::kPrimLong: {
2287 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002288 __ adds(out.AsRegisterPairLow<Register>(),
2289 first.AsRegisterPairLow<Register>(),
2290 ShifterOperand(second.AsRegisterPairLow<Register>()));
2291 __ adc(out.AsRegisterPairHigh<Register>(),
2292 first.AsRegisterPairHigh<Register>(),
2293 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002294 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002295 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002296
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002297 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002298 __ vadds(out.AsFpuRegister<SRegister>(),
2299 first.AsFpuRegister<SRegister>(),
2300 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002301 break;
2302
2303 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002304 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2305 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2306 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002307 break;
2308
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002309 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002310 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002311 }
2312}
2313
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002314void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002315 LocationSummary* locations =
2316 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002317 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002318 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002319 locations->SetInAt(0, Location::RequiresRegister());
2320 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002321 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2322 break;
2323 }
2324
2325 case Primitive::kPrimLong: {
2326 locations->SetInAt(0, Location::RequiresRegister());
2327 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002328 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002329 break;
2330 }
Calin Juravle11351682014-10-23 15:38:15 +01002331 case Primitive::kPrimFloat:
2332 case Primitive::kPrimDouble: {
2333 locations->SetInAt(0, Location::RequiresFpuRegister());
2334 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002335 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002336 break;
Calin Juravle11351682014-10-23 15:38:15 +01002337 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002338 default:
Calin Juravle11351682014-10-23 15:38:15 +01002339 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002340 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002341}
2342
2343void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2344 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002345 Location out = locations->Out();
2346 Location first = locations->InAt(0);
2347 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002348 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002349 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002350 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002351 __ sub(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>(),
Calin Juravle11351682014-10-23 15:38:15 +01002357 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002358 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002359 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002360 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002361
Calin Juravle11351682014-10-23 15:38:15 +01002362 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002363 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002364 __ subs(out.AsRegisterPairLow<Register>(),
2365 first.AsRegisterPairLow<Register>(),
2366 ShifterOperand(second.AsRegisterPairLow<Register>()));
2367 __ sbc(out.AsRegisterPairHigh<Register>(),
2368 first.AsRegisterPairHigh<Register>(),
2369 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002370 break;
Calin Juravle11351682014-10-23 15:38:15 +01002371 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002372
Calin Juravle11351682014-10-23 15:38:15 +01002373 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002374 __ vsubs(out.AsFpuRegister<SRegister>(),
2375 first.AsFpuRegister<SRegister>(),
2376 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002377 break;
Calin Juravle11351682014-10-23 15:38:15 +01002378 }
2379
2380 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002381 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2382 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2383 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002384 break;
2385 }
2386
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002387
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002388 default:
Calin Juravle11351682014-10-23 15:38:15 +01002389 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002390 }
2391}
2392
Calin Juravle34bacdf2014-10-07 20:23:36 +01002393void LocationsBuilderARM::VisitMul(HMul* mul) {
2394 LocationSummary* locations =
2395 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2396 switch (mul->GetResultType()) {
2397 case Primitive::kPrimInt:
2398 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002399 locations->SetInAt(0, Location::RequiresRegister());
2400 locations->SetInAt(1, Location::RequiresRegister());
2401 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002402 break;
2403 }
2404
Calin Juravleb5bfa962014-10-21 18:02:24 +01002405 case Primitive::kPrimFloat:
2406 case Primitive::kPrimDouble: {
2407 locations->SetInAt(0, Location::RequiresFpuRegister());
2408 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002409 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002410 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002411 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002412
2413 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002414 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002415 }
2416}
2417
2418void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2419 LocationSummary* locations = mul->GetLocations();
2420 Location out = locations->Out();
2421 Location first = locations->InAt(0);
2422 Location second = locations->InAt(1);
2423 switch (mul->GetResultType()) {
2424 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002425 __ mul(out.AsRegister<Register>(),
2426 first.AsRegister<Register>(),
2427 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002428 break;
2429 }
2430 case Primitive::kPrimLong: {
2431 Register out_hi = out.AsRegisterPairHigh<Register>();
2432 Register out_lo = out.AsRegisterPairLow<Register>();
2433 Register in1_hi = first.AsRegisterPairHigh<Register>();
2434 Register in1_lo = first.AsRegisterPairLow<Register>();
2435 Register in2_hi = second.AsRegisterPairHigh<Register>();
2436 Register in2_lo = second.AsRegisterPairLow<Register>();
2437
2438 // Extra checks to protect caused by the existence of R1_R2.
2439 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2440 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2441 DCHECK_NE(out_hi, in1_lo);
2442 DCHECK_NE(out_hi, in2_lo);
2443
2444 // input: in1 - 64 bits, in2 - 64 bits
2445 // output: out
2446 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2447 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2448 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2449
2450 // IP <- in1.lo * in2.hi
2451 __ mul(IP, in1_lo, in2_hi);
2452 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2453 __ mla(out_hi, in1_hi, in2_lo, IP);
2454 // out.lo <- (in1.lo * in2.lo)[31:0];
2455 __ umull(out_lo, IP, in1_lo, in2_lo);
2456 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2457 __ add(out_hi, out_hi, ShifterOperand(IP));
2458 break;
2459 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002460
2461 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002462 __ vmuls(out.AsFpuRegister<SRegister>(),
2463 first.AsFpuRegister<SRegister>(),
2464 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002465 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002466 }
2467
2468 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002469 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2470 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2471 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002472 break;
2473 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002474
2475 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002476 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002477 }
2478}
2479
Zheng Xuc6667102015-05-15 16:08:45 +08002480void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2481 DCHECK(instruction->IsDiv() || instruction->IsRem());
2482 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2483
2484 LocationSummary* locations = instruction->GetLocations();
2485 Location second = locations->InAt(1);
2486 DCHECK(second.IsConstant());
2487
2488 Register out = locations->Out().AsRegister<Register>();
2489 Register dividend = locations->InAt(0).AsRegister<Register>();
2490 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2491 DCHECK(imm == 1 || imm == -1);
2492
2493 if (instruction->IsRem()) {
2494 __ LoadImmediate(out, 0);
2495 } else {
2496 if (imm == 1) {
2497 __ Mov(out, dividend);
2498 } else {
2499 __ rsb(out, dividend, ShifterOperand(0));
2500 }
2501 }
2502}
2503
2504void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2505 DCHECK(instruction->IsDiv() || instruction->IsRem());
2506 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2507
2508 LocationSummary* locations = instruction->GetLocations();
2509 Location second = locations->InAt(1);
2510 DCHECK(second.IsConstant());
2511
2512 Register out = locations->Out().AsRegister<Register>();
2513 Register dividend = locations->InAt(0).AsRegister<Register>();
2514 Register temp = locations->GetTemp(0).AsRegister<Register>();
2515 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002516 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002517 DCHECK(IsPowerOfTwo(abs_imm));
2518 int ctz_imm = CTZ(abs_imm);
2519
2520 if (ctz_imm == 1) {
2521 __ Lsr(temp, dividend, 32 - ctz_imm);
2522 } else {
2523 __ Asr(temp, dividend, 31);
2524 __ Lsr(temp, temp, 32 - ctz_imm);
2525 }
2526 __ add(out, temp, ShifterOperand(dividend));
2527
2528 if (instruction->IsDiv()) {
2529 __ Asr(out, out, ctz_imm);
2530 if (imm < 0) {
2531 __ rsb(out, out, ShifterOperand(0));
2532 }
2533 } else {
2534 __ ubfx(out, out, 0, ctz_imm);
2535 __ sub(out, out, ShifterOperand(temp));
2536 }
2537}
2538
2539void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2540 DCHECK(instruction->IsDiv() || instruction->IsRem());
2541 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2542
2543 LocationSummary* locations = instruction->GetLocations();
2544 Location second = locations->InAt(1);
2545 DCHECK(second.IsConstant());
2546
2547 Register out = locations->Out().AsRegister<Register>();
2548 Register dividend = locations->InAt(0).AsRegister<Register>();
2549 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2550 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2551 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2552
2553 int64_t magic;
2554 int shift;
2555 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2556
2557 __ LoadImmediate(temp1, magic);
2558 __ smull(temp2, temp1, dividend, temp1);
2559
2560 if (imm > 0 && magic < 0) {
2561 __ add(temp1, temp1, ShifterOperand(dividend));
2562 } else if (imm < 0 && magic > 0) {
2563 __ sub(temp1, temp1, ShifterOperand(dividend));
2564 }
2565
2566 if (shift != 0) {
2567 __ Asr(temp1, temp1, shift);
2568 }
2569
2570 if (instruction->IsDiv()) {
2571 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2572 } else {
2573 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2574 // TODO: Strength reduction for mls.
2575 __ LoadImmediate(temp2, imm);
2576 __ mls(out, temp1, temp2, dividend);
2577 }
2578}
2579
2580void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2581 DCHECK(instruction->IsDiv() || instruction->IsRem());
2582 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2583
2584 LocationSummary* locations = instruction->GetLocations();
2585 Location second = locations->InAt(1);
2586 DCHECK(second.IsConstant());
2587
2588 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2589 if (imm == 0) {
2590 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2591 } else if (imm == 1 || imm == -1) {
2592 DivRemOneOrMinusOne(instruction);
2593 } else if (IsPowerOfTwo(std::abs(imm))) {
2594 DivRemByPowerOfTwo(instruction);
2595 } else {
2596 DCHECK(imm <= -2 || imm >= 2);
2597 GenerateDivRemWithAnyConstant(instruction);
2598 }
2599}
2600
Calin Juravle7c4954d2014-10-28 16:57:40 +00002601void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002602 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2603 if (div->GetResultType() == Primitive::kPrimLong) {
2604 // pLdiv runtime call.
2605 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002606 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2607 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002608 } else if (div->GetResultType() == Primitive::kPrimInt &&
2609 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2610 // pIdivmod runtime call.
2611 call_kind = LocationSummary::kCall;
2612 }
2613
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002614 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2615
Calin Juravle7c4954d2014-10-28 16:57:40 +00002616 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002617 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002618 if (div->InputAt(1)->IsConstant()) {
2619 locations->SetInAt(0, Location::RequiresRegister());
2620 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2621 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2622 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2623 if (abs_imm <= 1) {
2624 // No temp register required.
2625 } else {
2626 locations->AddTemp(Location::RequiresRegister());
2627 if (!IsPowerOfTwo(abs_imm)) {
2628 locations->AddTemp(Location::RequiresRegister());
2629 }
2630 }
2631 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002632 locations->SetInAt(0, Location::RequiresRegister());
2633 locations->SetInAt(1, Location::RequiresRegister());
2634 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2635 } else {
2636 InvokeRuntimeCallingConvention calling_convention;
2637 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2638 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2639 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2640 // we only need the former.
2641 locations->SetOut(Location::RegisterLocation(R0));
2642 }
Calin Juravled0d48522014-11-04 16:40:20 +00002643 break;
2644 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002645 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002646 InvokeRuntimeCallingConvention calling_convention;
2647 locations->SetInAt(0, Location::RegisterPairLocation(
2648 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2649 locations->SetInAt(1, Location::RegisterPairLocation(
2650 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002651 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002652 break;
2653 }
2654 case Primitive::kPrimFloat:
2655 case Primitive::kPrimDouble: {
2656 locations->SetInAt(0, Location::RequiresFpuRegister());
2657 locations->SetInAt(1, Location::RequiresFpuRegister());
2658 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2659 break;
2660 }
2661
2662 default:
2663 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2664 }
2665}
2666
2667void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2668 LocationSummary* locations = div->GetLocations();
2669 Location out = locations->Out();
2670 Location first = locations->InAt(0);
2671 Location second = locations->InAt(1);
2672
2673 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002674 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002675 if (second.IsConstant()) {
2676 GenerateDivRemConstantIntegral(div);
2677 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002678 __ sdiv(out.AsRegister<Register>(),
2679 first.AsRegister<Register>(),
2680 second.AsRegister<Register>());
2681 } else {
2682 InvokeRuntimeCallingConvention calling_convention;
2683 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2684 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2685 DCHECK_EQ(R0, out.AsRegister<Register>());
2686
2687 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2688 }
Calin Juravled0d48522014-11-04 16:40:20 +00002689 break;
2690 }
2691
Calin Juravle7c4954d2014-10-28 16:57:40 +00002692 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002693 InvokeRuntimeCallingConvention calling_convention;
2694 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2695 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2696 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2697 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2698 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002699 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002700
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002701 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002702 break;
2703 }
2704
2705 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002706 __ vdivs(out.AsFpuRegister<SRegister>(),
2707 first.AsFpuRegister<SRegister>(),
2708 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002709 break;
2710 }
2711
2712 case Primitive::kPrimDouble: {
2713 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2714 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2715 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2716 break;
2717 }
2718
2719 default:
2720 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2721 }
2722}
2723
Calin Juravlebacfec32014-11-14 15:54:36 +00002724void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002725 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002726
2727 // Most remainders are implemented in the runtime.
2728 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002729 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2730 // sdiv will be replaced by other instruction sequence.
2731 call_kind = LocationSummary::kNoCall;
2732 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2733 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002734 // Have hardware divide instruction for int, do it with three instructions.
2735 call_kind = LocationSummary::kNoCall;
2736 }
2737
Calin Juravlebacfec32014-11-14 15:54:36 +00002738 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2739
Calin Juravled2ec87d2014-12-08 14:24:46 +00002740 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002741 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002742 if (rem->InputAt(1)->IsConstant()) {
2743 locations->SetInAt(0, Location::RequiresRegister());
2744 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2745 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2746 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2747 if (abs_imm <= 1) {
2748 // No temp register required.
2749 } else {
2750 locations->AddTemp(Location::RequiresRegister());
2751 if (!IsPowerOfTwo(abs_imm)) {
2752 locations->AddTemp(Location::RequiresRegister());
2753 }
2754 }
2755 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002756 locations->SetInAt(0, Location::RequiresRegister());
2757 locations->SetInAt(1, Location::RequiresRegister());
2758 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2759 locations->AddTemp(Location::RequiresRegister());
2760 } else {
2761 InvokeRuntimeCallingConvention calling_convention;
2762 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2763 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2764 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2765 // we only need the latter.
2766 locations->SetOut(Location::RegisterLocation(R1));
2767 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002768 break;
2769 }
2770 case Primitive::kPrimLong: {
2771 InvokeRuntimeCallingConvention calling_convention;
2772 locations->SetInAt(0, Location::RegisterPairLocation(
2773 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2774 locations->SetInAt(1, Location::RegisterPairLocation(
2775 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2776 // The runtime helper puts the output in R2,R3.
2777 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2778 break;
2779 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002780 case Primitive::kPrimFloat: {
2781 InvokeRuntimeCallingConvention calling_convention;
2782 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2783 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2784 locations->SetOut(Location::FpuRegisterLocation(S0));
2785 break;
2786 }
2787
Calin Juravlebacfec32014-11-14 15:54:36 +00002788 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002789 InvokeRuntimeCallingConvention calling_convention;
2790 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2791 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2792 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2793 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2794 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002795 break;
2796 }
2797
2798 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002799 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002800 }
2801}
2802
2803void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2804 LocationSummary* locations = rem->GetLocations();
2805 Location out = locations->Out();
2806 Location first = locations->InAt(0);
2807 Location second = locations->InAt(1);
2808
Calin Juravled2ec87d2014-12-08 14:24:46 +00002809 Primitive::Type type = rem->GetResultType();
2810 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002811 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002812 if (second.IsConstant()) {
2813 GenerateDivRemConstantIntegral(rem);
2814 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002815 Register reg1 = first.AsRegister<Register>();
2816 Register reg2 = second.AsRegister<Register>();
2817 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002818
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002819 // temp = reg1 / reg2 (integer division)
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002820 // dest = reg1 - temp * reg2
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002821 __ sdiv(temp, reg1, reg2);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002822 __ mls(out.AsRegister<Register>(), temp, reg2, reg1);
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002823 } else {
2824 InvokeRuntimeCallingConvention calling_convention;
2825 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2826 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2827 DCHECK_EQ(R1, out.AsRegister<Register>());
2828
2829 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2830 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002831 break;
2832 }
2833
2834 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002835 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002836 break;
2837 }
2838
Calin Juravled2ec87d2014-12-08 14:24:46 +00002839 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002840 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002841 break;
2842 }
2843
Calin Juravlebacfec32014-11-14 15:54:36 +00002844 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002845 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002846 break;
2847 }
2848
2849 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002850 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002851 }
2852}
2853
Calin Juravled0d48522014-11-04 16:40:20 +00002854void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00002855 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
2856 ? LocationSummary::kCallOnSlowPath
2857 : LocationSummary::kNoCall;
2858 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002859 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002860 if (instruction->HasUses()) {
2861 locations->SetOut(Location::SameAsFirstInput());
2862 }
2863}
2864
2865void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2866 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2867 codegen_->AddSlowPath(slow_path);
2868
2869 LocationSummary* locations = instruction->GetLocations();
2870 Location value = locations->InAt(0);
2871
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002872 switch (instruction->GetType()) {
Serguei Katkov8c0676c2015-08-03 13:55:33 +06002873 case Primitive::kPrimByte:
2874 case Primitive::kPrimChar:
2875 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002876 case Primitive::kPrimInt: {
2877 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01002878 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002879 } else {
2880 DCHECK(value.IsConstant()) << value;
2881 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2882 __ b(slow_path->GetEntryLabel());
2883 }
2884 }
2885 break;
2886 }
2887 case Primitive::kPrimLong: {
2888 if (value.IsRegisterPair()) {
2889 __ orrs(IP,
2890 value.AsRegisterPairLow<Register>(),
2891 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2892 __ b(slow_path->GetEntryLabel(), EQ);
2893 } else {
2894 DCHECK(value.IsConstant()) << value;
2895 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2896 __ b(slow_path->GetEntryLabel());
2897 }
2898 }
2899 break;
2900 default:
2901 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2902 }
2903 }
Calin Juravled0d48522014-11-04 16:40:20 +00002904}
2905
Calin Juravle9aec02f2014-11-18 23:06:35 +00002906void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2907 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2908
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002909 LocationSummary* locations =
2910 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002911
2912 switch (op->GetResultType()) {
2913 case Primitive::kPrimInt: {
2914 locations->SetInAt(0, Location::RequiresRegister());
2915 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002916 // Make the output overlap, as it will be used to hold the masked
2917 // second input.
2918 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002919 break;
2920 }
2921 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002922 locations->SetInAt(0, Location::RequiresRegister());
2923 locations->SetInAt(1, Location::RequiresRegister());
2924 locations->AddTemp(Location::RequiresRegister());
2925 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002926 break;
2927 }
2928 default:
2929 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2930 }
2931}
2932
2933void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2934 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2935
2936 LocationSummary* locations = op->GetLocations();
2937 Location out = locations->Out();
2938 Location first = locations->InAt(0);
2939 Location second = locations->InAt(1);
2940
2941 Primitive::Type type = op->GetResultType();
2942 switch (type) {
2943 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002944 Register out_reg = out.AsRegister<Register>();
2945 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002946 // Arm doesn't mask the shift count so we need to do it ourselves.
2947 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002948 Register second_reg = second.AsRegister<Register>();
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002949 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002950 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002951 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002952 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002953 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002954 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002955 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002956 }
2957 } else {
2958 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2959 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2960 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2961 __ Mov(out_reg, first_reg);
2962 } else if (op->IsShl()) {
2963 __ Lsl(out_reg, first_reg, shift_value);
2964 } else if (op->IsShr()) {
2965 __ Asr(out_reg, first_reg, shift_value);
2966 } else {
2967 __ Lsr(out_reg, first_reg, shift_value);
2968 }
2969 }
2970 break;
2971 }
2972 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002973 Register o_h = out.AsRegisterPairHigh<Register>();
2974 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002975
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002976 Register temp = locations->GetTemp(0).AsRegister<Register>();
2977
2978 Register high = first.AsRegisterPairHigh<Register>();
2979 Register low = first.AsRegisterPairLow<Register>();
2980
2981 Register second_reg = second.AsRegister<Register>();
2982
Calin Juravle9aec02f2014-11-18 23:06:35 +00002983 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002984 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002985 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002986 __ Lsl(o_h, high, o_l);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002987 // Shift the low part and `or` what overflew on the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002988 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002989 __ Lsr(temp, low, temp);
2990 __ orr(o_h, o_h, ShifterOperand(temp));
2991 // If the shift is > 32 bits, override the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002992 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002993 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01002994 __ Lsl(o_h, low, temp, PL);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002995 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002996 __ Lsl(o_l, low, o_l);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002997 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002998 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002999 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003000 __ Lsr(o_l, low, o_h);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003001 // Shift the high part and `or` what underflew on the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003002 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003003 __ Lsl(temp, high, temp);
3004 __ orr(o_l, o_l, ShifterOperand(temp));
3005 // If the shift is > 32 bits, override the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003006 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003007 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003008 __ Asr(o_l, high, temp, PL);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003009 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003010 __ Asr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003011 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003012 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003013 // same as Shr except we use `Lsr`s and not `Asr`s
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003014 __ Lsr(o_l, low, o_h);
3015 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003016 __ Lsl(temp, high, temp);
3017 __ orr(o_l, o_l, ShifterOperand(temp));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003018 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00003019 __ it(PL);
Vladimir Marko73cf0fb2015-07-30 15:07:22 +01003020 __ Lsr(o_l, high, temp, PL);
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01003021 __ Lsr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00003022 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00003023 break;
3024 }
3025 default:
3026 LOG(FATAL) << "Unexpected operation type " << type;
3027 }
3028}
3029
3030void LocationsBuilderARM::VisitShl(HShl* shl) {
3031 HandleShift(shl);
3032}
3033
3034void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
3035 HandleShift(shl);
3036}
3037
3038void LocationsBuilderARM::VisitShr(HShr* shr) {
3039 HandleShift(shr);
3040}
3041
3042void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
3043 HandleShift(shr);
3044}
3045
3046void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
3047 HandleShift(ushr);
3048}
3049
3050void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
3051 HandleShift(ushr);
3052}
3053
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003054void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003055 LocationSummary* locations =
3056 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01003057 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003058 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003059 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003060 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003061}
3062
3063void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
3064 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003065 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003066 // Note: if heap poisoning is enabled, the entry point takes cares
3067 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01003068 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003069 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003070 instruction->GetDexPc(),
3071 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01003072}
3073
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003074void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
3075 LocationSummary* locations =
3076 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3077 InvokeRuntimeCallingConvention calling_convention;
3078 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003079 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08003080 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003081 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003082}
3083
3084void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3085 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003086 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003087 // Note: if heap poisoning is enabled, the entry point takes cares
3088 // of poisoning the reference.
Calin Juravle175dc732015-08-25 15:42:32 +01003089 codegen_->InvokeRuntime(instruction->GetEntrypoint(),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003090 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003091 instruction->GetDexPc(),
3092 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003093}
3094
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003095void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003096 LocationSummary* locations =
3097 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003098 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3099 if (location.IsStackSlot()) {
3100 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3101 } else if (location.IsDoubleStackSlot()) {
3102 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003103 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003104 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003105}
3106
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003107void InstructionCodeGeneratorARM::VisitParameterValue(
3108 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003109 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003110}
3111
3112void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3113 LocationSummary* locations =
3114 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3115 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3116}
3117
3118void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3119 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003120}
3121
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003122void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003123 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003124 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003125 locations->SetInAt(0, Location::RequiresRegister());
3126 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003127}
3128
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003129void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3130 LocationSummary* locations = not_->GetLocations();
3131 Location out = locations->Out();
3132 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003133 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003134 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003135 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003136 break;
3137
3138 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003139 __ mvn(out.AsRegisterPairLow<Register>(),
3140 ShifterOperand(in.AsRegisterPairLow<Register>()));
3141 __ mvn(out.AsRegisterPairHigh<Register>(),
3142 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003143 break;
3144
3145 default:
3146 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3147 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003148}
3149
David Brazdil66d126e2015-04-03 16:02:44 +01003150void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3151 LocationSummary* locations =
3152 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3153 locations->SetInAt(0, Location::RequiresRegister());
3154 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3155}
3156
3157void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003158 LocationSummary* locations = bool_not->GetLocations();
3159 Location out = locations->Out();
3160 Location in = locations->InAt(0);
3161 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3162}
3163
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003164void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003165 LocationSummary* locations =
3166 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003167 switch (compare->InputAt(0)->GetType()) {
3168 case Primitive::kPrimLong: {
3169 locations->SetInAt(0, Location::RequiresRegister());
3170 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003171 // Output overlaps because it is written before doing the low comparison.
3172 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003173 break;
3174 }
3175 case Primitive::kPrimFloat:
3176 case Primitive::kPrimDouble: {
3177 locations->SetInAt(0, Location::RequiresFpuRegister());
3178 locations->SetInAt(1, Location::RequiresFpuRegister());
3179 locations->SetOut(Location::RequiresRegister());
3180 break;
3181 }
3182 default:
3183 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3184 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003185}
3186
3187void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003188 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003189 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003190 Location left = locations->InAt(0);
3191 Location right = locations->InAt(1);
3192
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003193 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003194 Primitive::Type type = compare->InputAt(0)->GetType();
3195 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003196 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003197 __ cmp(left.AsRegisterPairHigh<Register>(),
3198 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003199 __ b(&less, LT);
3200 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003201 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003202 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003203 __ cmp(left.AsRegisterPairLow<Register>(),
3204 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00003205 break;
3206 }
3207 case Primitive::kPrimFloat:
3208 case Primitive::kPrimDouble: {
3209 __ LoadImmediate(out, 0);
3210 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003211 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00003212 } else {
3213 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
3214 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
3215 }
3216 __ vmstat(); // transfer FP status register to ARM APSR.
3217 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003218 break;
3219 }
3220 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003221 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003222 }
Calin Juravleddb7df22014-11-25 20:56:51 +00003223 __ b(&done, EQ);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003224 __ b(&less, LO); // LO is for both: unsigned compare for longs and 'less than' for floats.
Calin Juravleddb7df22014-11-25 20:56:51 +00003225
3226 __ Bind(&greater);
3227 __ LoadImmediate(out, 1);
3228 __ b(&done);
3229
3230 __ Bind(&less);
3231 __ LoadImmediate(out, -1);
3232
3233 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003234}
3235
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003236void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003237 LocationSummary* locations =
3238 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003239 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
3240 locations->SetInAt(i, Location::Any());
3241 }
3242 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003243}
3244
3245void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003246 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003247 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003248}
3249
Calin Juravle52c48962014-12-16 17:02:57 +00003250void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3251 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07003252 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00003253 switch (kind) {
3254 case MemBarrierKind::kAnyStore:
3255 case MemBarrierKind::kLoadAny:
3256 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003257 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003258 break;
3259 }
3260 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003261 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003262 break;
3263 }
3264 default:
3265 LOG(FATAL) << "Unexpected memory barrier " << kind;
3266 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003267 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003268}
3269
3270void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3271 uint32_t offset,
3272 Register out_lo,
3273 Register out_hi) {
3274 if (offset != 0) {
3275 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003276 __ add(IP, addr, ShifterOperand(out_lo));
3277 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003278 }
3279 __ ldrexd(out_lo, out_hi, addr);
3280}
3281
3282void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3283 uint32_t offset,
3284 Register value_lo,
3285 Register value_hi,
3286 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003287 Register temp2,
3288 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003289 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003290 if (offset != 0) {
3291 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003292 __ add(IP, addr, ShifterOperand(temp1));
3293 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003294 }
3295 __ Bind(&fail);
3296 // We need a load followed by store. (The address used in a STREX instruction must
3297 // be the same as the address in the most recently executed LDREX instruction.)
3298 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003299 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003300 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003301 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003302}
3303
3304void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3305 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3306
Nicolas Geoffray39468442014-09-02 15:17:15 +01003307 LocationSummary* locations =
3308 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003309 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003310
Calin Juravle52c48962014-12-16 17:02:57 +00003311 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003312 if (Primitive::IsFloatingPointType(field_type)) {
3313 locations->SetInAt(1, Location::RequiresFpuRegister());
3314 } else {
3315 locations->SetInAt(1, Location::RequiresRegister());
3316 }
3317
Calin Juravle52c48962014-12-16 17:02:57 +00003318 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003319 bool generate_volatile = field_info.IsVolatile()
3320 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003321 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003322 bool needs_write_barrier =
3323 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003324 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003325 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003326 if (needs_write_barrier) {
3327 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003328 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003329 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003330 // Arm encoding have some additional constraints for ldrexd/strexd:
3331 // - registers need to be consecutive
3332 // - the first register should be even but not R14.
3333 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3334 // enable Arm encoding.
3335 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3336
3337 locations->AddTemp(Location::RequiresRegister());
3338 locations->AddTemp(Location::RequiresRegister());
3339 if (field_type == Primitive::kPrimDouble) {
3340 // For doubles we need two more registers to copy the value.
3341 locations->AddTemp(Location::RegisterLocation(R2));
3342 locations->AddTemp(Location::RegisterLocation(R3));
3343 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003344 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003345}
3346
Calin Juravle52c48962014-12-16 17:02:57 +00003347void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003348 const FieldInfo& field_info,
3349 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003350 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3351
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003352 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003353 Register base = locations->InAt(0).AsRegister<Register>();
3354 Location value = locations->InAt(1);
3355
3356 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003357 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003358 Primitive::Type field_type = field_info.GetFieldType();
3359 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003360 bool needs_write_barrier =
3361 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003362
3363 if (is_volatile) {
3364 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3365 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003366
3367 switch (field_type) {
3368 case Primitive::kPrimBoolean:
3369 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003370 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003371 break;
3372 }
3373
3374 case Primitive::kPrimShort:
3375 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003376 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003377 break;
3378 }
3379
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003380 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003381 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003382 if (kPoisonHeapReferences && needs_write_barrier) {
3383 // Note that in the case where `value` is a null reference,
3384 // we do not enter this block, as a null reference does not
3385 // need poisoning.
3386 DCHECK_EQ(field_type, Primitive::kPrimNot);
3387 Register temp = locations->GetTemp(0).AsRegister<Register>();
3388 __ Mov(temp, value.AsRegister<Register>());
3389 __ PoisonHeapReference(temp);
3390 __ StoreToOffset(kStoreWord, temp, base, offset);
3391 } else {
3392 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3393 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003394 break;
3395 }
3396
3397 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003398 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003399 GenerateWideAtomicStore(base, offset,
3400 value.AsRegisterPairLow<Register>(),
3401 value.AsRegisterPairHigh<Register>(),
3402 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003403 locations->GetTemp(1).AsRegister<Register>(),
3404 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003405 } else {
3406 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003407 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003408 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003409 break;
3410 }
3411
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003412 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003413 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003414 break;
3415 }
3416
3417 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003418 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003419 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003420 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3421 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3422
3423 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3424
3425 GenerateWideAtomicStore(base, offset,
3426 value_reg_lo,
3427 value_reg_hi,
3428 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003429 locations->GetTemp(3).AsRegister<Register>(),
3430 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003431 } else {
3432 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003433 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003434 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003435 break;
3436 }
3437
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003438 case Primitive::kPrimVoid:
3439 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003440 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003441 }
Calin Juravle52c48962014-12-16 17:02:57 +00003442
Calin Juravle77520bc2015-01-12 18:45:46 +00003443 // Longs and doubles are handled in the switch.
3444 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3445 codegen_->MaybeRecordImplicitNullCheck(instruction);
3446 }
3447
3448 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3449 Register temp = locations->GetTemp(0).AsRegister<Register>();
3450 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003451 codegen_->MarkGCCard(
3452 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003453 }
3454
Calin Juravle52c48962014-12-16 17:02:57 +00003455 if (is_volatile) {
3456 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3457 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003458}
3459
Calin Juravle52c48962014-12-16 17:02:57 +00003460void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3461 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003462 LocationSummary* locations =
3463 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003464 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003465
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003466 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003467 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003468 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003469 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003470
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003471 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3472 locations->SetOut(Location::RequiresFpuRegister());
3473 } else {
3474 locations->SetOut(Location::RequiresRegister(),
3475 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3476 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003477 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003478 // Arm encoding have some additional constraints for ldrexd/strexd:
3479 // - registers need to be consecutive
3480 // - the first register should be even but not R14.
3481 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3482 // enable Arm encoding.
3483 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3484 locations->AddTemp(Location::RequiresRegister());
3485 locations->AddTemp(Location::RequiresRegister());
3486 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003487}
3488
Calin Juravle52c48962014-12-16 17:02:57 +00003489void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3490 const FieldInfo& field_info) {
3491 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003492
Calin Juravle52c48962014-12-16 17:02:57 +00003493 LocationSummary* locations = instruction->GetLocations();
3494 Register base = locations->InAt(0).AsRegister<Register>();
3495 Location out = locations->Out();
3496 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003497 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003498 Primitive::Type field_type = field_info.GetFieldType();
3499 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3500
3501 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003502 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003503 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003504 break;
3505 }
3506
3507 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003508 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003509 break;
3510 }
3511
3512 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003513 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003514 break;
3515 }
3516
3517 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003518 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003519 break;
3520 }
3521
3522 case Primitive::kPrimInt:
3523 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003524 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003525 break;
3526 }
3527
3528 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003529 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003530 GenerateWideAtomicLoad(base, offset,
3531 out.AsRegisterPairLow<Register>(),
3532 out.AsRegisterPairHigh<Register>());
3533 } else {
3534 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3535 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003536 break;
3537 }
3538
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003539 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003540 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003541 break;
3542 }
3543
3544 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003545 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003546 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003547 Register lo = locations->GetTemp(0).AsRegister<Register>();
3548 Register hi = locations->GetTemp(1).AsRegister<Register>();
3549 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003550 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003551 __ vmovdrr(out_reg, lo, hi);
3552 } else {
3553 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003554 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003555 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003556 break;
3557 }
3558
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003559 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003560 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003561 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003562 }
Calin Juravle52c48962014-12-16 17:02:57 +00003563
Calin Juravle77520bc2015-01-12 18:45:46 +00003564 // Doubles are handled in the switch.
3565 if (field_type != Primitive::kPrimDouble) {
3566 codegen_->MaybeRecordImplicitNullCheck(instruction);
3567 }
3568
Calin Juravle52c48962014-12-16 17:02:57 +00003569 if (is_volatile) {
3570 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3571 }
Roland Levillain4d027112015-07-01 15:41:14 +01003572
3573 if (field_type == Primitive::kPrimNot) {
3574 __ MaybeUnpoisonHeapReference(out.AsRegister<Register>());
3575 }
Calin Juravle52c48962014-12-16 17:02:57 +00003576}
3577
3578void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3579 HandleFieldSet(instruction, instruction->GetFieldInfo());
3580}
3581
3582void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003583 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003584}
3585
3586void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3587 HandleFieldGet(instruction, instruction->GetFieldInfo());
3588}
3589
3590void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3591 HandleFieldGet(instruction, instruction->GetFieldInfo());
3592}
3593
3594void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3595 HandleFieldGet(instruction, instruction->GetFieldInfo());
3596}
3597
3598void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3599 HandleFieldGet(instruction, instruction->GetFieldInfo());
3600}
3601
3602void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3603 HandleFieldSet(instruction, instruction->GetFieldInfo());
3604}
3605
3606void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003607 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003608}
3609
Calin Juravle23a8e352015-09-08 19:56:31 +01003610void LocationsBuilderARM::VisitUnresolvedInstanceFieldGet(
3611 HUnresolvedInstanceFieldGet* instruction) {
3612 FieldAccessCallingConvetionARM calling_convention;
3613 codegen_->CreateUnresolvedFieldLocationSummary(
3614 instruction, instruction->GetFieldType(), calling_convention);
3615}
3616
3617void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldGet(
3618 HUnresolvedInstanceFieldGet* instruction) {
3619 codegen_->GenerateUnresolvedFieldAccess(instruction,
3620 instruction->GetFieldType(),
3621 instruction->GetFieldIndex(),
3622 instruction->GetDexPc());
3623}
3624
3625void LocationsBuilderARM::VisitUnresolvedInstanceFieldSet(
3626 HUnresolvedInstanceFieldSet* instruction) {
3627 FieldAccessCallingConvetionARM calling_convention;
3628 codegen_->CreateUnresolvedFieldLocationSummary(
3629 instruction, instruction->GetFieldType(), calling_convention);
3630}
3631
3632void InstructionCodeGeneratorARM::VisitUnresolvedInstanceFieldSet(
3633 HUnresolvedInstanceFieldSet* instruction) {
3634 codegen_->GenerateUnresolvedFieldAccess(instruction,
3635 instruction->GetFieldType(),
3636 instruction->GetFieldIndex(),
3637 instruction->GetDexPc());
3638}
3639
3640void LocationsBuilderARM::VisitUnresolvedStaticFieldGet(
3641 HUnresolvedStaticFieldGet* instruction) {
3642 FieldAccessCallingConvetionARM calling_convention;
3643 codegen_->CreateUnresolvedFieldLocationSummary(
3644 instruction, instruction->GetFieldType(), calling_convention);
3645}
3646
3647void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldGet(
3648 HUnresolvedStaticFieldGet* instruction) {
3649 codegen_->GenerateUnresolvedFieldAccess(instruction,
3650 instruction->GetFieldType(),
3651 instruction->GetFieldIndex(),
3652 instruction->GetDexPc());
3653}
3654
3655void LocationsBuilderARM::VisitUnresolvedStaticFieldSet(
3656 HUnresolvedStaticFieldSet* instruction) {
3657 FieldAccessCallingConvetionARM calling_convention;
3658 codegen_->CreateUnresolvedFieldLocationSummary(
3659 instruction, instruction->GetFieldType(), calling_convention);
3660}
3661
3662void InstructionCodeGeneratorARM::VisitUnresolvedStaticFieldSet(
3663 HUnresolvedStaticFieldSet* instruction) {
3664 codegen_->GenerateUnresolvedFieldAccess(instruction,
3665 instruction->GetFieldType(),
3666 instruction->GetFieldIndex(),
3667 instruction->GetDexPc());
3668}
3669
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003670void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003671 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
3672 ? LocationSummary::kCallOnSlowPath
3673 : LocationSummary::kNoCall;
3674 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Calin Juravle77520bc2015-01-12 18:45:46 +00003675 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003676 if (instruction->HasUses()) {
3677 locations->SetOut(Location::SameAsFirstInput());
3678 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003679}
3680
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003681void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003682 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3683 return;
3684 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003685 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003686
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003687 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3688 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3689}
3690
3691void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003692 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003693 codegen_->AddSlowPath(slow_path);
3694
3695 LocationSummary* locations = instruction->GetLocations();
3696 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003697
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003698 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003699}
3700
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003701void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00003702 if (codegen_->IsImplicitNullCheckAllowed(instruction)) {
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003703 GenerateImplicitNullCheck(instruction);
3704 } else {
3705 GenerateExplicitNullCheck(instruction);
3706 }
3707}
3708
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003709void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003710 LocationSummary* locations =
3711 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003712 locations->SetInAt(0, Location::RequiresRegister());
3713 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003714 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3715 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3716 } else {
3717 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3718 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003719}
3720
3721void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3722 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003723 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003724 Location index = locations->InAt(1);
Roland Levillain4d027112015-07-01 15:41:14 +01003725 Primitive::Type type = instruction->GetType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003726
Roland Levillain4d027112015-07-01 15:41:14 +01003727 switch (type) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003728 case Primitive::kPrimBoolean: {
3729 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003730 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003731 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003732 size_t offset =
3733 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003734 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3735 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003736 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003737 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3738 }
3739 break;
3740 }
3741
3742 case Primitive::kPrimByte: {
3743 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003744 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003745 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003746 size_t offset =
3747 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003748 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3749 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003750 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003751 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3752 }
3753 break;
3754 }
3755
3756 case Primitive::kPrimShort: {
3757 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003758 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003759 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003760 size_t offset =
3761 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003762 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3763 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003764 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003765 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3766 }
3767 break;
3768 }
3769
3770 case Primitive::kPrimChar: {
3771 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003772 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003773 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003774 size_t offset =
3775 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003776 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3777 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003778 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003779 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3780 }
3781 break;
3782 }
3783
3784 case Primitive::kPrimInt:
3785 case Primitive::kPrimNot: {
Roland Levillain33d69032015-06-18 18:20:59 +01003786 static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
3787 "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003788 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003789 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003790 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003791 size_t offset =
3792 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003793 __ LoadFromOffset(kLoadWord, out, obj, offset);
3794 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003795 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003796 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3797 }
3798 break;
3799 }
3800
3801 case Primitive::kPrimLong: {
3802 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003803 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003804 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003805 size_t offset =
3806 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003807 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003808 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003809 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003810 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003811 }
3812 break;
3813 }
3814
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003815 case Primitive::kPrimFloat: {
3816 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3817 Location out = locations->Out();
3818 DCHECK(out.IsFpuRegister());
3819 if (index.IsConstant()) {
3820 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3821 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3822 } else {
3823 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3824 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3825 }
3826 break;
3827 }
3828
3829 case Primitive::kPrimDouble: {
3830 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3831 Location out = locations->Out();
3832 DCHECK(out.IsFpuRegisterPair());
3833 if (index.IsConstant()) {
3834 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3835 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3836 } else {
3837 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3838 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3839 }
3840 break;
3841 }
3842
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003843 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01003844 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003845 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003846 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003847 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01003848
3849 if (type == Primitive::kPrimNot) {
3850 Register out = locations->Out().AsRegister<Register>();
3851 __ MaybeUnpoisonHeapReference(out);
3852 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003853}
3854
3855void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003856 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003857
3858 bool needs_write_barrier =
3859 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3860 bool needs_runtime_call = instruction->NeedsTypeCheck();
3861
Nicolas Geoffray39468442014-09-02 15:17:15 +01003862 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003863 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3864 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003865 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003866 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3867 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3868 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003869 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003870 locations->SetInAt(0, Location::RequiresRegister());
3871 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003872 if (Primitive::IsFloatingPointType(value_type)) {
3873 locations->SetInAt(2, Location::RequiresFpuRegister());
3874 } else {
3875 locations->SetInAt(2, Location::RequiresRegister());
3876 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003877
3878 if (needs_write_barrier) {
3879 // Temporary registers for the write barrier.
Roland Levillain4d027112015-07-01 15:41:14 +01003880 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003881 locations->AddTemp(Location::RequiresRegister());
3882 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003883 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003884}
3885
3886void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3887 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003888 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003889 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003890 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003891 bool needs_runtime_call = locations->WillCall();
3892 bool needs_write_barrier =
3893 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003894
3895 switch (value_type) {
3896 case Primitive::kPrimBoolean:
3897 case Primitive::kPrimByte: {
3898 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003899 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003900 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003901 size_t offset =
3902 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003903 __ StoreToOffset(kStoreByte, value, obj, offset);
3904 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003905 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003906 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3907 }
3908 break;
3909 }
3910
3911 case Primitive::kPrimShort:
3912 case Primitive::kPrimChar: {
3913 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003914 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003915 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003916 size_t offset =
3917 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003918 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3919 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003920 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003921 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3922 }
3923 break;
3924 }
3925
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003926 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003927 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003928 if (!needs_runtime_call) {
3929 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003930 Register value = locations->InAt(2).AsRegister<Register>();
Roland Levillain4d027112015-07-01 15:41:14 +01003931 Register source = value;
3932 if (kPoisonHeapReferences && needs_write_barrier) {
3933 // Note that in the case where `value` is a null reference,
3934 // we do not enter this block, as a null reference does not
3935 // need poisoning.
3936 DCHECK_EQ(value_type, Primitive::kPrimNot);
3937 Register temp = locations->GetTemp(0).AsRegister<Register>();
3938 __ Mov(temp, value);
3939 __ PoisonHeapReference(temp);
3940 source = temp;
3941 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003942 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003943 size_t offset =
3944 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillain4d027112015-07-01 15:41:14 +01003945 __ StoreToOffset(kStoreWord, source, obj, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003946 } else {
3947 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003948 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillain4d027112015-07-01 15:41:14 +01003949 __ StoreToOffset(kStoreWord, source, IP, data_offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003950 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003951 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003952 if (needs_write_barrier) {
3953 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003954 Register temp = locations->GetTemp(0).AsRegister<Register>();
3955 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003956 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003957 }
3958 } else {
3959 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain4d027112015-07-01 15:41:14 +01003960 // Note: if heap poisoning is enabled, pAputObject takes cares
3961 // of poisoning the reference.
Roland Levillain199f3362014-11-27 17:15:16 +00003962 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3963 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003964 instruction->GetDexPc(),
3965 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003966 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003967 break;
3968 }
3969
3970 case Primitive::kPrimLong: {
3971 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003972 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003973 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003974 size_t offset =
3975 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003976 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003977 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003978 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003979 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003980 }
3981 break;
3982 }
3983
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003984 case Primitive::kPrimFloat: {
3985 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3986 Location value = locations->InAt(2);
3987 DCHECK(value.IsFpuRegister());
3988 if (index.IsConstant()) {
3989 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3990 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3991 } else {
3992 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3993 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3994 }
3995 break;
3996 }
3997
3998 case Primitive::kPrimDouble: {
3999 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
4000 Location value = locations->InAt(2);
4001 DCHECK(value.IsFpuRegisterPair());
4002 if (index.IsConstant()) {
4003 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
4004 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
4005 } else {
4006 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
4007 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
4008 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004009
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004010 break;
4011 }
4012
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004013 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004014 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07004015 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004016 }
Calin Juravle77520bc2015-01-12 18:45:46 +00004017
4018 // Ints and objects are handled in the switch.
4019 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
4020 codegen_->MaybeRecordImplicitNullCheck(instruction);
4021 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004022}
4023
4024void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01004025 LocationSummary* locations =
4026 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01004027 locations->SetInAt(0, Location::RequiresRegister());
4028 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004029}
4030
4031void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
4032 LocationSummary* locations = instruction->GetLocations();
4033 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004034 Register obj = locations->InAt(0).AsRegister<Register>();
4035 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004036 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00004037 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004038}
4039
4040void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
David Brazdil77a48ae2015-09-15 12:34:04 +00004041 LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock()
4042 ? LocationSummary::kCallOnSlowPath
4043 : LocationSummary::kNoCall;
4044 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004045 locations->SetInAt(0, Location::RequiresRegister());
4046 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01004047 if (instruction->HasUses()) {
4048 locations->SetOut(Location::SameAsFirstInput());
4049 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004050}
4051
4052void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
4053 LocationSummary* locations = instruction->GetLocations();
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01004054 SlowPathCodeARM* slow_path =
4055 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004056 codegen_->AddSlowPath(slow_path);
4057
Roland Levillain271ab9c2014-11-27 15:23:57 +00004058 Register index = locations->InAt(0).AsRegister<Register>();
4059 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004060
4061 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01004062 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004063}
4064
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004065void CodeGeneratorARM::MarkGCCard(Register temp,
4066 Register card,
4067 Register object,
4068 Register value,
4069 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004070 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004071 if (can_be_null) {
4072 __ CompareAndBranchIfZero(value, &is_null);
4073 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004074 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
4075 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
4076 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01004077 if (can_be_null) {
4078 __ Bind(&is_null);
4079 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01004080}
4081
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004082void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
4083 temp->SetLocations(nullptr);
4084}
4085
4086void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
4087 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07004088 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01004089}
4090
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004091void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07004092 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004093 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004094}
4095
4096void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004097 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
4098}
4099
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004100void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
4101 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
4102}
4103
4104void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004105 HBasicBlock* block = instruction->GetBlock();
4106 if (block->GetLoopInformation() != nullptr) {
4107 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
4108 // The back edge will generate the suspend check.
4109 return;
4110 }
4111 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
4112 // The goto will generate the suspend check.
4113 return;
4114 }
4115 GenerateSuspendCheck(instruction, nullptr);
4116}
4117
4118void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
4119 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004120 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01004121 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
4122 if (slow_path == nullptr) {
4123 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
4124 instruction->SetSlowPath(slow_path);
4125 codegen_->AddSlowPath(slow_path);
4126 if (successor != nullptr) {
4127 DCHECK(successor->IsLoopHeader());
4128 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
4129 }
4130 } else {
4131 DCHECK_EQ(slow_path->GetSuccessor(), successor);
4132 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004133
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00004134 __ LoadFromOffset(
4135 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004136 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004137 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004138 __ Bind(slow_path->GetReturnLabel());
4139 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004140 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01004141 __ b(slow_path->GetEntryLabel());
4142 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00004143}
4144
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004145ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
4146 return codegen_->GetAssembler();
4147}
4148
4149void ParallelMoveResolverARM::EmitMove(size_t index) {
4150 MoveOperands* move = moves_.Get(index);
4151 Location source = move->GetSource();
4152 Location destination = move->GetDestination();
4153
4154 if (source.IsRegister()) {
4155 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004156 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004157 } else {
4158 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00004159 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004160 SP, destination.GetStackIndex());
4161 }
4162 } else if (source.IsStackSlot()) {
4163 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004164 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004165 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004166 } else if (destination.IsFpuRegister()) {
4167 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004168 } else {
4169 DCHECK(destination.IsStackSlot());
4170 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
4171 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4172 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004173 } else if (source.IsFpuRegister()) {
4174 if (destination.IsFpuRegister()) {
4175 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004176 } else {
4177 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004178 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
4179 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004180 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004181 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004182 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
4183 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004184 } else if (destination.IsRegisterPair()) {
4185 DCHECK(ExpectedPairLayout(destination));
4186 __ LoadFromOffset(
4187 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
4188 } else {
4189 DCHECK(destination.IsFpuRegisterPair()) << destination;
4190 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4191 SP,
4192 source.GetStackIndex());
4193 }
4194 } else if (source.IsRegisterPair()) {
4195 if (destination.IsRegisterPair()) {
4196 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
4197 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
4198 } else {
4199 DCHECK(destination.IsDoubleStackSlot()) << destination;
4200 DCHECK(ExpectedPairLayout(source));
4201 __ StoreToOffset(
4202 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
4203 }
4204 } else if (source.IsFpuRegisterPair()) {
4205 if (destination.IsFpuRegisterPair()) {
4206 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4207 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
4208 } else {
4209 DCHECK(destination.IsDoubleStackSlot()) << destination;
4210 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
4211 SP,
4212 destination.GetStackIndex());
4213 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004214 } else {
4215 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00004216 HConstant* constant = source.GetConstant();
4217 if (constant->IsIntConstant() || constant->IsNullConstant()) {
4218 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004219 if (destination.IsRegister()) {
4220 __ LoadImmediate(destination.AsRegister<Register>(), value);
4221 } else {
4222 DCHECK(destination.IsStackSlot());
4223 __ LoadImmediate(IP, value);
4224 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4225 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004226 } else if (constant->IsLongConstant()) {
4227 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004228 if (destination.IsRegisterPair()) {
4229 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
4230 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004231 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004232 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004233 __ LoadImmediate(IP, Low32Bits(value));
4234 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4235 __ LoadImmediate(IP, High32Bits(value));
4236 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4237 }
4238 } else if (constant->IsDoubleConstant()) {
4239 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004240 if (destination.IsFpuRegisterPair()) {
4241 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004242 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004243 DCHECK(destination.IsDoubleStackSlot()) << destination;
4244 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004245 __ LoadImmediate(IP, Low32Bits(int_value));
4246 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4247 __ LoadImmediate(IP, High32Bits(int_value));
4248 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4249 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004250 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004251 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004252 float value = constant->AsFloatConstant()->GetValue();
4253 if (destination.IsFpuRegister()) {
4254 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
4255 } else {
4256 DCHECK(destination.IsStackSlot());
4257 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
4258 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4259 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004260 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004261 }
4262}
4263
4264void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
4265 __ Mov(IP, reg);
4266 __ LoadFromOffset(kLoadWord, reg, SP, mem);
4267 __ StoreToOffset(kStoreWord, IP, SP, mem);
4268}
4269
4270void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
4271 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
4272 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
4273 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
4274 SP, mem1 + stack_offset);
4275 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
4276 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
4277 SP, mem2 + stack_offset);
4278 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
4279}
4280
4281void ParallelMoveResolverARM::EmitSwap(size_t index) {
4282 MoveOperands* move = moves_.Get(index);
4283 Location source = move->GetSource();
4284 Location destination = move->GetDestination();
4285
4286 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004287 DCHECK_NE(source.AsRegister<Register>(), IP);
4288 DCHECK_NE(destination.AsRegister<Register>(), IP);
4289 __ Mov(IP, source.AsRegister<Register>());
4290 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
4291 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004292 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004293 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004294 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004295 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004296 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
4297 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004298 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004299 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004300 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004301 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004302 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004303 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004304 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004305 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004306 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
4307 destination.AsRegisterPairHigh<Register>(),
4308 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004309 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004310 Register low_reg = source.IsRegisterPair()
4311 ? source.AsRegisterPairLow<Register>()
4312 : destination.AsRegisterPairLow<Register>();
4313 int mem = source.IsRegisterPair()
4314 ? destination.GetStackIndex()
4315 : source.GetStackIndex();
4316 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004317 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004318 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004319 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004320 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004321 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
4322 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004323 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004324 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004325 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004326 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
4327 DRegister reg = source.IsFpuRegisterPair()
4328 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
4329 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
4330 int mem = source.IsFpuRegisterPair()
4331 ? destination.GetStackIndex()
4332 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004333 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004334 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004335 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004336 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
4337 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
4338 : destination.AsFpuRegister<SRegister>();
4339 int mem = source.IsFpuRegister()
4340 ? destination.GetStackIndex()
4341 : source.GetStackIndex();
4342
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004343 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004344 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004345 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004346 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004347 Exchange(source.GetStackIndex(), destination.GetStackIndex());
4348 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004349 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004350 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004351 }
4352}
4353
4354void ParallelMoveResolverARM::SpillScratch(int reg) {
4355 __ Push(static_cast<Register>(reg));
4356}
4357
4358void ParallelMoveResolverARM::RestoreScratch(int reg) {
4359 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004360}
4361
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004362void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004363 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
4364 ? LocationSummary::kCallOnSlowPath
4365 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004366 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004367 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004368 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004369 locations->SetOut(Location::RequiresRegister());
4370}
4371
4372void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004373 LocationSummary* locations = cls->GetLocations();
4374 Register out = locations->Out().AsRegister<Register>();
4375 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004376 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004377 DCHECK(!cls->CanCallRuntime());
4378 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004379 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004380 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004381 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004382 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004383 __ LoadFromOffset(kLoadWord,
4384 out,
4385 current_method,
Vladimir Marko05792b92015-08-03 11:56:49 +01004386 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004387 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01004388 // TODO: We will need a read barrier here.
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004389
4390 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4391 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4392 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004393 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004394 if (cls->MustGenerateClinitCheck()) {
4395 GenerateClassInitializationCheck(slow_path, out);
4396 } else {
4397 __ Bind(slow_path->GetExitLabel());
4398 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004399 }
4400}
4401
4402void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
4403 LocationSummary* locations =
4404 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
4405 locations->SetInAt(0, Location::RequiresRegister());
4406 if (check->HasUses()) {
4407 locations->SetOut(Location::SameAsFirstInput());
4408 }
4409}
4410
4411void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004412 // We assume the class is not null.
4413 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4414 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004415 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004416 GenerateClassInitializationCheck(slow_path,
4417 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004418}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004419
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004420void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
4421 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004422 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4423 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4424 __ b(slow_path->GetEntryLabel(), LT);
4425 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4426 // properly. Therefore, we do a memory fence.
4427 __ dmb(ISH);
4428 __ Bind(slow_path->GetExitLabel());
4429}
4430
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004431void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4432 LocationSummary* locations =
4433 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004434 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004435 locations->SetOut(Location::RequiresRegister());
4436}
4437
4438void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4439 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4440 codegen_->AddSlowPath(slow_path);
4441
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004442 LocationSummary* locations = load->GetLocations();
4443 Register out = locations->Out().AsRegister<Register>();
4444 Register current_method = locations->InAt(0).AsRegister<Register>();
4445 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004446 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004447 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004448 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Vladimir Marko05792b92015-08-03 11:56:49 +01004449 // TODO: We will need a read barrier here.
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004450 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004451 __ Bind(slow_path->GetExitLabel());
4452}
4453
David Brazdilcb1c0552015-08-04 16:22:25 +01004454static int32_t GetExceptionTlsOffset() {
4455 return Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4456}
4457
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004458void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4459 LocationSummary* locations =
4460 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4461 locations->SetOut(Location::RequiresRegister());
4462}
4463
4464void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004465 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01004466 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4467}
4468
4469void LocationsBuilderARM::VisitClearException(HClearException* clear) {
4470 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4471}
4472
4473void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004474 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01004475 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004476}
4477
4478void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4479 LocationSummary* locations =
4480 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4481 InvokeRuntimeCallingConvention calling_convention;
4482 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4483}
4484
4485void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4486 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004487 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004488}
4489
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004490void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004491 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
4492 switch (instruction->GetTypeCheckKind()) {
4493 case TypeCheckKind::kExactCheck:
4494 case TypeCheckKind::kAbstractClassCheck:
4495 case TypeCheckKind::kClassHierarchyCheck:
4496 case TypeCheckKind::kArrayObjectCheck:
4497 call_kind = LocationSummary::kNoCall;
4498 break;
4499 case TypeCheckKind::kInterfaceCheck:
4500 call_kind = LocationSummary::kCall;
4501 break;
4502 case TypeCheckKind::kArrayCheck:
4503 call_kind = LocationSummary::kCallOnSlowPath;
4504 break;
4505 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004506 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004507 if (call_kind != LocationSummary::kCall) {
4508 locations->SetInAt(0, Location::RequiresRegister());
4509 locations->SetInAt(1, Location::RequiresRegister());
4510 // The out register is used as a temporary, so it overlaps with the inputs.
4511 // Note that TypeCheckSlowPathARM uses this register too.
4512 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
4513 } else {
4514 InvokeRuntimeCallingConvention calling_convention;
4515 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4516 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4517 locations->SetOut(Location::RegisterLocation(R0));
4518 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004519}
4520
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004521void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004522 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004523 Register obj = locations->InAt(0).AsRegister<Register>();
4524 Register cls = locations->InAt(1).AsRegister<Register>();
4525 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004526 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004527 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4528 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4529 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004530 Label done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004531 SlowPathCodeARM* slow_path = nullptr;
4532
4533 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004534 // avoid null check if we know obj is not null.
4535 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004536 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004537 }
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004538
4539 // In case of an interface check, we put the object class into the object register.
4540 // This is safe, as the register is caller-save, and the object must be in another
4541 // register if it survives the runtime call.
4542 Register target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck)
4543 ? obj
4544 : out;
4545 __ LoadFromOffset(kLoadWord, target, obj, class_offset);
4546 __ MaybeUnpoisonHeapReference(target);
4547
4548 switch (instruction->GetTypeCheckKind()) {
4549 case TypeCheckKind::kExactCheck: {
4550 __ cmp(out, ShifterOperand(cls));
4551 // Classes must be equal for the instanceof to succeed.
4552 __ b(&zero, NE);
4553 __ LoadImmediate(out, 1);
4554 __ b(&done);
4555 break;
4556 }
4557 case TypeCheckKind::kAbstractClassCheck: {
4558 // If the class is abstract, we eagerly fetch the super class of the
4559 // object to avoid doing a comparison we know will fail.
4560 Label loop;
4561 __ Bind(&loop);
4562 __ LoadFromOffset(kLoadWord, out, out, super_offset);
4563 __ MaybeUnpoisonHeapReference(out);
4564 // If `out` is null, we use it for the result, and jump to `done`.
4565 __ CompareAndBranchIfZero(out, &done);
4566 __ cmp(out, ShifterOperand(cls));
4567 __ b(&loop, NE);
4568 __ LoadImmediate(out, 1);
4569 if (zero.IsLinked()) {
4570 __ b(&done);
4571 }
4572 break;
4573 }
4574 case TypeCheckKind::kClassHierarchyCheck: {
4575 // Walk over the class hierarchy to find a match.
4576 Label loop, success;
4577 __ Bind(&loop);
4578 __ cmp(out, ShifterOperand(cls));
4579 __ b(&success, EQ);
4580 __ LoadFromOffset(kLoadWord, out, out, super_offset);
4581 __ MaybeUnpoisonHeapReference(out);
4582 __ CompareAndBranchIfNonZero(out, &loop);
4583 // If `out` is null, we use it for the result, and jump to `done`.
4584 __ b(&done);
4585 __ Bind(&success);
4586 __ LoadImmediate(out, 1);
4587 if (zero.IsLinked()) {
4588 __ b(&done);
4589 }
4590 break;
4591 }
4592 case TypeCheckKind::kArrayObjectCheck: {
4593 // Just need to check that the object's class is a non primitive array.
4594 __ LoadFromOffset(kLoadWord, out, out, component_offset);
4595 __ MaybeUnpoisonHeapReference(out);
4596 // If `out` is null, we use it for the result, and jump to `done`.
4597 __ CompareAndBranchIfZero(out, &done);
4598 __ LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset);
4599 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
4600 __ CompareAndBranchIfNonZero(out, &zero);
4601 __ LoadImmediate(out, 1);
4602 __ b(&done);
4603 break;
4604 }
4605 case TypeCheckKind::kArrayCheck: {
4606 __ cmp(out, ShifterOperand(cls));
4607 DCHECK(locations->OnlyCallsOnSlowPath());
4608 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4609 instruction, /* is_fatal */ false);
4610 codegen_->AddSlowPath(slow_path);
4611 __ b(slow_path->GetEntryLabel(), NE);
4612 __ LoadImmediate(out, 1);
4613 if (zero.IsLinked()) {
4614 __ b(&done);
4615 }
4616 break;
4617 }
4618
4619 case TypeCheckKind::kInterfaceCheck:
4620 default: {
4621 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial),
4622 instruction,
4623 instruction->GetDexPc(),
4624 nullptr);
4625 if (zero.IsLinked()) {
4626 __ b(&done);
4627 }
4628 break;
4629 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004630 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004631
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004632 if (zero.IsLinked()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004633 __ Bind(&zero);
4634 __ LoadImmediate(out, 0);
4635 }
4636
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004637 if (done.IsLinked()) {
4638 __ Bind(&done);
4639 }
4640
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004641 if (slow_path != nullptr) {
4642 __ Bind(slow_path->GetExitLabel());
4643 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004644}
4645
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004646void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004647 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
4648 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
4649
4650 switch (instruction->GetTypeCheckKind()) {
4651 case TypeCheckKind::kExactCheck:
4652 case TypeCheckKind::kAbstractClassCheck:
4653 case TypeCheckKind::kClassHierarchyCheck:
4654 case TypeCheckKind::kArrayObjectCheck:
4655 call_kind = throws_into_catch
4656 ? LocationSummary::kCallOnSlowPath
4657 : LocationSummary::kNoCall;
4658 break;
4659 case TypeCheckKind::kInterfaceCheck:
4660 call_kind = LocationSummary::kCall;
4661 break;
4662 case TypeCheckKind::kArrayCheck:
4663 call_kind = LocationSummary::kCallOnSlowPath;
4664 break;
4665 }
4666
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004667 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004668 instruction, call_kind);
4669 if (call_kind != LocationSummary::kCall) {
4670 locations->SetInAt(0, Location::RequiresRegister());
4671 locations->SetInAt(1, Location::RequiresRegister());
4672 // Note that TypeCheckSlowPathARM uses this register too.
4673 locations->AddTemp(Location::RequiresRegister());
4674 } else {
4675 InvokeRuntimeCallingConvention calling_convention;
4676 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4677 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
4678 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004679}
4680
4681void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4682 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004683 Register obj = locations->InAt(0).AsRegister<Register>();
4684 Register cls = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004685 Register temp = locations->WillCall()
4686 ? Register(kNoRegister)
4687 : locations->GetTemp(0).AsRegister<Register>();
4688
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004689 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004690 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
4691 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
4692 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
4693 SlowPathCodeARM* slow_path = nullptr;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004694
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004695 if (!locations->WillCall()) {
4696 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4697 instruction, !locations->CanCall());
4698 codegen_->AddSlowPath(slow_path);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004699 }
Nicolas Geoffray64acf302015-09-14 22:20:29 +01004700
4701 Label done;
4702 // Avoid null check if we know obj is not null.
4703 if (instruction->MustDoNullCheck()) {
4704 __ CompareAndBranchIfZero(obj, &done);
4705 }
4706
4707 if (locations->WillCall()) {
4708 __ LoadFromOffset(kLoadWord, obj, obj, class_offset);
4709 __ MaybeUnpoisonHeapReference(obj);
4710 } else {
4711 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4712 __ MaybeUnpoisonHeapReference(temp);
4713 }
4714
4715 switch (instruction->GetTypeCheckKind()) {
4716 case TypeCheckKind::kExactCheck:
4717 case TypeCheckKind::kArrayCheck: {
4718 __ cmp(temp, ShifterOperand(cls));
4719 // Jump to slow path for throwing the exception or doing a
4720 // more involved array check.
4721 __ b(slow_path->GetEntryLabel(), NE);
4722 break;
4723 }
4724 case TypeCheckKind::kAbstractClassCheck: {
4725 // If the class is abstract, we eagerly fetch the super class of the
4726 // object to avoid doing a comparison we know will fail.
4727 Label loop;
4728 __ Bind(&loop);
4729 __ LoadFromOffset(kLoadWord, temp, temp, super_offset);
4730 __ MaybeUnpoisonHeapReference(temp);
4731 // Jump to the slow path to throw the exception.
4732 __ CompareAndBranchIfZero(temp, slow_path->GetEntryLabel());
4733 __ cmp(temp, ShifterOperand(cls));
4734 __ b(&loop, NE);
4735 break;
4736 }
4737 case TypeCheckKind::kClassHierarchyCheck: {
4738 // Walk over the class hierarchy to find a match.
4739 Label loop, success;
4740 __ Bind(&loop);
4741 __ cmp(temp, ShifterOperand(cls));
4742 __ b(&success, EQ);
4743 __ LoadFromOffset(kLoadWord, temp, temp, super_offset);
4744 __ MaybeUnpoisonHeapReference(temp);
4745 __ CompareAndBranchIfNonZero(temp, &loop);
4746 // Jump to the slow path to throw the exception.
4747 __ b(slow_path->GetEntryLabel());
4748 __ Bind(&success);
4749 break;
4750 }
4751 case TypeCheckKind::kArrayObjectCheck: {
4752 // Just need to check that the object's class is a non primitive array.
4753 __ LoadFromOffset(kLoadWord, temp, temp, component_offset);
4754 __ MaybeUnpoisonHeapReference(temp);
4755 __ CompareAndBranchIfZero(temp, slow_path->GetEntryLabel());
4756 __ LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset);
4757 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
4758 __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel());
4759 break;
4760 }
4761 case TypeCheckKind::kInterfaceCheck:
4762 default:
4763 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast),
4764 instruction,
4765 instruction->GetDexPc(),
4766 nullptr);
4767 break;
4768 }
4769 __ Bind(&done);
4770
4771 if (slow_path != nullptr) {
4772 __ Bind(slow_path->GetExitLabel());
4773 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004774}
4775
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004776void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4777 LocationSummary* locations =
4778 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4779 InvokeRuntimeCallingConvention calling_convention;
4780 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4781}
4782
4783void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4784 codegen_->InvokeRuntime(instruction->IsEnter()
4785 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4786 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004787 instruction->GetDexPc(),
4788 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004789}
4790
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004791void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4792void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4793void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4794
4795void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4796 LocationSummary* locations =
4797 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4798 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4799 || instruction->GetResultType() == Primitive::kPrimLong);
4800 locations->SetInAt(0, Location::RequiresRegister());
4801 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004802 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004803}
4804
4805void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4806 HandleBitwiseOperation(instruction);
4807}
4808
4809void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4810 HandleBitwiseOperation(instruction);
4811}
4812
4813void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4814 HandleBitwiseOperation(instruction);
4815}
4816
4817void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4818 LocationSummary* locations = instruction->GetLocations();
4819
4820 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004821 Register first = locations->InAt(0).AsRegister<Register>();
4822 Register second = locations->InAt(1).AsRegister<Register>();
4823 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004824 if (instruction->IsAnd()) {
4825 __ and_(out, first, ShifterOperand(second));
4826 } else if (instruction->IsOr()) {
4827 __ orr(out, first, ShifterOperand(second));
4828 } else {
4829 DCHECK(instruction->IsXor());
4830 __ eor(out, first, ShifterOperand(second));
4831 }
4832 } else {
4833 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4834 Location first = locations->InAt(0);
4835 Location second = locations->InAt(1);
4836 Location out = locations->Out();
4837 if (instruction->IsAnd()) {
4838 __ and_(out.AsRegisterPairLow<Register>(),
4839 first.AsRegisterPairLow<Register>(),
4840 ShifterOperand(second.AsRegisterPairLow<Register>()));
4841 __ and_(out.AsRegisterPairHigh<Register>(),
4842 first.AsRegisterPairHigh<Register>(),
4843 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4844 } else if (instruction->IsOr()) {
4845 __ orr(out.AsRegisterPairLow<Register>(),
4846 first.AsRegisterPairLow<Register>(),
4847 ShifterOperand(second.AsRegisterPairLow<Register>()));
4848 __ orr(out.AsRegisterPairHigh<Register>(),
4849 first.AsRegisterPairHigh<Register>(),
4850 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4851 } else {
4852 DCHECK(instruction->IsXor());
4853 __ eor(out.AsRegisterPairLow<Register>(),
4854 first.AsRegisterPairLow<Register>(),
4855 ShifterOperand(second.AsRegisterPairLow<Register>()));
4856 __ eor(out.AsRegisterPairHigh<Register>(),
4857 first.AsRegisterPairHigh<Register>(),
4858 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4859 }
4860 }
4861}
4862
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004863void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00004864 // For better instruction scheduling we load the direct code pointer before the method pointer.
4865 bool direct_code_loaded = false;
4866 switch (invoke->GetCodePtrLocation()) {
4867 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
4868 if (IsSameDexFile(*invoke->GetTargetMethod().dex_file, GetGraph()->GetDexFile())) {
4869 break;
4870 }
4871 // Calls across dex files are more likely to exceed the available BL range,
4872 // so use absolute patch by falling through to kDirectCodeFixup.
4873 FALLTHROUGH_INTENDED;
4874 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4875 // LR = code address from literal pool with link-time patch.
4876 __ LoadLiteral(LR, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
4877 direct_code_loaded = true;
4878 break;
4879 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4880 // LR = invoke->GetDirectCodePtr();
4881 __ LoadImmediate(LR, invoke->GetDirectCodePtr());
4882 direct_code_loaded = true;
4883 break;
4884 default:
4885 break;
4886 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004887
Vladimir Marko58155012015-08-19 12:49:41 +00004888 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
4889 switch (invoke->GetMethodLoadKind()) {
4890 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit:
4891 // temp = thread->string_init_entrypoint
4892 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), TR, invoke->GetStringInitOffset());
4893 break;
4894 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
4895 callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4896 break;
4897 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
4898 __ LoadImmediate(temp.AsRegister<Register>(), invoke->GetMethodAddress());
4899 break;
4900 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
4901 __ LoadLiteral(temp.AsRegister<Register>(),
4902 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
4903 break;
4904 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
4905 // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod.
4906 FALLTHROUGH_INTENDED;
4907 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
4908 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4909 Register method_reg;
4910 Register reg = temp.AsRegister<Register>();
4911 if (current_method.IsRegister()) {
4912 method_reg = current_method.AsRegister<Register>();
4913 } else {
4914 DCHECK(invoke->GetLocations()->Intrinsified());
4915 DCHECK(!current_method.IsValid());
4916 method_reg = reg;
4917 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4918 }
4919 // temp = current_method->dex_cache_resolved_methods_;
4920 __ LoadFromOffset(
Vladimir Marko05792b92015-08-03 11:56:49 +01004921 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset(
4922 kArmPointerSize).Int32Value());
Vladimir Marko58155012015-08-19 12:49:41 +00004923 // temp = temp[index_in_cache]
4924 uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index;
4925 __ LoadFromOffset(kLoadWord, reg, reg, CodeGenerator::GetCachePointerOffset(index_in_cache));
4926 break;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004927 }
Vladimir Marko58155012015-08-19 12:49:41 +00004928 }
4929
4930 switch (invoke->GetCodePtrLocation()) {
4931 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
4932 __ bl(GetFrameEntryLabel());
4933 break;
4934 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
4935 if (!direct_code_loaded) {
4936 relative_call_patches_.emplace_back(invoke->GetTargetMethod());
4937 __ Bind(&relative_call_patches_.back().label);
4938 Label label;
4939 __ bl(&label); // Arbitrarily branch to the instruction after BL, override at link time.
4940 __ Bind(&label);
4941 break;
4942 }
4943 // If we loaded the direct code above, fall through.
4944 FALLTHROUGH_INTENDED;
4945 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4946 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4947 // LR prepared above for better instruction scheduling.
4948 DCHECK(direct_code_loaded);
4949 // LR()
4950 __ blx(LR);
4951 break;
4952 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
4953 // LR = callee_method->entry_point_from_quick_compiled_code_
4954 __ LoadFromOffset(
4955 kLoadWord, LR, callee_method.AsRegister<Register>(),
4956 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmWordSize).Int32Value());
4957 // LR()
4958 __ blx(LR);
4959 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004960 }
4961
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004962 DCHECK(!IsLeafMethod());
4963}
4964
Andreas Gampebfb5ba92015-09-01 15:45:02 +00004965void CodeGeneratorARM::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
4966 Register temp = temp_location.AsRegister<Register>();
4967 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
4968 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
4969 LocationSummary* locations = invoke->GetLocations();
4970 Location receiver = locations->InAt(0);
4971 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4972 // temp = object->GetClass();
4973 DCHECK(receiver.IsRegister());
4974 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
4975 MaybeRecordImplicitNullCheck(invoke);
4976 __ MaybeUnpoisonHeapReference(temp);
4977 // temp = temp->GetMethodAt(method_offset);
4978 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4979 kArmWordSize).Int32Value();
4980 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
4981 // LR = temp->GetEntryPoint();
4982 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
4983 // LR();
4984 __ blx(LR);
4985}
4986
Vladimir Marko58155012015-08-19 12:49:41 +00004987void CodeGeneratorARM::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
4988 DCHECK(linker_patches->empty());
4989 size_t size = method_patches_.size() + call_patches_.size() + relative_call_patches_.size();
4990 linker_patches->reserve(size);
4991 for (const auto& entry : method_patches_) {
4992 const MethodReference& target_method = entry.first;
4993 Literal* literal = entry.second;
4994 DCHECK(literal->GetLabel()->IsBound());
4995 uint32_t literal_offset = literal->GetLabel()->Position();
4996 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
4997 target_method.dex_file,
4998 target_method.dex_method_index));
4999 }
5000 for (const auto& entry : call_patches_) {
5001 const MethodReference& target_method = entry.first;
5002 Literal* literal = entry.second;
5003 DCHECK(literal->GetLabel()->IsBound());
5004 uint32_t literal_offset = literal->GetLabel()->Position();
5005 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
5006 target_method.dex_file,
5007 target_method.dex_method_index));
5008 }
5009 for (const MethodPatchInfo<Label>& info : relative_call_patches_) {
5010 uint32_t literal_offset = info.label.Position();
5011 linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset,
5012 info.target_method.dex_file,
5013 info.target_method.dex_method_index));
5014 }
5015}
5016
5017Literal* CodeGeneratorARM::DeduplicateMethodLiteral(MethodReference target_method,
5018 MethodToLiteralMap* map) {
5019 // Look up the literal for target_method.
5020 auto lb = map->lower_bound(target_method);
5021 if (lb != map->end() && !map->key_comp()(target_method, lb->first)) {
5022 return lb->second;
5023 }
5024 // We don't have a literal for this method yet, insert a new one.
5025 Literal* literal = __ NewLiteral<uint32_t>(0u);
5026 map->PutBefore(lb, target_method, literal);
5027 return literal;
5028}
5029
5030Literal* CodeGeneratorARM::DeduplicateMethodAddressLiteral(MethodReference target_method) {
5031 return DeduplicateMethodLiteral(target_method, &method_patches_);
5032}
5033
5034Literal* CodeGeneratorARM::DeduplicateMethodCodeLiteral(MethodReference target_method) {
5035 return DeduplicateMethodLiteral(target_method, &call_patches_);
5036}
5037
Calin Juravleb1498f62015-02-16 13:13:29 +00005038void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
5039 // Nothing to do, this should be removed during prepare for register allocator.
5040 UNUSED(instruction);
5041 LOG(FATAL) << "Unreachable";
5042}
5043
5044void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
5045 // Nothing to do, this should be removed during prepare for register allocator.
5046 UNUSED(instruction);
5047 LOG(FATAL) << "Unreachable";
5048}
5049
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01005050void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) {
5051 DCHECK(codegen_->IsBaseline());
5052 LocationSummary* locations =
5053 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5054 locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
5055}
5056
5057void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
5058 DCHECK(codegen_->IsBaseline());
5059 // Will be generated at use site.
5060}
5061
Roland Levillain4d027112015-07-01 15:41:14 +01005062#undef __
5063#undef QUICK_ENTRY_POINT
5064
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00005065} // namespace arm
5066} // namespace art