blob: f4e4f5a74a529bc114d2e3e805efdf3068b1b2e8 [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"
Ian Rogers7e70b002014-10-08 11:47:24 -070022#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000023#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010024#include "mirror/class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070025#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010026#include "utils/arm/assembler_arm.h"
27#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000028#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010029#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000030
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000031namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010032
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000033namespace arm {
34
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000035static DRegister FromLowSToD(SRegister reg) {
36 DCHECK_EQ(reg % 2, 0);
37 return static_cast<DRegister>(reg / 2);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010038}
39
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000040static bool ExpectedPairLayout(Location location) {
41 // We expected this for both core and fpu register pairs.
42 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
43}
44
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010045static constexpr int kCurrentMethodStackOffset = 0;
46
Calin Juravled6fb6cf2014-11-11 19:07:44 +000047static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010048static constexpr size_t kRuntimeParameterCoreRegistersLength =
49 arraysize(kRuntimeParameterCoreRegisters);
Calin Juravled2ec87d2014-12-08 14:24:46 +000050static constexpr SRegister kRuntimeParameterFpuRegisters[] = { S0, S1, S2, S3 };
Roland Levillain624279f2014-12-04 11:54:28 +000051static constexpr size_t kRuntimeParameterFpuRegistersLength =
52 arraysize(kRuntimeParameterFpuRegisters);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010053
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000054class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010055 public:
56 InvokeRuntimeCallingConvention()
57 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010058 kRuntimeParameterCoreRegistersLength,
59 kRuntimeParameterFpuRegisters,
60 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010061
62 private:
63 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
64};
65
Nicolas Geoffraye5038322014-07-04 09:41:32 +010066#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010067#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010068
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010069class SlowPathCodeARM : public SlowPathCode {
70 public:
71 SlowPathCodeARM() : entry_label_(), exit_label_() {}
72
73 Label* GetEntryLabel() { return &entry_label_; }
74 Label* GetExitLabel() { return &exit_label_; }
75
76 private:
77 Label entry_label_;
78 Label exit_label_;
79
80 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
81};
82
83class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010084 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010085 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010086
Alexandre Rames67555f72014-11-18 10:55:16 +000087 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010088 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010089 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010090 arm_codegen->InvokeRuntime(
91 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010092 }
93
94 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010095 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010096 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
97};
98
Calin Juravled0d48522014-11-04 16:40:20 +000099class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
100 public:
101 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
102
Alexandre Rames67555f72014-11-18 10:55:16 +0000103 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +0000104 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
105 __ Bind(GetEntryLabel());
106 arm_codegen->InvokeRuntime(
107 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc());
108 }
109
110 private:
111 HDivZeroCheck* const instruction_;
112 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
113};
114
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100115class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000116 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000117 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100118 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000119
Alexandre Rames67555f72014-11-18 10:55:16 +0000120 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100121 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000122 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100123 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100124 arm_codegen->InvokeRuntime(
125 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100126 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100127 if (successor_ == nullptr) {
128 __ b(GetReturnLabel());
129 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100130 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100131 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132 }
133
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100134 Label* GetReturnLabel() {
135 DCHECK(successor_ == nullptr);
136 return &return_label_;
137 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000138
139 private:
140 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100141 // If not null, the block to branch to after the suspend check.
142 HBasicBlock* const successor_;
143
144 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000145 Label return_label_;
146
147 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
148};
149
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100150class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100151 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100152 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
153 Location index_location,
154 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100155 : instruction_(instruction),
156 index_location_(index_location),
157 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100158
Alexandre Rames67555f72014-11-18 10:55:16 +0000159 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100160 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100161 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000162 // We're moving two locations to locations that could overlap, so we need a parallel
163 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100164 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000165 codegen->EmitParallelMoves(
166 index_location_,
167 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
168 length_location_,
169 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100170 arm_codegen->InvokeRuntime(
171 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100172 }
173
174 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100175 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100176 const Location index_location_;
177 const Location length_location_;
178
179 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
180};
181
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000182class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100183 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000184 LoadClassSlowPathARM(HLoadClass* cls,
185 HInstruction* at,
186 uint32_t dex_pc,
187 bool do_clinit)
188 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
189 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
190 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100191
Alexandre Rames67555f72014-11-18 10:55:16 +0000192 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000193 LocationSummary* locations = at_->GetLocations();
194
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100195 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
196 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000197 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100198
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100199 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100201 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000202 int32_t entry_point_offset = do_clinit_
203 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
204 : QUICK_ENTRY_POINT(pInitializeType);
205 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
206
207 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000208 Location out = locations->Out();
209 if (out.IsValid()) {
210 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000211 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
212 }
213 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100214 __ b(GetExitLabel());
215 }
216
217 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000218 // The class this slow path will load.
219 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100220
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000221 // The instruction where this slow path is happening.
222 // (Might be the load class or an initialization check).
223 HInstruction* const at_;
224
225 // The dex PC of `at_`.
226 const uint32_t dex_pc_;
227
228 // Whether to initialize the class.
229 const bool do_clinit_;
230
231 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100232};
233
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000234class LoadStringSlowPathARM : public SlowPathCodeARM {
235 public:
236 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
237
Alexandre Rames67555f72014-11-18 10:55:16 +0000238 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000239 LocationSummary* locations = instruction_->GetLocations();
240 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
241
242 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
243 __ Bind(GetEntryLabel());
244 codegen->SaveLiveRegisters(locations);
245
246 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800247 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
248 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000249 arm_codegen->InvokeRuntime(
250 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
251 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
252
253 codegen->RestoreLiveRegisters(locations);
254 __ b(GetExitLabel());
255 }
256
257 private:
258 HLoadString* const instruction_;
259
260 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
261};
262
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000263class TypeCheckSlowPathARM : public SlowPathCodeARM {
264 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000265 TypeCheckSlowPathARM(HInstruction* instruction,
266 Location class_to_check,
267 Location object_class,
268 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000269 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000270 class_to_check_(class_to_check),
271 object_class_(object_class),
272 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000273
Alexandre Rames67555f72014-11-18 10:55:16 +0000274 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000275 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000276 DCHECK(instruction_->IsCheckCast()
277 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000278
279 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
280 __ Bind(GetEntryLabel());
281 codegen->SaveLiveRegisters(locations);
282
283 // We're moving two locations to locations that could overlap, so we need a parallel
284 // move resolver.
285 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000286 codegen->EmitParallelMoves(
287 class_to_check_,
288 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
289 object_class_,
290 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000291
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000292 if (instruction_->IsInstanceOf()) {
293 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_);
294 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
295 } else {
296 DCHECK(instruction_->IsCheckCast());
297 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_);
298 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000299
300 codegen->RestoreLiveRegisters(locations);
301 __ b(GetExitLabel());
302 }
303
304 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000305 HInstruction* const instruction_;
306 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000307 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000308 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000309
310 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
311};
312
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000313#undef __
314
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100315#undef __
316#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700317
318inline Condition ARMCondition(IfCondition cond) {
319 switch (cond) {
320 case kCondEQ: return EQ;
321 case kCondNE: return NE;
322 case kCondLT: return LT;
323 case kCondLE: return LE;
324 case kCondGT: return GT;
325 case kCondGE: return GE;
326 default:
327 LOG(FATAL) << "Unknown if condition";
328 }
329 return EQ; // Unreachable.
330}
331
332inline Condition ARMOppositeCondition(IfCondition cond) {
333 switch (cond) {
334 case kCondEQ: return NE;
335 case kCondNE: return EQ;
336 case kCondLT: return GE;
337 case kCondLE: return GT;
338 case kCondGT: return LE;
339 case kCondGE: return LT;
340 default:
341 LOG(FATAL) << "Unknown if condition";
342 }
343 return EQ; // Unreachable.
344}
345
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100346void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
347 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
348}
349
350void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000351 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100352}
353
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100354size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
355 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
356 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100357}
358
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100359size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
360 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
361 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100362}
363
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000364size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
365 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
366 return kArmWordSize;
367}
368
369size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
370 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
371 return kArmWordSize;
372}
373
Calin Juravle34166012014-12-19 17:22:29 +0000374CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000375 const ArmInstructionSetFeatures& isa_features,
376 const CompilerOptions& compiler_options)
377 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters,
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000378 kNumberOfRegisterPairs, (1 << R6) | (1 << R7) | (1 << LR), 0, compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100379 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100380 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100381 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100382 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000383 assembler_(true),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000384 isa_features_(isa_features) {
385 // We unconditionally allocate R6 and R7 to ensure we can do long operations
386 // with baseline.
387 AddAllocatedRegister(Location::RegisterLocation(R6));
388 AddAllocatedRegister(Location::RegisterLocation(R7));
389 // Save the link register to mimic Quick.
390 AddAllocatedRegister(Location::RegisterLocation(LR));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100391}
392
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100393Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100394 switch (type) {
395 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100396 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100397 ArmManagedRegister pair =
398 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100399 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
400 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
401
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100402 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
403 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100404 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100405 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100406 }
407
408 case Primitive::kPrimByte:
409 case Primitive::kPrimBoolean:
410 case Primitive::kPrimChar:
411 case Primitive::kPrimShort:
412 case Primitive::kPrimInt:
413 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100414 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100415 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100416 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
417 ArmManagedRegister current =
418 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
419 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100420 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100421 }
422 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100423 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100424 }
425
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000426 case Primitive::kPrimFloat: {
427 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100428 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100429 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100430
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000431 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000432 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
433 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000434 return Location::FpuRegisterPairLocation(reg, reg + 1);
435 }
436
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100437 case Primitive::kPrimVoid:
438 LOG(FATAL) << "Unreachable type " << type;
439 }
440
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100441 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100442}
443
Nicolas Geoffray98893962015-01-21 12:32:32 +0000444void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline ATTRIBUTE_UNUSED) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100445 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100446 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100447
448 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100449 blocked_core_registers_[SP] = true;
450 blocked_core_registers_[LR] = true;
451 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100452
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100453 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100454 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100455
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100456 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100457 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100458
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000459 // TODO: We currently don't use Quick's callee saved registers.
460 // We always save and restore R6 and R7 to make sure we can use three
461 // register pairs for long operations.
462 blocked_core_registers_[R4] = true;
463 blocked_core_registers_[R5] = true;
464 blocked_core_registers_[R8] = true;
465 blocked_core_registers_[R10] = true;
466 blocked_core_registers_[R11] = true;
467
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000468 blocked_fpu_registers_[S16] = true;
469 blocked_fpu_registers_[S17] = true;
470 blocked_fpu_registers_[S18] = true;
471 blocked_fpu_registers_[S19] = true;
472 blocked_fpu_registers_[S20] = true;
473 blocked_fpu_registers_[S21] = true;
474 blocked_fpu_registers_[S22] = true;
475 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000476 blocked_fpu_registers_[S24] = true;
477 blocked_fpu_registers_[S25] = true;
478 blocked_fpu_registers_[S26] = true;
479 blocked_fpu_registers_[S27] = true;
480 blocked_fpu_registers_[S28] = true;
481 blocked_fpu_registers_[S29] = true;
482 blocked_fpu_registers_[S30] = true;
483 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100484
485 UpdateBlockedPairRegisters();
486}
487
488void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
489 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
490 ArmManagedRegister current =
491 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
492 if (blocked_core_registers_[current.AsRegisterPairLow()]
493 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
494 blocked_register_pairs_[i] = true;
495 }
496 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100497}
498
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100499InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
500 : HGraphVisitor(graph),
501 assembler_(codegen->GetAssembler()),
502 codegen_(codegen) {}
503
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000504void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000505 bool skip_overflow_check =
506 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000507 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100508 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000509 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
510 __ LoadFromOffset(kLoadWord, IP, IP, 0);
511 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100512 }
513
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000514 __ PushList(core_spill_mask_);
515 __ AddConstant(SP, -(GetFrameSize() - FrameEntrySpillSize()));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100516 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000517}
518
519void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000520 __ AddConstant(SP, GetFrameSize() - FrameEntrySpillSize());
521 __ PopList((core_spill_mask_ & (~(1 << LR))) | 1 << PC);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000522}
523
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100524void CodeGeneratorARM::Bind(HBasicBlock* block) {
525 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000526}
527
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100528Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
529 switch (load->GetType()) {
530 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100531 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100532 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
533 break;
534
535 case Primitive::kPrimInt:
536 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100537 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100538 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100539
540 case Primitive::kPrimBoolean:
541 case Primitive::kPrimByte:
542 case Primitive::kPrimChar:
543 case Primitive::kPrimShort:
544 case Primitive::kPrimVoid:
545 LOG(FATAL) << "Unexpected type " << load->GetType();
546 }
547
548 LOG(FATAL) << "Unreachable";
549 return Location();
550}
551
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100552Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
553 switch (type) {
554 case Primitive::kPrimBoolean:
555 case Primitive::kPrimByte:
556 case Primitive::kPrimChar:
557 case Primitive::kPrimShort:
558 case Primitive::kPrimInt:
559 case Primitive::kPrimNot: {
560 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000561 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100562 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100563 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100564 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000565 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100566 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100567 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100568
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000569 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100570 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000571 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100572 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000573 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100574 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000575 if (calling_convention.GetRegisterAt(index) == R1) {
576 // Skip R1, and use R2_R3 instead.
577 gp_index_++;
578 index++;
579 }
580 }
581 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
582 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000583 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000584 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000585 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100586 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000587 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
588 }
589 }
590
591 case Primitive::kPrimFloat: {
592 uint32_t stack_index = stack_index_++;
593 if (float_index_ % 2 == 0) {
594 float_index_ = std::max(double_index_, float_index_);
595 }
596 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
597 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
598 } else {
599 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
600 }
601 }
602
603 case Primitive::kPrimDouble: {
604 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
605 uint32_t stack_index = stack_index_;
606 stack_index_ += 2;
607 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
608 uint32_t index = double_index_;
609 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000610 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000611 calling_convention.GetFpuRegisterAt(index),
612 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000613 DCHECK(ExpectedPairLayout(result));
614 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000615 } else {
616 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100617 }
618 }
619
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100620 case Primitive::kPrimVoid:
621 LOG(FATAL) << "Unexpected parameter type " << type;
622 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100623 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100624 return Location();
625}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100626
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000627Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
628 switch (type) {
629 case Primitive::kPrimBoolean:
630 case Primitive::kPrimByte:
631 case Primitive::kPrimChar:
632 case Primitive::kPrimShort:
633 case Primitive::kPrimInt:
634 case Primitive::kPrimNot: {
635 return Location::RegisterLocation(R0);
636 }
637
638 case Primitive::kPrimFloat: {
639 return Location::FpuRegisterLocation(S0);
640 }
641
642 case Primitive::kPrimLong: {
643 return Location::RegisterPairLocation(R0, R1);
644 }
645
646 case Primitive::kPrimDouble: {
647 return Location::FpuRegisterPairLocation(S0, S1);
648 }
649
650 case Primitive::kPrimVoid:
651 return Location();
652 }
653 UNREACHABLE();
654 return Location();
655}
656
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100657void CodeGeneratorARM::Move32(Location destination, Location source) {
658 if (source.Equals(destination)) {
659 return;
660 }
661 if (destination.IsRegister()) {
662 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000663 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100664 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000665 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100666 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000667 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100668 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100669 } else if (destination.IsFpuRegister()) {
670 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000671 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100672 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000673 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100674 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000675 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100676 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100677 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000678 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100679 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000680 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100681 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000682 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100683 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000684 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100685 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
686 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100687 }
688 }
689}
690
691void CodeGeneratorARM::Move64(Location destination, Location source) {
692 if (source.Equals(destination)) {
693 return;
694 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100695 if (destination.IsRegisterPair()) {
696 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000697 EmitParallelMoves(
698 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
699 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
700 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
701 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100702 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000703 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100704 } else {
705 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000706 DCHECK(ExpectedPairLayout(destination));
707 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
708 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100709 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000710 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100711 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000712 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
713 SP,
714 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100715 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000716 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100717 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100718 } else {
719 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100720 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000721 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100722 if (source.AsRegisterPairLow<Register>() == R1) {
723 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100724 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
725 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100726 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100727 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100728 SP, destination.GetStackIndex());
729 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000730 } else if (source.IsFpuRegisterPair()) {
731 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
732 SP,
733 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100734 } else {
735 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000736 EmitParallelMoves(
737 Location::StackSlot(source.GetStackIndex()),
738 Location::StackSlot(destination.GetStackIndex()),
739 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
740 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100741 }
742 }
743}
744
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100745void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100746 LocationSummary* locations = instruction->GetLocations();
747 if (locations != nullptr && locations->Out().Equals(location)) {
748 return;
749 }
750
Calin Juravlea21f5982014-11-13 15:53:04 +0000751 if (locations != nullptr && locations->Out().IsConstant()) {
752 HConstant* const_to_move = locations->Out().GetConstant();
753 if (const_to_move->IsIntConstant()) {
754 int32_t value = const_to_move->AsIntConstant()->GetValue();
755 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000756 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000757 } else {
758 DCHECK(location.IsStackSlot());
759 __ LoadImmediate(IP, value);
760 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
761 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000762 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000763 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000764 int64_t value = const_to_move->AsLongConstant()->GetValue();
765 if (location.IsRegisterPair()) {
766 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
767 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
768 } else {
769 DCHECK(location.IsDoubleStackSlot());
770 __ LoadImmediate(IP, Low32Bits(value));
771 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
772 __ LoadImmediate(IP, High32Bits(value));
773 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
774 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100775 }
Roland Levillain476df552014-10-09 17:51:36 +0100776 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100777 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
778 switch (instruction->GetType()) {
779 case Primitive::kPrimBoolean:
780 case Primitive::kPrimByte:
781 case Primitive::kPrimChar:
782 case Primitive::kPrimShort:
783 case Primitive::kPrimInt:
784 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100785 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100786 Move32(location, Location::StackSlot(stack_slot));
787 break;
788
789 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100790 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100791 Move64(location, Location::DoubleStackSlot(stack_slot));
792 break;
793
794 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100795 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100796 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000797 } else if (instruction->IsTemporary()) {
798 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000799 if (temp_location.IsStackSlot()) {
800 Move32(location, temp_location);
801 } else {
802 DCHECK(temp_location.IsDoubleStackSlot());
803 Move64(location, temp_location);
804 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000805 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100806 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100807 switch (instruction->GetType()) {
808 case Primitive::kPrimBoolean:
809 case Primitive::kPrimByte:
810 case Primitive::kPrimChar:
811 case Primitive::kPrimShort:
812 case Primitive::kPrimNot:
813 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100814 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100815 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100816 break;
817
818 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100819 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100820 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100821 break;
822
823 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100824 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100825 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000826 }
827}
828
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100829void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
830 HInstruction* instruction,
831 uint32_t dex_pc) {
832 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
833 __ blx(LR);
834 RecordPcInfo(instruction, dex_pc);
835 DCHECK(instruction->IsSuspendCheck()
836 || instruction->IsBoundsCheck()
837 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000838 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000839 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100840 || !IsLeafMethod());
841}
842
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000843void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000844 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000845}
846
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000847void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000848 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100849 DCHECK(!successor->IsExitBlock());
850
851 HBasicBlock* block = got->GetBlock();
852 HInstruction* previous = got->GetPrevious();
853
854 HLoopInformation* info = block->GetLoopInformation();
855 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
856 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
857 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
858 return;
859 }
860
861 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
862 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
863 }
864 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000865 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000866 }
867}
868
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000869void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000870 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000871}
872
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000873void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700874 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000875 if (kIsDebugBuild) {
876 __ Comment("Unreachable");
877 __ bkpt(0);
878 }
879}
880
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000881void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100882 LocationSummary* locations =
883 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100884 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100885 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100886 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100887 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000888}
889
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000890void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700891 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100892 if (cond->IsIntConstant()) {
893 // Constant condition, statically compared against 1.
894 int32_t cond_value = cond->AsIntConstant()->GetValue();
895 if (cond_value == 1) {
896 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
897 if_instr->IfTrueSuccessor())) {
898 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100899 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100900 return;
901 } else {
902 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100903 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100904 } else {
905 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
906 // Condition has been materialized, compare the output to 0
907 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000908 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100909 ShifterOperand(0));
910 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
911 } else {
912 // Condition has not been materialized, use its inputs as the
913 // comparison and its condition as the branch condition.
914 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000915 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000916 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100917 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000918 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100919 } else {
920 DCHECK(locations->InAt(1).IsConstant());
921 int32_t value =
922 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
923 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000924 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
925 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100926 } else {
927 Register temp = IP;
928 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000929 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100930 }
931 }
932 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
933 ARMCondition(cond->AsCondition()->GetCondition()));
934 }
Dave Allison20dfc792014-06-16 20:44:29 -0700935 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100936 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
937 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700938 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000939 }
940}
941
Dave Allison20dfc792014-06-16 20:44:29 -0700942
943void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100944 LocationSummary* locations =
945 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100946 locations->SetInAt(0, Location::RequiresRegister());
947 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100948 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100949 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100950 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000951}
952
Dave Allison20dfc792014-06-16 20:44:29 -0700953void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100954 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100955 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000956 Register left = locations->InAt(0).AsRegister<Register>();
957
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100958 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000959 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100960 } else {
961 DCHECK(locations->InAt(1).IsConstant());
962 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
963 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000964 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
965 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100966 } else {
967 Register temp = IP;
968 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000969 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100970 }
Dave Allison20dfc792014-06-16 20:44:29 -0700971 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100972 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +0000973 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100974 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +0000975 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100976 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700977}
978
979void LocationsBuilderARM::VisitEqual(HEqual* comp) {
980 VisitCondition(comp);
981}
982
983void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
984 VisitCondition(comp);
985}
986
987void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
988 VisitCondition(comp);
989}
990
991void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
992 VisitCondition(comp);
993}
994
995void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
996 VisitCondition(comp);
997}
998
999void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1000 VisitCondition(comp);
1001}
1002
1003void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1004 VisitCondition(comp);
1005}
1006
1007void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1008 VisitCondition(comp);
1009}
1010
1011void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1012 VisitCondition(comp);
1013}
1014
1015void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1016 VisitCondition(comp);
1017}
1018
1019void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1020 VisitCondition(comp);
1021}
1022
1023void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1024 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001025}
1026
1027void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001028 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001029}
1030
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001031void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1032 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001033}
1034
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001035void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001036 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001037}
1038
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001039void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001040 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001041 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001042}
1043
1044void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001045 LocationSummary* locations =
1046 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001047 switch (store->InputAt(1)->GetType()) {
1048 case Primitive::kPrimBoolean:
1049 case Primitive::kPrimByte:
1050 case Primitive::kPrimChar:
1051 case Primitive::kPrimShort:
1052 case Primitive::kPrimInt:
1053 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001054 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001055 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1056 break;
1057
1058 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001059 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001060 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1061 break;
1062
1063 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001064 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001065 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001066}
1067
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001068void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001069 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001070}
1071
1072void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001073 LocationSummary* locations =
1074 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001075 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001076}
1077
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001078void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001079 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001080 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001081}
1082
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001083void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001084 LocationSummary* locations =
1085 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001086 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001087}
1088
1089void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1090 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001091 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001092}
1093
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001094void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1095 LocationSummary* locations =
1096 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1097 locations->SetOut(Location::ConstantLocation(constant));
1098}
1099
1100void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1101 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001102 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001103}
1104
1105void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1106 LocationSummary* locations =
1107 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1108 locations->SetOut(Location::ConstantLocation(constant));
1109}
1110
1111void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1112 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001113 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001114}
1115
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001116void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001117 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001118}
1119
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001120void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001121 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001122 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001123}
1124
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001125void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001126 LocationSummary* locations =
1127 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001128 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001129}
1130
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001131void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001132 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001133 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001134}
1135
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001136void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001137 HandleInvoke(invoke);
1138}
1139
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001140void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001141 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001142}
1143
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001144void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001145 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001146
1147 // TODO: Implement all kinds of calls:
1148 // 1) boot -> boot
1149 // 2) app -> boot
1150 // 3) app -> app
1151 //
1152 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1153
1154 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001155 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001156 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001157 __ LoadFromOffset(
1158 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001159 // temp = temp[index_in_cache]
1160 __ LoadFromOffset(
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001161 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001162 // LR = temp[offset_of_quick_compiled_code]
1163 __ LoadFromOffset(kLoadWord, LR, temp,
1164 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1165 kArmWordSize).Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001166 // LR()
1167 __ blx(LR);
1168
1169 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1170 DCHECK(!codegen_->IsLeafMethod());
1171}
1172
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001173void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001174 LocationSummary* locations =
1175 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001176 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001177
1178 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001179 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001180 HInstruction* input = invoke->InputAt(i);
1181 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1182 }
1183
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001184 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001185}
1186
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001187void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1188 HandleInvoke(invoke);
1189}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001190
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001191void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001192 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001193 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1194 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1195 LocationSummary* locations = invoke->GetLocations();
1196 Location receiver = locations->InAt(0);
1197 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1198 // temp = object->GetClass();
1199 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001200 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1201 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001202 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001203 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001204 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001205 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001206 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001207 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001208 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001209 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001210 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001211 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001212 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001213 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001214 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001215 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001216}
1217
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001218void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1219 HandleInvoke(invoke);
1220 // Add the hidden argument.
1221 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1222}
1223
1224void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1225 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001226 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001227 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1228 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1229 LocationSummary* locations = invoke->GetLocations();
1230 Location receiver = locations->InAt(0);
1231 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1232
1233 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001234 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1235 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001236
1237 // temp = object->GetClass();
1238 if (receiver.IsStackSlot()) {
1239 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1240 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1241 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001242 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001243 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001244 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001245 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001246 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001247 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001248 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1249 // LR = temp->GetEntryPoint();
1250 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1251 // LR();
1252 __ blx(LR);
1253 DCHECK(!codegen_->IsLeafMethod());
1254 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1255}
1256
Roland Levillain88cb1752014-10-20 16:36:47 +01001257void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1258 LocationSummary* locations =
1259 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1260 switch (neg->GetResultType()) {
1261 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001262 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001263 Location::OutputOverlap output_overlaps = (neg->GetResultType() == Primitive::kPrimLong)
1264 ? Location::kOutputOverlap
1265 : Location::kNoOutputOverlap;
Roland Levillain88cb1752014-10-20 16:36:47 +01001266 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001267 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001268 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001269 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001270
Roland Levillain88cb1752014-10-20 16:36:47 +01001271 case Primitive::kPrimFloat:
1272 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001273 locations->SetInAt(0, Location::RequiresFpuRegister());
1274 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001275 break;
1276
1277 default:
1278 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1279 }
1280}
1281
1282void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1283 LocationSummary* locations = neg->GetLocations();
1284 Location out = locations->Out();
1285 Location in = locations->InAt(0);
1286 switch (neg->GetResultType()) {
1287 case Primitive::kPrimInt:
1288 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001289 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001290 break;
1291
1292 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001293 DCHECK(in.IsRegisterPair());
1294 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1295 __ rsbs(out.AsRegisterPairLow<Register>(),
1296 in.AsRegisterPairLow<Register>(),
1297 ShifterOperand(0));
1298 // We cannot emit an RSC (Reverse Subtract with Carry)
1299 // instruction here, as it does not exist in the Thumb-2
1300 // instruction set. We use the following approach
1301 // using SBC and SUB instead.
1302 //
1303 // out.hi = -C
1304 __ sbc(out.AsRegisterPairHigh<Register>(),
1305 out.AsRegisterPairHigh<Register>(),
1306 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1307 // out.hi = out.hi - in.hi
1308 __ sub(out.AsRegisterPairHigh<Register>(),
1309 out.AsRegisterPairHigh<Register>(),
1310 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1311 break;
1312
Roland Levillain88cb1752014-10-20 16:36:47 +01001313 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001314 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001315 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001316 break;
1317
Roland Levillain88cb1752014-10-20 16:36:47 +01001318 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001319 DCHECK(in.IsFpuRegisterPair());
1320 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1321 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001322 break;
1323
1324 default:
1325 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1326 }
1327}
1328
Roland Levillaindff1f282014-11-05 14:15:05 +00001329void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001330 Primitive::Type result_type = conversion->GetResultType();
1331 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001332 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001333
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001334 // The float-to-long and double-to-long type conversions rely on a
1335 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001336 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001337 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1338 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001339 ? LocationSummary::kCall
1340 : LocationSummary::kNoCall;
1341 LocationSummary* locations =
1342 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1343
Roland Levillaindff1f282014-11-05 14:15:05 +00001344 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001345 case Primitive::kPrimByte:
1346 switch (input_type) {
1347 case Primitive::kPrimShort:
1348 case Primitive::kPrimInt:
1349 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001350 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001351 locations->SetInAt(0, Location::RequiresRegister());
1352 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1353 break;
1354
1355 default:
1356 LOG(FATAL) << "Unexpected type conversion from " << input_type
1357 << " to " << result_type;
1358 }
1359 break;
1360
Roland Levillain01a8d712014-11-14 16:27:39 +00001361 case Primitive::kPrimShort:
1362 switch (input_type) {
1363 case Primitive::kPrimByte:
1364 case Primitive::kPrimInt:
1365 case Primitive::kPrimChar:
1366 // Processing a Dex `int-to-short' instruction.
1367 locations->SetInAt(0, Location::RequiresRegister());
1368 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1369 break;
1370
1371 default:
1372 LOG(FATAL) << "Unexpected type conversion from " << input_type
1373 << " to " << result_type;
1374 }
1375 break;
1376
Roland Levillain946e1432014-11-11 17:35:19 +00001377 case Primitive::kPrimInt:
1378 switch (input_type) {
1379 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001380 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001381 locations->SetInAt(0, Location::Any());
1382 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1383 break;
1384
1385 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001386 // Processing a Dex `float-to-int' instruction.
1387 locations->SetInAt(0, Location::RequiresFpuRegister());
1388 locations->SetOut(Location::RequiresRegister());
1389 locations->AddTemp(Location::RequiresFpuRegister());
1390 break;
1391
Roland Levillain946e1432014-11-11 17:35:19 +00001392 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001393 // Processing a Dex `double-to-int' instruction.
1394 locations->SetInAt(0, Location::RequiresFpuRegister());
1395 locations->SetOut(Location::RequiresRegister());
1396 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001397 break;
1398
1399 default:
1400 LOG(FATAL) << "Unexpected type conversion from " << input_type
1401 << " to " << result_type;
1402 }
1403 break;
1404
Roland Levillaindff1f282014-11-05 14:15:05 +00001405 case Primitive::kPrimLong:
1406 switch (input_type) {
1407 case Primitive::kPrimByte:
1408 case Primitive::kPrimShort:
1409 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001410 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001411 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001412 locations->SetInAt(0, Location::RequiresRegister());
1413 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1414 break;
1415
Roland Levillain624279f2014-12-04 11:54:28 +00001416 case Primitive::kPrimFloat: {
1417 // Processing a Dex `float-to-long' instruction.
1418 InvokeRuntimeCallingConvention calling_convention;
1419 locations->SetInAt(0, Location::FpuRegisterLocation(
1420 calling_convention.GetFpuRegisterAt(0)));
1421 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1422 break;
1423 }
1424
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001425 case Primitive::kPrimDouble: {
1426 // Processing a Dex `double-to-long' instruction.
1427 InvokeRuntimeCallingConvention calling_convention;
1428 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1429 calling_convention.GetFpuRegisterAt(0),
1430 calling_convention.GetFpuRegisterAt(1)));
1431 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001432 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001433 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001434
1435 default:
1436 LOG(FATAL) << "Unexpected type conversion from " << input_type
1437 << " to " << result_type;
1438 }
1439 break;
1440
Roland Levillain981e4542014-11-14 11:47:14 +00001441 case Primitive::kPrimChar:
1442 switch (input_type) {
1443 case Primitive::kPrimByte:
1444 case Primitive::kPrimShort:
1445 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001446 // Processing a Dex `int-to-char' instruction.
1447 locations->SetInAt(0, Location::RequiresRegister());
1448 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1449 break;
1450
1451 default:
1452 LOG(FATAL) << "Unexpected type conversion from " << input_type
1453 << " to " << result_type;
1454 }
1455 break;
1456
Roland Levillaindff1f282014-11-05 14:15:05 +00001457 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001458 switch (input_type) {
1459 case Primitive::kPrimByte:
1460 case Primitive::kPrimShort:
1461 case Primitive::kPrimInt:
1462 case Primitive::kPrimChar:
1463 // Processing a Dex `int-to-float' instruction.
1464 locations->SetInAt(0, Location::RequiresRegister());
1465 locations->SetOut(Location::RequiresFpuRegister());
1466 break;
1467
1468 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001469 // Processing a Dex `long-to-float' instruction.
1470 locations->SetInAt(0, Location::RequiresRegister());
1471 locations->SetOut(Location::RequiresFpuRegister());
1472 locations->AddTemp(Location::RequiresRegister());
1473 locations->AddTemp(Location::RequiresRegister());
1474 locations->AddTemp(Location::RequiresFpuRegister());
1475 locations->AddTemp(Location::RequiresFpuRegister());
1476 break;
1477
Roland Levillaincff13742014-11-17 14:32:17 +00001478 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001479 // Processing a Dex `double-to-float' instruction.
1480 locations->SetInAt(0, Location::RequiresFpuRegister());
1481 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001482 break;
1483
1484 default:
1485 LOG(FATAL) << "Unexpected type conversion from " << input_type
1486 << " to " << result_type;
1487 };
1488 break;
1489
Roland Levillaindff1f282014-11-05 14:15:05 +00001490 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001491 switch (input_type) {
1492 case Primitive::kPrimByte:
1493 case Primitive::kPrimShort:
1494 case Primitive::kPrimInt:
1495 case Primitive::kPrimChar:
1496 // Processing a Dex `int-to-double' instruction.
1497 locations->SetInAt(0, Location::RequiresRegister());
1498 locations->SetOut(Location::RequiresFpuRegister());
1499 break;
1500
1501 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001502 // Processing a Dex `long-to-double' instruction.
1503 locations->SetInAt(0, Location::RequiresRegister());
1504 locations->SetOut(Location::RequiresFpuRegister());
1505 locations->AddTemp(Location::RequiresRegister());
1506 locations->AddTemp(Location::RequiresRegister());
1507 locations->AddTemp(Location::RequiresFpuRegister());
1508 break;
1509
Roland Levillaincff13742014-11-17 14:32:17 +00001510 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001511 // Processing a Dex `float-to-double' instruction.
1512 locations->SetInAt(0, Location::RequiresFpuRegister());
1513 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001514 break;
1515
1516 default:
1517 LOG(FATAL) << "Unexpected type conversion from " << input_type
1518 << " to " << result_type;
1519 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001520 break;
1521
1522 default:
1523 LOG(FATAL) << "Unexpected type conversion from " << input_type
1524 << " to " << result_type;
1525 }
1526}
1527
1528void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1529 LocationSummary* locations = conversion->GetLocations();
1530 Location out = locations->Out();
1531 Location in = locations->InAt(0);
1532 Primitive::Type result_type = conversion->GetResultType();
1533 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001534 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001535 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001536 case Primitive::kPrimByte:
1537 switch (input_type) {
1538 case Primitive::kPrimShort:
1539 case Primitive::kPrimInt:
1540 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001541 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001542 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001543 break;
1544
1545 default:
1546 LOG(FATAL) << "Unexpected type conversion from " << input_type
1547 << " to " << result_type;
1548 }
1549 break;
1550
Roland Levillain01a8d712014-11-14 16:27:39 +00001551 case Primitive::kPrimShort:
1552 switch (input_type) {
1553 case Primitive::kPrimByte:
1554 case Primitive::kPrimInt:
1555 case Primitive::kPrimChar:
1556 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001557 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001558 break;
1559
1560 default:
1561 LOG(FATAL) << "Unexpected type conversion from " << input_type
1562 << " to " << result_type;
1563 }
1564 break;
1565
Roland Levillain946e1432014-11-11 17:35:19 +00001566 case Primitive::kPrimInt:
1567 switch (input_type) {
1568 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001569 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001570 DCHECK(out.IsRegister());
1571 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001572 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001573 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001574 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001575 } else {
1576 DCHECK(in.IsConstant());
1577 DCHECK(in.GetConstant()->IsLongConstant());
1578 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001579 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001580 }
1581 break;
1582
Roland Levillain3f8f9362014-12-02 17:45:01 +00001583 case Primitive::kPrimFloat: {
1584 // Processing a Dex `float-to-int' instruction.
1585 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1586 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1587 __ vcvtis(temp, temp);
1588 __ vmovrs(out.AsRegister<Register>(), temp);
1589 break;
1590 }
1591
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001592 case Primitive::kPrimDouble: {
1593 // Processing a Dex `double-to-int' instruction.
1594 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1595 DRegister temp_d = FromLowSToD(temp_s);
1596 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1597 __ vcvtid(temp_s, temp_d);
1598 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001599 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001600 }
Roland Levillain946e1432014-11-11 17:35:19 +00001601
1602 default:
1603 LOG(FATAL) << "Unexpected type conversion from " << input_type
1604 << " to " << result_type;
1605 }
1606 break;
1607
Roland Levillaindff1f282014-11-05 14:15:05 +00001608 case Primitive::kPrimLong:
1609 switch (input_type) {
1610 case Primitive::kPrimByte:
1611 case Primitive::kPrimShort:
1612 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001613 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001614 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001615 DCHECK(out.IsRegisterPair());
1616 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001617 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001618 // Sign extension.
1619 __ Asr(out.AsRegisterPairHigh<Register>(),
1620 out.AsRegisterPairLow<Register>(),
1621 31);
1622 break;
1623
1624 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001625 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001626 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1627 conversion,
1628 conversion->GetDexPc());
1629 break;
1630
Roland Levillaindff1f282014-11-05 14:15:05 +00001631 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001632 // Processing a Dex `double-to-long' instruction.
1633 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1634 conversion,
1635 conversion->GetDexPc());
Roland Levillaindff1f282014-11-05 14:15:05 +00001636 break;
1637
1638 default:
1639 LOG(FATAL) << "Unexpected type conversion from " << input_type
1640 << " to " << result_type;
1641 }
1642 break;
1643
Roland Levillain981e4542014-11-14 11:47:14 +00001644 case Primitive::kPrimChar:
1645 switch (input_type) {
1646 case Primitive::kPrimByte:
1647 case Primitive::kPrimShort:
1648 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001649 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001650 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001651 break;
1652
1653 default:
1654 LOG(FATAL) << "Unexpected type conversion from " << input_type
1655 << " to " << result_type;
1656 }
1657 break;
1658
Roland Levillaindff1f282014-11-05 14:15:05 +00001659 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001660 switch (input_type) {
1661 case Primitive::kPrimByte:
1662 case Primitive::kPrimShort:
1663 case Primitive::kPrimInt:
1664 case Primitive::kPrimChar: {
1665 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001666 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1667 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001668 break;
1669 }
1670
Roland Levillain6d0e4832014-11-27 18:31:21 +00001671 case Primitive::kPrimLong: {
1672 // Processing a Dex `long-to-float' instruction.
1673 Register low = in.AsRegisterPairLow<Register>();
1674 Register high = in.AsRegisterPairHigh<Register>();
1675 SRegister output = out.AsFpuRegister<SRegister>();
1676 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1677 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1678 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1679 DRegister temp1_d = FromLowSToD(temp1_s);
1680 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1681 DRegister temp2_d = FromLowSToD(temp2_s);
1682
1683 // Operations use doubles for precision reasons (each 32-bit
1684 // half of a long fits in the 53-bit mantissa of a double,
1685 // but not in the 24-bit mantissa of a float). This is
1686 // especially important for the low bits. The result is
1687 // eventually converted to float.
1688
1689 // temp1_d = int-to-double(high)
1690 __ vmovsr(temp1_s, high);
1691 __ vcvtdi(temp1_d, temp1_s);
1692 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1693 // as an immediate value into `temp2_d` does not work, as
1694 // this instruction only transfers 8 significant bits of its
1695 // immediate operand. Instead, use two 32-bit core
1696 // registers to load `k2Pow32EncodingForDouble` into
1697 // `temp2_d`.
1698 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1699 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1700 __ vmovdrr(temp2_d, constant_low, constant_high);
1701 // temp1_d = temp1_d * 2^32
1702 __ vmuld(temp1_d, temp1_d, temp2_d);
1703 // temp2_d = unsigned-to-double(low)
1704 __ vmovsr(temp2_s, low);
1705 __ vcvtdu(temp2_d, temp2_s);
1706 // temp1_d = temp1_d + temp2_d
1707 __ vaddd(temp1_d, temp1_d, temp2_d);
1708 // output = double-to-float(temp1_d);
1709 __ vcvtsd(output, temp1_d);
1710 break;
1711 }
1712
Roland Levillaincff13742014-11-17 14:32:17 +00001713 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001714 // Processing a Dex `double-to-float' instruction.
1715 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1716 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001717 break;
1718
1719 default:
1720 LOG(FATAL) << "Unexpected type conversion from " << input_type
1721 << " to " << result_type;
1722 };
1723 break;
1724
Roland Levillaindff1f282014-11-05 14:15:05 +00001725 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001726 switch (input_type) {
1727 case Primitive::kPrimByte:
1728 case Primitive::kPrimShort:
1729 case Primitive::kPrimInt:
1730 case Primitive::kPrimChar: {
1731 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001732 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001733 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1734 out.AsFpuRegisterPairLow<SRegister>());
1735 break;
1736 }
1737
Roland Levillain647b9ed2014-11-27 12:06:00 +00001738 case Primitive::kPrimLong: {
1739 // Processing a Dex `long-to-double' instruction.
1740 Register low = in.AsRegisterPairLow<Register>();
1741 Register high = in.AsRegisterPairHigh<Register>();
1742 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1743 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001744 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1745 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001746 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1747 DRegister temp_d = FromLowSToD(temp_s);
1748
Roland Levillain647b9ed2014-11-27 12:06:00 +00001749 // out_d = int-to-double(high)
1750 __ vmovsr(out_s, high);
1751 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001752 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1753 // as an immediate value into `temp_d` does not work, as
1754 // this instruction only transfers 8 significant bits of its
1755 // immediate operand. Instead, use two 32-bit core
1756 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1757 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1758 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001759 __ vmovdrr(temp_d, constant_low, constant_high);
1760 // out_d = out_d * 2^32
1761 __ vmuld(out_d, out_d, temp_d);
1762 // temp_d = unsigned-to-double(low)
1763 __ vmovsr(temp_s, low);
1764 __ vcvtdu(temp_d, temp_s);
1765 // out_d = out_d + temp_d
1766 __ vaddd(out_d, out_d, temp_d);
1767 break;
1768 }
1769
Roland Levillaincff13742014-11-17 14:32:17 +00001770 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001771 // Processing a Dex `float-to-double' instruction.
1772 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1773 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001774 break;
1775
1776 default:
1777 LOG(FATAL) << "Unexpected type conversion from " << input_type
1778 << " to " << result_type;
1779 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001780 break;
1781
1782 default:
1783 LOG(FATAL) << "Unexpected type conversion from " << input_type
1784 << " to " << result_type;
1785 }
1786}
1787
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001788void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001789 LocationSummary* locations =
1790 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001791 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001792 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001793 locations->SetInAt(0, Location::RequiresRegister());
1794 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001795 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1796 break;
1797 }
1798
1799 case Primitive::kPrimLong: {
1800 locations->SetInAt(0, Location::RequiresRegister());
1801 locations->SetInAt(1, Location::RequiresRegister());
1802 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001803 break;
1804 }
1805
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001806 case Primitive::kPrimFloat:
1807 case Primitive::kPrimDouble: {
1808 locations->SetInAt(0, Location::RequiresFpuRegister());
1809 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001810 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001811 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001812 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001813
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001814 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001815 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001816 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001817}
1818
1819void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1820 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001821 Location out = locations->Out();
1822 Location first = locations->InAt(0);
1823 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001824 switch (add->GetResultType()) {
1825 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001826 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001827 __ add(out.AsRegister<Register>(),
1828 first.AsRegister<Register>(),
1829 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001830 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001831 __ AddConstant(out.AsRegister<Register>(),
1832 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001833 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001834 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001835 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001836
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001837 case Primitive::kPrimLong: {
1838 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001839 __ adds(out.AsRegisterPairLow<Register>(),
1840 first.AsRegisterPairLow<Register>(),
1841 ShifterOperand(second.AsRegisterPairLow<Register>()));
1842 __ adc(out.AsRegisterPairHigh<Register>(),
1843 first.AsRegisterPairHigh<Register>(),
1844 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001845 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001846 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001847
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001848 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001849 __ vadds(out.AsFpuRegister<SRegister>(),
1850 first.AsFpuRegister<SRegister>(),
1851 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001852 break;
1853
1854 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001855 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1856 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1857 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001858 break;
1859
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001860 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001861 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001862 }
1863}
1864
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001865void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001866 LocationSummary* locations =
1867 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001868 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001869 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001870 locations->SetInAt(0, Location::RequiresRegister());
1871 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001872 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1873 break;
1874 }
1875
1876 case Primitive::kPrimLong: {
1877 locations->SetInAt(0, Location::RequiresRegister());
1878 locations->SetInAt(1, Location::RequiresRegister());
1879 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001880 break;
1881 }
Calin Juravle11351682014-10-23 15:38:15 +01001882 case Primitive::kPrimFloat:
1883 case Primitive::kPrimDouble: {
1884 locations->SetInAt(0, Location::RequiresFpuRegister());
1885 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001886 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001887 break;
Calin Juravle11351682014-10-23 15:38:15 +01001888 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001889 default:
Calin Juravle11351682014-10-23 15:38:15 +01001890 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001891 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001892}
1893
1894void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1895 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001896 Location out = locations->Out();
1897 Location first = locations->InAt(0);
1898 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001899 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001900 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001901 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001902 __ sub(out.AsRegister<Register>(),
1903 first.AsRegister<Register>(),
1904 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001905 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001906 __ AddConstant(out.AsRegister<Register>(),
1907 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001908 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001909 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001910 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001911 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001912
Calin Juravle11351682014-10-23 15:38:15 +01001913 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001914 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01001915 __ subs(out.AsRegisterPairLow<Register>(),
1916 first.AsRegisterPairLow<Register>(),
1917 ShifterOperand(second.AsRegisterPairLow<Register>()));
1918 __ sbc(out.AsRegisterPairHigh<Register>(),
1919 first.AsRegisterPairHigh<Register>(),
1920 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001921 break;
Calin Juravle11351682014-10-23 15:38:15 +01001922 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001923
Calin Juravle11351682014-10-23 15:38:15 +01001924 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001925 __ vsubs(out.AsFpuRegister<SRegister>(),
1926 first.AsFpuRegister<SRegister>(),
1927 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001928 break;
Calin Juravle11351682014-10-23 15:38:15 +01001929 }
1930
1931 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001932 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1933 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1934 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001935 break;
1936 }
1937
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001938
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001939 default:
Calin Juravle11351682014-10-23 15:38:15 +01001940 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001941 }
1942}
1943
Calin Juravle34bacdf2014-10-07 20:23:36 +01001944void LocationsBuilderARM::VisitMul(HMul* mul) {
1945 LocationSummary* locations =
1946 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1947 switch (mul->GetResultType()) {
1948 case Primitive::kPrimInt:
1949 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001950 locations->SetInAt(0, Location::RequiresRegister());
1951 locations->SetInAt(1, Location::RequiresRegister());
1952 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001953 break;
1954 }
1955
Calin Juravleb5bfa962014-10-21 18:02:24 +01001956 case Primitive::kPrimFloat:
1957 case Primitive::kPrimDouble: {
1958 locations->SetInAt(0, Location::RequiresFpuRegister());
1959 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001960 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001961 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001962 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001963
1964 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001965 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001966 }
1967}
1968
1969void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1970 LocationSummary* locations = mul->GetLocations();
1971 Location out = locations->Out();
1972 Location first = locations->InAt(0);
1973 Location second = locations->InAt(1);
1974 switch (mul->GetResultType()) {
1975 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00001976 __ mul(out.AsRegister<Register>(),
1977 first.AsRegister<Register>(),
1978 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001979 break;
1980 }
1981 case Primitive::kPrimLong: {
1982 Register out_hi = out.AsRegisterPairHigh<Register>();
1983 Register out_lo = out.AsRegisterPairLow<Register>();
1984 Register in1_hi = first.AsRegisterPairHigh<Register>();
1985 Register in1_lo = first.AsRegisterPairLow<Register>();
1986 Register in2_hi = second.AsRegisterPairHigh<Register>();
1987 Register in2_lo = second.AsRegisterPairLow<Register>();
1988
1989 // Extra checks to protect caused by the existence of R1_R2.
1990 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1991 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1992 DCHECK_NE(out_hi, in1_lo);
1993 DCHECK_NE(out_hi, in2_lo);
1994
1995 // input: in1 - 64 bits, in2 - 64 bits
1996 // output: out
1997 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1998 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1999 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2000
2001 // IP <- in1.lo * in2.hi
2002 __ mul(IP, in1_lo, in2_hi);
2003 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2004 __ mla(out_hi, in1_hi, in2_lo, IP);
2005 // out.lo <- (in1.lo * in2.lo)[31:0];
2006 __ umull(out_lo, IP, in1_lo, in2_lo);
2007 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2008 __ add(out_hi, out_hi, ShifterOperand(IP));
2009 break;
2010 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002011
2012 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002013 __ vmuls(out.AsFpuRegister<SRegister>(),
2014 first.AsFpuRegister<SRegister>(),
2015 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002016 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002017 }
2018
2019 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002020 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2021 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2022 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002023 break;
2024 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002025
2026 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002027 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002028 }
2029}
2030
Calin Juravle7c4954d2014-10-28 16:57:40 +00002031void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002032 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2033 ? LocationSummary::kCall
2034 : LocationSummary::kNoCall;
2035 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2036
Calin Juravle7c4954d2014-10-28 16:57:40 +00002037 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002038 case Primitive::kPrimInt: {
2039 locations->SetInAt(0, Location::RequiresRegister());
2040 locations->SetInAt(1, Location::RequiresRegister());
2041 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2042 break;
2043 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002044 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002045 InvokeRuntimeCallingConvention calling_convention;
2046 locations->SetInAt(0, Location::RegisterPairLocation(
2047 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2048 locations->SetInAt(1, Location::RegisterPairLocation(
2049 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002050 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002051 break;
2052 }
2053 case Primitive::kPrimFloat:
2054 case Primitive::kPrimDouble: {
2055 locations->SetInAt(0, Location::RequiresFpuRegister());
2056 locations->SetInAt(1, Location::RequiresFpuRegister());
2057 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2058 break;
2059 }
2060
2061 default:
2062 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2063 }
2064}
2065
2066void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2067 LocationSummary* locations = div->GetLocations();
2068 Location out = locations->Out();
2069 Location first = locations->InAt(0);
2070 Location second = locations->InAt(1);
2071
2072 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002073 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002074 __ sdiv(out.AsRegister<Register>(),
2075 first.AsRegister<Register>(),
2076 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002077 break;
2078 }
2079
Calin Juravle7c4954d2014-10-28 16:57:40 +00002080 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002081 InvokeRuntimeCallingConvention calling_convention;
2082 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2083 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2084 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2085 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2086 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002087 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002088
2089 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002090 break;
2091 }
2092
2093 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002094 __ vdivs(out.AsFpuRegister<SRegister>(),
2095 first.AsFpuRegister<SRegister>(),
2096 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002097 break;
2098 }
2099
2100 case Primitive::kPrimDouble: {
2101 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2102 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2103 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2104 break;
2105 }
2106
2107 default:
2108 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2109 }
2110}
2111
Calin Juravlebacfec32014-11-14 15:54:36 +00002112void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002113 Primitive::Type type = rem->GetResultType();
2114 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2115 ? LocationSummary::kNoCall
2116 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002117 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2118
Calin Juravled2ec87d2014-12-08 14:24:46 +00002119 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002120 case Primitive::kPrimInt: {
2121 locations->SetInAt(0, Location::RequiresRegister());
2122 locations->SetInAt(1, Location::RequiresRegister());
2123 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2124 locations->AddTemp(Location::RequiresRegister());
2125 break;
2126 }
2127 case Primitive::kPrimLong: {
2128 InvokeRuntimeCallingConvention calling_convention;
2129 locations->SetInAt(0, Location::RegisterPairLocation(
2130 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2131 locations->SetInAt(1, Location::RegisterPairLocation(
2132 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2133 // The runtime helper puts the output in R2,R3.
2134 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2135 break;
2136 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002137 case Primitive::kPrimFloat: {
2138 InvokeRuntimeCallingConvention calling_convention;
2139 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2140 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2141 locations->SetOut(Location::FpuRegisterLocation(S0));
2142 break;
2143 }
2144
Calin Juravlebacfec32014-11-14 15:54:36 +00002145 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002146 InvokeRuntimeCallingConvention calling_convention;
2147 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2148 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2149 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2150 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2151 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002152 break;
2153 }
2154
2155 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002156 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002157 }
2158}
2159
2160void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2161 LocationSummary* locations = rem->GetLocations();
2162 Location out = locations->Out();
2163 Location first = locations->InAt(0);
2164 Location second = locations->InAt(1);
2165
Calin Juravled2ec87d2014-12-08 14:24:46 +00002166 Primitive::Type type = rem->GetResultType();
2167 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002168 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002169 Register reg1 = first.AsRegister<Register>();
2170 Register reg2 = second.AsRegister<Register>();
2171 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002172
2173 // temp = reg1 / reg2 (integer division)
2174 // temp = temp * reg2
2175 // dest = reg1 - temp
2176 __ sdiv(temp, reg1, reg2);
2177 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002178 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002179 break;
2180 }
2181
2182 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002183 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2184 break;
2185 }
2186
Calin Juravled2ec87d2014-12-08 14:24:46 +00002187 case Primitive::kPrimFloat: {
2188 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2189 break;
2190 }
2191
Calin Juravlebacfec32014-11-14 15:54:36 +00002192 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002193 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002194 break;
2195 }
2196
2197 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002198 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002199 }
2200}
2201
Calin Juravled0d48522014-11-04 16:40:20 +00002202void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2203 LocationSummary* locations =
2204 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002205 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002206 if (instruction->HasUses()) {
2207 locations->SetOut(Location::SameAsFirstInput());
2208 }
2209}
2210
2211void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2212 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2213 codegen_->AddSlowPath(slow_path);
2214
2215 LocationSummary* locations = instruction->GetLocations();
2216 Location value = locations->InAt(0);
2217
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002218 switch (instruction->GetType()) {
2219 case Primitive::kPrimInt: {
2220 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002221 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002222 __ b(slow_path->GetEntryLabel(), EQ);
2223 } else {
2224 DCHECK(value.IsConstant()) << value;
2225 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2226 __ b(slow_path->GetEntryLabel());
2227 }
2228 }
2229 break;
2230 }
2231 case Primitive::kPrimLong: {
2232 if (value.IsRegisterPair()) {
2233 __ orrs(IP,
2234 value.AsRegisterPairLow<Register>(),
2235 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2236 __ b(slow_path->GetEntryLabel(), EQ);
2237 } else {
2238 DCHECK(value.IsConstant()) << value;
2239 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2240 __ b(slow_path->GetEntryLabel());
2241 }
2242 }
2243 break;
2244 default:
2245 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2246 }
2247 }
Calin Juravled0d48522014-11-04 16:40:20 +00002248}
2249
Calin Juravle9aec02f2014-11-18 23:06:35 +00002250void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2251 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2252
2253 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2254 ? LocationSummary::kCall
2255 : LocationSummary::kNoCall;
2256 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2257
2258 switch (op->GetResultType()) {
2259 case Primitive::kPrimInt: {
2260 locations->SetInAt(0, Location::RequiresRegister());
2261 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2262 locations->SetOut(Location::RequiresRegister());
2263 break;
2264 }
2265 case Primitive::kPrimLong: {
2266 InvokeRuntimeCallingConvention calling_convention;
2267 locations->SetInAt(0, Location::RegisterPairLocation(
2268 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2269 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002270 // The runtime helper puts the output in R0,R1.
2271 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle9aec02f2014-11-18 23:06:35 +00002272 break;
2273 }
2274 default:
2275 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2276 }
2277}
2278
2279void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2280 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2281
2282 LocationSummary* locations = op->GetLocations();
2283 Location out = locations->Out();
2284 Location first = locations->InAt(0);
2285 Location second = locations->InAt(1);
2286
2287 Primitive::Type type = op->GetResultType();
2288 switch (type) {
2289 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002290 Register out_reg = out.AsRegister<Register>();
2291 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002292 // Arm doesn't mask the shift count so we need to do it ourselves.
2293 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002294 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002295 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2296 if (op->IsShl()) {
2297 __ Lsl(out_reg, first_reg, second_reg);
2298 } else if (op->IsShr()) {
2299 __ Asr(out_reg, first_reg, second_reg);
2300 } else {
2301 __ Lsr(out_reg, first_reg, second_reg);
2302 }
2303 } else {
2304 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2305 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2306 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2307 __ Mov(out_reg, first_reg);
2308 } else if (op->IsShl()) {
2309 __ Lsl(out_reg, first_reg, shift_value);
2310 } else if (op->IsShr()) {
2311 __ Asr(out_reg, first_reg, shift_value);
2312 } else {
2313 __ Lsr(out_reg, first_reg, shift_value);
2314 }
2315 }
2316 break;
2317 }
2318 case Primitive::kPrimLong: {
2319 // TODO: Inline the assembly instead of calling the runtime.
2320 InvokeRuntimeCallingConvention calling_convention;
2321 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2322 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002323 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002324 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002325 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002326
2327 int32_t entry_point_offset;
2328 if (op->IsShl()) {
2329 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2330 } else if (op->IsShr()) {
2331 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2332 } else {
2333 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2334 }
2335 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2336 __ blx(LR);
2337 break;
2338 }
2339 default:
2340 LOG(FATAL) << "Unexpected operation type " << type;
2341 }
2342}
2343
2344void LocationsBuilderARM::VisitShl(HShl* shl) {
2345 HandleShift(shl);
2346}
2347
2348void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2349 HandleShift(shl);
2350}
2351
2352void LocationsBuilderARM::VisitShr(HShr* shr) {
2353 HandleShift(shr);
2354}
2355
2356void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2357 HandleShift(shr);
2358}
2359
2360void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2361 HandleShift(ushr);
2362}
2363
2364void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2365 HandleShift(ushr);
2366}
2367
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002368void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002369 LocationSummary* locations =
2370 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002371 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002372 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2373 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2374 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002375}
2376
2377void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2378 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002379 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002380 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002381 codegen_->InvokeRuntime(
2382 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002383}
2384
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002385void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2386 LocationSummary* locations =
2387 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2388 InvokeRuntimeCallingConvention calling_convention;
2389 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002390 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002391 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002392 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002393}
2394
2395void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2396 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002397 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002398 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002399 codegen_->InvokeRuntime(
2400 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002401}
2402
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002403void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002404 LocationSummary* locations =
2405 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002406 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2407 if (location.IsStackSlot()) {
2408 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2409 } else if (location.IsDoubleStackSlot()) {
2410 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002411 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002412 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002413}
2414
2415void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002416 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002417 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002418}
2419
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002420void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002421 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002422 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002423 locations->SetInAt(0, Location::RequiresRegister());
2424 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002425}
2426
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002427void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2428 LocationSummary* locations = not_->GetLocations();
2429 Location out = locations->Out();
2430 Location in = locations->InAt(0);
2431 switch (not_->InputAt(0)->GetType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002432 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002433 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002434 break;
2435
2436 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002437 __ mvn(out.AsRegisterPairLow<Register>(),
2438 ShifterOperand(in.AsRegisterPairLow<Register>()));
2439 __ mvn(out.AsRegisterPairHigh<Register>(),
2440 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002441 break;
2442
2443 default:
2444 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2445 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002446}
2447
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002448void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002449 LocationSummary* locations =
2450 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002451 switch (compare->InputAt(0)->GetType()) {
2452 case Primitive::kPrimLong: {
2453 locations->SetInAt(0, Location::RequiresRegister());
2454 locations->SetInAt(1, Location::RequiresRegister());
2455 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2456 break;
2457 }
2458 case Primitive::kPrimFloat:
2459 case Primitive::kPrimDouble: {
2460 locations->SetInAt(0, Location::RequiresFpuRegister());
2461 locations->SetInAt(1, Location::RequiresFpuRegister());
2462 locations->SetOut(Location::RequiresRegister());
2463 break;
2464 }
2465 default:
2466 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2467 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002468}
2469
2470void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002471 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002472 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002473 Location left = locations->InAt(0);
2474 Location right = locations->InAt(1);
2475
2476 Label less, greater, done;
2477 Primitive::Type type = compare->InputAt(0)->GetType();
2478 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002479 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002480 __ cmp(left.AsRegisterPairHigh<Register>(),
2481 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002482 __ b(&less, LT);
2483 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002484 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2485 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002486 __ cmp(left.AsRegisterPairLow<Register>(),
2487 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002488 break;
2489 }
2490 case Primitive::kPrimFloat:
2491 case Primitive::kPrimDouble: {
2492 __ LoadImmediate(out, 0);
2493 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002494 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002495 } else {
2496 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2497 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2498 }
2499 __ vmstat(); // transfer FP status register to ARM APSR.
2500 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002501 break;
2502 }
2503 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002504 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002505 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002506 __ b(&done, EQ);
2507 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2508
2509 __ Bind(&greater);
2510 __ LoadImmediate(out, 1);
2511 __ b(&done);
2512
2513 __ Bind(&less);
2514 __ LoadImmediate(out, -1);
2515
2516 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002517}
2518
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002519void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002520 LocationSummary* locations =
2521 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002522 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2523 locations->SetInAt(i, Location::Any());
2524 }
2525 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002526}
2527
2528void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002529 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002530 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002531}
2532
Calin Juravle52c48962014-12-16 17:02:57 +00002533void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2534 // TODO (ported from quick): revisit Arm barrier kinds
2535 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2536 switch (kind) {
2537 case MemBarrierKind::kAnyStore:
2538 case MemBarrierKind::kLoadAny:
2539 case MemBarrierKind::kAnyAny: {
2540 flavour = DmbOptions::ISH;
2541 break;
2542 }
2543 case MemBarrierKind::kStoreStore: {
2544 flavour = DmbOptions::ISHST;
2545 break;
2546 }
2547 default:
2548 LOG(FATAL) << "Unexpected memory barrier " << kind;
2549 }
2550 __ dmb(flavour);
2551}
2552
2553void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2554 uint32_t offset,
2555 Register out_lo,
2556 Register out_hi) {
2557 if (offset != 0) {
2558 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002559 __ add(IP, addr, ShifterOperand(out_lo));
2560 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002561 }
2562 __ ldrexd(out_lo, out_hi, addr);
2563}
2564
2565void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2566 uint32_t offset,
2567 Register value_lo,
2568 Register value_hi,
2569 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002570 Register temp2,
2571 HInstruction* instruction) {
Calin Juravle52c48962014-12-16 17:02:57 +00002572 Label fail;
2573 if (offset != 0) {
2574 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002575 __ add(IP, addr, ShifterOperand(temp1));
2576 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002577 }
2578 __ Bind(&fail);
2579 // We need a load followed by store. (The address used in a STREX instruction must
2580 // be the same as the address in the most recently executed LDREX instruction.)
2581 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002582 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002583 __ strexd(temp1, value_lo, value_hi, addr);
2584 __ cmp(temp1, ShifterOperand(0));
2585 __ b(&fail, NE);
2586}
2587
2588void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2589 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2590
Nicolas Geoffray39468442014-09-02 15:17:15 +01002591 LocationSummary* locations =
2592 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002593 locations->SetInAt(0, Location::RequiresRegister());
2594 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002595
Calin Juravle34166012014-12-19 17:22:29 +00002596
Calin Juravle52c48962014-12-16 17:02:57 +00002597 Primitive::Type field_type = field_info.GetFieldType();
2598 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002599 bool generate_volatile = field_info.IsVolatile()
2600 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002601 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002602 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002603 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2604 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002605 locations->AddTemp(Location::RequiresRegister());
2606 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002607 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002608 // Arm encoding have some additional constraints for ldrexd/strexd:
2609 // - registers need to be consecutive
2610 // - the first register should be even but not R14.
2611 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2612 // enable Arm encoding.
2613 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2614
2615 locations->AddTemp(Location::RequiresRegister());
2616 locations->AddTemp(Location::RequiresRegister());
2617 if (field_type == Primitive::kPrimDouble) {
2618 // For doubles we need two more registers to copy the value.
2619 locations->AddTemp(Location::RegisterLocation(R2));
2620 locations->AddTemp(Location::RegisterLocation(R3));
2621 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002622 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002623}
2624
Calin Juravle52c48962014-12-16 17:02:57 +00002625void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2626 const FieldInfo& field_info) {
2627 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2628
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002629 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002630 Register base = locations->InAt(0).AsRegister<Register>();
2631 Location value = locations->InAt(1);
2632
2633 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002634 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002635 Primitive::Type field_type = field_info.GetFieldType();
2636 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2637
2638 if (is_volatile) {
2639 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2640 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002641
2642 switch (field_type) {
2643 case Primitive::kPrimBoolean:
2644 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002645 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002646 break;
2647 }
2648
2649 case Primitive::kPrimShort:
2650 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002651 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002652 break;
2653 }
2654
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002655 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002656 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00002657 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002658 break;
2659 }
2660
2661 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002662 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002663 GenerateWideAtomicStore(base, offset,
2664 value.AsRegisterPairLow<Register>(),
2665 value.AsRegisterPairHigh<Register>(),
2666 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002667 locations->GetTemp(1).AsRegister<Register>(),
2668 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002669 } else {
2670 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002671 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002672 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002673 break;
2674 }
2675
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002676 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002677 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002678 break;
2679 }
2680
2681 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002682 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002683 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002684 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2685 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2686
2687 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2688
2689 GenerateWideAtomicStore(base, offset,
2690 value_reg_lo,
2691 value_reg_hi,
2692 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002693 locations->GetTemp(3).AsRegister<Register>(),
2694 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002695 } else {
2696 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002697 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002698 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002699 break;
2700 }
2701
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002702 case Primitive::kPrimVoid:
2703 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002704 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002705 }
Calin Juravle52c48962014-12-16 17:02:57 +00002706
Calin Juravle77520bc2015-01-12 18:45:46 +00002707 // Longs and doubles are handled in the switch.
2708 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
2709 codegen_->MaybeRecordImplicitNullCheck(instruction);
2710 }
2711
2712 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
2713 Register temp = locations->GetTemp(0).AsRegister<Register>();
2714 Register card = locations->GetTemp(1).AsRegister<Register>();
2715 codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>());
2716 }
2717
Calin Juravle52c48962014-12-16 17:02:57 +00002718 if (is_volatile) {
2719 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2720 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002721}
2722
Calin Juravle52c48962014-12-16 17:02:57 +00002723void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2724 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002725 LocationSummary* locations =
2726 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002727 locations->SetInAt(0, Location::RequiresRegister());
2728 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle52c48962014-12-16 17:02:57 +00002729
Calin Juravle34166012014-12-19 17:22:29 +00002730 bool generate_volatile = field_info.IsVolatile()
2731 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002732 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle34166012014-12-19 17:22:29 +00002733 if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002734 // Arm encoding have some additional constraints for ldrexd/strexd:
2735 // - registers need to be consecutive
2736 // - the first register should be even but not R14.
2737 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2738 // enable Arm encoding.
2739 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2740 locations->AddTemp(Location::RequiresRegister());
2741 locations->AddTemp(Location::RequiresRegister());
2742 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002743}
2744
Calin Juravle52c48962014-12-16 17:02:57 +00002745void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2746 const FieldInfo& field_info) {
2747 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002748
Calin Juravle52c48962014-12-16 17:02:57 +00002749 LocationSummary* locations = instruction->GetLocations();
2750 Register base = locations->InAt(0).AsRegister<Register>();
2751 Location out = locations->Out();
2752 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002753 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002754 Primitive::Type field_type = field_info.GetFieldType();
2755 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2756
2757 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002758 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002759 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002760 break;
2761 }
2762
2763 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002764 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002765 break;
2766 }
2767
2768 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002769 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002770 break;
2771 }
2772
2773 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002774 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002775 break;
2776 }
2777
2778 case Primitive::kPrimInt:
2779 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002780 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002781 break;
2782 }
2783
2784 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002785 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002786 GenerateWideAtomicLoad(base, offset,
2787 out.AsRegisterPairLow<Register>(),
2788 out.AsRegisterPairHigh<Register>());
2789 } else {
2790 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2791 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002792 break;
2793 }
2794
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002795 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002796 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002797 break;
2798 }
2799
2800 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002801 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002802 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002803 Register lo = locations->GetTemp(0).AsRegister<Register>();
2804 Register hi = locations->GetTemp(1).AsRegister<Register>();
2805 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00002806 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002807 __ vmovdrr(out_reg, lo, hi);
2808 } else {
2809 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002810 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002811 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002812 break;
2813 }
2814
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002815 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002816 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002817 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002818 }
Calin Juravle52c48962014-12-16 17:02:57 +00002819
Calin Juravle77520bc2015-01-12 18:45:46 +00002820 // Doubles are handled in the switch.
2821 if (field_type != Primitive::kPrimDouble) {
2822 codegen_->MaybeRecordImplicitNullCheck(instruction);
2823 }
2824
Calin Juravle52c48962014-12-16 17:02:57 +00002825 if (is_volatile) {
2826 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2827 }
2828}
2829
2830void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2831 HandleFieldSet(instruction, instruction->GetFieldInfo());
2832}
2833
2834void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2835 HandleFieldSet(instruction, instruction->GetFieldInfo());
2836}
2837
2838void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2839 HandleFieldGet(instruction, instruction->GetFieldInfo());
2840}
2841
2842void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2843 HandleFieldGet(instruction, instruction->GetFieldInfo());
2844}
2845
2846void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2847 HandleFieldGet(instruction, instruction->GetFieldInfo());
2848}
2849
2850void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2851 HandleFieldGet(instruction, instruction->GetFieldInfo());
2852}
2853
2854void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2855 HandleFieldSet(instruction, instruction->GetFieldInfo());
2856}
2857
2858void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2859 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002860}
2861
2862void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002863 LocationSummary* locations =
2864 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00002865 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002866 if (instruction->HasUses()) {
2867 locations->SetOut(Location::SameAsFirstInput());
2868 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002869}
2870
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002871void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002872 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2873 return;
2874 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002875 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002876
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002877 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
2878 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2879}
2880
2881void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002882 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002883 codegen_->AddSlowPath(slow_path);
2884
2885 LocationSummary* locations = instruction->GetLocations();
2886 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002887
Calin Juravle77520bc2015-01-12 18:45:46 +00002888 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
2889 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002890}
2891
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002892void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
2893 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2894 GenerateImplicitNullCheck(instruction);
2895 } else {
2896 GenerateExplicitNullCheck(instruction);
2897 }
2898}
2899
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002900void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002901 LocationSummary* locations =
2902 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002903 locations->SetInAt(0, Location::RequiresRegister());
2904 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2905 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002906}
2907
2908void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2909 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002910 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002911 Location index = locations->InAt(1);
2912
2913 switch (instruction->GetType()) {
2914 case Primitive::kPrimBoolean: {
2915 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002916 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002917 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002918 size_t offset =
2919 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002920 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2921 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002922 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002923 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2924 }
2925 break;
2926 }
2927
2928 case Primitive::kPrimByte: {
2929 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002930 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002931 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002932 size_t offset =
2933 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002934 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2935 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002936 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002937 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2938 }
2939 break;
2940 }
2941
2942 case Primitive::kPrimShort: {
2943 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002944 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002945 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002946 size_t offset =
2947 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002948 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2949 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002950 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002951 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2952 }
2953 break;
2954 }
2955
2956 case Primitive::kPrimChar: {
2957 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002958 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002959 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002960 size_t offset =
2961 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002962 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2963 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002964 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002965 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2966 }
2967 break;
2968 }
2969
2970 case Primitive::kPrimInt:
2971 case Primitive::kPrimNot: {
2972 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2973 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002974 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002975 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002976 size_t offset =
2977 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002978 __ LoadFromOffset(kLoadWord, out, obj, offset);
2979 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002980 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002981 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2982 }
2983 break;
2984 }
2985
2986 case Primitive::kPrimLong: {
2987 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002988 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002989 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002990 size_t offset =
2991 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002992 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002993 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002994 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002995 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002996 }
2997 break;
2998 }
2999
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003000 case Primitive::kPrimFloat: {
3001 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3002 Location out = locations->Out();
3003 DCHECK(out.IsFpuRegister());
3004 if (index.IsConstant()) {
3005 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3006 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3007 } else {
3008 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3009 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3010 }
3011 break;
3012 }
3013
3014 case Primitive::kPrimDouble: {
3015 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3016 Location out = locations->Out();
3017 DCHECK(out.IsFpuRegisterPair());
3018 if (index.IsConstant()) {
3019 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3020 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3021 } else {
3022 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3023 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3024 }
3025 break;
3026 }
3027
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003028 case Primitive::kPrimVoid:
3029 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003030 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003031 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003032 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003033}
3034
3035void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003036 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003037
3038 bool needs_write_barrier =
3039 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3040 bool needs_runtime_call = instruction->NeedsTypeCheck();
3041
Nicolas Geoffray39468442014-09-02 15:17:15 +01003042 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003043 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3044 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003045 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003046 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3047 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3048 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003049 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003050 locations->SetInAt(0, Location::RequiresRegister());
3051 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3052 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003053
3054 if (needs_write_barrier) {
3055 // Temporary registers for the write barrier.
3056 locations->AddTemp(Location::RequiresRegister());
3057 locations->AddTemp(Location::RequiresRegister());
3058 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003059 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003060}
3061
3062void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3063 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003064 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003065 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003066 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003067 bool needs_runtime_call = locations->WillCall();
3068 bool needs_write_barrier =
3069 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003070
3071 switch (value_type) {
3072 case Primitive::kPrimBoolean:
3073 case Primitive::kPrimByte: {
3074 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003075 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003076 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003077 size_t offset =
3078 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003079 __ StoreToOffset(kStoreByte, value, obj, offset);
3080 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003081 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003082 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3083 }
3084 break;
3085 }
3086
3087 case Primitive::kPrimShort:
3088 case Primitive::kPrimChar: {
3089 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003090 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003091 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003092 size_t offset =
3093 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003094 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3095 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003096 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003097 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3098 }
3099 break;
3100 }
3101
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003102 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003103 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003104 if (!needs_runtime_call) {
3105 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003106 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003107 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003108 size_t offset =
3109 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003110 __ StoreToOffset(kStoreWord, value, obj, offset);
3111 } else {
3112 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003113 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003114 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3115 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003116 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003117 if (needs_write_barrier) {
3118 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003119 Register temp = locations->GetTemp(0).AsRegister<Register>();
3120 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003121 codegen_->MarkGCCard(temp, card, obj, value);
3122 }
3123 } else {
3124 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003125 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3126 instruction,
3127 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003128 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003129 break;
3130 }
3131
3132 case Primitive::kPrimLong: {
3133 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003134 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003135 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003136 size_t offset =
3137 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003138 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003139 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003140 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003141 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003142 }
3143 break;
3144 }
3145
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003146 case Primitive::kPrimFloat: {
3147 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3148 Location value = locations->InAt(2);
3149 DCHECK(value.IsFpuRegister());
3150 if (index.IsConstant()) {
3151 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3152 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3153 } else {
3154 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3155 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3156 }
3157 break;
3158 }
3159
3160 case Primitive::kPrimDouble: {
3161 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3162 Location value = locations->InAt(2);
3163 DCHECK(value.IsFpuRegisterPair());
3164 if (index.IsConstant()) {
3165 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3166 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3167 } else {
3168 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3169 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3170 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003171
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003172 break;
3173 }
3174
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003175 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003176 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003177 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003178 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003179
3180 // Ints and objects are handled in the switch.
3181 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3182 codegen_->MaybeRecordImplicitNullCheck(instruction);
3183 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003184}
3185
3186void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003187 LocationSummary* locations =
3188 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003189 locations->SetInAt(0, Location::RequiresRegister());
3190 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003191}
3192
3193void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3194 LocationSummary* locations = instruction->GetLocations();
3195 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003196 Register obj = locations->InAt(0).AsRegister<Register>();
3197 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003198 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003199 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003200}
3201
3202void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003203 LocationSummary* locations =
3204 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003205 locations->SetInAt(0, Location::RequiresRegister());
3206 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003207 if (instruction->HasUses()) {
3208 locations->SetOut(Location::SameAsFirstInput());
3209 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003210}
3211
3212void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3213 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003214 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003215 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003216 codegen_->AddSlowPath(slow_path);
3217
Roland Levillain271ab9c2014-11-27 15:23:57 +00003218 Register index = locations->InAt(0).AsRegister<Register>();
3219 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003220
3221 __ cmp(index, ShifterOperand(length));
3222 __ b(slow_path->GetEntryLabel(), CS);
3223}
3224
3225void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3226 Label is_null;
3227 __ CompareAndBranchIfZero(value, &is_null);
3228 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3229 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3230 __ strb(card, Address(card, temp));
3231 __ Bind(&is_null);
3232}
3233
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003234void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3235 temp->SetLocations(nullptr);
3236}
3237
3238void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3239 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003240 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003241}
3242
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003243void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003244 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003245 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003246}
3247
3248void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003249 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3250}
3251
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003252void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3253 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3254}
3255
3256void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003257 HBasicBlock* block = instruction->GetBlock();
3258 if (block->GetLoopInformation() != nullptr) {
3259 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3260 // The back edge will generate the suspend check.
3261 return;
3262 }
3263 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3264 // The goto will generate the suspend check.
3265 return;
3266 }
3267 GenerateSuspendCheck(instruction, nullptr);
3268}
3269
3270void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3271 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003272 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003273 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003274 codegen_->AddSlowPath(slow_path);
3275
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003276 __ LoadFromOffset(
3277 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3278 __ cmp(IP, ShifterOperand(0));
3279 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003280 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003281 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003282 __ Bind(slow_path->GetReturnLabel());
3283 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003284 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003285 __ b(slow_path->GetEntryLabel());
3286 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003287}
3288
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003289ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3290 return codegen_->GetAssembler();
3291}
3292
3293void ParallelMoveResolverARM::EmitMove(size_t index) {
3294 MoveOperands* move = moves_.Get(index);
3295 Location source = move->GetSource();
3296 Location destination = move->GetDestination();
3297
3298 if (source.IsRegister()) {
3299 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003300 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003301 } else {
3302 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003303 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003304 SP, destination.GetStackIndex());
3305 }
3306 } else if (source.IsStackSlot()) {
3307 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003308 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003309 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003310 } else if (destination.IsFpuRegister()) {
3311 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003312 } else {
3313 DCHECK(destination.IsStackSlot());
3314 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3315 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3316 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003317 } else if (source.IsFpuRegister()) {
3318 if (destination.IsFpuRegister()) {
3319 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003320 } else {
3321 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003322 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3323 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003324 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003325 DCHECK(destination.IsDoubleStackSlot()) << destination;
3326 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3327 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3328 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
3329 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003330 } else {
3331 DCHECK(source.IsConstant()) << source;
3332 HInstruction* constant = source.GetConstant();
3333 if (constant->IsIntConstant()) {
3334 int32_t value = constant->AsIntConstant()->GetValue();
3335 if (destination.IsRegister()) {
3336 __ LoadImmediate(destination.AsRegister<Register>(), value);
3337 } else {
3338 DCHECK(destination.IsStackSlot());
3339 __ LoadImmediate(IP, value);
3340 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3341 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003342 } else if (constant->IsLongConstant()) {
3343 int64_t value = constant->AsLongConstant()->GetValue();
3344 if (destination.IsRegister()) {
3345 // In the presence of long or double constants, the parallel move resolver will
3346 // split the move into two, but keeps the same constant for both moves. Here,
3347 // we use the low or high part depending on which register this move goes to.
3348 if (destination.reg() % 2 == 0) {
3349 __ LoadImmediate(destination.AsRegister<Register>(), Low32Bits(value));
3350 } else {
3351 __ LoadImmediate(destination.AsRegister<Register>(), High32Bits(value));
3352 }
3353 } else {
3354 DCHECK(destination.IsDoubleStackSlot());
3355 __ LoadImmediate(IP, Low32Bits(value));
3356 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3357 __ LoadImmediate(IP, High32Bits(value));
3358 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3359 }
3360 } else if (constant->IsDoubleConstant()) {
3361 double value = constant->AsDoubleConstant()->GetValue();
3362 uint64_t int_value = bit_cast<uint64_t, double>(value);
3363 if (destination.IsFpuRegister()) {
3364 // In the presence of long or double constants, the parallel move resolver will
3365 // split the move into two, but keeps the same constant for both moves. Here,
3366 // we use the low or high part depending on which register this move goes to.
3367 if (destination.reg() % 2 == 0) {
3368 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(),
3369 bit_cast<float, uint32_t>(Low32Bits(int_value)));
3370 } else {
3371 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(),
3372 bit_cast<float, uint32_t>(High32Bits(int_value)));
3373 }
3374 } else {
3375 DCHECK(destination.IsDoubleStackSlot());
3376 __ LoadImmediate(IP, Low32Bits(int_value));
3377 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3378 __ LoadImmediate(IP, High32Bits(int_value));
3379 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3380 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003381 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003382 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003383 float value = constant->AsFloatConstant()->GetValue();
3384 if (destination.IsFpuRegister()) {
3385 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3386 } else {
3387 DCHECK(destination.IsStackSlot());
3388 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3389 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3390 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003391 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003392 }
3393}
3394
3395void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3396 __ Mov(IP, reg);
3397 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3398 __ StoreToOffset(kStoreWord, IP, SP, mem);
3399}
3400
3401void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3402 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3403 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3404 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3405 SP, mem1 + stack_offset);
3406 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3407 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3408 SP, mem2 + stack_offset);
3409 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3410}
3411
3412void ParallelMoveResolverARM::EmitSwap(size_t index) {
3413 MoveOperands* move = moves_.Get(index);
3414 Location source = move->GetSource();
3415 Location destination = move->GetDestination();
3416
3417 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003418 DCHECK_NE(source.AsRegister<Register>(), IP);
3419 DCHECK_NE(destination.AsRegister<Register>(), IP);
3420 __ Mov(IP, source.AsRegister<Register>());
3421 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3422 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003423 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003424 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003425 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003426 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003427 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3428 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003429 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003430 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003431 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003432 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003433 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3434 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3435 : destination.AsFpuRegister<SRegister>();
3436 int mem = source.IsFpuRegister()
3437 ? destination.GetStackIndex()
3438 : source.GetStackIndex();
3439
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003440 __ vmovrs(IP, reg);
3441 __ LoadFromOffset(kLoadWord, IP, SP, mem);
3442 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003443 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003444 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3445 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003446 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003447 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003448 }
3449}
3450
3451void ParallelMoveResolverARM::SpillScratch(int reg) {
3452 __ Push(static_cast<Register>(reg));
3453}
3454
3455void ParallelMoveResolverARM::RestoreScratch(int reg) {
3456 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003457}
3458
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003459void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003460 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3461 ? LocationSummary::kCallOnSlowPath
3462 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003463 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003464 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003465 locations->SetOut(Location::RequiresRegister());
3466}
3467
3468void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003469 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003470 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003471 DCHECK(!cls->CanCallRuntime());
3472 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003473 codegen_->LoadCurrentMethod(out);
3474 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3475 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003476 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003477 codegen_->LoadCurrentMethod(out);
3478 __ LoadFromOffset(
3479 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3480 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003481
3482 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3483 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3484 codegen_->AddSlowPath(slow_path);
3485 __ cmp(out, ShifterOperand(0));
3486 __ b(slow_path->GetEntryLabel(), EQ);
3487 if (cls->MustGenerateClinitCheck()) {
3488 GenerateClassInitializationCheck(slow_path, out);
3489 } else {
3490 __ Bind(slow_path->GetExitLabel());
3491 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003492 }
3493}
3494
3495void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3496 LocationSummary* locations =
3497 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3498 locations->SetInAt(0, Location::RequiresRegister());
3499 if (check->HasUses()) {
3500 locations->SetOut(Location::SameAsFirstInput());
3501 }
3502}
3503
3504void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003505 // We assume the class is not null.
3506 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3507 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003508 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003509 GenerateClassInitializationCheck(slow_path,
3510 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003511}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003512
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003513void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3514 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003515 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3516 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3517 __ b(slow_path->GetEntryLabel(), LT);
3518 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3519 // properly. Therefore, we do a memory fence.
3520 __ dmb(ISH);
3521 __ Bind(slow_path->GetExitLabel());
3522}
3523
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003524void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3525 LocationSummary* locations =
3526 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3527 locations->SetOut(Location::RequiresRegister());
3528}
3529
3530void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3531 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3532 codegen_->AddSlowPath(slow_path);
3533
Roland Levillain271ab9c2014-11-27 15:23:57 +00003534 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003535 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003536 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3537 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003538 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3539 __ cmp(out, ShifterOperand(0));
3540 __ b(slow_path->GetEntryLabel(), EQ);
3541 __ Bind(slow_path->GetExitLabel());
3542}
3543
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003544void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3545 LocationSummary* locations =
3546 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3547 locations->SetOut(Location::RequiresRegister());
3548}
3549
3550void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003551 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003552 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3553 __ LoadFromOffset(kLoadWord, out, TR, offset);
3554 __ LoadImmediate(IP, 0);
3555 __ StoreToOffset(kStoreWord, IP, TR, offset);
3556}
3557
3558void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3559 LocationSummary* locations =
3560 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3561 InvokeRuntimeCallingConvention calling_convention;
3562 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3563}
3564
3565void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3566 codegen_->InvokeRuntime(
3567 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3568}
3569
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003570void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003571 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3572 ? LocationSummary::kNoCall
3573 : LocationSummary::kCallOnSlowPath;
3574 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3575 locations->SetInAt(0, Location::RequiresRegister());
3576 locations->SetInAt(1, Location::RequiresRegister());
3577 locations->SetOut(Location::RequiresRegister());
3578}
3579
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003580void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003581 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003582 Register obj = locations->InAt(0).AsRegister<Register>();
3583 Register cls = locations->InAt(1).AsRegister<Register>();
3584 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003585 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3586 Label done, zero;
3587 SlowPathCodeARM* slow_path = nullptr;
3588
3589 // Return 0 if `obj` is null.
3590 // TODO: avoid this check if we know obj is not null.
3591 __ cmp(obj, ShifterOperand(0));
3592 __ b(&zero, EQ);
3593 // Compare the class of `obj` with `cls`.
3594 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3595 __ cmp(out, ShifterOperand(cls));
3596 if (instruction->IsClassFinal()) {
3597 // Classes must be equal for the instanceof to succeed.
3598 __ b(&zero, NE);
3599 __ LoadImmediate(out, 1);
3600 __ b(&done);
3601 } else {
3602 // If the classes are not equal, we go into a slow path.
3603 DCHECK(locations->OnlyCallsOnSlowPath());
3604 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003605 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003606 codegen_->AddSlowPath(slow_path);
3607 __ b(slow_path->GetEntryLabel(), NE);
3608 __ LoadImmediate(out, 1);
3609 __ b(&done);
3610 }
3611 __ Bind(&zero);
3612 __ LoadImmediate(out, 0);
3613 if (slow_path != nullptr) {
3614 __ Bind(slow_path->GetExitLabel());
3615 }
3616 __ Bind(&done);
3617}
3618
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003619void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3620 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3621 instruction, LocationSummary::kCallOnSlowPath);
3622 locations->SetInAt(0, Location::RequiresRegister());
3623 locations->SetInAt(1, Location::RequiresRegister());
3624 locations->AddTemp(Location::RequiresRegister());
3625}
3626
3627void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3628 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003629 Register obj = locations->InAt(0).AsRegister<Register>();
3630 Register cls = locations->InAt(1).AsRegister<Register>();
3631 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003632 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3633
3634 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3635 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3636 codegen_->AddSlowPath(slow_path);
3637
3638 // TODO: avoid this check if we know obj is not null.
3639 __ cmp(obj, ShifterOperand(0));
3640 __ b(slow_path->GetExitLabel(), EQ);
3641 // Compare the class of `obj` with `cls`.
3642 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3643 __ cmp(temp, ShifterOperand(cls));
3644 __ b(slow_path->GetEntryLabel(), NE);
3645 __ Bind(slow_path->GetExitLabel());
3646}
3647
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003648void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3649 LocationSummary* locations =
3650 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3651 InvokeRuntimeCallingConvention calling_convention;
3652 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3653}
3654
3655void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3656 codegen_->InvokeRuntime(instruction->IsEnter()
3657 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3658 instruction,
3659 instruction->GetDexPc());
3660}
3661
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003662void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3663void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3664void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3665
3666void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3667 LocationSummary* locations =
3668 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3669 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3670 || instruction->GetResultType() == Primitive::kPrimLong);
3671 locations->SetInAt(0, Location::RequiresRegister());
3672 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003673 Location::OutputOverlap output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong)
3674 ? Location::kOutputOverlap
3675 : Location::kNoOutputOverlap;
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003676 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3677}
3678
3679void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3680 HandleBitwiseOperation(instruction);
3681}
3682
3683void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3684 HandleBitwiseOperation(instruction);
3685}
3686
3687void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3688 HandleBitwiseOperation(instruction);
3689}
3690
3691void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3692 LocationSummary* locations = instruction->GetLocations();
3693
3694 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003695 Register first = locations->InAt(0).AsRegister<Register>();
3696 Register second = locations->InAt(1).AsRegister<Register>();
3697 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003698 if (instruction->IsAnd()) {
3699 __ and_(out, first, ShifterOperand(second));
3700 } else if (instruction->IsOr()) {
3701 __ orr(out, first, ShifterOperand(second));
3702 } else {
3703 DCHECK(instruction->IsXor());
3704 __ eor(out, first, ShifterOperand(second));
3705 }
3706 } else {
3707 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3708 Location first = locations->InAt(0);
3709 Location second = locations->InAt(1);
3710 Location out = locations->Out();
3711 if (instruction->IsAnd()) {
3712 __ and_(out.AsRegisterPairLow<Register>(),
3713 first.AsRegisterPairLow<Register>(),
3714 ShifterOperand(second.AsRegisterPairLow<Register>()));
3715 __ and_(out.AsRegisterPairHigh<Register>(),
3716 first.AsRegisterPairHigh<Register>(),
3717 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3718 } else if (instruction->IsOr()) {
3719 __ orr(out.AsRegisterPairLow<Register>(),
3720 first.AsRegisterPairLow<Register>(),
3721 ShifterOperand(second.AsRegisterPairLow<Register>()));
3722 __ orr(out.AsRegisterPairHigh<Register>(),
3723 first.AsRegisterPairHigh<Register>(),
3724 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3725 } else {
3726 DCHECK(instruction->IsXor());
3727 __ eor(out.AsRegisterPairLow<Register>(),
3728 first.AsRegisterPairLow<Register>(),
3729 ShifterOperand(second.AsRegisterPairLow<Register>()));
3730 __ eor(out.AsRegisterPairHigh<Register>(),
3731 first.AsRegisterPairHigh<Register>(),
3732 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3733 }
3734 }
3735}
3736
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003737} // namespace arm
3738} // namespace art