blob: 6c0292c551bf232dd25bb5913f83045e04e9d7bb [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"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070022#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010023#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080024#include "intrinsics.h"
25#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070026#include "mirror/array-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070027#include "mirror/class-inl.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070028#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010029#include "utils/arm/assembler_arm.h"
30#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000031#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010032#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000033
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000034namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010035
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000036namespace arm {
37
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000038static bool ExpectedPairLayout(Location location) {
39 // We expected this for both core and fpu register pairs.
40 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
41}
42
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010043static constexpr int kCurrentMethodStackOffset = 0;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +010044static constexpr Register kMethodRegisterArgument = R0;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010045
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000046// We unconditionally allocate R5 to ensure we can do long operations
47// with baseline.
48static constexpr Register kCoreSavedRegisterForBaseline = R5;
49static constexpr Register kCoreCalleeSaves[] =
50 { R5, R6, R7, R8, R10, R11, PC };
51static constexpr SRegister kFpuCalleeSaves[] =
52 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010053
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000054// D31 cannot be split into two S registers, and the register allocator only works on
55// S registers. Therefore there is no need to block it.
56static constexpr DRegister DTMP = D31;
57
Roland Levillain62a46b22015-06-01 18:24:13 +010058#define __ down_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010059#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010060
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010061class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010063 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064
Alexandre Rames67555f72014-11-18 10:55:16 +000065 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010066 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010067 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010068 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000069 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010070 }
71
Alexandre Rames8158f282015-08-07 10:26:17 +010072 bool IsFatal() const OVERRIDE { return true; }
73
Alexandre Rames9931f312015-06-19 14:47:01 +010074 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM"; }
75
Nicolas Geoffraye5038322014-07-04 09:41:32 +010076 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010077 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010078 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
79};
80
Calin Juravled0d48522014-11-04 16:40:20 +000081class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
82 public:
83 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
84
Alexandre Rames67555f72014-11-18 10:55:16 +000085 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000086 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
87 __ Bind(GetEntryLabel());
88 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000089 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +000090 }
91
Alexandre Rames8158f282015-08-07 10:26:17 +010092 bool IsFatal() const OVERRIDE { return true; }
93
Alexandre Rames9931f312015-06-19 14:47:01 +010094 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM"; }
95
Calin Juravled0d48522014-11-04 16:40:20 +000096 private:
97 HDivZeroCheck* const instruction_;
98 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
99};
100
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100101class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000102 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000103 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100104 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000105
Alexandre Rames67555f72014-11-18 10:55:16 +0000106 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100107 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000108 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000109 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100110 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000111 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000112 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100113 if (successor_ == nullptr) {
114 __ b(GetReturnLabel());
115 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100116 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100117 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000118 }
119
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100120 Label* GetReturnLabel() {
121 DCHECK(successor_ == nullptr);
122 return &return_label_;
123 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000124
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100125 HBasicBlock* GetSuccessor() const {
126 return successor_;
127 }
128
Alexandre Rames9931f312015-06-19 14:47:01 +0100129 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM"; }
130
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000131 private:
132 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100133 // If not null, the block to branch to after the suspend check.
134 HBasicBlock* const successor_;
135
136 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000137 Label return_label_;
138
139 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
140};
141
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100142class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100143 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100144 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
145 Location index_location,
146 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100147 : instruction_(instruction),
148 index_location_(index_location),
149 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100150
Alexandre Rames67555f72014-11-18 10:55:16 +0000151 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100152 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100153 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000154 // We're moving two locations to locations that could overlap, so we need a parallel
155 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100156 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000157 codegen->EmitParallelMoves(
158 index_location_,
159 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100160 Primitive::kPrimInt,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000161 length_location_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100162 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
163 Primitive::kPrimInt);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100164 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000165 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100166 }
167
Alexandre Rames8158f282015-08-07 10:26:17 +0100168 bool IsFatal() const OVERRIDE { return true; }
169
Alexandre Rames9931f312015-06-19 14:47:01 +0100170 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM"; }
171
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100172 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100173 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100174 const Location index_location_;
175 const Location length_location_;
176
177 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
178};
179
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000180class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100181 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000182 LoadClassSlowPathARM(HLoadClass* cls,
183 HInstruction* at,
184 uint32_t dex_pc,
185 bool do_clinit)
186 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
187 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
188 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100189
Alexandre Rames67555f72014-11-18 10:55:16 +0000190 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000191 LocationSummary* locations = at_->GetLocations();
192
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100193 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
194 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000195 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100196
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100197 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000198 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000199 int32_t entry_point_offset = do_clinit_
200 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
201 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000202 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000203
204 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000205 Location out = locations->Out();
206 if (out.IsValid()) {
207 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000208 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
209 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000210 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100211 __ b(GetExitLabel());
212 }
213
Alexandre Rames9931f312015-06-19 14:47:01 +0100214 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM"; }
215
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100216 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000217 // The class this slow path will load.
218 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100219
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000220 // The instruction where this slow path is happening.
221 // (Might be the load class or an initialization check).
222 HInstruction* const at_;
223
224 // The dex PC of `at_`.
225 const uint32_t dex_pc_;
226
227 // Whether to initialize the class.
228 const bool do_clinit_;
229
230 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100231};
232
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000233class LoadStringSlowPathARM : public SlowPathCodeARM {
234 public:
235 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
236
Alexandre Rames67555f72014-11-18 10:55:16 +0000237 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000238 LocationSummary* locations = instruction_->GetLocations();
239 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
240
241 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
242 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000243 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000244
245 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800246 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000247 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000248 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000249 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
250
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000251 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000252 __ b(GetExitLabel());
253 }
254
Alexandre Rames9931f312015-06-19 14:47:01 +0100255 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM"; }
256
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000257 private:
258 HLoadString* const instruction_;
259
260 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
261};
262
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000263class TypeCheckSlowPathARM : public SlowPathCodeARM {
264 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000265 TypeCheckSlowPathARM(HInstruction* instruction,
266 Location class_to_check,
267 Location object_class,
268 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000269 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000270 class_to_check_(class_to_check),
271 object_class_(object_class),
272 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000273
Alexandre Rames67555f72014-11-18 10:55:16 +0000274 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000275 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000276 DCHECK(instruction_->IsCheckCast()
277 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000278
279 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
280 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000281 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000282
283 // We're moving two locations to locations that could overlap, so we need a parallel
284 // move resolver.
285 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000286 codegen->EmitParallelMoves(
287 class_to_check_,
288 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100289 Primitive::kPrimNot,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000290 object_class_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100291 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
292 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000293
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000294 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000295 arm_codegen->InvokeRuntime(
296 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000297 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
298 } else {
299 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000300 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000301 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000302
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000303 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000304 __ b(GetExitLabel());
305 }
306
Alexandre Rames9931f312015-06-19 14:47:01 +0100307 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM"; }
308
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000309 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000310 HInstruction* const instruction_;
311 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000312 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000313 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000314
315 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
316};
317
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700318class DeoptimizationSlowPathARM : public SlowPathCodeARM {
319 public:
320 explicit DeoptimizationSlowPathARM(HInstruction* instruction)
321 : instruction_(instruction) {}
322
323 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
324 __ Bind(GetEntryLabel());
325 SaveLiveRegisters(codegen, instruction_->GetLocations());
326 DCHECK(instruction_->IsDeoptimize());
327 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
328 uint32_t dex_pc = deoptimize->GetDexPc();
329 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
330 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
331 }
332
Alexandre Rames9931f312015-06-19 14:47:01 +0100333 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM"; }
334
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700335 private:
336 HInstruction* const instruction_;
337 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
338};
339
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000340#undef __
Roland Levillain62a46b22015-06-01 18:24:13 +0100341#define __ down_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700342
Roland Levillain4fa13f62015-07-06 18:11:54 +0100343inline Condition ARMSignedOrFPCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700344 switch (cond) {
345 case kCondEQ: return EQ;
346 case kCondNE: return NE;
347 case kCondLT: return LT;
348 case kCondLE: return LE;
349 case kCondGT: return GT;
350 case kCondGE: return GE;
Dave Allison20dfc792014-06-16 20:44:29 -0700351 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100352 LOG(FATAL) << "Unreachable";
353 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700354}
355
Roland Levillain4fa13f62015-07-06 18:11:54 +0100356inline Condition ARMUnsignedCondition(IfCondition cond) {
Dave Allison20dfc792014-06-16 20:44:29 -0700357 switch (cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +0100358 case kCondEQ: return EQ;
359 case kCondNE: return NE;
360 case kCondLT: return LO;
361 case kCondLE: return LS;
362 case kCondGT: return HI;
363 case kCondGE: return HS;
Dave Allison20dfc792014-06-16 20:44:29 -0700364 }
Roland Levillain4fa13f62015-07-06 18:11:54 +0100365 LOG(FATAL) << "Unreachable";
366 UNREACHABLE();
Dave Allison20dfc792014-06-16 20:44:29 -0700367}
368
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100369void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100370 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100371}
372
373void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100374 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100375}
376
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100377size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
378 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
379 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100380}
381
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100382size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
383 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
384 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100385}
386
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000387size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
388 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
389 return kArmWordSize;
390}
391
392size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
393 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
394 return kArmWordSize;
395}
396
Calin Juravle34166012014-12-19 17:22:29 +0000397CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000398 const ArmInstructionSetFeatures& isa_features,
399 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000400 : CodeGenerator(graph,
401 kNumberOfCoreRegisters,
402 kNumberOfSRegisters,
403 kNumberOfRegisterPairs,
404 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
405 arraysize(kCoreCalleeSaves)),
406 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
407 arraysize(kFpuCalleeSaves)),
408 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100409 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100410 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100411 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100412 move_resolver_(graph->GetArena(), this),
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000413 assembler_(),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000414 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000415 // Save the PC register to mimic Quick.
416 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100417}
418
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000419void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
420 // Ensure that we fix up branches and literal loads and emit the literal pool.
421 __ FinalizeCode();
422
423 // Adjust native pc offsets in stack maps.
424 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
425 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
426 uint32_t new_position = __ GetAdjustedPosition(old_position);
427 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
428 }
429 // Adjust native pc offsets of block labels.
430 for (size_t block_idx = 0u, end = block_order_->Size(); block_idx != end; ++block_idx) {
431 HBasicBlock* block = block_order_->Get(block_idx);
432 // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid
433 // FirstNonEmptyBlock() which could lead to adjusting a label more than once.
434 DCHECK_LT(static_cast<size_t>(block->GetBlockId()), block_labels_.Size());
435 Label* block_label = &block_labels_.GetRawStorage()[block->GetBlockId()];
David Brazdilfc6a86a2015-06-26 10:33:45 +0000436 DCHECK_EQ(block_label->IsBound(), !block->IsSingleJump());
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000437 if (block_label->IsBound()) {
438 __ AdjustLabelPosition(block_label);
439 }
440 }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100441 // Adjust pc offsets for the disassembly information.
442 if (disasm_info_ != nullptr) {
443 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
444 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
445 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
446 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
447 it.second.start = __ GetAdjustedPosition(it.second.start);
448 it.second.end = __ GetAdjustedPosition(it.second.end);
449 }
450 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
451 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
452 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
453 }
454 }
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000455
456 CodeGenerator::Finalize(allocator);
457}
458
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100459Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100460 switch (type) {
461 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100462 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100463 ArmManagedRegister pair =
464 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100465 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
466 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
467
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100468 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
469 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100470 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100471 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100472 }
473
474 case Primitive::kPrimByte:
475 case Primitive::kPrimBoolean:
476 case Primitive::kPrimChar:
477 case Primitive::kPrimShort:
478 case Primitive::kPrimInt:
479 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100480 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100481 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100482 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
483 ArmManagedRegister current =
484 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
485 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100486 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100487 }
488 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100489 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100490 }
491
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000492 case Primitive::kPrimFloat: {
493 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100494 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100495 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100496
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000497 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000498 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
499 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000500 return Location::FpuRegisterPairLocation(reg, reg + 1);
501 }
502
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100503 case Primitive::kPrimVoid:
504 LOG(FATAL) << "Unreachable type " << type;
505 }
506
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100507 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100508}
509
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000510void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100511 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100512 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100513
514 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100515 blocked_core_registers_[SP] = true;
516 blocked_core_registers_[LR] = true;
517 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100518
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100519 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100520 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100521
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100522 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100523 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100524
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000525 if (is_baseline) {
526 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
527 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
528 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000529
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000530 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
531
532 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
533 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
534 }
535 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100536
537 UpdateBlockedPairRegisters();
538}
539
540void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
541 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
542 ArmManagedRegister current =
543 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
544 if (blocked_core_registers_[current.AsRegisterPairLow()]
545 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
546 blocked_register_pairs_[i] = true;
547 }
548 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100549}
550
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100551InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
552 : HGraphVisitor(graph),
553 assembler_(codegen->GetAssembler()),
554 codegen_(codegen) {}
555
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000556void CodeGeneratorARM::ComputeSpillMask() {
557 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000558 // Save one extra register for baseline. Note that on thumb2, there is no easy
559 // instruction to restore just the PC, so this actually helps both baseline
560 // and non-baseline to save and restore at least two registers at entry and exit.
561 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000562 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
563 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
564 // We use vpush and vpop for saving and restoring floating point registers, which take
565 // a SRegister and the number of registers to save/restore after that SRegister. We
566 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
567 // but in the range.
568 if (fpu_spill_mask_ != 0) {
569 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
570 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
571 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
572 fpu_spill_mask_ |= (1 << i);
573 }
574 }
575}
576
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100577static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100578 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100579}
580
581static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100582 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100583}
584
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000585void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000586 bool skip_overflow_check =
587 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000588 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000589 __ Bind(&frame_entry_label_);
590
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000591 if (HasEmptyFrame()) {
592 return;
593 }
594
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100595 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000596 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
597 __ LoadFromOffset(kLoadWord, IP, IP, 0);
598 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100599 }
600
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000601 // PC is in the list of callee-save to mimic Quick, but we need to push
602 // LR at entry instead.
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100603 uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR;
604 __ PushList(push_mask);
605 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100606 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, push_mask, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000607 if (fpu_spill_mask_ != 0) {
608 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
609 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100610 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100611 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000612 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100613 int adjust = GetFrameSize() - FrameEntrySpillSize();
614 __ AddConstant(SP, -adjust);
615 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100616 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000617}
618
619void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000620 if (HasEmptyFrame()) {
621 __ bx(LR);
622 return;
623 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100624 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100625 int adjust = GetFrameSize() - FrameEntrySpillSize();
626 __ AddConstant(SP, adjust);
627 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000628 if (fpu_spill_mask_ != 0) {
629 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
630 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100631 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
632 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000633 }
634 __ PopList(core_spill_mask_);
David Srbeckyc34dc932015-04-12 09:27:43 +0100635 __ cfi().RestoreState();
636 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000637}
638
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100639void CodeGeneratorARM::Bind(HBasicBlock* block) {
640 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000641}
642
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100643Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
644 switch (load->GetType()) {
645 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100646 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100647 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100648
649 case Primitive::kPrimInt:
650 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100651 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100652 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100653
654 case Primitive::kPrimBoolean:
655 case Primitive::kPrimByte:
656 case Primitive::kPrimChar:
657 case Primitive::kPrimShort:
658 case Primitive::kPrimVoid:
659 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700660 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100661 }
662
663 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700664 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100665}
666
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100667Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100668 switch (type) {
669 case Primitive::kPrimBoolean:
670 case Primitive::kPrimByte:
671 case Primitive::kPrimChar:
672 case Primitive::kPrimShort:
673 case Primitive::kPrimInt:
674 case Primitive::kPrimNot: {
675 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000676 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100677 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100678 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100679 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000680 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100681 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100682 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100683
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000684 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100685 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000686 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100687 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000688 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100689 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000690 if (calling_convention.GetRegisterAt(index) == R1) {
691 // Skip R1, and use R2_R3 instead.
692 gp_index_++;
693 index++;
694 }
695 }
696 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
697 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000698 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000699 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000700 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100701 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000702 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
703 }
704 }
705
706 case Primitive::kPrimFloat: {
707 uint32_t stack_index = stack_index_++;
708 if (float_index_ % 2 == 0) {
709 float_index_ = std::max(double_index_, float_index_);
710 }
711 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
712 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
713 } else {
714 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
715 }
716 }
717
718 case Primitive::kPrimDouble: {
719 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
720 uint32_t stack_index = stack_index_;
721 stack_index_ += 2;
722 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
723 uint32_t index = double_index_;
724 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000725 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000726 calling_convention.GetFpuRegisterAt(index),
727 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000728 DCHECK(ExpectedPairLayout(result));
729 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000730 } else {
731 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100732 }
733 }
734
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100735 case Primitive::kPrimVoid:
736 LOG(FATAL) << "Unexpected parameter type " << type;
737 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100738 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100739 return Location();
740}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100741
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100742Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000743 switch (type) {
744 case Primitive::kPrimBoolean:
745 case Primitive::kPrimByte:
746 case Primitive::kPrimChar:
747 case Primitive::kPrimShort:
748 case Primitive::kPrimInt:
749 case Primitive::kPrimNot: {
750 return Location::RegisterLocation(R0);
751 }
752
753 case Primitive::kPrimFloat: {
754 return Location::FpuRegisterLocation(S0);
755 }
756
757 case Primitive::kPrimLong: {
758 return Location::RegisterPairLocation(R0, R1);
759 }
760
761 case Primitive::kPrimDouble: {
762 return Location::FpuRegisterPairLocation(S0, S1);
763 }
764
765 case Primitive::kPrimVoid:
766 return Location();
767 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100768
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000769 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000770}
771
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100772Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
773 return Location::RegisterLocation(kMethodRegisterArgument);
774}
775
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100776void CodeGeneratorARM::Move32(Location destination, Location source) {
777 if (source.Equals(destination)) {
778 return;
779 }
780 if (destination.IsRegister()) {
781 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000782 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100783 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000784 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100785 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000786 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100787 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100788 } else if (destination.IsFpuRegister()) {
789 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000790 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100791 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000792 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100793 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000794 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100795 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100796 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000797 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100798 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000799 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100800 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000801 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100802 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000803 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100804 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
805 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100806 }
807 }
808}
809
810void CodeGeneratorARM::Move64(Location destination, Location source) {
811 if (source.Equals(destination)) {
812 return;
813 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100814 if (destination.IsRegisterPair()) {
815 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000816 EmitParallelMoves(
817 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
818 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100819 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000820 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100821 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
822 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100823 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000824 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100825 } else {
826 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000827 DCHECK(ExpectedPairLayout(destination));
828 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
829 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100830 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000831 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100832 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000833 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
834 SP,
835 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100836 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000837 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100838 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100839 } else {
840 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100841 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000842 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100843 if (source.AsRegisterPairLow<Register>() == R1) {
844 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100845 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
846 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100847 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100848 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100849 SP, destination.GetStackIndex());
850 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000851 } else if (source.IsFpuRegisterPair()) {
852 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
853 SP,
854 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100855 } else {
856 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000857 EmitParallelMoves(
858 Location::StackSlot(source.GetStackIndex()),
859 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100860 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000861 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100862 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
863 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100864 }
865 }
866}
867
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100868void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100869 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100870 if (instruction->IsCurrentMethod()) {
871 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
872 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100873 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100874 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000875 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000876 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
877 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000878 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000879 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000880 } else {
881 DCHECK(location.IsStackSlot());
882 __ LoadImmediate(IP, value);
883 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
884 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000885 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000886 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000887 int64_t value = const_to_move->AsLongConstant()->GetValue();
888 if (location.IsRegisterPair()) {
889 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
890 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
891 } else {
892 DCHECK(location.IsDoubleStackSlot());
893 __ LoadImmediate(IP, Low32Bits(value));
894 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
895 __ LoadImmediate(IP, High32Bits(value));
896 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
897 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100898 }
Roland Levillain476df552014-10-09 17:51:36 +0100899 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100900 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
901 switch (instruction->GetType()) {
902 case Primitive::kPrimBoolean:
903 case Primitive::kPrimByte:
904 case Primitive::kPrimChar:
905 case Primitive::kPrimShort:
906 case Primitive::kPrimInt:
907 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100908 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100909 Move32(location, Location::StackSlot(stack_slot));
910 break;
911
912 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100913 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100914 Move64(location, Location::DoubleStackSlot(stack_slot));
915 break;
916
917 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100918 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100919 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000920 } else if (instruction->IsTemporary()) {
921 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000922 if (temp_location.IsStackSlot()) {
923 Move32(location, temp_location);
924 } else {
925 DCHECK(temp_location.IsDoubleStackSlot());
926 Move64(location, temp_location);
927 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000928 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100929 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100930 switch (instruction->GetType()) {
931 case Primitive::kPrimBoolean:
932 case Primitive::kPrimByte:
933 case Primitive::kPrimChar:
934 case Primitive::kPrimShort:
935 case Primitive::kPrimNot:
936 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100937 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100938 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100939 break;
940
941 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100942 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100943 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100944 break;
945
946 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100947 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100948 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000949 }
950}
951
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100952void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
953 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000954 uint32_t dex_pc,
955 SlowPathCode* slow_path) {
Alexandre Rames8158f282015-08-07 10:26:17 +0100956 // Ensure that the call kind indication given to the register allocator is
957 // coherent with the runtime call generated.
958 if (slow_path == nullptr) {
959 DCHECK(instruction->GetLocations()->WillCall());
960 } else {
961 DCHECK(instruction->GetLocations()->OnlyCallsOnSlowPath() || slow_path->IsFatal());
962 }
963
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100964 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
965 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000966 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100967 DCHECK(instruction->IsSuspendCheck()
968 || instruction->IsBoundsCheck()
969 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000970 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000971 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100972 || !IsLeafMethod());
973}
974
David Brazdilfc6a86a2015-06-26 10:33:45 +0000975void InstructionCodeGeneratorARM::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100976 DCHECK(!successor->IsExitBlock());
977
978 HBasicBlock* block = got->GetBlock();
979 HInstruction* previous = got->GetPrevious();
980
981 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000982 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100983 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
984 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
985 return;
986 }
987
988 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
989 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
990 }
991 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000992 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000993 }
994}
995
David Brazdilfc6a86a2015-06-26 10:33:45 +0000996void LocationsBuilderARM::VisitGoto(HGoto* got) {
997 got->SetLocations(nullptr);
998}
999
1000void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
1001 HandleGoto(got, got->GetSuccessor());
1002}
1003
1004void LocationsBuilderARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1005 try_boundary->SetLocations(nullptr);
1006}
1007
1008void InstructionCodeGeneratorARM::VisitTryBoundary(HTryBoundary* try_boundary) {
1009 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
1010 if (!successor->IsExitBlock()) {
1011 HandleGoto(try_boundary, successor);
1012 }
1013}
1014
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001015void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001016 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001017}
1018
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001019void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001020 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001021}
1022
Roland Levillain4fa13f62015-07-06 18:11:54 +01001023void InstructionCodeGeneratorARM::GenerateCompareWithImmediate(Register left, int32_t right) {
1024 ShifterOperand operand;
1025 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, right, &operand)) {
1026 __ cmp(left, operand);
1027 } else {
1028 Register temp = IP;
1029 __ LoadImmediate(temp, right);
1030 __ cmp(left, ShifterOperand(temp));
1031 }
1032}
1033
1034void InstructionCodeGeneratorARM::GenerateFPJumps(HCondition* cond,
1035 Label* true_label,
1036 Label* false_label) {
1037 __ vmstat(); // transfer FP status register to ARM APSR.
1038 if (cond->IsFPConditionTrueIfNaN()) {
1039 __ b(true_label, VS); // VS for unordered.
1040 } else if (cond->IsFPConditionFalseIfNaN()) {
1041 __ b(false_label, VS); // VS for unordered.
1042 }
1043 __ b(true_label, ARMSignedOrFPCondition(cond->GetCondition()));
1044}
1045
1046void InstructionCodeGeneratorARM::GenerateLongComparesAndJumps(HCondition* cond,
1047 Label* true_label,
1048 Label* false_label) {
1049 LocationSummary* locations = cond->GetLocations();
1050 Location left = locations->InAt(0);
1051 Location right = locations->InAt(1);
1052 IfCondition if_cond = cond->GetCondition();
1053
1054 Register left_high = left.AsRegisterPairHigh<Register>();
1055 Register left_low = left.AsRegisterPairLow<Register>();
1056 IfCondition true_high_cond = if_cond;
1057 IfCondition false_high_cond = cond->GetOppositeCondition();
1058 Condition final_condition = ARMUnsignedCondition(if_cond);
1059
1060 // Set the conditions for the test, remembering that == needs to be
1061 // decided using the low words.
1062 switch (if_cond) {
1063 case kCondEQ:
1064 case kCondNE:
1065 // Nothing to do.
1066 break;
1067 case kCondLT:
1068 false_high_cond = kCondGT;
1069 break;
1070 case kCondLE:
1071 true_high_cond = kCondLT;
1072 break;
1073 case kCondGT:
1074 false_high_cond = kCondLT;
1075 break;
1076 case kCondGE:
1077 true_high_cond = kCondGT;
1078 break;
1079 }
1080 if (right.IsConstant()) {
1081 int64_t value = right.GetConstant()->AsLongConstant()->GetValue();
1082 int32_t val_low = Low32Bits(value);
1083 int32_t val_high = High32Bits(value);
1084
1085 GenerateCompareWithImmediate(left_high, val_high);
1086 if (if_cond == kCondNE) {
1087 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1088 } else if (if_cond == kCondEQ) {
1089 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1090 } else {
1091 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1092 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1093 }
1094 // Must be equal high, so compare the lows.
1095 GenerateCompareWithImmediate(left_low, val_low);
1096 } else {
1097 Register right_high = right.AsRegisterPairHigh<Register>();
1098 Register right_low = right.AsRegisterPairLow<Register>();
1099
1100 __ cmp(left_high, ShifterOperand(right_high));
1101 if (if_cond == kCondNE) {
1102 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1103 } else if (if_cond == kCondEQ) {
1104 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1105 } else {
1106 __ b(true_label, ARMSignedOrFPCondition(true_high_cond));
1107 __ b(false_label, ARMSignedOrFPCondition(false_high_cond));
1108 }
1109 // Must be equal high, so compare the lows.
1110 __ cmp(left_low, ShifterOperand(right_low));
1111 }
1112 // The last comparison might be unsigned.
1113 __ b(true_label, final_condition);
1114}
1115
1116void InstructionCodeGeneratorARM::GenerateCompareTestAndBranch(HIf* if_instr,
1117 HCondition* condition,
1118 Label* true_target,
1119 Label* false_target,
1120 Label* always_true_target) {
1121 LocationSummary* locations = condition->GetLocations();
1122 Location left = locations->InAt(0);
1123 Location right = locations->InAt(1);
1124
1125 // We don't want true_target as a nullptr.
1126 if (true_target == nullptr) {
1127 true_target = always_true_target;
1128 }
1129 bool falls_through = (false_target == nullptr);
1130
1131 // FP compares don't like null false_targets.
1132 if (false_target == nullptr) {
1133 false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1134 }
1135
1136 Primitive::Type type = condition->InputAt(0)->GetType();
1137 switch (type) {
1138 case Primitive::kPrimLong:
1139 GenerateLongComparesAndJumps(condition, true_target, false_target);
1140 break;
1141 case Primitive::kPrimFloat:
1142 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1143 GenerateFPJumps(condition, true_target, false_target);
1144 break;
1145 case Primitive::kPrimDouble:
1146 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1147 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1148 GenerateFPJumps(condition, true_target, false_target);
1149 break;
1150 default:
1151 LOG(FATAL) << "Unexpected compare type " << type;
1152 }
1153
1154 if (!falls_through) {
1155 __ b(false_target);
1156 }
1157}
1158
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001159void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
1160 Label* true_target,
1161 Label* false_target,
1162 Label* always_true_target) {
1163 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001164 if (cond->IsIntConstant()) {
1165 // Constant condition, statically compared against 1.
1166 int32_t cond_value = cond->AsIntConstant()->GetValue();
1167 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001168 if (always_true_target != nullptr) {
1169 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001170 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001171 return;
1172 } else {
1173 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001174 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001175 } else {
1176 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1177 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001178 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01001179 __ CompareAndBranchIfNonZero(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
1180 true_target);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001181 } else {
1182 // Condition has not been materialized, use its inputs as the
1183 // comparison and its condition as the branch condition.
Roland Levillain4fa13f62015-07-06 18:11:54 +01001184 Primitive::Type type =
1185 cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt;
1186 // Is this a long or FP comparison that has been folded into the HCondition?
1187 if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) {
1188 // Generate the comparison directly.
1189 GenerateCompareTestAndBranch(instruction->AsIf(), cond->AsCondition(),
1190 true_target, false_target, always_true_target);
1191 return;
1192 }
1193
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001194 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001195 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001196 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain4fa13f62015-07-06 18:11:54 +01001197 Location right = locations->InAt(1);
1198 if (right.IsRegister()) {
1199 __ cmp(left, ShifterOperand(right.AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001200 } else {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001201 DCHECK(right.IsConstant());
1202 GenerateCompareWithImmediate(left, CodeGenerator::GetInt32ValueOf(right.GetConstant()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001203 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001204 __ b(true_target, ARMSignedOrFPCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001205 }
Dave Allison20dfc792014-06-16 20:44:29 -07001206 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001207 if (false_target != nullptr) {
1208 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001209 }
1210}
1211
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001212void LocationsBuilderARM::VisitIf(HIf* if_instr) {
1213 LocationSummary* locations =
1214 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
1215 HInstruction* cond = if_instr->InputAt(0);
1216 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1217 locations->SetInAt(0, Location::RequiresRegister());
1218 }
1219}
1220
1221void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1222 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1223 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1224 Label* always_true_target = true_target;
1225 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1226 if_instr->IfTrueSuccessor())) {
1227 always_true_target = nullptr;
1228 }
1229 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1230 if_instr->IfFalseSuccessor())) {
1231 false_target = nullptr;
1232 }
1233 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1234}
1235
1236void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1237 LocationSummary* locations = new (GetGraph()->GetArena())
1238 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1239 HInstruction* cond = deoptimize->InputAt(0);
1240 DCHECK(cond->IsCondition());
1241 if (cond->AsCondition()->NeedsMaterialization()) {
1242 locations->SetInAt(0, Location::RequiresRegister());
1243 }
1244}
1245
1246void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1247 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1248 DeoptimizationSlowPathARM(deoptimize);
1249 codegen_->AddSlowPath(slow_path);
1250 Label* slow_path_entry = slow_path->GetEntryLabel();
1251 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1252}
Dave Allison20dfc792014-06-16 20:44:29 -07001253
Roland Levillain0d37cd02015-05-27 16:39:19 +01001254void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001255 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001256 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Roland Levillain4fa13f62015-07-06 18:11:54 +01001257 // Handle the long/FP comparisons made in instruction simplification.
1258 switch (cond->InputAt(0)->GetType()) {
1259 case Primitive::kPrimLong:
1260 locations->SetInAt(0, Location::RequiresRegister());
1261 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1262 if (cond->NeedsMaterialization()) {
1263 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1264 }
1265 break;
1266
1267 case Primitive::kPrimFloat:
1268 case Primitive::kPrimDouble:
1269 locations->SetInAt(0, Location::RequiresFpuRegister());
1270 locations->SetInAt(1, Location::RequiresFpuRegister());
1271 if (cond->NeedsMaterialization()) {
1272 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1273 }
1274 break;
1275
1276 default:
1277 locations->SetInAt(0, Location::RequiresRegister());
1278 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1279 if (cond->NeedsMaterialization()) {
1280 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1281 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001282 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001283}
1284
Roland Levillain0d37cd02015-05-27 16:39:19 +01001285void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
Roland Levillain4fa13f62015-07-06 18:11:54 +01001286 if (!cond->NeedsMaterialization()) {
1287 return;
Dave Allison20dfc792014-06-16 20:44:29 -07001288 }
Roland Levillain4fa13f62015-07-06 18:11:54 +01001289
1290 LocationSummary* locations = cond->GetLocations();
1291 Location left = locations->InAt(0);
1292 Location right = locations->InAt(1);
1293 Register out = locations->Out().AsRegister<Register>();
1294 Label true_label, false_label;
1295
1296 switch (cond->InputAt(0)->GetType()) {
1297 default: {
1298 // Integer case.
1299 if (right.IsRegister()) {
1300 __ cmp(left.AsRegister<Register>(), ShifterOperand(right.AsRegister<Register>()));
1301 } else {
1302 DCHECK(right.IsConstant());
1303 GenerateCompareWithImmediate(left.AsRegister<Register>(),
1304 CodeGenerator::GetInt32ValueOf(right.GetConstant()));
1305 }
1306 __ it(ARMSignedOrFPCondition(cond->GetCondition()), kItElse);
1307 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
1308 ARMSignedOrFPCondition(cond->GetCondition()));
1309 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
1310 ARMSignedOrFPCondition(cond->GetOppositeCondition()));
1311 return;
1312 }
1313 case Primitive::kPrimLong:
1314 GenerateLongComparesAndJumps(cond, &true_label, &false_label);
1315 break;
1316 case Primitive::kPrimFloat:
1317 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
1318 GenerateFPJumps(cond, &true_label, &false_label);
1319 break;
1320 case Primitive::kPrimDouble:
1321 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
1322 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
1323 GenerateFPJumps(cond, &true_label, &false_label);
1324 break;
1325 }
1326
1327 // Convert the jumps into the result.
1328 Label done_label;
1329
1330 // False case: result = 0.
1331 __ Bind(&false_label);
1332 __ LoadImmediate(out, 0);
1333 __ b(&done_label);
1334
1335 // True case: result = 1.
1336 __ Bind(&true_label);
1337 __ LoadImmediate(out, 1);
1338 __ Bind(&done_label);
Dave Allison20dfc792014-06-16 20:44:29 -07001339}
1340
1341void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1342 VisitCondition(comp);
1343}
1344
1345void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1346 VisitCondition(comp);
1347}
1348
1349void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1350 VisitCondition(comp);
1351}
1352
1353void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1354 VisitCondition(comp);
1355}
1356
1357void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1358 VisitCondition(comp);
1359}
1360
1361void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1362 VisitCondition(comp);
1363}
1364
1365void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1366 VisitCondition(comp);
1367}
1368
1369void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1370 VisitCondition(comp);
1371}
1372
1373void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1374 VisitCondition(comp);
1375}
1376
1377void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1378 VisitCondition(comp);
1379}
1380
1381void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1382 VisitCondition(comp);
1383}
1384
1385void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1386 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001387}
1388
1389void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001390 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001391}
1392
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001393void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1394 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001395}
1396
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001397void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001398 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001399}
1400
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001401void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001402 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001403 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001404}
1405
1406void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001407 LocationSummary* locations =
1408 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001409 switch (store->InputAt(1)->GetType()) {
1410 case Primitive::kPrimBoolean:
1411 case Primitive::kPrimByte:
1412 case Primitive::kPrimChar:
1413 case Primitive::kPrimShort:
1414 case Primitive::kPrimInt:
1415 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001416 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001417 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1418 break;
1419
1420 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001421 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001422 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1423 break;
1424
1425 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001426 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001427 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001428}
1429
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001430void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001431 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001432}
1433
1434void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001435 LocationSummary* locations =
1436 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001437 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001438}
1439
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001440void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001441 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001442 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001443}
1444
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001445void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1446 LocationSummary* locations =
1447 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1448 locations->SetOut(Location::ConstantLocation(constant));
1449}
1450
1451void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1452 // Will be generated at use site.
1453 UNUSED(constant);
1454}
1455
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001456void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001457 LocationSummary* locations =
1458 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001459 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001460}
1461
1462void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1463 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001464 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001465}
1466
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001467void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1468 LocationSummary* locations =
1469 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1470 locations->SetOut(Location::ConstantLocation(constant));
1471}
1472
1473void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1474 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001475 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001476}
1477
1478void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1479 LocationSummary* locations =
1480 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1481 locations->SetOut(Location::ConstantLocation(constant));
1482}
1483
1484void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1485 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001486 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001487}
1488
Calin Juravle27df7582015-04-17 19:12:31 +01001489void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1490 memory_barrier->SetLocations(nullptr);
1491}
1492
1493void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1494 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1495}
1496
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001497void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001498 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001499}
1500
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001501void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001502 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001503 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001504}
1505
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001506void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001507 LocationSummary* locations =
1508 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001509 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001510}
1511
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001512void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001513 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001514 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001515}
1516
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001517void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001518 // When we do not run baseline, explicit clinit checks triggered by static
1519 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1520 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001521
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001522 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1523 codegen_->GetInstructionSetFeatures());
1524 if (intrinsic.TryDispatch(invoke)) {
1525 return;
1526 }
1527
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001528 HandleInvoke(invoke);
1529}
1530
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001531static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1532 if (invoke->GetLocations()->Intrinsified()) {
1533 IntrinsicCodeGeneratorARM intrinsic(codegen);
1534 intrinsic.Dispatch(invoke);
1535 return true;
1536 }
1537 return false;
1538}
1539
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001540void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001541 // When we do not run baseline, explicit clinit checks triggered by static
1542 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1543 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001544
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001545 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1546 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001547 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001548
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001549 LocationSummary* locations = invoke->GetLocations();
1550 codegen_->GenerateStaticOrDirectCall(
1551 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001552 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001553}
1554
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001555void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001556 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001557 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001558}
1559
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001560void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001561 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1562 codegen_->GetInstructionSetFeatures());
1563 if (intrinsic.TryDispatch(invoke)) {
1564 return;
1565 }
1566
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001567 HandleInvoke(invoke);
1568}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001569
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001570void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001571 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1572 return;
1573 }
1574
Roland Levillain271ab9c2014-11-27 15:23:57 +00001575 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001576 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1577 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001578 LocationSummary* locations = invoke->GetLocations();
1579 Location receiver = locations->InAt(0);
1580 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1581 // temp = object->GetClass();
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001582 DCHECK(receiver.IsRegister());
1583 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00001584 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001585 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001586 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001587 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001588 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001589 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001590 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001591 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001592 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001593 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001594 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001595 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001596}
1597
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001598void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1599 HandleInvoke(invoke);
1600 // Add the hidden argument.
1601 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1602}
1603
1604void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1605 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001606 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001607 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1608 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001609 LocationSummary* locations = invoke->GetLocations();
1610 Location receiver = locations->InAt(0);
1611 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1612
1613 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001614 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1615 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001616
1617 // temp = object->GetClass();
1618 if (receiver.IsStackSlot()) {
1619 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1620 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1621 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001622 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001623 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001624 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01001625 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001626 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001627 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001628 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001629 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1630 // LR = temp->GetEntryPoint();
1631 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1632 // LR();
1633 __ blx(LR);
1634 DCHECK(!codegen_->IsLeafMethod());
1635 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1636}
1637
Roland Levillain88cb1752014-10-20 16:36:47 +01001638void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1639 LocationSummary* locations =
1640 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1641 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001642 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001643 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001644 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1645 break;
1646 }
1647 case Primitive::kPrimLong: {
1648 locations->SetInAt(0, Location::RequiresRegister());
1649 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001650 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001651 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001652
Roland Levillain88cb1752014-10-20 16:36:47 +01001653 case Primitive::kPrimFloat:
1654 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001655 locations->SetInAt(0, Location::RequiresFpuRegister());
1656 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001657 break;
1658
1659 default:
1660 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1661 }
1662}
1663
1664void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1665 LocationSummary* locations = neg->GetLocations();
1666 Location out = locations->Out();
1667 Location in = locations->InAt(0);
1668 switch (neg->GetResultType()) {
1669 case Primitive::kPrimInt:
1670 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001671 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001672 break;
1673
1674 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001675 DCHECK(in.IsRegisterPair());
1676 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1677 __ rsbs(out.AsRegisterPairLow<Register>(),
1678 in.AsRegisterPairLow<Register>(),
1679 ShifterOperand(0));
1680 // We cannot emit an RSC (Reverse Subtract with Carry)
1681 // instruction here, as it does not exist in the Thumb-2
1682 // instruction set. We use the following approach
1683 // using SBC and SUB instead.
1684 //
1685 // out.hi = -C
1686 __ sbc(out.AsRegisterPairHigh<Register>(),
1687 out.AsRegisterPairHigh<Register>(),
1688 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1689 // out.hi = out.hi - in.hi
1690 __ sub(out.AsRegisterPairHigh<Register>(),
1691 out.AsRegisterPairHigh<Register>(),
1692 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1693 break;
1694
Roland Levillain88cb1752014-10-20 16:36:47 +01001695 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001696 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001697 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001698 break;
1699
Roland Levillain88cb1752014-10-20 16:36:47 +01001700 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001701 DCHECK(in.IsFpuRegisterPair());
1702 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1703 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001704 break;
1705
1706 default:
1707 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1708 }
1709}
1710
Roland Levillaindff1f282014-11-05 14:15:05 +00001711void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001712 Primitive::Type result_type = conversion->GetResultType();
1713 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001714 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001715
Roland Levillain5b3ee562015-04-14 16:02:41 +01001716 // The float-to-long, double-to-long and long-to-float type conversions
1717 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001718 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001719 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1720 && result_type == Primitive::kPrimLong)
1721 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001722 ? LocationSummary::kCall
1723 : LocationSummary::kNoCall;
1724 LocationSummary* locations =
1725 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1726
David Brazdilb2bd1c52015-03-25 11:17:37 +00001727 // The Java language does not allow treating boolean as an integral type but
1728 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001729
Roland Levillaindff1f282014-11-05 14:15:05 +00001730 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001731 case Primitive::kPrimByte:
1732 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001733 case Primitive::kPrimBoolean:
1734 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001735 case Primitive::kPrimShort:
1736 case Primitive::kPrimInt:
1737 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001738 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001739 locations->SetInAt(0, Location::RequiresRegister());
1740 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1741 break;
1742
1743 default:
1744 LOG(FATAL) << "Unexpected type conversion from " << input_type
1745 << " to " << result_type;
1746 }
1747 break;
1748
Roland Levillain01a8d712014-11-14 16:27:39 +00001749 case Primitive::kPrimShort:
1750 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001751 case Primitive::kPrimBoolean:
1752 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001753 case Primitive::kPrimByte:
1754 case Primitive::kPrimInt:
1755 case Primitive::kPrimChar:
1756 // Processing a Dex `int-to-short' instruction.
1757 locations->SetInAt(0, Location::RequiresRegister());
1758 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1759 break;
1760
1761 default:
1762 LOG(FATAL) << "Unexpected type conversion from " << input_type
1763 << " to " << result_type;
1764 }
1765 break;
1766
Roland Levillain946e1432014-11-11 17:35:19 +00001767 case Primitive::kPrimInt:
1768 switch (input_type) {
1769 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001770 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001771 locations->SetInAt(0, Location::Any());
1772 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1773 break;
1774
1775 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001776 // Processing a Dex `float-to-int' instruction.
1777 locations->SetInAt(0, Location::RequiresFpuRegister());
1778 locations->SetOut(Location::RequiresRegister());
1779 locations->AddTemp(Location::RequiresFpuRegister());
1780 break;
1781
Roland Levillain946e1432014-11-11 17:35:19 +00001782 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001783 // Processing a Dex `double-to-int' instruction.
1784 locations->SetInAt(0, Location::RequiresFpuRegister());
1785 locations->SetOut(Location::RequiresRegister());
1786 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001787 break;
1788
1789 default:
1790 LOG(FATAL) << "Unexpected type conversion from " << input_type
1791 << " to " << result_type;
1792 }
1793 break;
1794
Roland Levillaindff1f282014-11-05 14:15:05 +00001795 case Primitive::kPrimLong:
1796 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001797 case Primitive::kPrimBoolean:
1798 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001799 case Primitive::kPrimByte:
1800 case Primitive::kPrimShort:
1801 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001802 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001803 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001804 locations->SetInAt(0, Location::RequiresRegister());
1805 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1806 break;
1807
Roland Levillain624279f2014-12-04 11:54:28 +00001808 case Primitive::kPrimFloat: {
1809 // Processing a Dex `float-to-long' instruction.
1810 InvokeRuntimeCallingConvention calling_convention;
1811 locations->SetInAt(0, Location::FpuRegisterLocation(
1812 calling_convention.GetFpuRegisterAt(0)));
1813 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1814 break;
1815 }
1816
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001817 case Primitive::kPrimDouble: {
1818 // Processing a Dex `double-to-long' instruction.
1819 InvokeRuntimeCallingConvention calling_convention;
1820 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1821 calling_convention.GetFpuRegisterAt(0),
1822 calling_convention.GetFpuRegisterAt(1)));
1823 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001824 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001825 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001826
1827 default:
1828 LOG(FATAL) << "Unexpected type conversion from " << input_type
1829 << " to " << result_type;
1830 }
1831 break;
1832
Roland Levillain981e4542014-11-14 11:47:14 +00001833 case Primitive::kPrimChar:
1834 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001835 case Primitive::kPrimBoolean:
1836 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001837 case Primitive::kPrimByte:
1838 case Primitive::kPrimShort:
1839 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001840 // Processing a Dex `int-to-char' instruction.
1841 locations->SetInAt(0, Location::RequiresRegister());
1842 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1843 break;
1844
1845 default:
1846 LOG(FATAL) << "Unexpected type conversion from " << input_type
1847 << " to " << result_type;
1848 }
1849 break;
1850
Roland Levillaindff1f282014-11-05 14:15:05 +00001851 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001852 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001853 case Primitive::kPrimBoolean:
1854 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001855 case Primitive::kPrimByte:
1856 case Primitive::kPrimShort:
1857 case Primitive::kPrimInt:
1858 case Primitive::kPrimChar:
1859 // Processing a Dex `int-to-float' instruction.
1860 locations->SetInAt(0, Location::RequiresRegister());
1861 locations->SetOut(Location::RequiresFpuRegister());
1862 break;
1863
Roland Levillain5b3ee562015-04-14 16:02:41 +01001864 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001865 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001866 InvokeRuntimeCallingConvention calling_convention;
1867 locations->SetInAt(0, Location::RegisterPairLocation(
1868 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1869 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001870 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001871 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001872
Roland Levillaincff13742014-11-17 14:32:17 +00001873 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001874 // Processing a Dex `double-to-float' instruction.
1875 locations->SetInAt(0, Location::RequiresFpuRegister());
1876 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001877 break;
1878
1879 default:
1880 LOG(FATAL) << "Unexpected type conversion from " << input_type
1881 << " to " << result_type;
1882 };
1883 break;
1884
Roland Levillaindff1f282014-11-05 14:15:05 +00001885 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001886 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001887 case Primitive::kPrimBoolean:
1888 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001889 case Primitive::kPrimByte:
1890 case Primitive::kPrimShort:
1891 case Primitive::kPrimInt:
1892 case Primitive::kPrimChar:
1893 // Processing a Dex `int-to-double' instruction.
1894 locations->SetInAt(0, Location::RequiresRegister());
1895 locations->SetOut(Location::RequiresFpuRegister());
1896 break;
1897
1898 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001899 // Processing a Dex `long-to-double' instruction.
1900 locations->SetInAt(0, Location::RequiresRegister());
1901 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001902 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001903 locations->AddTemp(Location::RequiresFpuRegister());
1904 break;
1905
Roland Levillaincff13742014-11-17 14:32:17 +00001906 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001907 // Processing a Dex `float-to-double' instruction.
1908 locations->SetInAt(0, Location::RequiresFpuRegister());
1909 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001910 break;
1911
1912 default:
1913 LOG(FATAL) << "Unexpected type conversion from " << input_type
1914 << " to " << result_type;
1915 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001916 break;
1917
1918 default:
1919 LOG(FATAL) << "Unexpected type conversion from " << input_type
1920 << " to " << result_type;
1921 }
1922}
1923
1924void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1925 LocationSummary* locations = conversion->GetLocations();
1926 Location out = locations->Out();
1927 Location in = locations->InAt(0);
1928 Primitive::Type result_type = conversion->GetResultType();
1929 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001930 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001931 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001932 case Primitive::kPrimByte:
1933 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001934 case Primitive::kPrimBoolean:
1935 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001936 case Primitive::kPrimShort:
1937 case Primitive::kPrimInt:
1938 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001939 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001940 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001941 break;
1942
1943 default:
1944 LOG(FATAL) << "Unexpected type conversion from " << input_type
1945 << " to " << result_type;
1946 }
1947 break;
1948
Roland Levillain01a8d712014-11-14 16:27:39 +00001949 case Primitive::kPrimShort:
1950 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001951 case Primitive::kPrimBoolean:
1952 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001953 case Primitive::kPrimByte:
1954 case Primitive::kPrimInt:
1955 case Primitive::kPrimChar:
1956 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001957 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001958 break;
1959
1960 default:
1961 LOG(FATAL) << "Unexpected type conversion from " << input_type
1962 << " to " << result_type;
1963 }
1964 break;
1965
Roland Levillain946e1432014-11-11 17:35:19 +00001966 case Primitive::kPrimInt:
1967 switch (input_type) {
1968 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001969 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001970 DCHECK(out.IsRegister());
1971 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001972 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001973 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001974 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001975 } else {
1976 DCHECK(in.IsConstant());
1977 DCHECK(in.GetConstant()->IsLongConstant());
1978 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001979 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001980 }
1981 break;
1982
Roland Levillain3f8f9362014-12-02 17:45:01 +00001983 case Primitive::kPrimFloat: {
1984 // Processing a Dex `float-to-int' instruction.
1985 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1986 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1987 __ vcvtis(temp, temp);
1988 __ vmovrs(out.AsRegister<Register>(), temp);
1989 break;
1990 }
1991
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001992 case Primitive::kPrimDouble: {
1993 // Processing a Dex `double-to-int' instruction.
1994 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1995 DRegister temp_d = FromLowSToD(temp_s);
1996 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1997 __ vcvtid(temp_s, temp_d);
1998 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001999 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002000 }
Roland Levillain946e1432014-11-11 17:35:19 +00002001
2002 default:
2003 LOG(FATAL) << "Unexpected type conversion from " << input_type
2004 << " to " << result_type;
2005 }
2006 break;
2007
Roland Levillaindff1f282014-11-05 14:15:05 +00002008 case Primitive::kPrimLong:
2009 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002010 case Primitive::kPrimBoolean:
2011 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00002012 case Primitive::kPrimByte:
2013 case Primitive::kPrimShort:
2014 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00002015 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00002016 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00002017 DCHECK(out.IsRegisterPair());
2018 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002019 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00002020 // Sign extension.
2021 __ Asr(out.AsRegisterPairHigh<Register>(),
2022 out.AsRegisterPairLow<Register>(),
2023 31);
2024 break;
2025
2026 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00002027 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00002028 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
2029 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002030 conversion->GetDexPc(),
2031 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00002032 break;
2033
Roland Levillaindff1f282014-11-05 14:15:05 +00002034 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00002035 // Processing a Dex `double-to-long' instruction.
2036 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
2037 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002038 conversion->GetDexPc(),
2039 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00002040 break;
2041
2042 default:
2043 LOG(FATAL) << "Unexpected type conversion from " << input_type
2044 << " to " << result_type;
2045 }
2046 break;
2047
Roland Levillain981e4542014-11-14 11:47:14 +00002048 case Primitive::kPrimChar:
2049 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002050 case Primitive::kPrimBoolean:
2051 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00002052 case Primitive::kPrimByte:
2053 case Primitive::kPrimShort:
2054 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00002055 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002056 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00002057 break;
2058
2059 default:
2060 LOG(FATAL) << "Unexpected type conversion from " << input_type
2061 << " to " << result_type;
2062 }
2063 break;
2064
Roland Levillaindff1f282014-11-05 14:15:05 +00002065 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00002066 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002067 case Primitive::kPrimBoolean:
2068 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002069 case Primitive::kPrimByte:
2070 case Primitive::kPrimShort:
2071 case Primitive::kPrimInt:
2072 case Primitive::kPrimChar: {
2073 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002074 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
2075 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002076 break;
2077 }
2078
Roland Levillain5b3ee562015-04-14 16:02:41 +01002079 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00002080 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01002081 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
2082 conversion,
2083 conversion->GetDexPc(),
2084 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00002085 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00002086
Roland Levillaincff13742014-11-17 14:32:17 +00002087 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002088 // Processing a Dex `double-to-float' instruction.
2089 __ vcvtsd(out.AsFpuRegister<SRegister>(),
2090 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00002091 break;
2092
2093 default:
2094 LOG(FATAL) << "Unexpected type conversion from " << input_type
2095 << " to " << result_type;
2096 };
2097 break;
2098
Roland Levillaindff1f282014-11-05 14:15:05 +00002099 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00002100 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00002101 case Primitive::kPrimBoolean:
2102 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00002103 case Primitive::kPrimByte:
2104 case Primitive::kPrimShort:
2105 case Primitive::kPrimInt:
2106 case Primitive::kPrimChar: {
2107 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00002108 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00002109 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2110 out.AsFpuRegisterPairLow<SRegister>());
2111 break;
2112 }
2113
Roland Levillain647b9ed2014-11-27 12:06:00 +00002114 case Primitive::kPrimLong: {
2115 // Processing a Dex `long-to-double' instruction.
2116 Register low = in.AsRegisterPairLow<Register>();
2117 Register high = in.AsRegisterPairHigh<Register>();
2118 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
2119 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002120 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00002121 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01002122 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
2123 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002124
Roland Levillain682393c2015-04-14 15:57:52 +01002125 // temp_d = int-to-double(high)
2126 __ vmovsr(temp_s, high);
2127 __ vcvtdi(temp_d, temp_s);
2128 // constant_d = k2Pow32EncodingForDouble
2129 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
2130 // out_d = unsigned-to-double(low)
2131 __ vmovsr(out_s, low);
2132 __ vcvtdu(out_d, out_s);
2133 // out_d += temp_d * constant_d
2134 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00002135 break;
2136 }
2137
Roland Levillaincff13742014-11-17 14:32:17 +00002138 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00002139 // Processing a Dex `float-to-double' instruction.
2140 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2141 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00002142 break;
2143
2144 default:
2145 LOG(FATAL) << "Unexpected type conversion from " << input_type
2146 << " to " << result_type;
2147 };
Roland Levillaindff1f282014-11-05 14:15:05 +00002148 break;
2149
2150 default:
2151 LOG(FATAL) << "Unexpected type conversion from " << input_type
2152 << " to " << result_type;
2153 }
2154}
2155
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002156void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002157 LocationSummary* locations =
2158 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002159 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002160 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002161 locations->SetInAt(0, Location::RequiresRegister());
2162 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002163 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2164 break;
2165 }
2166
2167 case Primitive::kPrimLong: {
2168 locations->SetInAt(0, Location::RequiresRegister());
2169 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002170 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002171 break;
2172 }
2173
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002174 case Primitive::kPrimFloat:
2175 case Primitive::kPrimDouble: {
2176 locations->SetInAt(0, Location::RequiresFpuRegister());
2177 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002178 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002179 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002180 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002181
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002182 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002183 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002184 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002185}
2186
2187void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
2188 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002189 Location out = locations->Out();
2190 Location first = locations->InAt(0);
2191 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002192 switch (add->GetResultType()) {
2193 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002194 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002195 __ add(out.AsRegister<Register>(),
2196 first.AsRegister<Register>(),
2197 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002198 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002199 __ AddConstant(out.AsRegister<Register>(),
2200 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002201 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002202 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002203 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002204
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002205 case Primitive::kPrimLong: {
2206 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002207 __ adds(out.AsRegisterPairLow<Register>(),
2208 first.AsRegisterPairLow<Register>(),
2209 ShifterOperand(second.AsRegisterPairLow<Register>()));
2210 __ adc(out.AsRegisterPairHigh<Register>(),
2211 first.AsRegisterPairHigh<Register>(),
2212 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002213 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002214 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002215
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002216 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002217 __ vadds(out.AsFpuRegister<SRegister>(),
2218 first.AsFpuRegister<SRegister>(),
2219 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002220 break;
2221
2222 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002223 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2224 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2225 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002226 break;
2227
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002228 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002229 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002230 }
2231}
2232
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002233void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002234 LocationSummary* locations =
2235 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002236 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002237 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002238 locations->SetInAt(0, Location::RequiresRegister());
2239 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002240 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2241 break;
2242 }
2243
2244 case Primitive::kPrimLong: {
2245 locations->SetInAt(0, Location::RequiresRegister());
2246 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002247 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002248 break;
2249 }
Calin Juravle11351682014-10-23 15:38:15 +01002250 case Primitive::kPrimFloat:
2251 case Primitive::kPrimDouble: {
2252 locations->SetInAt(0, Location::RequiresFpuRegister());
2253 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002254 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002255 break;
Calin Juravle11351682014-10-23 15:38:15 +01002256 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002257 default:
Calin Juravle11351682014-10-23 15:38:15 +01002258 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002259 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002260}
2261
2262void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2263 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002264 Location out = locations->Out();
2265 Location first = locations->InAt(0);
2266 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002267 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002268 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002269 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002270 __ sub(out.AsRegister<Register>(),
2271 first.AsRegister<Register>(),
2272 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002273 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002274 __ AddConstant(out.AsRegister<Register>(),
2275 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002276 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002277 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002278 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002279 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002280
Calin Juravle11351682014-10-23 15:38:15 +01002281 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002282 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002283 __ subs(out.AsRegisterPairLow<Register>(),
2284 first.AsRegisterPairLow<Register>(),
2285 ShifterOperand(second.AsRegisterPairLow<Register>()));
2286 __ sbc(out.AsRegisterPairHigh<Register>(),
2287 first.AsRegisterPairHigh<Register>(),
2288 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002289 break;
Calin Juravle11351682014-10-23 15:38:15 +01002290 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002291
Calin Juravle11351682014-10-23 15:38:15 +01002292 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002293 __ vsubs(out.AsFpuRegister<SRegister>(),
2294 first.AsFpuRegister<SRegister>(),
2295 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002296 break;
Calin Juravle11351682014-10-23 15:38:15 +01002297 }
2298
2299 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002300 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2301 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2302 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002303 break;
2304 }
2305
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002306
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002307 default:
Calin Juravle11351682014-10-23 15:38:15 +01002308 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002309 }
2310}
2311
Calin Juravle34bacdf2014-10-07 20:23:36 +01002312void LocationsBuilderARM::VisitMul(HMul* mul) {
2313 LocationSummary* locations =
2314 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2315 switch (mul->GetResultType()) {
2316 case Primitive::kPrimInt:
2317 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002318 locations->SetInAt(0, Location::RequiresRegister());
2319 locations->SetInAt(1, Location::RequiresRegister());
2320 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002321 break;
2322 }
2323
Calin Juravleb5bfa962014-10-21 18:02:24 +01002324 case Primitive::kPrimFloat:
2325 case Primitive::kPrimDouble: {
2326 locations->SetInAt(0, Location::RequiresFpuRegister());
2327 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002328 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002329 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002330 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002331
2332 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002333 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002334 }
2335}
2336
2337void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2338 LocationSummary* locations = mul->GetLocations();
2339 Location out = locations->Out();
2340 Location first = locations->InAt(0);
2341 Location second = locations->InAt(1);
2342 switch (mul->GetResultType()) {
2343 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002344 __ mul(out.AsRegister<Register>(),
2345 first.AsRegister<Register>(),
2346 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002347 break;
2348 }
2349 case Primitive::kPrimLong: {
2350 Register out_hi = out.AsRegisterPairHigh<Register>();
2351 Register out_lo = out.AsRegisterPairLow<Register>();
2352 Register in1_hi = first.AsRegisterPairHigh<Register>();
2353 Register in1_lo = first.AsRegisterPairLow<Register>();
2354 Register in2_hi = second.AsRegisterPairHigh<Register>();
2355 Register in2_lo = second.AsRegisterPairLow<Register>();
2356
2357 // Extra checks to protect caused by the existence of R1_R2.
2358 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2359 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2360 DCHECK_NE(out_hi, in1_lo);
2361 DCHECK_NE(out_hi, in2_lo);
2362
2363 // input: in1 - 64 bits, in2 - 64 bits
2364 // output: out
2365 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2366 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2367 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2368
2369 // IP <- in1.lo * in2.hi
2370 __ mul(IP, in1_lo, in2_hi);
2371 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2372 __ mla(out_hi, in1_hi, in2_lo, IP);
2373 // out.lo <- (in1.lo * in2.lo)[31:0];
2374 __ umull(out_lo, IP, in1_lo, in2_lo);
2375 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2376 __ add(out_hi, out_hi, ShifterOperand(IP));
2377 break;
2378 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002379
2380 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002381 __ vmuls(out.AsFpuRegister<SRegister>(),
2382 first.AsFpuRegister<SRegister>(),
2383 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002384 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002385 }
2386
2387 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002388 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2389 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2390 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002391 break;
2392 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002393
2394 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002395 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002396 }
2397}
2398
Zheng Xuc6667102015-05-15 16:08:45 +08002399void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2400 DCHECK(instruction->IsDiv() || instruction->IsRem());
2401 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2402
2403 LocationSummary* locations = instruction->GetLocations();
2404 Location second = locations->InAt(1);
2405 DCHECK(second.IsConstant());
2406
2407 Register out = locations->Out().AsRegister<Register>();
2408 Register dividend = locations->InAt(0).AsRegister<Register>();
2409 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2410 DCHECK(imm == 1 || imm == -1);
2411
2412 if (instruction->IsRem()) {
2413 __ LoadImmediate(out, 0);
2414 } else {
2415 if (imm == 1) {
2416 __ Mov(out, dividend);
2417 } else {
2418 __ rsb(out, dividend, ShifterOperand(0));
2419 }
2420 }
2421}
2422
2423void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2424 DCHECK(instruction->IsDiv() || instruction->IsRem());
2425 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2426
2427 LocationSummary* locations = instruction->GetLocations();
2428 Location second = locations->InAt(1);
2429 DCHECK(second.IsConstant());
2430
2431 Register out = locations->Out().AsRegister<Register>();
2432 Register dividend = locations->InAt(0).AsRegister<Register>();
2433 Register temp = locations->GetTemp(0).AsRegister<Register>();
2434 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002435 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002436 DCHECK(IsPowerOfTwo(abs_imm));
2437 int ctz_imm = CTZ(abs_imm);
2438
2439 if (ctz_imm == 1) {
2440 __ Lsr(temp, dividend, 32 - ctz_imm);
2441 } else {
2442 __ Asr(temp, dividend, 31);
2443 __ Lsr(temp, temp, 32 - ctz_imm);
2444 }
2445 __ add(out, temp, ShifterOperand(dividend));
2446
2447 if (instruction->IsDiv()) {
2448 __ Asr(out, out, ctz_imm);
2449 if (imm < 0) {
2450 __ rsb(out, out, ShifterOperand(0));
2451 }
2452 } else {
2453 __ ubfx(out, out, 0, ctz_imm);
2454 __ sub(out, out, ShifterOperand(temp));
2455 }
2456}
2457
2458void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2459 DCHECK(instruction->IsDiv() || instruction->IsRem());
2460 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2461
2462 LocationSummary* locations = instruction->GetLocations();
2463 Location second = locations->InAt(1);
2464 DCHECK(second.IsConstant());
2465
2466 Register out = locations->Out().AsRegister<Register>();
2467 Register dividend = locations->InAt(0).AsRegister<Register>();
2468 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2469 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2470 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2471
2472 int64_t magic;
2473 int shift;
2474 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2475
2476 __ LoadImmediate(temp1, magic);
2477 __ smull(temp2, temp1, dividend, temp1);
2478
2479 if (imm > 0 && magic < 0) {
2480 __ add(temp1, temp1, ShifterOperand(dividend));
2481 } else if (imm < 0 && magic > 0) {
2482 __ sub(temp1, temp1, ShifterOperand(dividend));
2483 }
2484
2485 if (shift != 0) {
2486 __ Asr(temp1, temp1, shift);
2487 }
2488
2489 if (instruction->IsDiv()) {
2490 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2491 } else {
2492 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2493 // TODO: Strength reduction for mls.
2494 __ LoadImmediate(temp2, imm);
2495 __ mls(out, temp1, temp2, dividend);
2496 }
2497}
2498
2499void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2500 DCHECK(instruction->IsDiv() || instruction->IsRem());
2501 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2502
2503 LocationSummary* locations = instruction->GetLocations();
2504 Location second = locations->InAt(1);
2505 DCHECK(second.IsConstant());
2506
2507 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2508 if (imm == 0) {
2509 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2510 } else if (imm == 1 || imm == -1) {
2511 DivRemOneOrMinusOne(instruction);
2512 } else if (IsPowerOfTwo(std::abs(imm))) {
2513 DivRemByPowerOfTwo(instruction);
2514 } else {
2515 DCHECK(imm <= -2 || imm >= 2);
2516 GenerateDivRemWithAnyConstant(instruction);
2517 }
2518}
2519
Calin Juravle7c4954d2014-10-28 16:57:40 +00002520void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002521 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2522 if (div->GetResultType() == Primitive::kPrimLong) {
2523 // pLdiv runtime call.
2524 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002525 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2526 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002527 } else if (div->GetResultType() == Primitive::kPrimInt &&
2528 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2529 // pIdivmod runtime call.
2530 call_kind = LocationSummary::kCall;
2531 }
2532
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002533 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2534
Calin Juravle7c4954d2014-10-28 16:57:40 +00002535 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002536 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002537 if (div->InputAt(1)->IsConstant()) {
2538 locations->SetInAt(0, Location::RequiresRegister());
2539 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2540 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2541 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2542 if (abs_imm <= 1) {
2543 // No temp register required.
2544 } else {
2545 locations->AddTemp(Location::RequiresRegister());
2546 if (!IsPowerOfTwo(abs_imm)) {
2547 locations->AddTemp(Location::RequiresRegister());
2548 }
2549 }
2550 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002551 locations->SetInAt(0, Location::RequiresRegister());
2552 locations->SetInAt(1, Location::RequiresRegister());
2553 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2554 } else {
2555 InvokeRuntimeCallingConvention calling_convention;
2556 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2557 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2558 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2559 // we only need the former.
2560 locations->SetOut(Location::RegisterLocation(R0));
2561 }
Calin Juravled0d48522014-11-04 16:40:20 +00002562 break;
2563 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002564 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002565 InvokeRuntimeCallingConvention calling_convention;
2566 locations->SetInAt(0, Location::RegisterPairLocation(
2567 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2568 locations->SetInAt(1, Location::RegisterPairLocation(
2569 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002570 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002571 break;
2572 }
2573 case Primitive::kPrimFloat:
2574 case Primitive::kPrimDouble: {
2575 locations->SetInAt(0, Location::RequiresFpuRegister());
2576 locations->SetInAt(1, Location::RequiresFpuRegister());
2577 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2578 break;
2579 }
2580
2581 default:
2582 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2583 }
2584}
2585
2586void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2587 LocationSummary* locations = div->GetLocations();
2588 Location out = locations->Out();
2589 Location first = locations->InAt(0);
2590 Location second = locations->InAt(1);
2591
2592 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002593 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002594 if (second.IsConstant()) {
2595 GenerateDivRemConstantIntegral(div);
2596 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002597 __ sdiv(out.AsRegister<Register>(),
2598 first.AsRegister<Register>(),
2599 second.AsRegister<Register>());
2600 } else {
2601 InvokeRuntimeCallingConvention calling_convention;
2602 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2603 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2604 DCHECK_EQ(R0, out.AsRegister<Register>());
2605
2606 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2607 }
Calin Juravled0d48522014-11-04 16:40:20 +00002608 break;
2609 }
2610
Calin Juravle7c4954d2014-10-28 16:57:40 +00002611 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002612 InvokeRuntimeCallingConvention calling_convention;
2613 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2614 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2615 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2616 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2617 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002618 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002619
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002620 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002621 break;
2622 }
2623
2624 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002625 __ vdivs(out.AsFpuRegister<SRegister>(),
2626 first.AsFpuRegister<SRegister>(),
2627 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002628 break;
2629 }
2630
2631 case Primitive::kPrimDouble: {
2632 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2633 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2634 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2635 break;
2636 }
2637
2638 default:
2639 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2640 }
2641}
2642
Calin Juravlebacfec32014-11-14 15:54:36 +00002643void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002644 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002645
2646 // Most remainders are implemented in the runtime.
2647 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002648 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2649 // sdiv will be replaced by other instruction sequence.
2650 call_kind = LocationSummary::kNoCall;
2651 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2652 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002653 // Have hardware divide instruction for int, do it with three instructions.
2654 call_kind = LocationSummary::kNoCall;
2655 }
2656
Calin Juravlebacfec32014-11-14 15:54:36 +00002657 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2658
Calin Juravled2ec87d2014-12-08 14:24:46 +00002659 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002660 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002661 if (rem->InputAt(1)->IsConstant()) {
2662 locations->SetInAt(0, Location::RequiresRegister());
2663 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2664 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2665 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2666 if (abs_imm <= 1) {
2667 // No temp register required.
2668 } else {
2669 locations->AddTemp(Location::RequiresRegister());
2670 if (!IsPowerOfTwo(abs_imm)) {
2671 locations->AddTemp(Location::RequiresRegister());
2672 }
2673 }
2674 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002675 locations->SetInAt(0, Location::RequiresRegister());
2676 locations->SetInAt(1, Location::RequiresRegister());
2677 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2678 locations->AddTemp(Location::RequiresRegister());
2679 } else {
2680 InvokeRuntimeCallingConvention calling_convention;
2681 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2682 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2683 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2684 // we only need the latter.
2685 locations->SetOut(Location::RegisterLocation(R1));
2686 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002687 break;
2688 }
2689 case Primitive::kPrimLong: {
2690 InvokeRuntimeCallingConvention calling_convention;
2691 locations->SetInAt(0, Location::RegisterPairLocation(
2692 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2693 locations->SetInAt(1, Location::RegisterPairLocation(
2694 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2695 // The runtime helper puts the output in R2,R3.
2696 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2697 break;
2698 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002699 case Primitive::kPrimFloat: {
2700 InvokeRuntimeCallingConvention calling_convention;
2701 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2702 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2703 locations->SetOut(Location::FpuRegisterLocation(S0));
2704 break;
2705 }
2706
Calin Juravlebacfec32014-11-14 15:54:36 +00002707 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002708 InvokeRuntimeCallingConvention calling_convention;
2709 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2710 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2711 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2712 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2713 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002714 break;
2715 }
2716
2717 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002718 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002719 }
2720}
2721
2722void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2723 LocationSummary* locations = rem->GetLocations();
2724 Location out = locations->Out();
2725 Location first = locations->InAt(0);
2726 Location second = locations->InAt(1);
2727
Calin Juravled2ec87d2014-12-08 14:24:46 +00002728 Primitive::Type type = rem->GetResultType();
2729 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002730 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002731 if (second.IsConstant()) {
2732 GenerateDivRemConstantIntegral(rem);
2733 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002734 Register reg1 = first.AsRegister<Register>();
2735 Register reg2 = second.AsRegister<Register>();
2736 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002737
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002738 // temp = reg1 / reg2 (integer division)
2739 // temp = temp * reg2
2740 // dest = reg1 - temp
2741 __ sdiv(temp, reg1, reg2);
2742 __ mul(temp, temp, reg2);
2743 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2744 } else {
2745 InvokeRuntimeCallingConvention calling_convention;
2746 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2747 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2748 DCHECK_EQ(R1, out.AsRegister<Register>());
2749
2750 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2751 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002752 break;
2753 }
2754
2755 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002756 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002757 break;
2758 }
2759
Calin Juravled2ec87d2014-12-08 14:24:46 +00002760 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002761 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002762 break;
2763 }
2764
Calin Juravlebacfec32014-11-14 15:54:36 +00002765 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002766 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002767 break;
2768 }
2769
2770 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002771 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002772 }
2773}
2774
Calin Juravled0d48522014-11-04 16:40:20 +00002775void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2776 LocationSummary* locations =
2777 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002778 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002779 if (instruction->HasUses()) {
2780 locations->SetOut(Location::SameAsFirstInput());
2781 }
2782}
2783
2784void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2785 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2786 codegen_->AddSlowPath(slow_path);
2787
2788 LocationSummary* locations = instruction->GetLocations();
2789 Location value = locations->InAt(0);
2790
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002791 switch (instruction->GetType()) {
Serguei Katkov8c0676c2015-08-03 13:55:33 +06002792 case Primitive::kPrimByte:
2793 case Primitive::kPrimChar:
2794 case Primitive::kPrimShort:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002795 case Primitive::kPrimInt: {
2796 if (value.IsRegister()) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01002797 __ CompareAndBranchIfZero(value.AsRegister<Register>(), slow_path->GetEntryLabel());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002798 } else {
2799 DCHECK(value.IsConstant()) << value;
2800 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2801 __ b(slow_path->GetEntryLabel());
2802 }
2803 }
2804 break;
2805 }
2806 case Primitive::kPrimLong: {
2807 if (value.IsRegisterPair()) {
2808 __ orrs(IP,
2809 value.AsRegisterPairLow<Register>(),
2810 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2811 __ b(slow_path->GetEntryLabel(), EQ);
2812 } else {
2813 DCHECK(value.IsConstant()) << value;
2814 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2815 __ b(slow_path->GetEntryLabel());
2816 }
2817 }
2818 break;
2819 default:
2820 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2821 }
2822 }
Calin Juravled0d48522014-11-04 16:40:20 +00002823}
2824
Calin Juravle9aec02f2014-11-18 23:06:35 +00002825void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2826 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2827
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002828 LocationSummary* locations =
2829 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002830
2831 switch (op->GetResultType()) {
2832 case Primitive::kPrimInt: {
2833 locations->SetInAt(0, Location::RequiresRegister());
2834 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002835 // Make the output overlap, as it will be used to hold the masked
2836 // second input.
2837 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002838 break;
2839 }
2840 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002841 locations->SetInAt(0, Location::RequiresRegister());
2842 locations->SetInAt(1, Location::RequiresRegister());
2843 locations->AddTemp(Location::RequiresRegister());
2844 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002845 break;
2846 }
2847 default:
2848 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2849 }
2850}
2851
2852void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2853 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2854
2855 LocationSummary* locations = op->GetLocations();
2856 Location out = locations->Out();
2857 Location first = locations->InAt(0);
2858 Location second = locations->InAt(1);
2859
2860 Primitive::Type type = op->GetResultType();
2861 switch (type) {
2862 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002863 Register out_reg = out.AsRegister<Register>();
2864 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002865 // Arm doesn't mask the shift count so we need to do it ourselves.
2866 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002867 Register second_reg = second.AsRegister<Register>();
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002868 __ and_(out_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002869 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002870 __ Lsl(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002871 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002872 __ Asr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002873 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002874 __ Lsr(out_reg, first_reg, out_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002875 }
2876 } else {
2877 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2878 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2879 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2880 __ Mov(out_reg, first_reg);
2881 } else if (op->IsShl()) {
2882 __ Lsl(out_reg, first_reg, shift_value);
2883 } else if (op->IsShr()) {
2884 __ Asr(out_reg, first_reg, shift_value);
2885 } else {
2886 __ Lsr(out_reg, first_reg, shift_value);
2887 }
2888 }
2889 break;
2890 }
2891 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002892 Register o_h = out.AsRegisterPairHigh<Register>();
2893 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002894
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002895 Register temp = locations->GetTemp(0).AsRegister<Register>();
2896
2897 Register high = first.AsRegisterPairHigh<Register>();
2898 Register low = first.AsRegisterPairLow<Register>();
2899
2900 Register second_reg = second.AsRegister<Register>();
2901
Calin Juravle9aec02f2014-11-18 23:06:35 +00002902 if (op->IsShl()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002903 __ and_(o_l, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002904 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002905 __ Lsl(o_h, high, o_l);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002906 // Shift the low part and `or` what overflew on the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002907 __ rsb(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002908 __ Lsr(temp, low, temp);
2909 __ orr(o_h, o_h, ShifterOperand(temp));
2910 // If the shift is > 32 bits, override the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002911 __ subs(temp, o_l, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002912 __ it(PL);
2913 __ Lsl(o_h, low, temp, false, PL);
2914 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002915 __ Lsl(o_l, low, o_l);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002916 } else if (op->IsShr()) {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002917 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002918 // Shift the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002919 __ Lsr(o_l, low, o_h);
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002920 // Shift the high part and `or` what underflew on the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002921 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002922 __ Lsl(temp, high, temp);
2923 __ orr(o_l, o_l, ShifterOperand(temp));
2924 // If the shift is > 32 bits, override the low part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002925 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002926 __ it(PL);
2927 __ Asr(o_l, high, temp, false, PL);
2928 // Shift the high part
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002929 __ Asr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002930 } else {
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002931 __ and_(o_h, second_reg, ShifterOperand(kMaxLongShiftValue));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002932 // same as Shr except we use `Lsr`s and not `Asr`s
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002933 __ Lsr(o_l, low, o_h);
2934 __ rsb(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002935 __ Lsl(temp, high, temp);
2936 __ orr(o_l, o_l, ShifterOperand(temp));
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002937 __ subs(temp, o_h, ShifterOperand(kArmBitsPerWord));
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002938 __ it(PL);
2939 __ Lsr(o_l, high, temp, false, PL);
Nicolas Geoffraya4f35812015-06-22 23:12:45 +01002940 __ Lsr(o_h, high, o_h);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002941 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002942 break;
2943 }
2944 default:
2945 LOG(FATAL) << "Unexpected operation type " << type;
2946 }
2947}
2948
2949void LocationsBuilderARM::VisitShl(HShl* shl) {
2950 HandleShift(shl);
2951}
2952
2953void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2954 HandleShift(shl);
2955}
2956
2957void LocationsBuilderARM::VisitShr(HShr* shr) {
2958 HandleShift(shr);
2959}
2960
2961void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2962 HandleShift(shr);
2963}
2964
2965void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2966 HandleShift(ushr);
2967}
2968
2969void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2970 HandleShift(ushr);
2971}
2972
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002973void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002974 LocationSummary* locations =
2975 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002976 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002977 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002978 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002979 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002980}
2981
2982void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2983 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002984 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01002985 // Note: if heap poisoning is enabled, the entry point takes cares
2986 // of poisoning the reference.
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002987 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2988 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002989 instruction->GetDexPc(),
2990 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002991}
2992
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002993void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2994 LocationSummary* locations =
2995 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2996 InvokeRuntimeCallingConvention calling_convention;
2997 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002998 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002999 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01003000 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003001}
3002
3003void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
3004 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003005 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01003006 // Note: if heap poisoning is enabled, the entry point takes cares
3007 // of poisoning the reference.
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00003008 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
3009 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003010 instruction->GetDexPc(),
3011 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01003012}
3013
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003014void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003015 LocationSummary* locations =
3016 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003017 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
3018 if (location.IsStackSlot()) {
3019 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
3020 } else if (location.IsDoubleStackSlot()) {
3021 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003022 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01003023 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003024}
3025
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003026void InstructionCodeGeneratorARM::VisitParameterValue(
3027 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01003028 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003029}
3030
3031void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
3032 LocationSummary* locations =
3033 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3034 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
3035}
3036
3037void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
3038 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01003039}
3040
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003041void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003042 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003043 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003044 locations->SetInAt(0, Location::RequiresRegister());
3045 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003046}
3047
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003048void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
3049 LocationSummary* locations = not_->GetLocations();
3050 Location out = locations->Out();
3051 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00003052 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003053 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00003054 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003055 break;
3056
3057 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01003058 __ mvn(out.AsRegisterPairLow<Register>(),
3059 ShifterOperand(in.AsRegisterPairLow<Register>()));
3060 __ mvn(out.AsRegisterPairHigh<Register>(),
3061 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01003062 break;
3063
3064 default:
3065 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
3066 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01003067}
3068
David Brazdil66d126e2015-04-03 16:02:44 +01003069void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
3070 LocationSummary* locations =
3071 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
3072 locations->SetInAt(0, Location::RequiresRegister());
3073 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3074}
3075
3076void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01003077 LocationSummary* locations = bool_not->GetLocations();
3078 Location out = locations->Out();
3079 Location in = locations->InAt(0);
3080 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
3081}
3082
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003083void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003084 LocationSummary* locations =
3085 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00003086 switch (compare->InputAt(0)->GetType()) {
3087 case Primitive::kPrimLong: {
3088 locations->SetInAt(0, Location::RequiresRegister());
3089 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003090 // Output overlaps because it is written before doing the low comparison.
3091 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00003092 break;
3093 }
3094 case Primitive::kPrimFloat:
3095 case Primitive::kPrimDouble: {
3096 locations->SetInAt(0, Location::RequiresFpuRegister());
3097 locations->SetInAt(1, Location::RequiresFpuRegister());
3098 locations->SetOut(Location::RequiresRegister());
3099 break;
3100 }
3101 default:
3102 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
3103 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003104}
3105
3106void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003107 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003108 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00003109 Location left = locations->InAt(0);
3110 Location right = locations->InAt(1);
3111
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003112 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00003113 Primitive::Type type = compare->InputAt(0)->GetType();
3114 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003115 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003116 __ cmp(left.AsRegisterPairHigh<Register>(),
3117 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003118 __ b(&less, LT);
3119 __ b(&greater, GT);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003120 // Do LoadImmediate before the last `cmp`, as LoadImmediate might affect the status flags.
Calin Juravleddb7df22014-11-25 20:56:51 +00003121 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003122 __ cmp(left.AsRegisterPairLow<Register>(),
3123 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00003124 break;
3125 }
3126 case Primitive::kPrimFloat:
3127 case Primitive::kPrimDouble: {
3128 __ LoadImmediate(out, 0);
3129 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003130 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00003131 } else {
3132 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
3133 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
3134 }
3135 __ vmstat(); // transfer FP status register to ARM APSR.
3136 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003137 break;
3138 }
3139 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00003140 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003141 }
Calin Juravleddb7df22014-11-25 20:56:51 +00003142 __ b(&done, EQ);
Roland Levillain4fa13f62015-07-06 18:11:54 +01003143 __ b(&less, LO); // LO is for both: unsigned compare for longs and 'less than' for floats.
Calin Juravleddb7df22014-11-25 20:56:51 +00003144
3145 __ Bind(&greater);
3146 __ LoadImmediate(out, 1);
3147 __ b(&done);
3148
3149 __ Bind(&less);
3150 __ LoadImmediate(out, -1);
3151
3152 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01003153}
3154
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003155void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003156 LocationSummary* locations =
3157 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01003158 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
3159 locations->SetInAt(i, Location::Any());
3160 }
3161 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003162}
3163
3164void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003165 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003166 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01003167}
3168
Calin Juravle52c48962014-12-16 17:02:57 +00003169void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
3170 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07003171 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00003172 switch (kind) {
3173 case MemBarrierKind::kAnyStore:
3174 case MemBarrierKind::kLoadAny:
3175 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003176 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00003177 break;
3178 }
3179 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07003180 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00003181 break;
3182 }
3183 default:
3184 LOG(FATAL) << "Unexpected memory barrier " << kind;
3185 }
Kenny Root1d8199d2015-06-02 11:01:10 -07003186 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00003187}
3188
3189void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
3190 uint32_t offset,
3191 Register out_lo,
3192 Register out_hi) {
3193 if (offset != 0) {
3194 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003195 __ add(IP, addr, ShifterOperand(out_lo));
3196 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003197 }
3198 __ ldrexd(out_lo, out_hi, addr);
3199}
3200
3201void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
3202 uint32_t offset,
3203 Register value_lo,
3204 Register value_hi,
3205 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00003206 Register temp2,
3207 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003208 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00003209 if (offset != 0) {
3210 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00003211 __ add(IP, addr, ShifterOperand(temp1));
3212 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00003213 }
3214 __ Bind(&fail);
3215 // We need a load followed by store. (The address used in a STREX instruction must
3216 // be the same as the address in the most recently executed LDREX instruction.)
3217 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00003218 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003219 __ strexd(temp1, value_lo, value_hi, addr);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003220 __ CompareAndBranchIfNonZero(temp1, &fail);
Calin Juravle52c48962014-12-16 17:02:57 +00003221}
3222
3223void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3224 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3225
Nicolas Geoffray39468442014-09-02 15:17:15 +01003226 LocationSummary* locations =
3227 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003228 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003229
Calin Juravle52c48962014-12-16 17:02:57 +00003230 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003231 if (Primitive::IsFloatingPointType(field_type)) {
3232 locations->SetInAt(1, Location::RequiresFpuRegister());
3233 } else {
3234 locations->SetInAt(1, Location::RequiresRegister());
3235 }
3236
Calin Juravle52c48962014-12-16 17:02:57 +00003237 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003238 bool generate_volatile = field_info.IsVolatile()
3239 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003240 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Roland Levillain4d027112015-07-01 15:41:14 +01003241 bool needs_write_barrier =
3242 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003243 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003244 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
Roland Levillain4d027112015-07-01 15:41:14 +01003245 if (needs_write_barrier) {
3246 locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too.
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003247 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003248 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003249 // Arm encoding have some additional constraints for ldrexd/strexd:
3250 // - registers need to be consecutive
3251 // - the first register should be even but not R14.
3252 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3253 // enable Arm encoding.
3254 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3255
3256 locations->AddTemp(Location::RequiresRegister());
3257 locations->AddTemp(Location::RequiresRegister());
3258 if (field_type == Primitive::kPrimDouble) {
3259 // For doubles we need two more registers to copy the value.
3260 locations->AddTemp(Location::RegisterLocation(R2));
3261 locations->AddTemp(Location::RegisterLocation(R3));
3262 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003263 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003264}
3265
Calin Juravle52c48962014-12-16 17:02:57 +00003266void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003267 const FieldInfo& field_info,
3268 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003269 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3270
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003271 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003272 Register base = locations->InAt(0).AsRegister<Register>();
3273 Location value = locations->InAt(1);
3274
3275 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003276 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003277 Primitive::Type field_type = field_info.GetFieldType();
3278 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01003279 bool needs_write_barrier =
3280 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Calin Juravle52c48962014-12-16 17:02:57 +00003281
3282 if (is_volatile) {
3283 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3284 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003285
3286 switch (field_type) {
3287 case Primitive::kPrimBoolean:
3288 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003289 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003290 break;
3291 }
3292
3293 case Primitive::kPrimShort:
3294 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003295 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003296 break;
3297 }
3298
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003299 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003300 case Primitive::kPrimNot: {
Roland Levillain4d027112015-07-01 15:41:14 +01003301 if (kPoisonHeapReferences && needs_write_barrier) {
3302 // Note that in the case where `value` is a null reference,
3303 // we do not enter this block, as a null reference does not
3304 // need poisoning.
3305 DCHECK_EQ(field_type, Primitive::kPrimNot);
3306 Register temp = locations->GetTemp(0).AsRegister<Register>();
3307 __ Mov(temp, value.AsRegister<Register>());
3308 __ PoisonHeapReference(temp);
3309 __ StoreToOffset(kStoreWord, temp, base, offset);
3310 } else {
3311 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
3312 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003313 break;
3314 }
3315
3316 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003317 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003318 GenerateWideAtomicStore(base, offset,
3319 value.AsRegisterPairLow<Register>(),
3320 value.AsRegisterPairHigh<Register>(),
3321 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003322 locations->GetTemp(1).AsRegister<Register>(),
3323 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003324 } else {
3325 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003326 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003327 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003328 break;
3329 }
3330
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003331 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003332 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003333 break;
3334 }
3335
3336 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003337 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003338 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003339 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3340 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3341
3342 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3343
3344 GenerateWideAtomicStore(base, offset,
3345 value_reg_lo,
3346 value_reg_hi,
3347 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003348 locations->GetTemp(3).AsRegister<Register>(),
3349 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003350 } else {
3351 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003352 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003353 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003354 break;
3355 }
3356
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003357 case Primitive::kPrimVoid:
3358 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003359 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003360 }
Calin Juravle52c48962014-12-16 17:02:57 +00003361
Calin Juravle77520bc2015-01-12 18:45:46 +00003362 // Longs and doubles are handled in the switch.
3363 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3364 codegen_->MaybeRecordImplicitNullCheck(instruction);
3365 }
3366
3367 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3368 Register temp = locations->GetTemp(0).AsRegister<Register>();
3369 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003370 codegen_->MarkGCCard(
3371 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003372 }
3373
Calin Juravle52c48962014-12-16 17:02:57 +00003374 if (is_volatile) {
3375 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3376 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003377}
3378
Calin Juravle52c48962014-12-16 17:02:57 +00003379void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3380 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003381 LocationSummary* locations =
3382 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003383 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003384
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003385 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003386 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003387 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003388 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003389
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003390 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3391 locations->SetOut(Location::RequiresFpuRegister());
3392 } else {
3393 locations->SetOut(Location::RequiresRegister(),
3394 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3395 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003396 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003397 // Arm encoding have some additional constraints for ldrexd/strexd:
3398 // - registers need to be consecutive
3399 // - the first register should be even but not R14.
3400 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3401 // enable Arm encoding.
3402 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3403 locations->AddTemp(Location::RequiresRegister());
3404 locations->AddTemp(Location::RequiresRegister());
3405 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003406}
3407
Calin Juravle52c48962014-12-16 17:02:57 +00003408void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3409 const FieldInfo& field_info) {
3410 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003411
Calin Juravle52c48962014-12-16 17:02:57 +00003412 LocationSummary* locations = instruction->GetLocations();
3413 Register base = locations->InAt(0).AsRegister<Register>();
3414 Location out = locations->Out();
3415 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003416 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003417 Primitive::Type field_type = field_info.GetFieldType();
3418 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3419
3420 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003421 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003422 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003423 break;
3424 }
3425
3426 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003427 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003428 break;
3429 }
3430
3431 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003432 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003433 break;
3434 }
3435
3436 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003437 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003438 break;
3439 }
3440
3441 case Primitive::kPrimInt:
3442 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003443 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003444 break;
3445 }
3446
3447 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003448 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003449 GenerateWideAtomicLoad(base, offset,
3450 out.AsRegisterPairLow<Register>(),
3451 out.AsRegisterPairHigh<Register>());
3452 } else {
3453 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3454 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003455 break;
3456 }
3457
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003458 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003459 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003460 break;
3461 }
3462
3463 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003464 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003465 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003466 Register lo = locations->GetTemp(0).AsRegister<Register>();
3467 Register hi = locations->GetTemp(1).AsRegister<Register>();
3468 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003469 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003470 __ vmovdrr(out_reg, lo, hi);
3471 } else {
3472 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003473 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003474 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003475 break;
3476 }
3477
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003478 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003479 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003480 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003481 }
Calin Juravle52c48962014-12-16 17:02:57 +00003482
Calin Juravle77520bc2015-01-12 18:45:46 +00003483 // Doubles are handled in the switch.
3484 if (field_type != Primitive::kPrimDouble) {
3485 codegen_->MaybeRecordImplicitNullCheck(instruction);
3486 }
3487
Calin Juravle52c48962014-12-16 17:02:57 +00003488 if (is_volatile) {
3489 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3490 }
Roland Levillain4d027112015-07-01 15:41:14 +01003491
3492 if (field_type == Primitive::kPrimNot) {
3493 __ MaybeUnpoisonHeapReference(out.AsRegister<Register>());
3494 }
Calin Juravle52c48962014-12-16 17:02:57 +00003495}
3496
3497void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3498 HandleFieldSet(instruction, instruction->GetFieldInfo());
3499}
3500
3501void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003502 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003503}
3504
3505void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3506 HandleFieldGet(instruction, instruction->GetFieldInfo());
3507}
3508
3509void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3510 HandleFieldGet(instruction, instruction->GetFieldInfo());
3511}
3512
3513void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3514 HandleFieldGet(instruction, instruction->GetFieldInfo());
3515}
3516
3517void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3518 HandleFieldGet(instruction, instruction->GetFieldInfo());
3519}
3520
3521void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3522 HandleFieldSet(instruction, instruction->GetFieldInfo());
3523}
3524
3525void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003526 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003527}
3528
3529void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003530 LocationSummary* locations =
3531 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003532 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003533 if (instruction->HasUses()) {
3534 locations->SetOut(Location::SameAsFirstInput());
3535 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003536}
3537
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003538void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003539 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3540 return;
3541 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003542 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003543
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003544 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3545 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3546}
3547
3548void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003549 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003550 codegen_->AddSlowPath(slow_path);
3551
3552 LocationSummary* locations = instruction->GetLocations();
3553 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003554
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003555 __ CompareAndBranchIfZero(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003556}
3557
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003558void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3559 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3560 GenerateImplicitNullCheck(instruction);
3561 } else {
3562 GenerateExplicitNullCheck(instruction);
3563 }
3564}
3565
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003566void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003567 LocationSummary* locations =
3568 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003569 locations->SetInAt(0, Location::RequiresRegister());
3570 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003571 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3572 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3573 } else {
3574 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3575 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003576}
3577
3578void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3579 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003580 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003581 Location index = locations->InAt(1);
Roland Levillain4d027112015-07-01 15:41:14 +01003582 Primitive::Type type = instruction->GetType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003583
Roland Levillain4d027112015-07-01 15:41:14 +01003584 switch (type) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003585 case Primitive::kPrimBoolean: {
3586 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003587 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003588 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003589 size_t offset =
3590 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003591 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3592 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003593 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003594 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3595 }
3596 break;
3597 }
3598
3599 case Primitive::kPrimByte: {
3600 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003601 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003602 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003603 size_t offset =
3604 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003605 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3606 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003607 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003608 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3609 }
3610 break;
3611 }
3612
3613 case Primitive::kPrimShort: {
3614 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003615 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003616 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003617 size_t offset =
3618 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003619 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3620 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003621 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003622 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3623 }
3624 break;
3625 }
3626
3627 case Primitive::kPrimChar: {
3628 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003629 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003630 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003631 size_t offset =
3632 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003633 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3634 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003635 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003636 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3637 }
3638 break;
3639 }
3640
3641 case Primitive::kPrimInt:
3642 case Primitive::kPrimNot: {
Roland Levillain33d69032015-06-18 18:20:59 +01003643 static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
3644 "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003645 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003646 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003647 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003648 size_t offset =
3649 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003650 __ LoadFromOffset(kLoadWord, out, obj, offset);
3651 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003652 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003653 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3654 }
3655 break;
3656 }
3657
3658 case Primitive::kPrimLong: {
3659 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003660 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003661 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003662 size_t offset =
3663 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003664 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003665 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003666 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003667 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003668 }
3669 break;
3670 }
3671
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003672 case Primitive::kPrimFloat: {
3673 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3674 Location out = locations->Out();
3675 DCHECK(out.IsFpuRegister());
3676 if (index.IsConstant()) {
3677 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3678 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3679 } else {
3680 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3681 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3682 }
3683 break;
3684 }
3685
3686 case Primitive::kPrimDouble: {
3687 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3688 Location out = locations->Out();
3689 DCHECK(out.IsFpuRegisterPair());
3690 if (index.IsConstant()) {
3691 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3692 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3693 } else {
3694 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3695 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3696 }
3697 break;
3698 }
3699
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003700 case Primitive::kPrimVoid:
Roland Levillain4d027112015-07-01 15:41:14 +01003701 LOG(FATAL) << "Unreachable type " << type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003702 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003703 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003704 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01003705
3706 if (type == Primitive::kPrimNot) {
3707 Register out = locations->Out().AsRegister<Register>();
3708 __ MaybeUnpoisonHeapReference(out);
3709 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003710}
3711
3712void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003713 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003714
3715 bool needs_write_barrier =
3716 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3717 bool needs_runtime_call = instruction->NeedsTypeCheck();
3718
Nicolas Geoffray39468442014-09-02 15:17:15 +01003719 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003720 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3721 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003722 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003723 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3724 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3725 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003726 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003727 locations->SetInAt(0, Location::RequiresRegister());
3728 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003729 if (Primitive::IsFloatingPointType(value_type)) {
3730 locations->SetInAt(2, Location::RequiresFpuRegister());
3731 } else {
3732 locations->SetInAt(2, Location::RequiresRegister());
3733 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003734
3735 if (needs_write_barrier) {
3736 // Temporary registers for the write barrier.
Roland Levillain4d027112015-07-01 15:41:14 +01003737 locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003738 locations->AddTemp(Location::RequiresRegister());
3739 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003740 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003741}
3742
3743void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3744 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003745 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003746 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003747 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003748 bool needs_runtime_call = locations->WillCall();
3749 bool needs_write_barrier =
3750 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003751
3752 switch (value_type) {
3753 case Primitive::kPrimBoolean:
3754 case Primitive::kPrimByte: {
3755 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003756 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003757 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003758 size_t offset =
3759 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003760 __ StoreToOffset(kStoreByte, value, obj, offset);
3761 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003762 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003763 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3764 }
3765 break;
3766 }
3767
3768 case Primitive::kPrimShort:
3769 case Primitive::kPrimChar: {
3770 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003771 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003772 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003773 size_t offset =
3774 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003775 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3776 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003777 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003778 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3779 }
3780 break;
3781 }
3782
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003783 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003784 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003785 if (!needs_runtime_call) {
3786 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003787 Register value = locations->InAt(2).AsRegister<Register>();
Roland Levillain4d027112015-07-01 15:41:14 +01003788 Register source = value;
3789 if (kPoisonHeapReferences && needs_write_barrier) {
3790 // Note that in the case where `value` is a null reference,
3791 // we do not enter this block, as a null reference does not
3792 // need poisoning.
3793 DCHECK_EQ(value_type, Primitive::kPrimNot);
3794 Register temp = locations->GetTemp(0).AsRegister<Register>();
3795 __ Mov(temp, value);
3796 __ PoisonHeapReference(temp);
3797 source = temp;
3798 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003799 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003800 size_t offset =
3801 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Roland Levillain4d027112015-07-01 15:41:14 +01003802 __ StoreToOffset(kStoreWord, source, obj, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003803 } else {
3804 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003805 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Roland Levillain4d027112015-07-01 15:41:14 +01003806 __ StoreToOffset(kStoreWord, source, IP, data_offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003807 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003808 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003809 if (needs_write_barrier) {
3810 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003811 Register temp = locations->GetTemp(0).AsRegister<Register>();
3812 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003813 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003814 }
3815 } else {
3816 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain4d027112015-07-01 15:41:14 +01003817 // Note: if heap poisoning is enabled, pAputObject takes cares
3818 // of poisoning the reference.
Roland Levillain199f3362014-11-27 17:15:16 +00003819 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3820 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003821 instruction->GetDexPc(),
3822 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003823 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003824 break;
3825 }
3826
3827 case Primitive::kPrimLong: {
3828 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003829 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003830 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003831 size_t offset =
3832 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003833 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003834 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003835 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003836 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003837 }
3838 break;
3839 }
3840
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003841 case Primitive::kPrimFloat: {
3842 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3843 Location value = locations->InAt(2);
3844 DCHECK(value.IsFpuRegister());
3845 if (index.IsConstant()) {
3846 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3847 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3848 } else {
3849 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3850 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3851 }
3852 break;
3853 }
3854
3855 case Primitive::kPrimDouble: {
3856 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3857 Location value = locations->InAt(2);
3858 DCHECK(value.IsFpuRegisterPair());
3859 if (index.IsConstant()) {
3860 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3861 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3862 } else {
3863 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3864 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3865 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003866
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003867 break;
3868 }
3869
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003870 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003871 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003872 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003873 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003874
3875 // Ints and objects are handled in the switch.
3876 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3877 codegen_->MaybeRecordImplicitNullCheck(instruction);
3878 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003879}
3880
3881void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003882 LocationSummary* locations =
3883 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003884 locations->SetInAt(0, Location::RequiresRegister());
3885 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003886}
3887
3888void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3889 LocationSummary* locations = instruction->GetLocations();
3890 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003891 Register obj = locations->InAt(0).AsRegister<Register>();
3892 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003893 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003894 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003895}
3896
3897void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003898 LocationSummary* locations =
3899 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003900 locations->SetInAt(0, Location::RequiresRegister());
3901 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003902 if (instruction->HasUses()) {
3903 locations->SetOut(Location::SameAsFirstInput());
3904 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003905}
3906
3907void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3908 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003909 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003910 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003911 codegen_->AddSlowPath(slow_path);
3912
Roland Levillain271ab9c2014-11-27 15:23:57 +00003913 Register index = locations->InAt(0).AsRegister<Register>();
3914 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003915
3916 __ cmp(index, ShifterOperand(length));
Roland Levillain4fa13f62015-07-06 18:11:54 +01003917 __ b(slow_path->GetEntryLabel(), HS);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003918}
3919
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003920void CodeGeneratorARM::MarkGCCard(Register temp,
3921 Register card,
3922 Register object,
3923 Register value,
3924 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003925 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003926 if (can_be_null) {
3927 __ CompareAndBranchIfZero(value, &is_null);
3928 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003929 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3930 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3931 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003932 if (can_be_null) {
3933 __ Bind(&is_null);
3934 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003935}
3936
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003937void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3938 temp->SetLocations(nullptr);
3939}
3940
3941void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3942 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003943 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003944}
3945
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003946void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003947 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003948 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003949}
3950
3951void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003952 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3953}
3954
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003955void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3956 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3957}
3958
3959void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003960 HBasicBlock* block = instruction->GetBlock();
3961 if (block->GetLoopInformation() != nullptr) {
3962 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3963 // The back edge will generate the suspend check.
3964 return;
3965 }
3966 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3967 // The goto will generate the suspend check.
3968 return;
3969 }
3970 GenerateSuspendCheck(instruction, nullptr);
3971}
3972
3973void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3974 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003975 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003976 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3977 if (slow_path == nullptr) {
3978 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3979 instruction->SetSlowPath(slow_path);
3980 codegen_->AddSlowPath(slow_path);
3981 if (successor != nullptr) {
3982 DCHECK(successor->IsLoopHeader());
3983 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3984 }
3985 } else {
3986 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3987 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003988
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003989 __ LoadFromOffset(
3990 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003991 if (successor == nullptr) {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003992 __ CompareAndBranchIfNonZero(IP, slow_path->GetEntryLabel());
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003993 __ Bind(slow_path->GetReturnLabel());
3994 } else {
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01003995 __ CompareAndBranchIfZero(IP, codegen_->GetLabelOf(successor));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003996 __ b(slow_path->GetEntryLabel());
3997 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003998}
3999
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004000ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
4001 return codegen_->GetAssembler();
4002}
4003
4004void ParallelMoveResolverARM::EmitMove(size_t index) {
4005 MoveOperands* move = moves_.Get(index);
4006 Location source = move->GetSource();
4007 Location destination = move->GetDestination();
4008
4009 if (source.IsRegister()) {
4010 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004011 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004012 } else {
4013 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00004014 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004015 SP, destination.GetStackIndex());
4016 }
4017 } else if (source.IsStackSlot()) {
4018 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004019 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004020 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004021 } else if (destination.IsFpuRegister()) {
4022 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004023 } else {
4024 DCHECK(destination.IsStackSlot());
4025 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
4026 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4027 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004028 } else if (source.IsFpuRegister()) {
4029 if (destination.IsFpuRegister()) {
4030 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004031 } else {
4032 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004033 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
4034 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004035 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004036 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004037 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
4038 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004039 } else if (destination.IsRegisterPair()) {
4040 DCHECK(ExpectedPairLayout(destination));
4041 __ LoadFromOffset(
4042 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
4043 } else {
4044 DCHECK(destination.IsFpuRegisterPair()) << destination;
4045 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4046 SP,
4047 source.GetStackIndex());
4048 }
4049 } else if (source.IsRegisterPair()) {
4050 if (destination.IsRegisterPair()) {
4051 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
4052 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
4053 } else {
4054 DCHECK(destination.IsDoubleStackSlot()) << destination;
4055 DCHECK(ExpectedPairLayout(source));
4056 __ StoreToOffset(
4057 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
4058 }
4059 } else if (source.IsFpuRegisterPair()) {
4060 if (destination.IsFpuRegisterPair()) {
4061 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
4062 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
4063 } else {
4064 DCHECK(destination.IsDoubleStackSlot()) << destination;
4065 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
4066 SP,
4067 destination.GetStackIndex());
4068 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004069 } else {
4070 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00004071 HConstant* constant = source.GetConstant();
4072 if (constant->IsIntConstant() || constant->IsNullConstant()) {
4073 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004074 if (destination.IsRegister()) {
4075 __ LoadImmediate(destination.AsRegister<Register>(), value);
4076 } else {
4077 DCHECK(destination.IsStackSlot());
4078 __ LoadImmediate(IP, value);
4079 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4080 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004081 } else if (constant->IsLongConstant()) {
4082 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004083 if (destination.IsRegisterPair()) {
4084 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
4085 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004086 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004087 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004088 __ LoadImmediate(IP, Low32Bits(value));
4089 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4090 __ LoadImmediate(IP, High32Bits(value));
4091 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4092 }
4093 } else if (constant->IsDoubleConstant()) {
4094 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004095 if (destination.IsFpuRegisterPair()) {
4096 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004097 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004098 DCHECK(destination.IsDoubleStackSlot()) << destination;
4099 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004100 __ LoadImmediate(IP, Low32Bits(int_value));
4101 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4102 __ LoadImmediate(IP, High32Bits(int_value));
4103 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
4104 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004105 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00004106 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004107 float value = constant->AsFloatConstant()->GetValue();
4108 if (destination.IsFpuRegister()) {
4109 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
4110 } else {
4111 DCHECK(destination.IsStackSlot());
4112 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
4113 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
4114 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01004115 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004116 }
4117}
4118
4119void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
4120 __ Mov(IP, reg);
4121 __ LoadFromOffset(kLoadWord, reg, SP, mem);
4122 __ StoreToOffset(kStoreWord, IP, SP, mem);
4123}
4124
4125void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
4126 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
4127 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
4128 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
4129 SP, mem1 + stack_offset);
4130 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
4131 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
4132 SP, mem2 + stack_offset);
4133 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
4134}
4135
4136void ParallelMoveResolverARM::EmitSwap(size_t index) {
4137 MoveOperands* move = moves_.Get(index);
4138 Location source = move->GetSource();
4139 Location destination = move->GetDestination();
4140
4141 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004142 DCHECK_NE(source.AsRegister<Register>(), IP);
4143 DCHECK_NE(destination.AsRegister<Register>(), IP);
4144 __ Mov(IP, source.AsRegister<Register>());
4145 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
4146 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004147 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004148 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004149 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004150 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004151 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
4152 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004153 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004154 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004155 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004156 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004157 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004158 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004159 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004160 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004161 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
4162 destination.AsRegisterPairHigh<Register>(),
4163 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004164 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004165 Register low_reg = source.IsRegisterPair()
4166 ? source.AsRegisterPairLow<Register>()
4167 : destination.AsRegisterPairLow<Register>();
4168 int mem = source.IsRegisterPair()
4169 ? destination.GetStackIndex()
4170 : source.GetStackIndex();
4171 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004172 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004173 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004174 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004175 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004176 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
4177 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004178 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004179 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004180 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004181 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
4182 DRegister reg = source.IsFpuRegisterPair()
4183 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
4184 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
4185 int mem = source.IsFpuRegisterPair()
4186 ? destination.GetStackIndex()
4187 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004188 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004189 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00004190 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00004191 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
4192 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
4193 : destination.AsFpuRegister<SRegister>();
4194 int mem = source.IsFpuRegister()
4195 ? destination.GetStackIndex()
4196 : source.GetStackIndex();
4197
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004198 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00004199 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00004200 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004201 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004202 Exchange(source.GetStackIndex(), destination.GetStackIndex());
4203 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004204 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00004205 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01004206 }
4207}
4208
4209void ParallelMoveResolverARM::SpillScratch(int reg) {
4210 __ Push(static_cast<Register>(reg));
4211}
4212
4213void ParallelMoveResolverARM::RestoreScratch(int reg) {
4214 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01004215}
4216
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004217void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004218 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
4219 ? LocationSummary::kCallOnSlowPath
4220 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004221 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004222 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004223 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004224 locations->SetOut(Location::RequiresRegister());
4225}
4226
4227void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004228 LocationSummary* locations = cls->GetLocations();
4229 Register out = locations->Out().AsRegister<Register>();
4230 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004231 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004232 DCHECK(!cls->CanCallRuntime());
4233 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004234 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004235 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004236 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004237 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004238 __ LoadFromOffset(kLoadWord,
4239 out,
4240 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004241 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004242 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Roland Levillain4d027112015-07-01 15:41:14 +01004243 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004244
4245 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4246 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4247 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004248 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004249 if (cls->MustGenerateClinitCheck()) {
4250 GenerateClassInitializationCheck(slow_path, out);
4251 } else {
4252 __ Bind(slow_path->GetExitLabel());
4253 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004254 }
4255}
4256
4257void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
4258 LocationSummary* locations =
4259 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
4260 locations->SetInAt(0, Location::RequiresRegister());
4261 if (check->HasUses()) {
4262 locations->SetOut(Location::SameAsFirstInput());
4263 }
4264}
4265
4266void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004267 // We assume the class is not null.
4268 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4269 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004270 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004271 GenerateClassInitializationCheck(slow_path,
4272 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004273}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004274
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004275void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
4276 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004277 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4278 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4279 __ b(slow_path->GetEntryLabel(), LT);
4280 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4281 // properly. Therefore, we do a memory fence.
4282 __ dmb(ISH);
4283 __ Bind(slow_path->GetExitLabel());
4284}
4285
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004286void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4287 LocationSummary* locations =
4288 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004289 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004290 locations->SetOut(Location::RequiresRegister());
4291}
4292
4293void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4294 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4295 codegen_->AddSlowPath(slow_path);
4296
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004297 LocationSummary* locations = load->GetLocations();
4298 Register out = locations->Out().AsRegister<Register>();
4299 Register current_method = locations->InAt(0).AsRegister<Register>();
4300 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004301 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004302 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Roland Levillain4d027112015-07-01 15:41:14 +01004303 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004304 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
Roland Levillain4d027112015-07-01 15:41:14 +01004305 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray2bcb4312015-07-01 12:22:56 +01004306 __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004307 __ Bind(slow_path->GetExitLabel());
4308}
4309
David Brazdilcb1c0552015-08-04 16:22:25 +01004310static int32_t GetExceptionTlsOffset() {
4311 return Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4312}
4313
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004314void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4315 LocationSummary* locations =
4316 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4317 locations->SetOut(Location::RequiresRegister());
4318}
4319
4320void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004321 Register out = load->GetLocations()->Out().AsRegister<Register>();
David Brazdilcb1c0552015-08-04 16:22:25 +01004322 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4323}
4324
4325void LocationsBuilderARM::VisitClearException(HClearException* clear) {
4326 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4327}
4328
4329void InstructionCodeGeneratorARM::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004330 __ LoadImmediate(IP, 0);
David Brazdilcb1c0552015-08-04 16:22:25 +01004331 __ StoreToOffset(kStoreWord, IP, TR, GetExceptionTlsOffset());
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004332}
4333
4334void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4335 LocationSummary* locations =
4336 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4337 InvokeRuntimeCallingConvention calling_convention;
4338 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4339}
4340
4341void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4342 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004343 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004344}
4345
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004346void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004347 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4348 ? LocationSummary::kNoCall
4349 : LocationSummary::kCallOnSlowPath;
4350 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4351 locations->SetInAt(0, Location::RequiresRegister());
4352 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004353 // The out register is used as a temporary, so it overlaps with the inputs.
4354 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004355}
4356
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004357void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004358 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004359 Register obj = locations->InAt(0).AsRegister<Register>();
4360 Register cls = locations->InAt(1).AsRegister<Register>();
4361 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004362 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004363 Label done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004364 SlowPathCodeARM* slow_path = nullptr;
4365
4366 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004367 // avoid null check if we know obj is not null.
4368 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004369 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004370 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004371 // Compare the class of `obj` with `cls`.
4372 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
Roland Levillain4d027112015-07-01 15:41:14 +01004373 __ MaybeUnpoisonHeapReference(out);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004374 __ cmp(out, ShifterOperand(cls));
4375 if (instruction->IsClassFinal()) {
4376 // Classes must be equal for the instanceof to succeed.
4377 __ b(&zero, NE);
4378 __ LoadImmediate(out, 1);
4379 __ b(&done);
4380 } else {
4381 // If the classes are not equal, we go into a slow path.
4382 DCHECK(locations->OnlyCallsOnSlowPath());
4383 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004384 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004385 codegen_->AddSlowPath(slow_path);
4386 __ b(slow_path->GetEntryLabel(), NE);
4387 __ LoadImmediate(out, 1);
4388 __ b(&done);
4389 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004390
4391 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4392 __ Bind(&zero);
4393 __ LoadImmediate(out, 0);
4394 }
4395
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004396 if (slow_path != nullptr) {
4397 __ Bind(slow_path->GetExitLabel());
4398 }
4399 __ Bind(&done);
4400}
4401
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004402void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4403 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4404 instruction, LocationSummary::kCallOnSlowPath);
4405 locations->SetInAt(0, Location::RequiresRegister());
4406 locations->SetInAt(1, Location::RequiresRegister());
4407 locations->AddTemp(Location::RequiresRegister());
4408}
4409
4410void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4411 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004412 Register obj = locations->InAt(0).AsRegister<Register>();
4413 Register cls = locations->InAt(1).AsRegister<Register>();
4414 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004415 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4416
4417 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4418 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4419 codegen_->AddSlowPath(slow_path);
4420
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004421 // avoid null check if we know obj is not null.
4422 if (instruction->MustDoNullCheck()) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004423 __ CompareAndBranchIfZero(obj, slow_path->GetExitLabel());
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004424 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004425 // Compare the class of `obj` with `cls`.
4426 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
Roland Levillain4d027112015-07-01 15:41:14 +01004427 __ MaybeUnpoisonHeapReference(temp);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004428 __ cmp(temp, ShifterOperand(cls));
Roland Levillain4d027112015-07-01 15:41:14 +01004429 // The checkcast succeeds if the classes are equal (fast path).
4430 // Otherwise, we need to go into the slow path to check the types.
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004431 __ b(slow_path->GetEntryLabel(), NE);
4432 __ Bind(slow_path->GetExitLabel());
4433}
4434
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004435void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4436 LocationSummary* locations =
4437 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4438 InvokeRuntimeCallingConvention calling_convention;
4439 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4440}
4441
4442void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4443 codegen_->InvokeRuntime(instruction->IsEnter()
4444 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4445 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004446 instruction->GetDexPc(),
4447 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004448}
4449
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004450void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4451void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4452void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4453
4454void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4455 LocationSummary* locations =
4456 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4457 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4458 || instruction->GetResultType() == Primitive::kPrimLong);
4459 locations->SetInAt(0, Location::RequiresRegister());
4460 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004461 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004462}
4463
4464void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4465 HandleBitwiseOperation(instruction);
4466}
4467
4468void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4469 HandleBitwiseOperation(instruction);
4470}
4471
4472void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4473 HandleBitwiseOperation(instruction);
4474}
4475
4476void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4477 LocationSummary* locations = instruction->GetLocations();
4478
4479 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004480 Register first = locations->InAt(0).AsRegister<Register>();
4481 Register second = locations->InAt(1).AsRegister<Register>();
4482 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004483 if (instruction->IsAnd()) {
4484 __ and_(out, first, ShifterOperand(second));
4485 } else if (instruction->IsOr()) {
4486 __ orr(out, first, ShifterOperand(second));
4487 } else {
4488 DCHECK(instruction->IsXor());
4489 __ eor(out, first, ShifterOperand(second));
4490 }
4491 } else {
4492 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4493 Location first = locations->InAt(0);
4494 Location second = locations->InAt(1);
4495 Location out = locations->Out();
4496 if (instruction->IsAnd()) {
4497 __ and_(out.AsRegisterPairLow<Register>(),
4498 first.AsRegisterPairLow<Register>(),
4499 ShifterOperand(second.AsRegisterPairLow<Register>()));
4500 __ and_(out.AsRegisterPairHigh<Register>(),
4501 first.AsRegisterPairHigh<Register>(),
4502 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4503 } else if (instruction->IsOr()) {
4504 __ orr(out.AsRegisterPairLow<Register>(),
4505 first.AsRegisterPairLow<Register>(),
4506 ShifterOperand(second.AsRegisterPairLow<Register>()));
4507 __ orr(out.AsRegisterPairHigh<Register>(),
4508 first.AsRegisterPairHigh<Register>(),
4509 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4510 } else {
4511 DCHECK(instruction->IsXor());
4512 __ eor(out.AsRegisterPairLow<Register>(),
4513 first.AsRegisterPairLow<Register>(),
4514 ShifterOperand(second.AsRegisterPairLow<Register>()));
4515 __ eor(out.AsRegisterPairHigh<Register>(),
4516 first.AsRegisterPairHigh<Register>(),
4517 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4518 }
4519 }
4520}
4521
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004522void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004523 // TODO: Implement all kinds of calls:
4524 // 1) boot -> boot
4525 // 2) app -> boot
4526 // 3) app -> app
4527 //
4528 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4529
Jeff Hao848f70a2014-01-15 13:49:50 -08004530 if (invoke->IsStringInit()) {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004531 Register reg = temp.AsRegister<Register>();
Jeff Hao848f70a2014-01-15 13:49:50 -08004532 // temp = thread->string_init_entrypoint
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004533 __ LoadFromOffset(kLoadWord, reg, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004534 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004535 __ LoadFromOffset(kLoadWord, LR, reg,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004536 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004537 kArmWordSize).Int32Value());
4538 // LR()
4539 __ blx(LR);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004540 } else if (invoke->IsRecursive()) {
4541 __ bl(GetFrameEntryLabel());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004542 } else {
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004543 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4544 Register method_reg;
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004545 Register reg = temp.AsRegister<Register>();
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004546 if (current_method.IsRegister()) {
4547 method_reg = current_method.AsRegister<Register>();
4548 } else {
4549 DCHECK(invoke->GetLocations()->Intrinsified());
4550 DCHECK(!current_method.IsValid());
4551 method_reg = reg;
4552 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4553 }
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004554 // reg = current_method->dex_cache_resolved_methods_;
4555 __ LoadFromOffset(
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004556 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004557 // reg = reg[index_in_cache]
4558 __ LoadFromOffset(
4559 kLoadWord, reg, reg, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4560 // LR = reg[offset_of_quick_compiled_code]
4561 __ LoadFromOffset(kLoadWord, LR, reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4562 kArmWordSize).Int32Value());
4563 // LR()
4564 __ blx(LR);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004565 }
4566
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004567 DCHECK(!IsLeafMethod());
4568}
4569
Calin Juravleb1498f62015-02-16 13:13:29 +00004570void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4571 // Nothing to do, this should be removed during prepare for register allocator.
4572 UNUSED(instruction);
4573 LOG(FATAL) << "Unreachable";
4574}
4575
4576void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4577 // Nothing to do, this should be removed during prepare for register allocator.
4578 UNUSED(instruction);
4579 LOG(FATAL) << "Unreachable";
4580}
4581
Nicolas Geoffray2e7cd752015-07-10 11:38:52 +01004582void LocationsBuilderARM::VisitFakeString(HFakeString* instruction) {
4583 DCHECK(codegen_->IsBaseline());
4584 LocationSummary* locations =
4585 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4586 locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant()));
4587}
4588
4589void InstructionCodeGeneratorARM::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) {
4590 DCHECK(codegen_->IsBaseline());
4591 // Will be generated at use site.
4592}
4593
Roland Levillain4d027112015-07-01 15:41:14 +01004594#undef __
4595#undef QUICK_ENTRY_POINT
4596
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004597} // namespace arm
4598} // namespace art