blob: 41d80174bb8f94480dda6bbf6dd72b28ba590075 [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"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070020#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010021#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080022#include "intrinsics.h"
23#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070024#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000025#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010026#include "mirror/class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070027#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010028#include "utils/arm/assembler_arm.h"
29#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000030#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010031#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000032
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000033namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010034
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000035namespace arm {
36
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000037static bool ExpectedPairLayout(Location location) {
38 // We expected this for both core and fpu register pairs.
39 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
40}
41
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010042static constexpr int kCurrentMethodStackOffset = 0;
43
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000044// We unconditionally allocate R5 to ensure we can do long operations
45// with baseline.
46static constexpr Register kCoreSavedRegisterForBaseline = R5;
47static constexpr Register kCoreCalleeSaves[] =
48 { R5, R6, R7, R8, R10, R11, PC };
49static constexpr SRegister kFpuCalleeSaves[] =
50 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010051
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000052// D31 cannot be split into two S registers, and the register allocator only works on
53// S registers. Therefore there is no need to block it.
54static constexpr DRegister DTMP = D31;
55
Nicolas Geoffraye5038322014-07-04 09:41:32 +010056#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010057#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010058
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010059class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010060 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010061 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062
Alexandre Rames67555f72014-11-18 10:55:16 +000063 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010064 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010065 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010066 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000067 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010068 }
69
70 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010071 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010072 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
73};
74
Calin Juravled0d48522014-11-04 16:40:20 +000075class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
76 public:
77 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
78
Alexandre Rames67555f72014-11-18 10:55:16 +000079 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000080 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
81 __ Bind(GetEntryLabel());
82 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000083 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +000084 }
85
86 private:
87 HDivZeroCheck* const instruction_;
88 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
89};
90
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010091class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000092 public:
Alexandre Rames67555f72014-11-18 10:55:16 +000093 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +010094 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000095
Alexandre Rames67555f72014-11-18 10:55:16 +000096 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010097 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000098 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +000099 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100100 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000101 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000102 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100103 if (successor_ == nullptr) {
104 __ b(GetReturnLabel());
105 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100106 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100107 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000108 }
109
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100110 Label* GetReturnLabel() {
111 DCHECK(successor_ == nullptr);
112 return &return_label_;
113 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000114
115 private:
116 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100117 // If not null, the block to branch to after the suspend check.
118 HBasicBlock* const successor_;
119
120 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000121 Label return_label_;
122
123 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
124};
125
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100126class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100127 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100128 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
129 Location index_location,
130 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100131 : instruction_(instruction),
132 index_location_(index_location),
133 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100134
Alexandre Rames67555f72014-11-18 10:55:16 +0000135 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100136 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100137 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000138 // We're moving two locations to locations that could overlap, so we need a parallel
139 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100140 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000141 codegen->EmitParallelMoves(
142 index_location_,
143 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100144 Primitive::kPrimInt,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000145 length_location_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100146 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
147 Primitive::kPrimInt);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100148 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000149 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100150 }
151
152 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100153 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100154 const Location index_location_;
155 const Location length_location_;
156
157 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
158};
159
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000160class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100161 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000162 LoadClassSlowPathARM(HLoadClass* cls,
163 HInstruction* at,
164 uint32_t dex_pc,
165 bool do_clinit)
166 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
167 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
168 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100169
Alexandre Rames67555f72014-11-18 10:55:16 +0000170 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000171 LocationSummary* locations = at_->GetLocations();
172
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100173 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
174 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000175 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100176
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100177 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000178 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100179 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000180 int32_t entry_point_offset = do_clinit_
181 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
182 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000183 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000184
185 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000186 Location out = locations->Out();
187 if (out.IsValid()) {
188 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000189 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
190 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000191 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100192 __ b(GetExitLabel());
193 }
194
195 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000196 // The class this slow path will load.
197 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100198
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000199 // The instruction where this slow path is happening.
200 // (Might be the load class or an initialization check).
201 HInstruction* const at_;
202
203 // The dex PC of `at_`.
204 const uint32_t dex_pc_;
205
206 // Whether to initialize the class.
207 const bool do_clinit_;
208
209 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210};
211
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000212class LoadStringSlowPathARM : public SlowPathCodeARM {
213 public:
214 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
215
Alexandre Rames67555f72014-11-18 10:55:16 +0000216 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000217 LocationSummary* locations = instruction_->GetLocations();
218 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
219
220 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
221 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000222 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000223
224 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800225 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
226 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000227 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000228 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000229 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
230
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000231 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000232 __ b(GetExitLabel());
233 }
234
235 private:
236 HLoadString* const instruction_;
237
238 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
239};
240
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000241class TypeCheckSlowPathARM : public SlowPathCodeARM {
242 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000243 TypeCheckSlowPathARM(HInstruction* instruction,
244 Location class_to_check,
245 Location object_class,
246 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000247 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000248 class_to_check_(class_to_check),
249 object_class_(object_class),
250 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000251
Alexandre Rames67555f72014-11-18 10:55:16 +0000252 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000253 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000254 DCHECK(instruction_->IsCheckCast()
255 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000256
257 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
258 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000259 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000260
261 // We're moving two locations to locations that could overlap, so we need a parallel
262 // move resolver.
263 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000264 codegen->EmitParallelMoves(
265 class_to_check_,
266 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100267 Primitive::kPrimNot,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000268 object_class_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100269 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
270 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000271
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000272 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000273 arm_codegen->InvokeRuntime(
274 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000275 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
276 } else {
277 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000278 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000279 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000280
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000281 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000282 __ b(GetExitLabel());
283 }
284
285 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000286 HInstruction* const instruction_;
287 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000288 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000289 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000290
291 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
292};
293
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700294class DeoptimizationSlowPathARM : public SlowPathCodeARM {
295 public:
296 explicit DeoptimizationSlowPathARM(HInstruction* instruction)
297 : instruction_(instruction) {}
298
299 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
300 __ Bind(GetEntryLabel());
301 SaveLiveRegisters(codegen, instruction_->GetLocations());
302 DCHECK(instruction_->IsDeoptimize());
303 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
304 uint32_t dex_pc = deoptimize->GetDexPc();
305 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
306 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
307 }
308
309 private:
310 HInstruction* const instruction_;
311 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
312};
313
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000314#undef __
315
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100316#undef __
317#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700318
319inline Condition ARMCondition(IfCondition cond) {
320 switch (cond) {
321 case kCondEQ: return EQ;
322 case kCondNE: return NE;
323 case kCondLT: return LT;
324 case kCondLE: return LE;
325 case kCondGT: return GT;
326 case kCondGE: return GE;
327 default:
328 LOG(FATAL) << "Unknown if condition";
329 }
330 return EQ; // Unreachable.
331}
332
333inline Condition ARMOppositeCondition(IfCondition cond) {
334 switch (cond) {
335 case kCondEQ: return NE;
336 case kCondNE: return EQ;
337 case kCondLT: return GE;
338 case kCondLE: return GT;
339 case kCondGT: return LE;
340 case kCondGE: return LT;
341 default:
342 LOG(FATAL) << "Unknown if condition";
343 }
344 return EQ; // Unreachable.
345}
346
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100347void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
348 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
349}
350
351void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000352 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100353}
354
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100355size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
356 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
357 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100358}
359
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100360size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
361 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
362 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100363}
364
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000365size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
366 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
367 return kArmWordSize;
368}
369
370size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
371 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
372 return kArmWordSize;
373}
374
Calin Juravle34166012014-12-19 17:22:29 +0000375CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000376 const ArmInstructionSetFeatures& isa_features,
377 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000378 : CodeGenerator(graph,
379 kNumberOfCoreRegisters,
380 kNumberOfSRegisters,
381 kNumberOfRegisterPairs,
382 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
383 arraysize(kCoreCalleeSaves)),
384 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
385 arraysize(kFpuCalleeSaves)),
386 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100387 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100388 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100389 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100390 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000391 assembler_(true),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000392 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000393 // Save the PC register to mimic Quick.
394 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100395}
396
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100397Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100398 switch (type) {
399 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100400 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100401 ArmManagedRegister pair =
402 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100403 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
404 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
405
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100406 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
407 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100408 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100409 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100410 }
411
412 case Primitive::kPrimByte:
413 case Primitive::kPrimBoolean:
414 case Primitive::kPrimChar:
415 case Primitive::kPrimShort:
416 case Primitive::kPrimInt:
417 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100418 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100419 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100420 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
421 ArmManagedRegister current =
422 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
423 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100424 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100425 }
426 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100427 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100428 }
429
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000430 case Primitive::kPrimFloat: {
431 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100432 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100433 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100434
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000435 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000436 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
437 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000438 return Location::FpuRegisterPairLocation(reg, reg + 1);
439 }
440
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100441 case Primitive::kPrimVoid:
442 LOG(FATAL) << "Unreachable type " << type;
443 }
444
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100445 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100446}
447
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000448void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100449 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100450 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100451
452 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100453 blocked_core_registers_[SP] = true;
454 blocked_core_registers_[LR] = true;
455 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100456
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100457 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100458 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100459
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100460 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100461 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100462
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000463 if (is_baseline) {
464 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
465 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
466 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000467
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000468 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
469
470 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
471 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
472 }
473 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100474
475 UpdateBlockedPairRegisters();
476}
477
478void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
479 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
480 ArmManagedRegister current =
481 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
482 if (blocked_core_registers_[current.AsRegisterPairLow()]
483 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
484 blocked_register_pairs_[i] = true;
485 }
486 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100487}
488
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100489InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
490 : HGraphVisitor(graph),
491 assembler_(codegen->GetAssembler()),
492 codegen_(codegen) {}
493
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000494static uint32_t LeastSignificantBit(uint32_t mask) {
495 // ffs starts at 1.
496 return ffs(mask) - 1;
497}
498
499void CodeGeneratorARM::ComputeSpillMask() {
500 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000501 // Save one extra register for baseline. Note that on thumb2, there is no easy
502 // instruction to restore just the PC, so this actually helps both baseline
503 // and non-baseline to save and restore at least two registers at entry and exit.
504 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000505 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
506 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
507 // We use vpush and vpop for saving and restoring floating point registers, which take
508 // a SRegister and the number of registers to save/restore after that SRegister. We
509 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
510 // but in the range.
511 if (fpu_spill_mask_ != 0) {
512 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
513 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
514 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
515 fpu_spill_mask_ |= (1 << i);
516 }
517 }
518}
519
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100520static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100521 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100522}
523
524static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100525 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100526}
527
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000528void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000529 bool skip_overflow_check =
530 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000531 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000532 __ Bind(&frame_entry_label_);
533
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000534 if (HasEmptyFrame()) {
535 return;
536 }
537
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100538 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000539 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
540 __ LoadFromOffset(kLoadWord, IP, IP, 0);
541 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100542 }
543
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000544 // PC is in the list of callee-save to mimic Quick, but we need to push
545 // LR at entry instead.
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100546 uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR;
547 __ PushList(push_mask);
548 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask));
David Srbecky9d8606d2015-04-12 09:35:32 +0100549 __ cfi().RelOffsetForMany(DWARFReg(R0), 0, push_mask, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000550 if (fpu_spill_mask_ != 0) {
551 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
552 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100553 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100554 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000555 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100556 int adjust = GetFrameSize() - FrameEntrySpillSize();
557 __ AddConstant(SP, -adjust);
558 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100559 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000560}
561
562void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000563 if (HasEmptyFrame()) {
564 __ bx(LR);
565 return;
566 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100567 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100568 int adjust = GetFrameSize() - FrameEntrySpillSize();
569 __ AddConstant(SP, adjust);
570 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000571 if (fpu_spill_mask_ != 0) {
572 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
573 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100574 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
575 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000576 }
577 __ PopList(core_spill_mask_);
David Srbeckyc34dc932015-04-12 09:27:43 +0100578 __ cfi().RestoreState();
579 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000580}
581
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100582void CodeGeneratorARM::Bind(HBasicBlock* block) {
583 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000584}
585
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100586Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
587 switch (load->GetType()) {
588 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100589 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100590 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100591
592 case Primitive::kPrimInt:
593 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100594 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100595 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100596
597 case Primitive::kPrimBoolean:
598 case Primitive::kPrimByte:
599 case Primitive::kPrimChar:
600 case Primitive::kPrimShort:
601 case Primitive::kPrimVoid:
602 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700603 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100604 }
605
606 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700607 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100608}
609
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100610Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
611 switch (type) {
612 case Primitive::kPrimBoolean:
613 case Primitive::kPrimByte:
614 case Primitive::kPrimChar:
615 case Primitive::kPrimShort:
616 case Primitive::kPrimInt:
617 case Primitive::kPrimNot: {
618 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000619 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100620 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100621 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100622 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000623 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100624 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100625 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100626
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000627 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100628 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000629 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100630 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000631 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100632 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000633 if (calling_convention.GetRegisterAt(index) == R1) {
634 // Skip R1, and use R2_R3 instead.
635 gp_index_++;
636 index++;
637 }
638 }
639 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
640 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000641 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000642 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000643 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100644 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000645 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
646 }
647 }
648
649 case Primitive::kPrimFloat: {
650 uint32_t stack_index = stack_index_++;
651 if (float_index_ % 2 == 0) {
652 float_index_ = std::max(double_index_, float_index_);
653 }
654 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
655 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
656 } else {
657 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
658 }
659 }
660
661 case Primitive::kPrimDouble: {
662 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
663 uint32_t stack_index = stack_index_;
664 stack_index_ += 2;
665 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
666 uint32_t index = double_index_;
667 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000668 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000669 calling_convention.GetFpuRegisterAt(index),
670 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000671 DCHECK(ExpectedPairLayout(result));
672 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000673 } else {
674 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100675 }
676 }
677
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100678 case Primitive::kPrimVoid:
679 LOG(FATAL) << "Unexpected parameter type " << type;
680 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100681 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100682 return Location();
683}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100684
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000685Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
686 switch (type) {
687 case Primitive::kPrimBoolean:
688 case Primitive::kPrimByte:
689 case Primitive::kPrimChar:
690 case Primitive::kPrimShort:
691 case Primitive::kPrimInt:
692 case Primitive::kPrimNot: {
693 return Location::RegisterLocation(R0);
694 }
695
696 case Primitive::kPrimFloat: {
697 return Location::FpuRegisterLocation(S0);
698 }
699
700 case Primitive::kPrimLong: {
701 return Location::RegisterPairLocation(R0, R1);
702 }
703
704 case Primitive::kPrimDouble: {
705 return Location::FpuRegisterPairLocation(S0, S1);
706 }
707
708 case Primitive::kPrimVoid:
709 return Location();
710 }
711 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000712}
713
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100714void CodeGeneratorARM::Move32(Location destination, Location source) {
715 if (source.Equals(destination)) {
716 return;
717 }
718 if (destination.IsRegister()) {
719 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000720 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100721 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000722 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100723 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000724 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100725 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100726 } else if (destination.IsFpuRegister()) {
727 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000728 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100729 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000730 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100731 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000732 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100733 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100734 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000735 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100736 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000737 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100738 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000739 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100740 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000741 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100742 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
743 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100744 }
745 }
746}
747
748void CodeGeneratorARM::Move64(Location destination, Location source) {
749 if (source.Equals(destination)) {
750 return;
751 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100752 if (destination.IsRegisterPair()) {
753 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000754 EmitParallelMoves(
755 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
756 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100757 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000758 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100759 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
760 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100761 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000762 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100763 } else {
764 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000765 DCHECK(ExpectedPairLayout(destination));
766 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
767 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100768 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000769 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100770 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000771 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
772 SP,
773 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100774 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000775 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100776 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100777 } else {
778 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100779 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000780 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100781 if (source.AsRegisterPairLow<Register>() == R1) {
782 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100783 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
784 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100785 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100786 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100787 SP, destination.GetStackIndex());
788 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000789 } else if (source.IsFpuRegisterPair()) {
790 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
791 SP,
792 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100793 } else {
794 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000795 EmitParallelMoves(
796 Location::StackSlot(source.GetStackIndex()),
797 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100798 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000799 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100800 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
801 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100802 }
803 }
804}
805
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100806void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100807 LocationSummary* locations = instruction->GetLocations();
808 if (locations != nullptr && locations->Out().Equals(location)) {
809 return;
810 }
811
Calin Juravlea21f5982014-11-13 15:53:04 +0000812 if (locations != nullptr && locations->Out().IsConstant()) {
813 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000814 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
815 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000816 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000817 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000818 } else {
819 DCHECK(location.IsStackSlot());
820 __ LoadImmediate(IP, value);
821 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
822 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000823 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000824 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000825 int64_t value = const_to_move->AsLongConstant()->GetValue();
826 if (location.IsRegisterPair()) {
827 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
828 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
829 } else {
830 DCHECK(location.IsDoubleStackSlot());
831 __ LoadImmediate(IP, Low32Bits(value));
832 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
833 __ LoadImmediate(IP, High32Bits(value));
834 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
835 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100836 }
Roland Levillain476df552014-10-09 17:51:36 +0100837 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100838 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
839 switch (instruction->GetType()) {
840 case Primitive::kPrimBoolean:
841 case Primitive::kPrimByte:
842 case Primitive::kPrimChar:
843 case Primitive::kPrimShort:
844 case Primitive::kPrimInt:
845 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100846 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100847 Move32(location, Location::StackSlot(stack_slot));
848 break;
849
850 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100851 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100852 Move64(location, Location::DoubleStackSlot(stack_slot));
853 break;
854
855 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100856 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100857 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000858 } else if (instruction->IsTemporary()) {
859 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000860 if (temp_location.IsStackSlot()) {
861 Move32(location, temp_location);
862 } else {
863 DCHECK(temp_location.IsDoubleStackSlot());
864 Move64(location, temp_location);
865 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000866 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100867 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100868 switch (instruction->GetType()) {
869 case Primitive::kPrimBoolean:
870 case Primitive::kPrimByte:
871 case Primitive::kPrimChar:
872 case Primitive::kPrimShort:
873 case Primitive::kPrimNot:
874 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100875 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100876 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100877 break;
878
879 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100880 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100881 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100882 break;
883
884 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100885 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100886 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000887 }
888}
889
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100890void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
891 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000892 uint32_t dex_pc,
893 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100894 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
895 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000896 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100897 DCHECK(instruction->IsSuspendCheck()
898 || instruction->IsBoundsCheck()
899 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000900 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000901 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100902 || !IsLeafMethod());
903}
904
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000905void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000906 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000907}
908
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000909void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000910 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100911 DCHECK(!successor->IsExitBlock());
912
913 HBasicBlock* block = got->GetBlock();
914 HInstruction* previous = got->GetPrevious();
915
916 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000917 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100918 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
919 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
920 return;
921 }
922
923 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
924 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
925 }
926 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000927 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000928 }
929}
930
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000931void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000932 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000933}
934
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000935void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700936 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000937}
938
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700939void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
940 Label* true_target,
941 Label* false_target,
942 Label* always_true_target) {
943 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100944 if (cond->IsIntConstant()) {
945 // Constant condition, statically compared against 1.
946 int32_t cond_value = cond->AsIntConstant()->GetValue();
947 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700948 if (always_true_target != nullptr) {
949 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100950 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100951 return;
952 } else {
953 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100954 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100955 } else {
956 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
957 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700958 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
959 __ cmp(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100960 ShifterOperand(0));
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700961 __ b(true_target, NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100962 } else {
963 // Condition has not been materialized, use its inputs as the
964 // comparison and its condition as the branch condition.
965 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000966 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000967 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100968 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000969 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100970 } else {
971 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000972 HConstant* constant = locations->InAt(1).GetConstant();
973 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100974 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000975 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
976 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100977 } else {
978 Register temp = IP;
979 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000980 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100981 }
982 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700983 __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100984 }
Dave Allison20dfc792014-06-16 20:44:29 -0700985 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700986 if (false_target != nullptr) {
987 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000988 }
989}
990
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700991void LocationsBuilderARM::VisitIf(HIf* if_instr) {
992 LocationSummary* locations =
993 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
994 HInstruction* cond = if_instr->InputAt(0);
995 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
996 locations->SetInAt(0, Location::RequiresRegister());
997 }
998}
999
1000void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1001 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1002 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1003 Label* always_true_target = true_target;
1004 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1005 if_instr->IfTrueSuccessor())) {
1006 always_true_target = nullptr;
1007 }
1008 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1009 if_instr->IfFalseSuccessor())) {
1010 false_target = nullptr;
1011 }
1012 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1013}
1014
1015void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1016 LocationSummary* locations = new (GetGraph()->GetArena())
1017 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1018 HInstruction* cond = deoptimize->InputAt(0);
1019 DCHECK(cond->IsCondition());
1020 if (cond->AsCondition()->NeedsMaterialization()) {
1021 locations->SetInAt(0, Location::RequiresRegister());
1022 }
1023}
1024
1025void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1026 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1027 DeoptimizationSlowPathARM(deoptimize);
1028 codegen_->AddSlowPath(slow_path);
1029 Label* slow_path_entry = slow_path->GetEntryLabel();
1030 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1031}
Dave Allison20dfc792014-06-16 20:44:29 -07001032
1033void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001034 LocationSummary* locations =
1035 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001036 locations->SetInAt(0, Location::RequiresRegister());
1037 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001038 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001039 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001040 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001041}
1042
Dave Allison20dfc792014-06-16 20:44:29 -07001043void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001044 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001045 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001046 Register left = locations->InAt(0).AsRegister<Register>();
1047
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001048 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001049 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001050 } else {
1051 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -08001052 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001053 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001054 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1055 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001056 } else {
1057 Register temp = IP;
1058 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001059 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001060 }
Dave Allison20dfc792014-06-16 20:44:29 -07001061 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001062 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001063 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001064 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001065 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001066 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001067}
1068
1069void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1070 VisitCondition(comp);
1071}
1072
1073void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1074 VisitCondition(comp);
1075}
1076
1077void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1078 VisitCondition(comp);
1079}
1080
1081void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1082 VisitCondition(comp);
1083}
1084
1085void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1086 VisitCondition(comp);
1087}
1088
1089void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1090 VisitCondition(comp);
1091}
1092
1093void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1094 VisitCondition(comp);
1095}
1096
1097void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1098 VisitCondition(comp);
1099}
1100
1101void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1102 VisitCondition(comp);
1103}
1104
1105void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1106 VisitCondition(comp);
1107}
1108
1109void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1110 VisitCondition(comp);
1111}
1112
1113void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1114 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001115}
1116
1117void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001118 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001119}
1120
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001121void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1122 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001123}
1124
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001125void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001126 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001127}
1128
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001129void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001130 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001131 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001132}
1133
1134void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001135 LocationSummary* locations =
1136 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001137 switch (store->InputAt(1)->GetType()) {
1138 case Primitive::kPrimBoolean:
1139 case Primitive::kPrimByte:
1140 case Primitive::kPrimChar:
1141 case Primitive::kPrimShort:
1142 case Primitive::kPrimInt:
1143 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001144 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001145 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1146 break;
1147
1148 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001149 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001150 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1151 break;
1152
1153 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001154 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001155 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001156}
1157
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001158void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001159 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001160}
1161
1162void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001163 LocationSummary* locations =
1164 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001165 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001166}
1167
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001168void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001169 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001170 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001171}
1172
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001173void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1174 LocationSummary* locations =
1175 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1176 locations->SetOut(Location::ConstantLocation(constant));
1177}
1178
1179void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1180 // Will be generated at use site.
1181 UNUSED(constant);
1182}
1183
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001184void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001185 LocationSummary* locations =
1186 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001187 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001188}
1189
1190void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1191 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001192 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001193}
1194
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001195void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1196 LocationSummary* locations =
1197 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1198 locations->SetOut(Location::ConstantLocation(constant));
1199}
1200
1201void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1202 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001203 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001204}
1205
1206void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1207 LocationSummary* locations =
1208 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1209 locations->SetOut(Location::ConstantLocation(constant));
1210}
1211
1212void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1213 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001214 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001215}
1216
Calin Juravle27df7582015-04-17 19:12:31 +01001217void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1218 memory_barrier->SetLocations(nullptr);
1219}
1220
1221void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1222 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1223}
1224
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001225void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001226 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001227}
1228
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001229void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001230 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001231 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001232}
1233
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001234void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001235 LocationSummary* locations =
1236 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001237 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001238}
1239
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001240void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001241 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001242 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001243}
1244
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001245void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain4c0eb422015-04-24 16:43:49 +01001246 // Explicit clinit checks triggered by static invokes must have been
1247 // pruned by art::PrepareForRegisterAllocation.
1248 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
1249
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001250 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1251 codegen_->GetInstructionSetFeatures());
1252 if (intrinsic.TryDispatch(invoke)) {
1253 return;
1254 }
1255
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001256 HandleInvoke(invoke);
1257}
1258
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001259void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001260 DCHECK(RequiresCurrentMethod());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001261 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001262}
1263
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001264static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1265 if (invoke->GetLocations()->Intrinsified()) {
1266 IntrinsicCodeGeneratorARM intrinsic(codegen);
1267 intrinsic.Dispatch(invoke);
1268 return true;
1269 }
1270 return false;
1271}
1272
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001273void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain4c0eb422015-04-24 16:43:49 +01001274 // Explicit clinit checks triggered by static invokes must have been
1275 // pruned by art::PrepareForRegisterAllocation.
1276 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
1277
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001278 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1279 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001280 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001281
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001282 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
1283
1284 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001285 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001286}
1287
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001288void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001289 LocationSummary* locations =
1290 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001291 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001292
1293 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001294 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001295 HInstruction* input = invoke->InputAt(i);
1296 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1297 }
1298
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001299 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001300}
1301
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001302void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001303 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1304 codegen_->GetInstructionSetFeatures());
1305 if (intrinsic.TryDispatch(invoke)) {
1306 return;
1307 }
1308
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001309 HandleInvoke(invoke);
1310}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001311
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001312void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001313 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1314 return;
1315 }
1316
Roland Levillain271ab9c2014-11-27 15:23:57 +00001317 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001318 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1319 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1320 LocationSummary* locations = invoke->GetLocations();
1321 Location receiver = locations->InAt(0);
1322 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1323 // temp = object->GetClass();
1324 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001325 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1326 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001327 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001328 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001329 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001330 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001331 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001332 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001333 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001334 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001335 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001336 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001337 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001338 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001339 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001340 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001341}
1342
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001343void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1344 HandleInvoke(invoke);
1345 // Add the hidden argument.
1346 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1347}
1348
1349void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1350 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001351 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001352 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1353 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1354 LocationSummary* locations = invoke->GetLocations();
1355 Location receiver = locations->InAt(0);
1356 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1357
1358 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001359 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1360 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001361
1362 // temp = object->GetClass();
1363 if (receiver.IsStackSlot()) {
1364 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1365 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1366 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001367 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001368 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001369 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001370 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001371 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001372 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001373 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1374 // LR = temp->GetEntryPoint();
1375 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1376 // LR();
1377 __ blx(LR);
1378 DCHECK(!codegen_->IsLeafMethod());
1379 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1380}
1381
Roland Levillain88cb1752014-10-20 16:36:47 +01001382void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1383 LocationSummary* locations =
1384 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1385 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001386 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001387 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001388 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1389 break;
1390 }
1391 case Primitive::kPrimLong: {
1392 locations->SetInAt(0, Location::RequiresRegister());
1393 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001394 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001395 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001396
Roland Levillain88cb1752014-10-20 16:36:47 +01001397 case Primitive::kPrimFloat:
1398 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001399 locations->SetInAt(0, Location::RequiresFpuRegister());
1400 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001401 break;
1402
1403 default:
1404 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1405 }
1406}
1407
1408void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1409 LocationSummary* locations = neg->GetLocations();
1410 Location out = locations->Out();
1411 Location in = locations->InAt(0);
1412 switch (neg->GetResultType()) {
1413 case Primitive::kPrimInt:
1414 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001415 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001416 break;
1417
1418 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001419 DCHECK(in.IsRegisterPair());
1420 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1421 __ rsbs(out.AsRegisterPairLow<Register>(),
1422 in.AsRegisterPairLow<Register>(),
1423 ShifterOperand(0));
1424 // We cannot emit an RSC (Reverse Subtract with Carry)
1425 // instruction here, as it does not exist in the Thumb-2
1426 // instruction set. We use the following approach
1427 // using SBC and SUB instead.
1428 //
1429 // out.hi = -C
1430 __ sbc(out.AsRegisterPairHigh<Register>(),
1431 out.AsRegisterPairHigh<Register>(),
1432 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1433 // out.hi = out.hi - in.hi
1434 __ sub(out.AsRegisterPairHigh<Register>(),
1435 out.AsRegisterPairHigh<Register>(),
1436 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1437 break;
1438
Roland Levillain88cb1752014-10-20 16:36:47 +01001439 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001440 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001441 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001442 break;
1443
Roland Levillain88cb1752014-10-20 16:36:47 +01001444 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001445 DCHECK(in.IsFpuRegisterPair());
1446 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1447 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001448 break;
1449
1450 default:
1451 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1452 }
1453}
1454
Roland Levillaindff1f282014-11-05 14:15:05 +00001455void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001456 Primitive::Type result_type = conversion->GetResultType();
1457 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001458 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001459
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001460 // The float-to-long and double-to-long type conversions rely on a
1461 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001462 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001463 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1464 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001465 ? LocationSummary::kCall
1466 : LocationSummary::kNoCall;
1467 LocationSummary* locations =
1468 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1469
David Brazdilb2bd1c52015-03-25 11:17:37 +00001470 // The Java language does not allow treating boolean as an integral type but
1471 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001472
Roland Levillaindff1f282014-11-05 14:15:05 +00001473 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001474 case Primitive::kPrimByte:
1475 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001476 case Primitive::kPrimBoolean:
1477 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001478 case Primitive::kPrimShort:
1479 case Primitive::kPrimInt:
1480 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001481 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001482 locations->SetInAt(0, Location::RequiresRegister());
1483 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1484 break;
1485
1486 default:
1487 LOG(FATAL) << "Unexpected type conversion from " << input_type
1488 << " to " << result_type;
1489 }
1490 break;
1491
Roland Levillain01a8d712014-11-14 16:27:39 +00001492 case Primitive::kPrimShort:
1493 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001494 case Primitive::kPrimBoolean:
1495 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001496 case Primitive::kPrimByte:
1497 case Primitive::kPrimInt:
1498 case Primitive::kPrimChar:
1499 // Processing a Dex `int-to-short' instruction.
1500 locations->SetInAt(0, Location::RequiresRegister());
1501 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1502 break;
1503
1504 default:
1505 LOG(FATAL) << "Unexpected type conversion from " << input_type
1506 << " to " << result_type;
1507 }
1508 break;
1509
Roland Levillain946e1432014-11-11 17:35:19 +00001510 case Primitive::kPrimInt:
1511 switch (input_type) {
1512 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001513 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001514 locations->SetInAt(0, Location::Any());
1515 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1516 break;
1517
1518 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001519 // Processing a Dex `float-to-int' instruction.
1520 locations->SetInAt(0, Location::RequiresFpuRegister());
1521 locations->SetOut(Location::RequiresRegister());
1522 locations->AddTemp(Location::RequiresFpuRegister());
1523 break;
1524
Roland Levillain946e1432014-11-11 17:35:19 +00001525 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001526 // Processing a Dex `double-to-int' instruction.
1527 locations->SetInAt(0, Location::RequiresFpuRegister());
1528 locations->SetOut(Location::RequiresRegister());
1529 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001530 break;
1531
1532 default:
1533 LOG(FATAL) << "Unexpected type conversion from " << input_type
1534 << " to " << result_type;
1535 }
1536 break;
1537
Roland Levillaindff1f282014-11-05 14:15:05 +00001538 case Primitive::kPrimLong:
1539 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001540 case Primitive::kPrimBoolean:
1541 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001542 case Primitive::kPrimByte:
1543 case Primitive::kPrimShort:
1544 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001545 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001546 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001547 locations->SetInAt(0, Location::RequiresRegister());
1548 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1549 break;
1550
Roland Levillain624279f2014-12-04 11:54:28 +00001551 case Primitive::kPrimFloat: {
1552 // Processing a Dex `float-to-long' instruction.
1553 InvokeRuntimeCallingConvention calling_convention;
1554 locations->SetInAt(0, Location::FpuRegisterLocation(
1555 calling_convention.GetFpuRegisterAt(0)));
1556 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1557 break;
1558 }
1559
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001560 case Primitive::kPrimDouble: {
1561 // Processing a Dex `double-to-long' instruction.
1562 InvokeRuntimeCallingConvention calling_convention;
1563 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1564 calling_convention.GetFpuRegisterAt(0),
1565 calling_convention.GetFpuRegisterAt(1)));
1566 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001567 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001568 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001569
1570 default:
1571 LOG(FATAL) << "Unexpected type conversion from " << input_type
1572 << " to " << result_type;
1573 }
1574 break;
1575
Roland Levillain981e4542014-11-14 11:47:14 +00001576 case Primitive::kPrimChar:
1577 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001578 case Primitive::kPrimBoolean:
1579 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001580 case Primitive::kPrimByte:
1581 case Primitive::kPrimShort:
1582 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001583 // Processing a Dex `int-to-char' instruction.
1584 locations->SetInAt(0, Location::RequiresRegister());
1585 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1586 break;
1587
1588 default:
1589 LOG(FATAL) << "Unexpected type conversion from " << input_type
1590 << " to " << result_type;
1591 }
1592 break;
1593
Roland Levillaindff1f282014-11-05 14:15:05 +00001594 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001595 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001596 case Primitive::kPrimBoolean:
1597 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001598 case Primitive::kPrimByte:
1599 case Primitive::kPrimShort:
1600 case Primitive::kPrimInt:
1601 case Primitive::kPrimChar:
1602 // Processing a Dex `int-to-float' instruction.
1603 locations->SetInAt(0, Location::RequiresRegister());
1604 locations->SetOut(Location::RequiresFpuRegister());
1605 break;
1606
1607 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001608 // Processing a Dex `long-to-float' instruction.
1609 locations->SetInAt(0, Location::RequiresRegister());
1610 locations->SetOut(Location::RequiresFpuRegister());
1611 locations->AddTemp(Location::RequiresRegister());
1612 locations->AddTemp(Location::RequiresRegister());
1613 locations->AddTemp(Location::RequiresFpuRegister());
1614 locations->AddTemp(Location::RequiresFpuRegister());
1615 break;
1616
Roland Levillaincff13742014-11-17 14:32:17 +00001617 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001618 // Processing a Dex `double-to-float' instruction.
1619 locations->SetInAt(0, Location::RequiresFpuRegister());
1620 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001621 break;
1622
1623 default:
1624 LOG(FATAL) << "Unexpected type conversion from " << input_type
1625 << " to " << result_type;
1626 };
1627 break;
1628
Roland Levillaindff1f282014-11-05 14:15:05 +00001629 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001630 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001631 case Primitive::kPrimBoolean:
1632 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001633 case Primitive::kPrimByte:
1634 case Primitive::kPrimShort:
1635 case Primitive::kPrimInt:
1636 case Primitive::kPrimChar:
1637 // Processing a Dex `int-to-double' instruction.
1638 locations->SetInAt(0, Location::RequiresRegister());
1639 locations->SetOut(Location::RequiresFpuRegister());
1640 break;
1641
1642 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001643 // Processing a Dex `long-to-double' instruction.
1644 locations->SetInAt(0, Location::RequiresRegister());
1645 locations->SetOut(Location::RequiresFpuRegister());
1646 locations->AddTemp(Location::RequiresRegister());
1647 locations->AddTemp(Location::RequiresRegister());
1648 locations->AddTemp(Location::RequiresFpuRegister());
1649 break;
1650
Roland Levillaincff13742014-11-17 14:32:17 +00001651 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001652 // Processing a Dex `float-to-double' instruction.
1653 locations->SetInAt(0, Location::RequiresFpuRegister());
1654 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001655 break;
1656
1657 default:
1658 LOG(FATAL) << "Unexpected type conversion from " << input_type
1659 << " to " << result_type;
1660 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001661 break;
1662
1663 default:
1664 LOG(FATAL) << "Unexpected type conversion from " << input_type
1665 << " to " << result_type;
1666 }
1667}
1668
1669void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1670 LocationSummary* locations = conversion->GetLocations();
1671 Location out = locations->Out();
1672 Location in = locations->InAt(0);
1673 Primitive::Type result_type = conversion->GetResultType();
1674 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001675 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001676 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001677 case Primitive::kPrimByte:
1678 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001679 case Primitive::kPrimBoolean:
1680 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001681 case Primitive::kPrimShort:
1682 case Primitive::kPrimInt:
1683 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001684 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001685 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001686 break;
1687
1688 default:
1689 LOG(FATAL) << "Unexpected type conversion from " << input_type
1690 << " to " << result_type;
1691 }
1692 break;
1693
Roland Levillain01a8d712014-11-14 16:27:39 +00001694 case Primitive::kPrimShort:
1695 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001696 case Primitive::kPrimBoolean:
1697 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001698 case Primitive::kPrimByte:
1699 case Primitive::kPrimInt:
1700 case Primitive::kPrimChar:
1701 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001702 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001703 break;
1704
1705 default:
1706 LOG(FATAL) << "Unexpected type conversion from " << input_type
1707 << " to " << result_type;
1708 }
1709 break;
1710
Roland Levillain946e1432014-11-11 17:35:19 +00001711 case Primitive::kPrimInt:
1712 switch (input_type) {
1713 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001714 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001715 DCHECK(out.IsRegister());
1716 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001717 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001718 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001719 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001720 } else {
1721 DCHECK(in.IsConstant());
1722 DCHECK(in.GetConstant()->IsLongConstant());
1723 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001724 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001725 }
1726 break;
1727
Roland Levillain3f8f9362014-12-02 17:45:01 +00001728 case Primitive::kPrimFloat: {
1729 // Processing a Dex `float-to-int' instruction.
1730 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1731 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1732 __ vcvtis(temp, temp);
1733 __ vmovrs(out.AsRegister<Register>(), temp);
1734 break;
1735 }
1736
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001737 case Primitive::kPrimDouble: {
1738 // Processing a Dex `double-to-int' instruction.
1739 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1740 DRegister temp_d = FromLowSToD(temp_s);
1741 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1742 __ vcvtid(temp_s, temp_d);
1743 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001744 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001745 }
Roland Levillain946e1432014-11-11 17:35:19 +00001746
1747 default:
1748 LOG(FATAL) << "Unexpected type conversion from " << input_type
1749 << " to " << result_type;
1750 }
1751 break;
1752
Roland Levillaindff1f282014-11-05 14:15:05 +00001753 case Primitive::kPrimLong:
1754 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001755 case Primitive::kPrimBoolean:
1756 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001757 case Primitive::kPrimByte:
1758 case Primitive::kPrimShort:
1759 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001760 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001761 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001762 DCHECK(out.IsRegisterPair());
1763 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001764 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001765 // Sign extension.
1766 __ Asr(out.AsRegisterPairHigh<Register>(),
1767 out.AsRegisterPairLow<Register>(),
1768 31);
1769 break;
1770
1771 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001772 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001773 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1774 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001775 conversion->GetDexPc(),
1776 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001777 break;
1778
Roland Levillaindff1f282014-11-05 14:15:05 +00001779 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001780 // Processing a Dex `double-to-long' instruction.
1781 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1782 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001783 conversion->GetDexPc(),
1784 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001785 break;
1786
1787 default:
1788 LOG(FATAL) << "Unexpected type conversion from " << input_type
1789 << " to " << result_type;
1790 }
1791 break;
1792
Roland Levillain981e4542014-11-14 11:47:14 +00001793 case Primitive::kPrimChar:
1794 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001795 case Primitive::kPrimBoolean:
1796 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001797 case Primitive::kPrimByte:
1798 case Primitive::kPrimShort:
1799 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001800 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001801 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001802 break;
1803
1804 default:
1805 LOG(FATAL) << "Unexpected type conversion from " << input_type
1806 << " to " << result_type;
1807 }
1808 break;
1809
Roland Levillaindff1f282014-11-05 14:15:05 +00001810 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001811 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001812 case Primitive::kPrimBoolean:
1813 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001814 case Primitive::kPrimByte:
1815 case Primitive::kPrimShort:
1816 case Primitive::kPrimInt:
1817 case Primitive::kPrimChar: {
1818 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001819 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1820 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001821 break;
1822 }
1823
Roland Levillain6d0e4832014-11-27 18:31:21 +00001824 case Primitive::kPrimLong: {
1825 // Processing a Dex `long-to-float' instruction.
1826 Register low = in.AsRegisterPairLow<Register>();
1827 Register high = in.AsRegisterPairHigh<Register>();
1828 SRegister output = out.AsFpuRegister<SRegister>();
1829 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1830 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1831 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1832 DRegister temp1_d = FromLowSToD(temp1_s);
1833 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1834 DRegister temp2_d = FromLowSToD(temp2_s);
1835
1836 // Operations use doubles for precision reasons (each 32-bit
1837 // half of a long fits in the 53-bit mantissa of a double,
1838 // but not in the 24-bit mantissa of a float). This is
1839 // especially important for the low bits. The result is
1840 // eventually converted to float.
1841
1842 // temp1_d = int-to-double(high)
1843 __ vmovsr(temp1_s, high);
1844 __ vcvtdi(temp1_d, temp1_s);
1845 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1846 // as an immediate value into `temp2_d` does not work, as
1847 // this instruction only transfers 8 significant bits of its
1848 // immediate operand. Instead, use two 32-bit core
1849 // registers to load `k2Pow32EncodingForDouble` into
1850 // `temp2_d`.
1851 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1852 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1853 __ vmovdrr(temp2_d, constant_low, constant_high);
1854 // temp1_d = temp1_d * 2^32
1855 __ vmuld(temp1_d, temp1_d, temp2_d);
1856 // temp2_d = unsigned-to-double(low)
1857 __ vmovsr(temp2_s, low);
1858 __ vcvtdu(temp2_d, temp2_s);
1859 // temp1_d = temp1_d + temp2_d
1860 __ vaddd(temp1_d, temp1_d, temp2_d);
1861 // output = double-to-float(temp1_d);
1862 __ vcvtsd(output, temp1_d);
1863 break;
1864 }
1865
Roland Levillaincff13742014-11-17 14:32:17 +00001866 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001867 // Processing a Dex `double-to-float' instruction.
1868 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1869 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001870 break;
1871
1872 default:
1873 LOG(FATAL) << "Unexpected type conversion from " << input_type
1874 << " to " << result_type;
1875 };
1876 break;
1877
Roland Levillaindff1f282014-11-05 14:15:05 +00001878 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001879 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001880 case Primitive::kPrimBoolean:
1881 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001882 case Primitive::kPrimByte:
1883 case Primitive::kPrimShort:
1884 case Primitive::kPrimInt:
1885 case Primitive::kPrimChar: {
1886 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001887 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001888 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1889 out.AsFpuRegisterPairLow<SRegister>());
1890 break;
1891 }
1892
Roland Levillain647b9ed2014-11-27 12:06:00 +00001893 case Primitive::kPrimLong: {
1894 // Processing a Dex `long-to-double' instruction.
1895 Register low = in.AsRegisterPairLow<Register>();
1896 Register high = in.AsRegisterPairHigh<Register>();
1897 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1898 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001899 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1900 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001901 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1902 DRegister temp_d = FromLowSToD(temp_s);
1903
Roland Levillain647b9ed2014-11-27 12:06:00 +00001904 // out_d = int-to-double(high)
1905 __ vmovsr(out_s, high);
1906 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001907 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1908 // as an immediate value into `temp_d` does not work, as
1909 // this instruction only transfers 8 significant bits of its
1910 // immediate operand. Instead, use two 32-bit core
1911 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1912 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1913 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001914 __ vmovdrr(temp_d, constant_low, constant_high);
1915 // out_d = out_d * 2^32
1916 __ vmuld(out_d, out_d, temp_d);
1917 // temp_d = unsigned-to-double(low)
1918 __ vmovsr(temp_s, low);
1919 __ vcvtdu(temp_d, temp_s);
1920 // out_d = out_d + temp_d
1921 __ vaddd(out_d, out_d, temp_d);
1922 break;
1923 }
1924
Roland Levillaincff13742014-11-17 14:32:17 +00001925 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001926 // Processing a Dex `float-to-double' instruction.
1927 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1928 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001929 break;
1930
1931 default:
1932 LOG(FATAL) << "Unexpected type conversion from " << input_type
1933 << " to " << result_type;
1934 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001935 break;
1936
1937 default:
1938 LOG(FATAL) << "Unexpected type conversion from " << input_type
1939 << " to " << result_type;
1940 }
1941}
1942
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001943void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001944 LocationSummary* locations =
1945 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001946 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001947 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001948 locations->SetInAt(0, Location::RequiresRegister());
1949 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001950 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1951 break;
1952 }
1953
1954 case Primitive::kPrimLong: {
1955 locations->SetInAt(0, Location::RequiresRegister());
1956 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001957 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001958 break;
1959 }
1960
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001961 case Primitive::kPrimFloat:
1962 case Primitive::kPrimDouble: {
1963 locations->SetInAt(0, Location::RequiresFpuRegister());
1964 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001965 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001966 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001967 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001968
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001969 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001970 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001971 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001972}
1973
1974void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1975 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001976 Location out = locations->Out();
1977 Location first = locations->InAt(0);
1978 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001979 switch (add->GetResultType()) {
1980 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001981 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001982 __ add(out.AsRegister<Register>(),
1983 first.AsRegister<Register>(),
1984 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001985 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001986 __ AddConstant(out.AsRegister<Register>(),
1987 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001988 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001989 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001990 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001991
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001992 case Primitive::kPrimLong: {
1993 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001994 __ adds(out.AsRegisterPairLow<Register>(),
1995 first.AsRegisterPairLow<Register>(),
1996 ShifterOperand(second.AsRegisterPairLow<Register>()));
1997 __ adc(out.AsRegisterPairHigh<Register>(),
1998 first.AsRegisterPairHigh<Register>(),
1999 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002000 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002001 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002002
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002003 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002004 __ vadds(out.AsFpuRegister<SRegister>(),
2005 first.AsFpuRegister<SRegister>(),
2006 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002007 break;
2008
2009 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002010 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2011 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2012 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002013 break;
2014
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002015 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002016 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002017 }
2018}
2019
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002020void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002021 LocationSummary* locations =
2022 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002023 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002024 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002025 locations->SetInAt(0, Location::RequiresRegister());
2026 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002027 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2028 break;
2029 }
2030
2031 case Primitive::kPrimLong: {
2032 locations->SetInAt(0, Location::RequiresRegister());
2033 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002034 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002035 break;
2036 }
Calin Juravle11351682014-10-23 15:38:15 +01002037 case Primitive::kPrimFloat:
2038 case Primitive::kPrimDouble: {
2039 locations->SetInAt(0, Location::RequiresFpuRegister());
2040 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002041 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002042 break;
Calin Juravle11351682014-10-23 15:38:15 +01002043 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002044 default:
Calin Juravle11351682014-10-23 15:38:15 +01002045 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002046 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002047}
2048
2049void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2050 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002051 Location out = locations->Out();
2052 Location first = locations->InAt(0);
2053 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002054 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002055 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002056 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002057 __ sub(out.AsRegister<Register>(),
2058 first.AsRegister<Register>(),
2059 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002060 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002061 __ AddConstant(out.AsRegister<Register>(),
2062 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002063 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002064 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002065 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002066 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002067
Calin Juravle11351682014-10-23 15:38:15 +01002068 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002069 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002070 __ subs(out.AsRegisterPairLow<Register>(),
2071 first.AsRegisterPairLow<Register>(),
2072 ShifterOperand(second.AsRegisterPairLow<Register>()));
2073 __ sbc(out.AsRegisterPairHigh<Register>(),
2074 first.AsRegisterPairHigh<Register>(),
2075 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002076 break;
Calin Juravle11351682014-10-23 15:38:15 +01002077 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002078
Calin Juravle11351682014-10-23 15:38:15 +01002079 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002080 __ vsubs(out.AsFpuRegister<SRegister>(),
2081 first.AsFpuRegister<SRegister>(),
2082 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002083 break;
Calin Juravle11351682014-10-23 15:38:15 +01002084 }
2085
2086 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002087 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2088 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2089 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002090 break;
2091 }
2092
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002093
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002094 default:
Calin Juravle11351682014-10-23 15:38:15 +01002095 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002096 }
2097}
2098
Calin Juravle34bacdf2014-10-07 20:23:36 +01002099void LocationsBuilderARM::VisitMul(HMul* mul) {
2100 LocationSummary* locations =
2101 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2102 switch (mul->GetResultType()) {
2103 case Primitive::kPrimInt:
2104 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002105 locations->SetInAt(0, Location::RequiresRegister());
2106 locations->SetInAt(1, Location::RequiresRegister());
2107 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002108 break;
2109 }
2110
Calin Juravleb5bfa962014-10-21 18:02:24 +01002111 case Primitive::kPrimFloat:
2112 case Primitive::kPrimDouble: {
2113 locations->SetInAt(0, Location::RequiresFpuRegister());
2114 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002115 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002116 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002117 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002118
2119 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002120 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002121 }
2122}
2123
2124void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2125 LocationSummary* locations = mul->GetLocations();
2126 Location out = locations->Out();
2127 Location first = locations->InAt(0);
2128 Location second = locations->InAt(1);
2129 switch (mul->GetResultType()) {
2130 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002131 __ mul(out.AsRegister<Register>(),
2132 first.AsRegister<Register>(),
2133 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002134 break;
2135 }
2136 case Primitive::kPrimLong: {
2137 Register out_hi = out.AsRegisterPairHigh<Register>();
2138 Register out_lo = out.AsRegisterPairLow<Register>();
2139 Register in1_hi = first.AsRegisterPairHigh<Register>();
2140 Register in1_lo = first.AsRegisterPairLow<Register>();
2141 Register in2_hi = second.AsRegisterPairHigh<Register>();
2142 Register in2_lo = second.AsRegisterPairLow<Register>();
2143
2144 // Extra checks to protect caused by the existence of R1_R2.
2145 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2146 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2147 DCHECK_NE(out_hi, in1_lo);
2148 DCHECK_NE(out_hi, in2_lo);
2149
2150 // input: in1 - 64 bits, in2 - 64 bits
2151 // output: out
2152 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2153 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2154 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2155
2156 // IP <- in1.lo * in2.hi
2157 __ mul(IP, in1_lo, in2_hi);
2158 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2159 __ mla(out_hi, in1_hi, in2_lo, IP);
2160 // out.lo <- (in1.lo * in2.lo)[31:0];
2161 __ umull(out_lo, IP, in1_lo, in2_lo);
2162 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2163 __ add(out_hi, out_hi, ShifterOperand(IP));
2164 break;
2165 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002166
2167 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002168 __ vmuls(out.AsFpuRegister<SRegister>(),
2169 first.AsFpuRegister<SRegister>(),
2170 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002171 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002172 }
2173
2174 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002175 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2176 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2177 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002178 break;
2179 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002180
2181 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002182 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002183 }
2184}
2185
Calin Juravle7c4954d2014-10-28 16:57:40 +00002186void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002187 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2188 if (div->GetResultType() == Primitive::kPrimLong) {
2189 // pLdiv runtime call.
2190 call_kind = LocationSummary::kCall;
2191 } else if (div->GetResultType() == Primitive::kPrimInt &&
2192 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2193 // pIdivmod runtime call.
2194 call_kind = LocationSummary::kCall;
2195 }
2196
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002197 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2198
Calin Juravle7c4954d2014-10-28 16:57:40 +00002199 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002200 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002201 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2202 locations->SetInAt(0, Location::RequiresRegister());
2203 locations->SetInAt(1, Location::RequiresRegister());
2204 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2205 } else {
2206 InvokeRuntimeCallingConvention calling_convention;
2207 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2208 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2209 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2210 // we only need the former.
2211 locations->SetOut(Location::RegisterLocation(R0));
2212 }
Calin Juravled0d48522014-11-04 16:40:20 +00002213 break;
2214 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002215 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002216 InvokeRuntimeCallingConvention calling_convention;
2217 locations->SetInAt(0, Location::RegisterPairLocation(
2218 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2219 locations->SetInAt(1, Location::RegisterPairLocation(
2220 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002221 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002222 break;
2223 }
2224 case Primitive::kPrimFloat:
2225 case Primitive::kPrimDouble: {
2226 locations->SetInAt(0, Location::RequiresFpuRegister());
2227 locations->SetInAt(1, Location::RequiresFpuRegister());
2228 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2229 break;
2230 }
2231
2232 default:
2233 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2234 }
2235}
2236
2237void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2238 LocationSummary* locations = div->GetLocations();
2239 Location out = locations->Out();
2240 Location first = locations->InAt(0);
2241 Location second = locations->InAt(1);
2242
2243 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002244 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002245 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2246 __ sdiv(out.AsRegister<Register>(),
2247 first.AsRegister<Register>(),
2248 second.AsRegister<Register>());
2249 } else {
2250 InvokeRuntimeCallingConvention calling_convention;
2251 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2252 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2253 DCHECK_EQ(R0, out.AsRegister<Register>());
2254
2255 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2256 }
Calin Juravled0d48522014-11-04 16:40:20 +00002257 break;
2258 }
2259
Calin Juravle7c4954d2014-10-28 16:57:40 +00002260 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002261 InvokeRuntimeCallingConvention calling_convention;
2262 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2263 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2264 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2265 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2266 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002267 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002268
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002269 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002270 break;
2271 }
2272
2273 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002274 __ vdivs(out.AsFpuRegister<SRegister>(),
2275 first.AsFpuRegister<SRegister>(),
2276 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002277 break;
2278 }
2279
2280 case Primitive::kPrimDouble: {
2281 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2282 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2283 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2284 break;
2285 }
2286
2287 default:
2288 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2289 }
2290}
2291
Calin Juravlebacfec32014-11-14 15:54:36 +00002292void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002293 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002294
2295 // Most remainders are implemented in the runtime.
2296 LocationSummary::CallKind call_kind = LocationSummary::kCall;
2297 if (rem->GetResultType() == Primitive::kPrimInt &&
2298 codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2299 // Have hardware divide instruction for int, do it with three instructions.
2300 call_kind = LocationSummary::kNoCall;
2301 }
2302
Calin Juravlebacfec32014-11-14 15:54:36 +00002303 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2304
Calin Juravled2ec87d2014-12-08 14:24:46 +00002305 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002306 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002307 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2308 locations->SetInAt(0, Location::RequiresRegister());
2309 locations->SetInAt(1, Location::RequiresRegister());
2310 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2311 locations->AddTemp(Location::RequiresRegister());
2312 } else {
2313 InvokeRuntimeCallingConvention calling_convention;
2314 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2315 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2316 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2317 // we only need the latter.
2318 locations->SetOut(Location::RegisterLocation(R1));
2319 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002320 break;
2321 }
2322 case Primitive::kPrimLong: {
2323 InvokeRuntimeCallingConvention calling_convention;
2324 locations->SetInAt(0, Location::RegisterPairLocation(
2325 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2326 locations->SetInAt(1, Location::RegisterPairLocation(
2327 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2328 // The runtime helper puts the output in R2,R3.
2329 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2330 break;
2331 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002332 case Primitive::kPrimFloat: {
2333 InvokeRuntimeCallingConvention calling_convention;
2334 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2335 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2336 locations->SetOut(Location::FpuRegisterLocation(S0));
2337 break;
2338 }
2339
Calin Juravlebacfec32014-11-14 15:54:36 +00002340 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002341 InvokeRuntimeCallingConvention calling_convention;
2342 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2343 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2344 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2345 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2346 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002347 break;
2348 }
2349
2350 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002351 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002352 }
2353}
2354
2355void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2356 LocationSummary* locations = rem->GetLocations();
2357 Location out = locations->Out();
2358 Location first = locations->InAt(0);
2359 Location second = locations->InAt(1);
2360
Calin Juravled2ec87d2014-12-08 14:24:46 +00002361 Primitive::Type type = rem->GetResultType();
2362 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002363 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002364 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2365 Register reg1 = first.AsRegister<Register>();
2366 Register reg2 = second.AsRegister<Register>();
2367 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002368
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002369 // temp = reg1 / reg2 (integer division)
2370 // temp = temp * reg2
2371 // dest = reg1 - temp
2372 __ sdiv(temp, reg1, reg2);
2373 __ mul(temp, temp, reg2);
2374 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2375 } else {
2376 InvokeRuntimeCallingConvention calling_convention;
2377 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2378 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2379 DCHECK_EQ(R1, out.AsRegister<Register>());
2380
2381 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2382 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002383 break;
2384 }
2385
2386 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002387 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002388 break;
2389 }
2390
Calin Juravled2ec87d2014-12-08 14:24:46 +00002391 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002392 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002393 break;
2394 }
2395
Calin Juravlebacfec32014-11-14 15:54:36 +00002396 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002397 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002398 break;
2399 }
2400
2401 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002402 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002403 }
2404}
2405
Calin Juravled0d48522014-11-04 16:40:20 +00002406void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2407 LocationSummary* locations =
2408 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002409 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002410 if (instruction->HasUses()) {
2411 locations->SetOut(Location::SameAsFirstInput());
2412 }
2413}
2414
2415void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2416 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2417 codegen_->AddSlowPath(slow_path);
2418
2419 LocationSummary* locations = instruction->GetLocations();
2420 Location value = locations->InAt(0);
2421
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002422 switch (instruction->GetType()) {
2423 case Primitive::kPrimInt: {
2424 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002425 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002426 __ b(slow_path->GetEntryLabel(), EQ);
2427 } else {
2428 DCHECK(value.IsConstant()) << value;
2429 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2430 __ b(slow_path->GetEntryLabel());
2431 }
2432 }
2433 break;
2434 }
2435 case Primitive::kPrimLong: {
2436 if (value.IsRegisterPair()) {
2437 __ orrs(IP,
2438 value.AsRegisterPairLow<Register>(),
2439 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2440 __ b(slow_path->GetEntryLabel(), EQ);
2441 } else {
2442 DCHECK(value.IsConstant()) << value;
2443 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2444 __ b(slow_path->GetEntryLabel());
2445 }
2446 }
2447 break;
2448 default:
2449 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2450 }
2451 }
Calin Juravled0d48522014-11-04 16:40:20 +00002452}
2453
Calin Juravle9aec02f2014-11-18 23:06:35 +00002454void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2455 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2456
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002457 LocationSummary* locations =
2458 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002459
2460 switch (op->GetResultType()) {
2461 case Primitive::kPrimInt: {
2462 locations->SetInAt(0, Location::RequiresRegister());
2463 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002464 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002465 break;
2466 }
2467 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002468 locations->SetInAt(0, Location::RequiresRegister());
2469 locations->SetInAt(1, Location::RequiresRegister());
2470 locations->AddTemp(Location::RequiresRegister());
2471 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002472 break;
2473 }
2474 default:
2475 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2476 }
2477}
2478
2479void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2480 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2481
2482 LocationSummary* locations = op->GetLocations();
2483 Location out = locations->Out();
2484 Location first = locations->InAt(0);
2485 Location second = locations->InAt(1);
2486
2487 Primitive::Type type = op->GetResultType();
2488 switch (type) {
2489 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002490 Register out_reg = out.AsRegister<Register>();
2491 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002492 // Arm doesn't mask the shift count so we need to do it ourselves.
2493 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002494 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002495 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2496 if (op->IsShl()) {
2497 __ Lsl(out_reg, first_reg, second_reg);
2498 } else if (op->IsShr()) {
2499 __ Asr(out_reg, first_reg, second_reg);
2500 } else {
2501 __ Lsr(out_reg, first_reg, second_reg);
2502 }
2503 } else {
2504 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2505 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2506 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2507 __ Mov(out_reg, first_reg);
2508 } else if (op->IsShl()) {
2509 __ Lsl(out_reg, first_reg, shift_value);
2510 } else if (op->IsShr()) {
2511 __ Asr(out_reg, first_reg, shift_value);
2512 } else {
2513 __ Lsr(out_reg, first_reg, shift_value);
2514 }
2515 }
2516 break;
2517 }
2518 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002519 Register o_h = out.AsRegisterPairHigh<Register>();
2520 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002521
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002522 Register temp = locations->GetTemp(0).AsRegister<Register>();
2523
2524 Register high = first.AsRegisterPairHigh<Register>();
2525 Register low = first.AsRegisterPairLow<Register>();
2526
2527 Register second_reg = second.AsRegister<Register>();
2528
Calin Juravle9aec02f2014-11-18 23:06:35 +00002529 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002530 // Shift the high part
2531 __ and_(second_reg, second_reg, ShifterOperand(63));
2532 __ Lsl(o_h, high, second_reg);
2533 // Shift the low part and `or` what overflew on the high part
2534 __ rsb(temp, second_reg, ShifterOperand(32));
2535 __ Lsr(temp, low, temp);
2536 __ orr(o_h, o_h, ShifterOperand(temp));
2537 // If the shift is > 32 bits, override the high part
2538 __ subs(temp, second_reg, ShifterOperand(32));
2539 __ it(PL);
2540 __ Lsl(o_h, low, temp, false, PL);
2541 // Shift the low part
2542 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002543 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002544 // Shift the low part
2545 __ and_(second_reg, second_reg, ShifterOperand(63));
2546 __ Lsr(o_l, low, second_reg);
2547 // Shift the high part and `or` what underflew on the low part
2548 __ rsb(temp, second_reg, ShifterOperand(32));
2549 __ Lsl(temp, high, temp);
2550 __ orr(o_l, o_l, ShifterOperand(temp));
2551 // If the shift is > 32 bits, override the low part
2552 __ subs(temp, second_reg, ShifterOperand(32));
2553 __ it(PL);
2554 __ Asr(o_l, high, temp, false, PL);
2555 // Shift the high part
2556 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002557 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002558 // same as Shr except we use `Lsr`s and not `Asr`s
2559 __ and_(second_reg, second_reg, ShifterOperand(63));
2560 __ Lsr(o_l, low, second_reg);
2561 __ rsb(temp, second_reg, ShifterOperand(32));
2562 __ Lsl(temp, high, temp);
2563 __ orr(o_l, o_l, ShifterOperand(temp));
2564 __ subs(temp, second_reg, ShifterOperand(32));
2565 __ it(PL);
2566 __ Lsr(o_l, high, temp, false, PL);
2567 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002568 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002569 break;
2570 }
2571 default:
2572 LOG(FATAL) << "Unexpected operation type " << type;
2573 }
2574}
2575
2576void LocationsBuilderARM::VisitShl(HShl* shl) {
2577 HandleShift(shl);
2578}
2579
2580void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2581 HandleShift(shl);
2582}
2583
2584void LocationsBuilderARM::VisitShr(HShr* shr) {
2585 HandleShift(shr);
2586}
2587
2588void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2589 HandleShift(shr);
2590}
2591
2592void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2593 HandleShift(ushr);
2594}
2595
2596void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2597 HandleShift(ushr);
2598}
2599
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002600void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002601 LocationSummary* locations =
2602 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002603 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002604 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2605 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2606 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002607}
2608
2609void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2610 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002611 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002612 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002613 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2614 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002615 instruction->GetDexPc(),
2616 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002617}
2618
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002619void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2620 LocationSummary* locations =
2621 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2622 InvokeRuntimeCallingConvention calling_convention;
2623 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002624 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002625 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002626 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002627}
2628
2629void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2630 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002631 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002632 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002633 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2634 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002635 instruction->GetDexPc(),
2636 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002637}
2638
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002639void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002640 LocationSummary* locations =
2641 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002642 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2643 if (location.IsStackSlot()) {
2644 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2645 } else if (location.IsDoubleStackSlot()) {
2646 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002647 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002648 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002649}
2650
2651void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002652 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002653 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002654}
2655
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002656void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002657 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002658 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002659 locations->SetInAt(0, Location::RequiresRegister());
2660 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002661}
2662
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002663void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2664 LocationSummary* locations = not_->GetLocations();
2665 Location out = locations->Out();
2666 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002667 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002668 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002669 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002670 break;
2671
2672 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002673 __ mvn(out.AsRegisterPairLow<Register>(),
2674 ShifterOperand(in.AsRegisterPairLow<Register>()));
2675 __ mvn(out.AsRegisterPairHigh<Register>(),
2676 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002677 break;
2678
2679 default:
2680 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2681 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002682}
2683
David Brazdil66d126e2015-04-03 16:02:44 +01002684void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2685 LocationSummary* locations =
2686 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2687 locations->SetInAt(0, Location::RequiresRegister());
2688 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2689}
2690
2691void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002692 LocationSummary* locations = bool_not->GetLocations();
2693 Location out = locations->Out();
2694 Location in = locations->InAt(0);
2695 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2696}
2697
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002698void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002699 LocationSummary* locations =
2700 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002701 switch (compare->InputAt(0)->GetType()) {
2702 case Primitive::kPrimLong: {
2703 locations->SetInAt(0, Location::RequiresRegister());
2704 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002705 // Output overlaps because it is written before doing the low comparison.
2706 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002707 break;
2708 }
2709 case Primitive::kPrimFloat:
2710 case Primitive::kPrimDouble: {
2711 locations->SetInAt(0, Location::RequiresFpuRegister());
2712 locations->SetInAt(1, Location::RequiresFpuRegister());
2713 locations->SetOut(Location::RequiresRegister());
2714 break;
2715 }
2716 default:
2717 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2718 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002719}
2720
2721void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002722 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002723 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002724 Location left = locations->InAt(0);
2725 Location right = locations->InAt(1);
2726
2727 Label less, greater, done;
2728 Primitive::Type type = compare->InputAt(0)->GetType();
2729 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002730 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002731 __ cmp(left.AsRegisterPairHigh<Register>(),
2732 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002733 __ b(&less, LT);
2734 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002735 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2736 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002737 __ cmp(left.AsRegisterPairLow<Register>(),
2738 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002739 break;
2740 }
2741 case Primitive::kPrimFloat:
2742 case Primitive::kPrimDouble: {
2743 __ LoadImmediate(out, 0);
2744 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002745 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002746 } else {
2747 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2748 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2749 }
2750 __ vmstat(); // transfer FP status register to ARM APSR.
2751 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002752 break;
2753 }
2754 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002755 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002756 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002757 __ b(&done, EQ);
2758 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2759
2760 __ Bind(&greater);
2761 __ LoadImmediate(out, 1);
2762 __ b(&done);
2763
2764 __ Bind(&less);
2765 __ LoadImmediate(out, -1);
2766
2767 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002768}
2769
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002770void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002771 LocationSummary* locations =
2772 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002773 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2774 locations->SetInAt(i, Location::Any());
2775 }
2776 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002777}
2778
2779void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002780 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002781 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002782}
2783
Calin Juravle52c48962014-12-16 17:02:57 +00002784void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2785 // TODO (ported from quick): revisit Arm barrier kinds
2786 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2787 switch (kind) {
2788 case MemBarrierKind::kAnyStore:
2789 case MemBarrierKind::kLoadAny:
2790 case MemBarrierKind::kAnyAny: {
2791 flavour = DmbOptions::ISH;
2792 break;
2793 }
2794 case MemBarrierKind::kStoreStore: {
2795 flavour = DmbOptions::ISHST;
2796 break;
2797 }
2798 default:
2799 LOG(FATAL) << "Unexpected memory barrier " << kind;
2800 }
2801 __ dmb(flavour);
2802}
2803
2804void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2805 uint32_t offset,
2806 Register out_lo,
2807 Register out_hi) {
2808 if (offset != 0) {
2809 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002810 __ add(IP, addr, ShifterOperand(out_lo));
2811 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002812 }
2813 __ ldrexd(out_lo, out_hi, addr);
2814}
2815
2816void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2817 uint32_t offset,
2818 Register value_lo,
2819 Register value_hi,
2820 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002821 Register temp2,
2822 HInstruction* instruction) {
Calin Juravle52c48962014-12-16 17:02:57 +00002823 Label fail;
2824 if (offset != 0) {
2825 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002826 __ add(IP, addr, ShifterOperand(temp1));
2827 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002828 }
2829 __ Bind(&fail);
2830 // We need a load followed by store. (The address used in a STREX instruction must
2831 // be the same as the address in the most recently executed LDREX instruction.)
2832 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002833 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002834 __ strexd(temp1, value_lo, value_hi, addr);
2835 __ cmp(temp1, ShifterOperand(0));
2836 __ b(&fail, NE);
2837}
2838
2839void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2840 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2841
Nicolas Geoffray39468442014-09-02 15:17:15 +01002842 LocationSummary* locations =
2843 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002844 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002845
Calin Juravle52c48962014-12-16 17:02:57 +00002846 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01002847 if (Primitive::IsFloatingPointType(field_type)) {
2848 locations->SetInAt(1, Location::RequiresFpuRegister());
2849 } else {
2850 locations->SetInAt(1, Location::RequiresRegister());
2851 }
2852
Calin Juravle52c48962014-12-16 17:02:57 +00002853 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002854 bool generate_volatile = field_info.IsVolatile()
2855 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002856 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002857 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002858 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2859 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002860 locations->AddTemp(Location::RequiresRegister());
2861 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002862 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002863 // Arm encoding have some additional constraints for ldrexd/strexd:
2864 // - registers need to be consecutive
2865 // - the first register should be even but not R14.
2866 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2867 // enable Arm encoding.
2868 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2869
2870 locations->AddTemp(Location::RequiresRegister());
2871 locations->AddTemp(Location::RequiresRegister());
2872 if (field_type == Primitive::kPrimDouble) {
2873 // For doubles we need two more registers to copy the value.
2874 locations->AddTemp(Location::RegisterLocation(R2));
2875 locations->AddTemp(Location::RegisterLocation(R3));
2876 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002877 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002878}
2879
Calin Juravle52c48962014-12-16 17:02:57 +00002880void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2881 const FieldInfo& field_info) {
2882 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2883
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002884 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002885 Register base = locations->InAt(0).AsRegister<Register>();
2886 Location value = locations->InAt(1);
2887
2888 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002889 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002890 Primitive::Type field_type = field_info.GetFieldType();
2891 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2892
2893 if (is_volatile) {
2894 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2895 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002896
2897 switch (field_type) {
2898 case Primitive::kPrimBoolean:
2899 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002900 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002901 break;
2902 }
2903
2904 case Primitive::kPrimShort:
2905 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002906 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002907 break;
2908 }
2909
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002910 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002911 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00002912 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002913 break;
2914 }
2915
2916 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002917 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002918 GenerateWideAtomicStore(base, offset,
2919 value.AsRegisterPairLow<Register>(),
2920 value.AsRegisterPairHigh<Register>(),
2921 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002922 locations->GetTemp(1).AsRegister<Register>(),
2923 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002924 } else {
2925 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002926 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002927 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002928 break;
2929 }
2930
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002931 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002932 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002933 break;
2934 }
2935
2936 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002937 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002938 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002939 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2940 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2941
2942 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2943
2944 GenerateWideAtomicStore(base, offset,
2945 value_reg_lo,
2946 value_reg_hi,
2947 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002948 locations->GetTemp(3).AsRegister<Register>(),
2949 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002950 } else {
2951 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002952 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002953 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002954 break;
2955 }
2956
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002957 case Primitive::kPrimVoid:
2958 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002959 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002960 }
Calin Juravle52c48962014-12-16 17:02:57 +00002961
Calin Juravle77520bc2015-01-12 18:45:46 +00002962 // Longs and doubles are handled in the switch.
2963 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
2964 codegen_->MaybeRecordImplicitNullCheck(instruction);
2965 }
2966
2967 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
2968 Register temp = locations->GetTemp(0).AsRegister<Register>();
2969 Register card = locations->GetTemp(1).AsRegister<Register>();
2970 codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>());
2971 }
2972
Calin Juravle52c48962014-12-16 17:02:57 +00002973 if (is_volatile) {
2974 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2975 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002976}
2977
Calin Juravle52c48962014-12-16 17:02:57 +00002978void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2979 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002980 LocationSummary* locations =
2981 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002982 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002983
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002984 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00002985 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002986 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002987 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01002988
Alexandre Rames88c13cd2015-04-14 17:35:39 +01002989 if (Primitive::IsFloatingPointType(instruction->GetType())) {
2990 locations->SetOut(Location::RequiresFpuRegister());
2991 } else {
2992 locations->SetOut(Location::RequiresRegister(),
2993 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
2994 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002995 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00002996 // Arm encoding have some additional constraints for ldrexd/strexd:
2997 // - registers need to be consecutive
2998 // - the first register should be even but not R14.
2999 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3000 // enable Arm encoding.
3001 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3002 locations->AddTemp(Location::RequiresRegister());
3003 locations->AddTemp(Location::RequiresRegister());
3004 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003005}
3006
Calin Juravle52c48962014-12-16 17:02:57 +00003007void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3008 const FieldInfo& field_info) {
3009 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003010
Calin Juravle52c48962014-12-16 17:02:57 +00003011 LocationSummary* locations = instruction->GetLocations();
3012 Register base = locations->InAt(0).AsRegister<Register>();
3013 Location out = locations->Out();
3014 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003015 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003016 Primitive::Type field_type = field_info.GetFieldType();
3017 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3018
3019 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003020 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003021 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003022 break;
3023 }
3024
3025 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003026 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003027 break;
3028 }
3029
3030 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003031 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003032 break;
3033 }
3034
3035 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003036 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003037 break;
3038 }
3039
3040 case Primitive::kPrimInt:
3041 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003042 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003043 break;
3044 }
3045
3046 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003047 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003048 GenerateWideAtomicLoad(base, offset,
3049 out.AsRegisterPairLow<Register>(),
3050 out.AsRegisterPairHigh<Register>());
3051 } else {
3052 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3053 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003054 break;
3055 }
3056
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003057 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003058 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003059 break;
3060 }
3061
3062 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003063 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003064 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003065 Register lo = locations->GetTemp(0).AsRegister<Register>();
3066 Register hi = locations->GetTemp(1).AsRegister<Register>();
3067 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003068 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003069 __ vmovdrr(out_reg, lo, hi);
3070 } else {
3071 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003072 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003073 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003074 break;
3075 }
3076
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003077 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003078 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003079 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003080 }
Calin Juravle52c48962014-12-16 17:02:57 +00003081
Calin Juravle77520bc2015-01-12 18:45:46 +00003082 // Doubles are handled in the switch.
3083 if (field_type != Primitive::kPrimDouble) {
3084 codegen_->MaybeRecordImplicitNullCheck(instruction);
3085 }
3086
Calin Juravle52c48962014-12-16 17:02:57 +00003087 if (is_volatile) {
3088 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3089 }
3090}
3091
3092void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3093 HandleFieldSet(instruction, instruction->GetFieldInfo());
3094}
3095
3096void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3097 HandleFieldSet(instruction, instruction->GetFieldInfo());
3098}
3099
3100void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3101 HandleFieldGet(instruction, instruction->GetFieldInfo());
3102}
3103
3104void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3105 HandleFieldGet(instruction, instruction->GetFieldInfo());
3106}
3107
3108void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3109 HandleFieldGet(instruction, instruction->GetFieldInfo());
3110}
3111
3112void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3113 HandleFieldGet(instruction, instruction->GetFieldInfo());
3114}
3115
3116void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3117 HandleFieldSet(instruction, instruction->GetFieldInfo());
3118}
3119
3120void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3121 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003122}
3123
3124void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003125 LocationSummary* locations =
3126 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003127 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003128 if (instruction->HasUses()) {
3129 locations->SetOut(Location::SameAsFirstInput());
3130 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003131}
3132
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003133void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003134 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3135 return;
3136 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003137 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003138
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003139 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3140 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3141}
3142
3143void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003144 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003145 codegen_->AddSlowPath(slow_path);
3146
3147 LocationSummary* locations = instruction->GetLocations();
3148 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003149
Calin Juravle77520bc2015-01-12 18:45:46 +00003150 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3151 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003152}
3153
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003154void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3155 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3156 GenerateImplicitNullCheck(instruction);
3157 } else {
3158 GenerateExplicitNullCheck(instruction);
3159 }
3160}
3161
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003162void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003163 LocationSummary* locations =
3164 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003165 locations->SetInAt(0, Location::RequiresRegister());
3166 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003167 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3168 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3169 } else {
3170 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3171 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003172}
3173
3174void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3175 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003176 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003177 Location index = locations->InAt(1);
3178
3179 switch (instruction->GetType()) {
3180 case Primitive::kPrimBoolean: {
3181 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003182 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003183 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003184 size_t offset =
3185 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003186 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3187 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003188 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003189 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3190 }
3191 break;
3192 }
3193
3194 case Primitive::kPrimByte: {
3195 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003196 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003197 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003198 size_t offset =
3199 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003200 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3201 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003202 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003203 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3204 }
3205 break;
3206 }
3207
3208 case Primitive::kPrimShort: {
3209 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003210 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003211 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003212 size_t offset =
3213 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003214 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3215 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003216 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003217 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3218 }
3219 break;
3220 }
3221
3222 case Primitive::kPrimChar: {
3223 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003224 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003225 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003226 size_t offset =
3227 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003228 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3229 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003230 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003231 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3232 }
3233 break;
3234 }
3235
3236 case Primitive::kPrimInt:
3237 case Primitive::kPrimNot: {
3238 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3239 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003240 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003241 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003242 size_t offset =
3243 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003244 __ LoadFromOffset(kLoadWord, out, obj, offset);
3245 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003246 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003247 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3248 }
3249 break;
3250 }
3251
3252 case Primitive::kPrimLong: {
3253 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003254 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003255 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003256 size_t offset =
3257 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003258 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003259 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003260 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003261 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003262 }
3263 break;
3264 }
3265
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003266 case Primitive::kPrimFloat: {
3267 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3268 Location out = locations->Out();
3269 DCHECK(out.IsFpuRegister());
3270 if (index.IsConstant()) {
3271 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3272 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3273 } else {
3274 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3275 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3276 }
3277 break;
3278 }
3279
3280 case Primitive::kPrimDouble: {
3281 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3282 Location out = locations->Out();
3283 DCHECK(out.IsFpuRegisterPair());
3284 if (index.IsConstant()) {
3285 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3286 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3287 } else {
3288 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3289 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3290 }
3291 break;
3292 }
3293
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003294 case Primitive::kPrimVoid:
3295 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003296 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003297 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003298 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003299}
3300
3301void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003302 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003303
3304 bool needs_write_barrier =
3305 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3306 bool needs_runtime_call = instruction->NeedsTypeCheck();
3307
Nicolas Geoffray39468442014-09-02 15:17:15 +01003308 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003309 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3310 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003311 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003312 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3313 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3314 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003315 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003316 locations->SetInAt(0, Location::RequiresRegister());
3317 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003318 if (Primitive::IsFloatingPointType(value_type)) {
3319 locations->SetInAt(2, Location::RequiresFpuRegister());
3320 } else {
3321 locations->SetInAt(2, Location::RequiresRegister());
3322 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003323
3324 if (needs_write_barrier) {
3325 // Temporary registers for the write barrier.
3326 locations->AddTemp(Location::RequiresRegister());
3327 locations->AddTemp(Location::RequiresRegister());
3328 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003329 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003330}
3331
3332void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3333 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003334 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003335 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003336 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003337 bool needs_runtime_call = locations->WillCall();
3338 bool needs_write_barrier =
3339 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003340
3341 switch (value_type) {
3342 case Primitive::kPrimBoolean:
3343 case Primitive::kPrimByte: {
3344 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003345 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003346 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003347 size_t offset =
3348 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003349 __ StoreToOffset(kStoreByte, value, obj, offset);
3350 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003351 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003352 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3353 }
3354 break;
3355 }
3356
3357 case Primitive::kPrimShort:
3358 case Primitive::kPrimChar: {
3359 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003360 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003361 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003362 size_t offset =
3363 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003364 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3365 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003366 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003367 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3368 }
3369 break;
3370 }
3371
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003372 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003373 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003374 if (!needs_runtime_call) {
3375 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003376 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003377 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003378 size_t offset =
3379 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003380 __ StoreToOffset(kStoreWord, value, obj, offset);
3381 } else {
3382 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003383 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003384 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3385 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003386 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003387 if (needs_write_barrier) {
3388 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003389 Register temp = locations->GetTemp(0).AsRegister<Register>();
3390 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003391 codegen_->MarkGCCard(temp, card, obj, value);
3392 }
3393 } else {
3394 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003395 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3396 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003397 instruction->GetDexPc(),
3398 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003399 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003400 break;
3401 }
3402
3403 case Primitive::kPrimLong: {
3404 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003405 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003406 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003407 size_t offset =
3408 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003409 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003410 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003411 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003412 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003413 }
3414 break;
3415 }
3416
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003417 case Primitive::kPrimFloat: {
3418 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3419 Location value = locations->InAt(2);
3420 DCHECK(value.IsFpuRegister());
3421 if (index.IsConstant()) {
3422 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3423 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3424 } else {
3425 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3426 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3427 }
3428 break;
3429 }
3430
3431 case Primitive::kPrimDouble: {
3432 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3433 Location value = locations->InAt(2);
3434 DCHECK(value.IsFpuRegisterPair());
3435 if (index.IsConstant()) {
3436 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3437 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3438 } else {
3439 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3440 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3441 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003442
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003443 break;
3444 }
3445
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003446 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003447 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003448 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003449 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003450
3451 // Ints and objects are handled in the switch.
3452 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3453 codegen_->MaybeRecordImplicitNullCheck(instruction);
3454 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003455}
3456
3457void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003458 LocationSummary* locations =
3459 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003460 locations->SetInAt(0, Location::RequiresRegister());
3461 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003462}
3463
3464void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3465 LocationSummary* locations = instruction->GetLocations();
3466 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003467 Register obj = locations->InAt(0).AsRegister<Register>();
3468 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003469 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003470 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003471}
3472
3473void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003474 LocationSummary* locations =
3475 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003476 locations->SetInAt(0, Location::RequiresRegister());
3477 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003478 if (instruction->HasUses()) {
3479 locations->SetOut(Location::SameAsFirstInput());
3480 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003481}
3482
3483void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3484 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003485 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003486 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003487 codegen_->AddSlowPath(slow_path);
3488
Roland Levillain271ab9c2014-11-27 15:23:57 +00003489 Register index = locations->InAt(0).AsRegister<Register>();
3490 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003491
3492 __ cmp(index, ShifterOperand(length));
3493 __ b(slow_path->GetEntryLabel(), CS);
3494}
3495
3496void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3497 Label is_null;
3498 __ CompareAndBranchIfZero(value, &is_null);
3499 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3500 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3501 __ strb(card, Address(card, temp));
3502 __ Bind(&is_null);
3503}
3504
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003505void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3506 temp->SetLocations(nullptr);
3507}
3508
3509void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3510 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003511 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003512}
3513
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003514void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003515 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003516 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003517}
3518
3519void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003520 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3521}
3522
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003523void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3524 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3525}
3526
3527void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003528 HBasicBlock* block = instruction->GetBlock();
3529 if (block->GetLoopInformation() != nullptr) {
3530 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3531 // The back edge will generate the suspend check.
3532 return;
3533 }
3534 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3535 // The goto will generate the suspend check.
3536 return;
3537 }
3538 GenerateSuspendCheck(instruction, nullptr);
3539}
3540
3541void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3542 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003543 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003544 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003545 codegen_->AddSlowPath(slow_path);
3546
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003547 __ LoadFromOffset(
3548 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3549 __ cmp(IP, ShifterOperand(0));
3550 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003551 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003552 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003553 __ Bind(slow_path->GetReturnLabel());
3554 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003555 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003556 __ b(slow_path->GetEntryLabel());
3557 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003558}
3559
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003560ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3561 return codegen_->GetAssembler();
3562}
3563
3564void ParallelMoveResolverARM::EmitMove(size_t index) {
3565 MoveOperands* move = moves_.Get(index);
3566 Location source = move->GetSource();
3567 Location destination = move->GetDestination();
3568
3569 if (source.IsRegister()) {
3570 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003571 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003572 } else {
3573 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003574 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003575 SP, destination.GetStackIndex());
3576 }
3577 } else if (source.IsStackSlot()) {
3578 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003579 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003580 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003581 } else if (destination.IsFpuRegister()) {
3582 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003583 } else {
3584 DCHECK(destination.IsStackSlot());
3585 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3586 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3587 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003588 } else if (source.IsFpuRegister()) {
3589 if (destination.IsFpuRegister()) {
3590 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003591 } else {
3592 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003593 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3594 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003595 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003596 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003597 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3598 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003599 } else if (destination.IsRegisterPair()) {
3600 DCHECK(ExpectedPairLayout(destination));
3601 __ LoadFromOffset(
3602 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3603 } else {
3604 DCHECK(destination.IsFpuRegisterPair()) << destination;
3605 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3606 SP,
3607 source.GetStackIndex());
3608 }
3609 } else if (source.IsRegisterPair()) {
3610 if (destination.IsRegisterPair()) {
3611 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3612 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3613 } else {
3614 DCHECK(destination.IsDoubleStackSlot()) << destination;
3615 DCHECK(ExpectedPairLayout(source));
3616 __ StoreToOffset(
3617 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3618 }
3619 } else if (source.IsFpuRegisterPair()) {
3620 if (destination.IsFpuRegisterPair()) {
3621 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3622 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3623 } else {
3624 DCHECK(destination.IsDoubleStackSlot()) << destination;
3625 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3626 SP,
3627 destination.GetStackIndex());
3628 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003629 } else {
3630 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003631 HConstant* constant = source.GetConstant();
3632 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3633 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003634 if (destination.IsRegister()) {
3635 __ LoadImmediate(destination.AsRegister<Register>(), value);
3636 } else {
3637 DCHECK(destination.IsStackSlot());
3638 __ LoadImmediate(IP, value);
3639 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3640 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003641 } else if (constant->IsLongConstant()) {
3642 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003643 if (destination.IsRegisterPair()) {
3644 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3645 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003646 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003647 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003648 __ LoadImmediate(IP, Low32Bits(value));
3649 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3650 __ LoadImmediate(IP, High32Bits(value));
3651 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3652 }
3653 } else if (constant->IsDoubleConstant()) {
3654 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003655 if (destination.IsFpuRegisterPair()) {
3656 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003657 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003658 DCHECK(destination.IsDoubleStackSlot()) << destination;
3659 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003660 __ LoadImmediate(IP, Low32Bits(int_value));
3661 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3662 __ LoadImmediate(IP, High32Bits(int_value));
3663 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3664 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003665 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003666 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003667 float value = constant->AsFloatConstant()->GetValue();
3668 if (destination.IsFpuRegister()) {
3669 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3670 } else {
3671 DCHECK(destination.IsStackSlot());
3672 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3673 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3674 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003675 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003676 }
3677}
3678
3679void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3680 __ Mov(IP, reg);
3681 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3682 __ StoreToOffset(kStoreWord, IP, SP, mem);
3683}
3684
3685void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3686 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3687 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3688 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3689 SP, mem1 + stack_offset);
3690 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3691 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3692 SP, mem2 + stack_offset);
3693 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3694}
3695
3696void ParallelMoveResolverARM::EmitSwap(size_t index) {
3697 MoveOperands* move = moves_.Get(index);
3698 Location source = move->GetSource();
3699 Location destination = move->GetDestination();
3700
3701 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003702 DCHECK_NE(source.AsRegister<Register>(), IP);
3703 DCHECK_NE(destination.AsRegister<Register>(), IP);
3704 __ Mov(IP, source.AsRegister<Register>());
3705 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3706 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003707 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003708 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003709 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003710 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003711 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3712 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003713 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003714 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003715 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003716 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003717 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003718 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003719 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003720 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003721 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3722 destination.AsRegisterPairHigh<Register>(),
3723 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003724 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003725 Register low_reg = source.IsRegisterPair()
3726 ? source.AsRegisterPairLow<Register>()
3727 : destination.AsRegisterPairLow<Register>();
3728 int mem = source.IsRegisterPair()
3729 ? destination.GetStackIndex()
3730 : source.GetStackIndex();
3731 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003732 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003733 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003734 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003735 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003736 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3737 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003738 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003739 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003740 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003741 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3742 DRegister reg = source.IsFpuRegisterPair()
3743 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3744 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3745 int mem = source.IsFpuRegisterPair()
3746 ? destination.GetStackIndex()
3747 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003748 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003749 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003750 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003751 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3752 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3753 : destination.AsFpuRegister<SRegister>();
3754 int mem = source.IsFpuRegister()
3755 ? destination.GetStackIndex()
3756 : source.GetStackIndex();
3757
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003758 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003759 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003760 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003761 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003762 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3763 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003764 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003765 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003766 }
3767}
3768
3769void ParallelMoveResolverARM::SpillScratch(int reg) {
3770 __ Push(static_cast<Register>(reg));
3771}
3772
3773void ParallelMoveResolverARM::RestoreScratch(int reg) {
3774 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003775}
3776
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003777void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003778 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3779 ? LocationSummary::kCallOnSlowPath
3780 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003781 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003782 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003783 locations->SetOut(Location::RequiresRegister());
3784}
3785
3786void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003787 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003788 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003789 DCHECK(!cls->CanCallRuntime());
3790 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003791 codegen_->LoadCurrentMethod(out);
3792 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3793 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003794 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003795 codegen_->LoadCurrentMethod(out);
3796 __ LoadFromOffset(
3797 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3798 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003799
3800 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3801 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3802 codegen_->AddSlowPath(slow_path);
3803 __ cmp(out, ShifterOperand(0));
3804 __ b(slow_path->GetEntryLabel(), EQ);
3805 if (cls->MustGenerateClinitCheck()) {
3806 GenerateClassInitializationCheck(slow_path, out);
3807 } else {
3808 __ Bind(slow_path->GetExitLabel());
3809 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003810 }
3811}
3812
3813void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3814 LocationSummary* locations =
3815 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3816 locations->SetInAt(0, Location::RequiresRegister());
3817 if (check->HasUses()) {
3818 locations->SetOut(Location::SameAsFirstInput());
3819 }
3820}
3821
3822void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003823 // We assume the class is not null.
3824 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3825 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003826 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003827 GenerateClassInitializationCheck(slow_path,
3828 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003829}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003830
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003831void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3832 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003833 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3834 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3835 __ b(slow_path->GetEntryLabel(), LT);
3836 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3837 // properly. Therefore, we do a memory fence.
3838 __ dmb(ISH);
3839 __ Bind(slow_path->GetExitLabel());
3840}
3841
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003842void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3843 LocationSummary* locations =
3844 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3845 locations->SetOut(Location::RequiresRegister());
3846}
3847
3848void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3849 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3850 codegen_->AddSlowPath(slow_path);
3851
Roland Levillain271ab9c2014-11-27 15:23:57 +00003852 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003853 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003854 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3855 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003856 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3857 __ cmp(out, ShifterOperand(0));
3858 __ b(slow_path->GetEntryLabel(), EQ);
3859 __ Bind(slow_path->GetExitLabel());
3860}
3861
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003862void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3863 LocationSummary* locations =
3864 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3865 locations->SetOut(Location::RequiresRegister());
3866}
3867
3868void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003869 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003870 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3871 __ LoadFromOffset(kLoadWord, out, TR, offset);
3872 __ LoadImmediate(IP, 0);
3873 __ StoreToOffset(kStoreWord, IP, TR, offset);
3874}
3875
3876void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3877 LocationSummary* locations =
3878 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3879 InvokeRuntimeCallingConvention calling_convention;
3880 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3881}
3882
3883void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3884 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003885 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003886}
3887
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003888void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003889 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3890 ? LocationSummary::kNoCall
3891 : LocationSummary::kCallOnSlowPath;
3892 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3893 locations->SetInAt(0, Location::RequiresRegister());
3894 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003895 // The out register is used as a temporary, so it overlaps with the inputs.
3896 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003897}
3898
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003899void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003900 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003901 Register obj = locations->InAt(0).AsRegister<Register>();
3902 Register cls = locations->InAt(1).AsRegister<Register>();
3903 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003904 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3905 Label done, zero;
3906 SlowPathCodeARM* slow_path = nullptr;
3907
3908 // Return 0 if `obj` is null.
3909 // TODO: avoid this check if we know obj is not null.
3910 __ cmp(obj, ShifterOperand(0));
3911 __ b(&zero, EQ);
3912 // Compare the class of `obj` with `cls`.
3913 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3914 __ cmp(out, ShifterOperand(cls));
3915 if (instruction->IsClassFinal()) {
3916 // Classes must be equal for the instanceof to succeed.
3917 __ b(&zero, NE);
3918 __ LoadImmediate(out, 1);
3919 __ b(&done);
3920 } else {
3921 // If the classes are not equal, we go into a slow path.
3922 DCHECK(locations->OnlyCallsOnSlowPath());
3923 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003924 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003925 codegen_->AddSlowPath(slow_path);
3926 __ b(slow_path->GetEntryLabel(), NE);
3927 __ LoadImmediate(out, 1);
3928 __ b(&done);
3929 }
3930 __ Bind(&zero);
3931 __ LoadImmediate(out, 0);
3932 if (slow_path != nullptr) {
3933 __ Bind(slow_path->GetExitLabel());
3934 }
3935 __ Bind(&done);
3936}
3937
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003938void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3939 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3940 instruction, LocationSummary::kCallOnSlowPath);
3941 locations->SetInAt(0, Location::RequiresRegister());
3942 locations->SetInAt(1, Location::RequiresRegister());
3943 locations->AddTemp(Location::RequiresRegister());
3944}
3945
3946void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3947 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003948 Register obj = locations->InAt(0).AsRegister<Register>();
3949 Register cls = locations->InAt(1).AsRegister<Register>();
3950 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003951 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3952
3953 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3954 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3955 codegen_->AddSlowPath(slow_path);
3956
3957 // TODO: avoid this check if we know obj is not null.
3958 __ cmp(obj, ShifterOperand(0));
3959 __ b(slow_path->GetExitLabel(), EQ);
3960 // Compare the class of `obj` with `cls`.
3961 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3962 __ cmp(temp, ShifterOperand(cls));
3963 __ b(slow_path->GetEntryLabel(), NE);
3964 __ Bind(slow_path->GetExitLabel());
3965}
3966
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003967void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3968 LocationSummary* locations =
3969 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3970 InvokeRuntimeCallingConvention calling_convention;
3971 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3972}
3973
3974void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3975 codegen_->InvokeRuntime(instruction->IsEnter()
3976 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3977 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003978 instruction->GetDexPc(),
3979 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003980}
3981
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003982void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3983void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3984void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3985
3986void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3987 LocationSummary* locations =
3988 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3989 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3990 || instruction->GetResultType() == Primitive::kPrimLong);
3991 locations->SetInAt(0, Location::RequiresRegister());
3992 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003993 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003994}
3995
3996void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3997 HandleBitwiseOperation(instruction);
3998}
3999
4000void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4001 HandleBitwiseOperation(instruction);
4002}
4003
4004void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4005 HandleBitwiseOperation(instruction);
4006}
4007
4008void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4009 LocationSummary* locations = instruction->GetLocations();
4010
4011 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004012 Register first = locations->InAt(0).AsRegister<Register>();
4013 Register second = locations->InAt(1).AsRegister<Register>();
4014 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004015 if (instruction->IsAnd()) {
4016 __ and_(out, first, ShifterOperand(second));
4017 } else if (instruction->IsOr()) {
4018 __ orr(out, first, ShifterOperand(second));
4019 } else {
4020 DCHECK(instruction->IsXor());
4021 __ eor(out, first, ShifterOperand(second));
4022 }
4023 } else {
4024 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4025 Location first = locations->InAt(0);
4026 Location second = locations->InAt(1);
4027 Location out = locations->Out();
4028 if (instruction->IsAnd()) {
4029 __ and_(out.AsRegisterPairLow<Register>(),
4030 first.AsRegisterPairLow<Register>(),
4031 ShifterOperand(second.AsRegisterPairLow<Register>()));
4032 __ and_(out.AsRegisterPairHigh<Register>(),
4033 first.AsRegisterPairHigh<Register>(),
4034 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4035 } else if (instruction->IsOr()) {
4036 __ orr(out.AsRegisterPairLow<Register>(),
4037 first.AsRegisterPairLow<Register>(),
4038 ShifterOperand(second.AsRegisterPairLow<Register>()));
4039 __ orr(out.AsRegisterPairHigh<Register>(),
4040 first.AsRegisterPairHigh<Register>(),
4041 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4042 } else {
4043 DCHECK(instruction->IsXor());
4044 __ eor(out.AsRegisterPairLow<Register>(),
4045 first.AsRegisterPairLow<Register>(),
4046 ShifterOperand(second.AsRegisterPairLow<Register>()));
4047 __ eor(out.AsRegisterPairHigh<Register>(),
4048 first.AsRegisterPairHigh<Register>(),
4049 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4050 }
4051 }
4052}
4053
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004054void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
4055 DCHECK_EQ(temp, kArtMethodRegister);
4056
4057 // TODO: Implement all kinds of calls:
4058 // 1) boot -> boot
4059 // 2) app -> boot
4060 // 3) app -> app
4061 //
4062 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4063
4064 // temp = method;
4065 LoadCurrentMethod(temp);
4066 if (!invoke->IsRecursive()) {
4067 // temp = temp->dex_cache_resolved_methods_;
4068 __ LoadFromOffset(
4069 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
4070 // temp = temp[index_in_cache]
4071 __ LoadFromOffset(
4072 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4073 // LR = temp[offset_of_quick_compiled_code]
4074 __ LoadFromOffset(kLoadWord, LR, temp,
4075 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4076 kArmWordSize).Int32Value());
4077 // LR()
4078 __ blx(LR);
4079 } else {
4080 __ bl(GetFrameEntryLabel());
4081 }
4082
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004083 DCHECK(!IsLeafMethod());
4084}
4085
Calin Juravleb1498f62015-02-16 13:13:29 +00004086void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4087 // Nothing to do, this should be removed during prepare for register allocator.
4088 UNUSED(instruction);
4089 LOG(FATAL) << "Unreachable";
4090}
4091
4092void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4093 // Nothing to do, this should be removed during prepare for register allocator.
4094 UNUSED(instruction);
4095 LOG(FATAL) << "Unreachable";
4096}
4097
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004098} // namespace arm
4099} // namespace art