blob: 5fe8adc86a6e5aff79f72a07660aee6633ee9f44 [file] [log] [blame]
Alexandre Rames5319def2014-10-23 10:03:10 +01001/*
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_arm64.h"
18
Serban Constantinescu579885a2015-02-22 20:51:33 +000019#include "arch/arm64/instruction_set_features_arm64.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080020#include "common_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010021#include "entrypoints/quick/quick_entrypoints.h"
Andreas Gampe1cc7dba2014-12-17 18:43:01 -080022#include "entrypoints/quick/quick_entrypoints_enum.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010023#include "gc/accounting/card_table.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080024#include "intrinsics.h"
25#include "intrinsics_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010026#include "mirror/array-inl.h"
27#include "mirror/art_method.h"
28#include "mirror/class.h"
Calin Juravlecd6dffe2015-01-08 17:35:35 +000029#include "offsets.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010030#include "thread.h"
31#include "utils/arm64/assembler_arm64.h"
32#include "utils/assembler.h"
33#include "utils/stack_checks.h"
34
35
36using namespace vixl; // NOLINT(build/namespaces)
37
38#ifdef __
39#error "ARM64 Codegen VIXL macro-assembler macro already defined."
40#endif
41
Alexandre Rames5319def2014-10-23 10:03:10 +010042namespace art {
43
44namespace arm64 {
45
Andreas Gampe878d58c2015-01-15 23:24:00 -080046using helpers::CPURegisterFrom;
47using helpers::DRegisterFrom;
48using helpers::FPRegisterFrom;
49using helpers::HeapOperand;
50using helpers::HeapOperandFrom;
51using helpers::InputCPURegisterAt;
52using helpers::InputFPRegisterAt;
53using helpers::InputRegisterAt;
54using helpers::InputOperandAt;
55using helpers::Int64ConstantFrom;
Andreas Gampe878d58c2015-01-15 23:24:00 -080056using helpers::LocationFrom;
57using helpers::OperandFromMemOperand;
58using helpers::OutputCPURegister;
59using helpers::OutputFPRegister;
60using helpers::OutputRegister;
61using helpers::RegisterFrom;
62using helpers::StackOperandFrom;
63using helpers::VIXLRegCodeFromART;
64using helpers::WRegisterFrom;
65using helpers::XRegisterFrom;
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +000066using helpers::ARM64EncodableConstantOrRegister;
Andreas Gampe878d58c2015-01-15 23:24:00 -080067
Alexandre Rames5319def2014-10-23 10:03:10 +010068static constexpr size_t kHeapRefSize = sizeof(mirror::HeapReference<mirror::Object>);
69static constexpr int kCurrentMethodStackOffset = 0;
70
Alexandre Rames5319def2014-10-23 10:03:10 +010071inline Condition ARM64Condition(IfCondition cond) {
72 switch (cond) {
73 case kCondEQ: return eq;
74 case kCondNE: return ne;
75 case kCondLT: return lt;
76 case kCondLE: return le;
77 case kCondGT: return gt;
78 case kCondGE: return ge;
79 default:
80 LOG(FATAL) << "Unknown if condition";
81 }
82 return nv; // Unreachable.
83}
84
Alexandre Ramesa89086e2014-11-07 17:13:25 +000085Location ARM64ReturnLocation(Primitive::Type return_type) {
86 DCHECK_NE(return_type, Primitive::kPrimVoid);
87 // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the
88 // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`,
89 // but we use the exact registers for clarity.
90 if (return_type == Primitive::kPrimFloat) {
91 return LocationFrom(s0);
92 } else if (return_type == Primitive::kPrimDouble) {
93 return LocationFrom(d0);
94 } else if (return_type == Primitive::kPrimLong) {
95 return LocationFrom(x0);
96 } else {
97 return LocationFrom(w0);
98 }
99}
100
Alexandre Rames5319def2014-10-23 10:03:10 +0100101Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000102 return ARM64ReturnLocation(return_type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100103}
104
Alexandre Rames67555f72014-11-18 10:55:16 +0000105#define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()->
106#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value()
Alexandre Rames5319def2014-10-23 10:03:10 +0100107
Alexandre Rames5319def2014-10-23 10:03:10 +0100108class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 {
109 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000110 BoundsCheckSlowPathARM64(HBoundsCheck* instruction,
111 Location index_location,
112 Location length_location)
113 : instruction_(instruction),
114 index_location_(index_location),
115 length_location_(length_location) {}
116
Alexandre Rames5319def2014-10-23 10:03:10 +0100117
Alexandre Rames67555f72014-11-18 10:55:16 +0000118 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000119 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100120 __ Bind(GetEntryLabel());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000121 // We're moving two locations to locations that could overlap, so we need a parallel
122 // move resolver.
123 InvokeRuntimeCallingConvention calling_convention;
124 codegen->EmitParallelMoves(
125 index_location_, LocationFrom(calling_convention.GetRegisterAt(0)),
126 length_location_, LocationFrom(calling_convention.GetRegisterAt(1)));
127 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000128 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800129 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100130 }
131
132 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000133 HBoundsCheck* const instruction_;
134 const Location index_location_;
135 const Location length_location_;
136
Alexandre Rames5319def2014-10-23 10:03:10 +0100137 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64);
138};
139
Alexandre Rames67555f72014-11-18 10:55:16 +0000140class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 {
141 public:
142 explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : instruction_(instruction) {}
143
144 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
145 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
146 __ Bind(GetEntryLabel());
147 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000148 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800149 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000150 }
151
152 private:
153 HDivZeroCheck* const instruction_;
154 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64);
155};
156
157class LoadClassSlowPathARM64 : public SlowPathCodeARM64 {
158 public:
159 LoadClassSlowPathARM64(HLoadClass* cls,
160 HInstruction* at,
161 uint32_t dex_pc,
162 bool do_clinit)
163 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
164 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
165 }
166
167 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
168 LocationSummary* locations = at_->GetLocations();
169 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
170
171 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000172 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000173
174 InvokeRuntimeCallingConvention calling_convention;
175 __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex());
176 arm64_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1).W());
177 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
178 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000179 arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800180 if (do_clinit_) {
181 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t, mirror::ArtMethod*>();
182 } else {
183 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t, mirror::ArtMethod*>();
184 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000185
186 // Move the class to the desired location.
187 Location out = locations->Out();
188 if (out.IsValid()) {
189 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
190 Primitive::Type type = at_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000191 arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000192 }
193
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000194 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000195 __ B(GetExitLabel());
196 }
197
198 private:
199 // The class this slow path will load.
200 HLoadClass* const cls_;
201
202 // The instruction where this slow path is happening.
203 // (Might be the load class or an initialization check).
204 HInstruction* const at_;
205
206 // The dex PC of `at_`.
207 const uint32_t dex_pc_;
208
209 // Whether to initialize the class.
210 const bool do_clinit_;
211
212 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64);
213};
214
215class LoadStringSlowPathARM64 : public SlowPathCodeARM64 {
216 public:
217 explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {}
218
219 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
220 LocationSummary* locations = instruction_->GetLocations();
221 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
222 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
223
224 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000225 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000226
227 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800228 arm64_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1).W());
229 __ Mov(calling_convention.GetRegisterAt(0).W(), instruction_->GetStringIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +0000230 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000231 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800232 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000233 Primitive::Type type = instruction_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000234 arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000235
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000236 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000237 __ B(GetExitLabel());
238 }
239
240 private:
241 HLoadString* const instruction_;
242
243 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64);
244};
245
Alexandre Rames5319def2014-10-23 10:03:10 +0100246class NullCheckSlowPathARM64 : public SlowPathCodeARM64 {
247 public:
248 explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {}
249
Alexandre Rames67555f72014-11-18 10:55:16 +0000250 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
251 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100252 __ Bind(GetEntryLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000253 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000254 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800255 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100256 }
257
258 private:
259 HNullCheck* const instruction_;
260
261 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64);
262};
263
264class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 {
265 public:
266 explicit SuspendCheckSlowPathARM64(HSuspendCheck* instruction,
267 HBasicBlock* successor)
268 : instruction_(instruction), successor_(successor) {}
269
Alexandre Rames67555f72014-11-18 10:55:16 +0000270 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
271 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100272 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000273 SaveLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000274 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000275 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800276 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000277 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000278 if (successor_ == nullptr) {
279 __ B(GetReturnLabel());
280 } else {
281 __ B(arm64_codegen->GetLabelOf(successor_));
282 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100283 }
284
285 vixl::Label* GetReturnLabel() {
286 DCHECK(successor_ == nullptr);
287 return &return_label_;
288 }
289
Alexandre Rames5319def2014-10-23 10:03:10 +0100290 private:
291 HSuspendCheck* const instruction_;
292 // If not null, the block to branch to after the suspend check.
293 HBasicBlock* const successor_;
294
295 // If `successor_` is null, the label to branch to after the suspend check.
296 vixl::Label return_label_;
297
298 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64);
299};
300
Alexandre Rames67555f72014-11-18 10:55:16 +0000301class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 {
302 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000303 TypeCheckSlowPathARM64(HInstruction* instruction,
304 Location class_to_check,
305 Location object_class,
306 uint32_t dex_pc)
307 : instruction_(instruction),
308 class_to_check_(class_to_check),
309 object_class_(object_class),
310 dex_pc_(dex_pc) {}
Alexandre Rames67555f72014-11-18 10:55:16 +0000311
312 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000313 LocationSummary* locations = instruction_->GetLocations();
314 DCHECK(instruction_->IsCheckCast()
315 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
316 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
317
Alexandre Rames67555f72014-11-18 10:55:16 +0000318 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000319 SaveLiveRegisters(codegen, locations);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000320
321 // We're moving two locations to locations that could overlap, so we need a parallel
322 // move resolver.
323 InvokeRuntimeCallingConvention calling_convention;
324 codegen->EmitParallelMoves(
325 class_to_check_, LocationFrom(calling_convention.GetRegisterAt(0)),
326 object_class_, LocationFrom(calling_convention.GetRegisterAt(1)));
327
328 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000329 arm64_codegen->InvokeRuntime(
330 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000331 Primitive::Type ret_type = instruction_->GetType();
332 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
333 arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800334 CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t,
335 const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000336 } else {
337 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000338 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800339 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000340 }
341
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000342 RestoreLiveRegisters(codegen, locations);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000343 __ B(GetExitLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000344 }
345
346 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000347 HInstruction* const instruction_;
348 const Location class_to_check_;
349 const Location object_class_;
350 uint32_t dex_pc_;
351
Alexandre Rames67555f72014-11-18 10:55:16 +0000352 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64);
353};
354
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700355class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 {
356 public:
357 explicit DeoptimizationSlowPathARM64(HInstruction* instruction)
358 : instruction_(instruction) {}
359
360 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
361 __ Bind(GetEntryLabel());
362 SaveLiveRegisters(codegen, instruction_->GetLocations());
363 DCHECK(instruction_->IsDeoptimize());
364 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
365 uint32_t dex_pc = deoptimize->GetDexPc();
366 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
367 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
368 }
369
370 private:
371 HInstruction* const instruction_;
372 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64);
373};
374
Alexandre Rames5319def2014-10-23 10:03:10 +0100375#undef __
376
377Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
378 Location next_location;
379 if (type == Primitive::kPrimVoid) {
380 LOG(FATAL) << "Unreachable type " << type;
381 }
382
Alexandre Rames542361f2015-01-29 16:57:31 +0000383 if (Primitive::IsFloatingPointType(type) &&
384 (fp_index_ < calling_convention.GetNumberOfFpuRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000385 next_location = LocationFrom(calling_convention.GetFpuRegisterAt(fp_index_++));
Alexandre Rames542361f2015-01-29 16:57:31 +0000386 } else if (!Primitive::IsFloatingPointType(type) &&
387 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000388 next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++));
389 } else {
390 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Alexandre Rames542361f2015-01-29 16:57:31 +0000391 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
392 : Location::StackSlot(stack_offset);
Alexandre Rames5319def2014-10-23 10:03:10 +0100393 }
394
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000395 // Space on the stack is reserved for all arguments.
Alexandre Rames542361f2015-01-29 16:57:31 +0000396 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
Alexandre Rames5319def2014-10-23 10:03:10 +0100397 return next_location;
398}
399
Serban Constantinescu579885a2015-02-22 20:51:33 +0000400CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph,
401 const Arm64InstructionSetFeatures& isa_features,
402 const CompilerOptions& compiler_options)
Alexandre Rames5319def2014-10-23 10:03:10 +0100403 : CodeGenerator(graph,
404 kNumberOfAllocatableRegisters,
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000405 kNumberOfAllocatableFPRegisters,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000406 kNumberOfAllocatableRegisterPairs,
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000407 callee_saved_core_registers.list(),
408 callee_saved_fp_registers.list(),
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000409 compiler_options),
Alexandre Rames5319def2014-10-23 10:03:10 +0100410 block_labels_(nullptr),
411 location_builder_(graph, this),
Alexandre Rames3e69f162014-12-10 10:36:50 +0000412 instruction_visitor_(graph, this),
Serban Constantinescu579885a2015-02-22 20:51:33 +0000413 move_resolver_(graph->GetArena(), this),
414 isa_features_(isa_features) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000415 // Save the link register (containing the return address) to mimic Quick.
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000416 AddAllocatedRegister(LocationFrom(lr));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000417}
Alexandre Rames5319def2014-10-23 10:03:10 +0100418
Alexandre Rames67555f72014-11-18 10:55:16 +0000419#undef __
420#define __ GetVIXLAssembler()->
Alexandre Rames5319def2014-10-23 10:03:10 +0100421
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000422void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) {
423 // Ensure we emit the literal pool.
424 __ FinalizeCode();
425 CodeGenerator::Finalize(allocator);
426}
427
Alexandre Rames3e69f162014-12-10 10:36:50 +0000428void ParallelMoveResolverARM64::EmitMove(size_t index) {
429 MoveOperands* move = moves_.Get(index);
430 codegen_->MoveLocation(move->GetDestination(), move->GetSource());
431}
432
433void ParallelMoveResolverARM64::EmitSwap(size_t index) {
434 MoveOperands* move = moves_.Get(index);
435 codegen_->SwapLocations(move->GetDestination(), move->GetSource());
436}
437
438void ParallelMoveResolverARM64::RestoreScratch(int reg) {
439 __ Pop(Register(VIXLRegCodeFromART(reg), kXRegSize));
440}
441
442void ParallelMoveResolverARM64::SpillScratch(int reg) {
443 __ Push(Register(VIXLRegCodeFromART(reg), kXRegSize));
444}
445
Alexandre Rames5319def2014-10-23 10:03:10 +0100446void CodeGeneratorARM64::GenerateFrameEntry() {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000447 __ Bind(&frame_entry_label_);
448
Serban Constantinescu02164b32014-11-13 14:05:07 +0000449 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod();
450 if (do_overflow_check) {
451 UseScratchRegisterScope temps(GetVIXLAssembler());
452 Register temp = temps.AcquireX();
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000453 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000454 __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64)));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000455 __ Ldr(wzr, MemOperand(temp, 0));
456 RecordPcInfo(nullptr, 0);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000457 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100458
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000459 if (!HasEmptyFrame()) {
460 int frame_size = GetFrameSize();
461 // Stack layout:
462 // sp[frame_size - 8] : lr.
463 // ... : other preserved core registers.
464 // ... : other preserved fp registers.
465 // ... : reserved frame space.
466 // sp[0] : current method.
467 __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100468 GetAssembler()->cfi().AdjustCFAOffset(frame_size);
469 SpillRegisters(GetFramePreservedCoreRegisters(), frame_size - GetCoreSpillSize());
470 SpillRegisters(GetFramePreservedFPRegisters(), frame_size - FrameEntrySpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000471 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100472}
473
474void CodeGeneratorARM64::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000475 if (!HasEmptyFrame()) {
476 int frame_size = GetFrameSize();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100477 UnspillRegisters(GetFramePreservedFPRegisters(), frame_size - FrameEntrySpillSize());
478 UnspillRegisters(GetFramePreservedCoreRegisters(), frame_size - GetCoreSpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000479 __ Drop(frame_size);
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100480 GetAssembler()->cfi().AdjustCFAOffset(-frame_size);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000481 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100482}
483
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100484static inline dwarf::Reg DWARFReg(CPURegister reg) {
485 if (reg.IsFPRegister()) {
486 return dwarf::Reg::Arm64Fp(reg.code());
487 } else {
488 DCHECK_LT(reg.code(), 31u); // X0 - X30.
489 return dwarf::Reg::Arm64Core(reg.code());
490 }
491}
492
493void CodeGeneratorARM64::SpillRegisters(vixl::CPURegList registers, int offset) {
494 int size = registers.RegisterSizeInBytes();
495 while (registers.Count() >= 2) {
496 const CPURegister& dst0 = registers.PopLowestIndex();
497 const CPURegister& dst1 = registers.PopLowestIndex();
498 __ Stp(dst0, dst1, MemOperand(__ StackPointer(), offset));
499 GetAssembler()->cfi().RelOffset(DWARFReg(dst0), offset);
500 GetAssembler()->cfi().RelOffset(DWARFReg(dst1), offset + size);
501 offset += 2 * size;
502 }
503 if (!registers.IsEmpty()) {
504 const CPURegister& dst0 = registers.PopLowestIndex();
505 __ Str(dst0, MemOperand(__ StackPointer(), offset));
506 GetAssembler()->cfi().RelOffset(DWARFReg(dst0), offset);
507 }
508 DCHECK(registers.IsEmpty());
509}
510
511void CodeGeneratorARM64::UnspillRegisters(vixl::CPURegList registers, int offset) {
512 int size = registers.RegisterSizeInBytes();
513 while (registers.Count() >= 2) {
514 const CPURegister& dst0 = registers.PopLowestIndex();
515 const CPURegister& dst1 = registers.PopLowestIndex();
516 __ Ldp(dst0, dst1, MemOperand(__ StackPointer(), offset));
517 GetAssembler()->cfi().Restore(DWARFReg(dst0));
518 GetAssembler()->cfi().Restore(DWARFReg(dst1));
519 offset += 2 * size;
520 }
521 if (!registers.IsEmpty()) {
522 const CPURegister& dst0 = registers.PopLowestIndex();
523 __ Ldr(dst0, MemOperand(__ StackPointer(), offset));
524 GetAssembler()->cfi().Restore(DWARFReg(dst0));
525 }
526 DCHECK(registers.IsEmpty());
527}
528
Alexandre Rames5319def2014-10-23 10:03:10 +0100529void CodeGeneratorARM64::Bind(HBasicBlock* block) {
530 __ Bind(GetLabelOf(block));
531}
532
Alexandre Rames5319def2014-10-23 10:03:10 +0100533void CodeGeneratorARM64::Move(HInstruction* instruction,
534 Location location,
535 HInstruction* move_for) {
536 LocationSummary* locations = instruction->GetLocations();
537 if (locations != nullptr && locations->Out().Equals(location)) {
538 return;
539 }
540
541 Primitive::Type type = instruction->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000542 DCHECK_NE(type, Primitive::kPrimVoid);
Alexandre Rames5319def2014-10-23 10:03:10 +0100543
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000544 if (instruction->IsIntConstant()
545 || instruction->IsLongConstant()
546 || instruction->IsNullConstant()) {
547 int64_t value = GetInt64ValueOf(instruction->AsConstant());
Alexandre Rames5319def2014-10-23 10:03:10 +0100548 if (location.IsRegister()) {
549 Register dst = RegisterFrom(location, type);
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000550 DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) ||
Alexandre Rames5319def2014-10-23 10:03:10 +0100551 (instruction->IsLongConstant() && dst.Is64Bits()));
552 __ Mov(dst, value);
553 } else {
554 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000555 UseScratchRegisterScope temps(GetVIXLAssembler());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000556 Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant())
557 ? temps.AcquireW()
558 : temps.AcquireX();
Alexandre Rames5319def2014-10-23 10:03:10 +0100559 __ Mov(temp, value);
560 __ Str(temp, StackOperandFrom(location));
561 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000562 } else if (instruction->IsTemporary()) {
563 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000564 MoveLocation(location, temp_location, type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100565 } else if (instruction->IsLoadLocal()) {
566 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Alexandre Rames542361f2015-01-29 16:57:31 +0000567 if (Primitive::Is64BitType(type)) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000568 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000569 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000570 MoveLocation(location, Location::StackSlot(stack_slot), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100571 }
572
573 } else {
574 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000575 MoveLocation(location, locations->Out(), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100576 }
577}
578
Alexandre Rames5319def2014-10-23 10:03:10 +0100579Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const {
580 Primitive::Type type = load->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000581
Alexandre Rames5319def2014-10-23 10:03:10 +0100582 switch (type) {
583 case Primitive::kPrimNot:
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000584 case Primitive::kPrimInt:
585 case Primitive::kPrimFloat:
586 return Location::StackSlot(GetStackSlot(load->GetLocal()));
587
588 case Primitive::kPrimLong:
589 case Primitive::kPrimDouble:
590 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
591
Alexandre Rames5319def2014-10-23 10:03:10 +0100592 case Primitive::kPrimBoolean:
593 case Primitive::kPrimByte:
594 case Primitive::kPrimChar:
595 case Primitive::kPrimShort:
Alexandre Rames5319def2014-10-23 10:03:10 +0100596 case Primitive::kPrimVoid:
Alexandre Rames5319def2014-10-23 10:03:10 +0100597 LOG(FATAL) << "Unexpected type " << type;
598 }
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000599
Alexandre Rames5319def2014-10-23 10:03:10 +0100600 LOG(FATAL) << "Unreachable";
601 return Location::NoLocation();
602}
603
604void CodeGeneratorARM64::MarkGCCard(Register object, Register value) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000605 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +0100606 Register card = temps.AcquireX();
Serban Constantinescu02164b32014-11-13 14:05:07 +0000607 Register temp = temps.AcquireW(); // Index within the CardTable - 32bit.
Alexandre Rames5319def2014-10-23 10:03:10 +0100608 vixl::Label done;
609 __ Cbz(value, &done);
610 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value()));
611 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000612 __ Strb(card, MemOperand(card, temp.X()));
Alexandre Rames5319def2014-10-23 10:03:10 +0100613 __ Bind(&done);
614}
615
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000616void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const {
617 // Blocked core registers:
618 // lr : Runtime reserved.
619 // tr : Runtime reserved.
620 // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it.
621 // ip1 : VIXL core temp.
622 // ip0 : VIXL core temp.
623 //
624 // Blocked fp registers:
625 // d31 : VIXL fp temp.
Alexandre Rames5319def2014-10-23 10:03:10 +0100626 CPURegList reserved_core_registers = vixl_reserved_core_registers;
627 reserved_core_registers.Combine(runtime_reserved_core_registers);
Alexandre Rames5319def2014-10-23 10:03:10 +0100628 while (!reserved_core_registers.IsEmpty()) {
629 blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true;
630 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000631
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000632 CPURegList reserved_fp_registers = vixl_reserved_fp_registers;
Zheng Xua3ec3942015-02-15 18:39:46 +0800633 while (!reserved_fp_registers.IsEmpty()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000634 blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true;
635 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000636
637 if (is_baseline) {
638 CPURegList reserved_core_baseline_registers = callee_saved_core_registers;
639 while (!reserved_core_baseline_registers.IsEmpty()) {
640 blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true;
641 }
642
643 CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers;
644 while (!reserved_fp_baseline_registers.IsEmpty()) {
645 blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true;
646 }
647 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100648}
649
650Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const {
651 if (type == Primitive::kPrimVoid) {
652 LOG(FATAL) << "Unreachable type " << type;
653 }
654
Alexandre Rames542361f2015-01-29 16:57:31 +0000655 if (Primitive::IsFloatingPointType(type)) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000656 ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters);
657 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100658 return Location::FpuRegisterLocation(reg);
659 } else {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000660 ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters);
661 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100662 return Location::RegisterLocation(reg);
663 }
664}
665
Alexandre Rames3e69f162014-12-10 10:36:50 +0000666size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
667 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
668 __ Str(reg, MemOperand(sp, stack_index));
669 return kArm64WordSize;
670}
671
672size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
673 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
674 __ Ldr(reg, MemOperand(sp, stack_index));
675 return kArm64WordSize;
676}
677
678size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
679 FPRegister reg = FPRegister(reg_id, kDRegSize);
680 __ Str(reg, MemOperand(sp, stack_index));
681 return kArm64WordSize;
682}
683
684size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
685 FPRegister reg = FPRegister(reg_id, kDRegSize);
686 __ Ldr(reg, MemOperand(sp, stack_index));
687 return kArm64WordSize;
688}
689
Alexandre Rames5319def2014-10-23 10:03:10 +0100690void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
691 stream << Arm64ManagedRegister::FromXRegister(XRegister(reg));
692}
693
694void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
695 stream << Arm64ManagedRegister::FromDRegister(DRegister(reg));
696}
697
Alexandre Rames67555f72014-11-18 10:55:16 +0000698void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000699 if (constant->IsIntConstant()) {
700 __ Mov(Register(destination), constant->AsIntConstant()->GetValue());
701 } else if (constant->IsLongConstant()) {
702 __ Mov(Register(destination), constant->AsLongConstant()->GetValue());
703 } else if (constant->IsNullConstant()) {
704 __ Mov(Register(destination), 0);
Alexandre Rames67555f72014-11-18 10:55:16 +0000705 } else if (constant->IsFloatConstant()) {
706 __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue());
707 } else {
708 DCHECK(constant->IsDoubleConstant());
709 __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue());
710 }
711}
712
Alexandre Rames3e69f162014-12-10 10:36:50 +0000713
714static bool CoherentConstantAndType(Location constant, Primitive::Type type) {
715 DCHECK(constant.IsConstant());
716 HConstant* cst = constant.GetConstant();
717 return (cst->IsIntConstant() && type == Primitive::kPrimInt) ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000718 // Null is mapped to a core W register, which we associate with kPrimInt.
719 (cst->IsNullConstant() && type == Primitive::kPrimInt) ||
Alexandre Rames3e69f162014-12-10 10:36:50 +0000720 (cst->IsLongConstant() && type == Primitive::kPrimLong) ||
721 (cst->IsFloatConstant() && type == Primitive::kPrimFloat) ||
722 (cst->IsDoubleConstant() && type == Primitive::kPrimDouble);
723}
724
725void CodeGeneratorARM64::MoveLocation(Location destination, Location source, Primitive::Type type) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000726 if (source.Equals(destination)) {
727 return;
728 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000729
730 // A valid move can always be inferred from the destination and source
731 // locations. When moving from and to a register, the argument type can be
732 // used to generate 32bit instead of 64bit moves. In debug mode we also
733 // checks the coherency of the locations and the type.
734 bool unspecified_type = (type == Primitive::kPrimVoid);
735
736 if (destination.IsRegister() || destination.IsFpuRegister()) {
737 if (unspecified_type) {
738 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
739 if (source.IsStackSlot() ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000740 (src_cst != nullptr && (src_cst->IsIntConstant()
741 || src_cst->IsFloatConstant()
742 || src_cst->IsNullConstant()))) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000743 // For stack slots and 32bit constants, a 64bit type is appropriate.
744 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexandre Rames67555f72014-11-18 10:55:16 +0000745 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000746 // If the source is a double stack slot or a 64bit constant, a 64bit
747 // type is appropriate. Else the source is a register, and since the
748 // type has not been specified, we chose a 64bit type to force a 64bit
749 // move.
750 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexandre Rames67555f72014-11-18 10:55:16 +0000751 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000752 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000753 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
754 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000755 CPURegister dst = CPURegisterFrom(destination, type);
756 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
757 DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot());
758 __ Ldr(dst, StackOperandFrom(source));
759 } else if (source.IsConstant()) {
760 DCHECK(CoherentConstantAndType(source, type));
761 MoveConstant(dst, source.GetConstant());
762 } else {
763 if (destination.IsRegister()) {
764 __ Mov(Register(dst), RegisterFrom(source, type));
765 } else {
766 __ Fmov(FPRegister(dst), FPRegisterFrom(source, type));
767 }
768 }
769
770 } else { // The destination is not a register. It must be a stack slot.
771 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
772 if (source.IsRegister() || source.IsFpuRegister()) {
773 if (unspecified_type) {
774 if (source.IsRegister()) {
775 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
776 } else {
777 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
778 }
779 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000780 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
781 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000782 __ Str(CPURegisterFrom(source, type), StackOperandFrom(destination));
783 } else if (source.IsConstant()) {
784 DCHECK(unspecified_type || CoherentConstantAndType(source, type));
785 UseScratchRegisterScope temps(GetVIXLAssembler());
786 HConstant* src_cst = source.GetConstant();
787 CPURegister temp;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000788 if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000789 temp = temps.AcquireW();
790 } else if (src_cst->IsLongConstant()) {
791 temp = temps.AcquireX();
792 } else if (src_cst->IsFloatConstant()) {
793 temp = temps.AcquireS();
794 } else {
795 DCHECK(src_cst->IsDoubleConstant());
796 temp = temps.AcquireD();
797 }
798 MoveConstant(temp, src_cst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000799 __ Str(temp, StackOperandFrom(destination));
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000800 } else {
Alexandre Rames67555f72014-11-18 10:55:16 +0000801 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000802 DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000803 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000804 // There is generally less pressure on FP registers.
805 FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS();
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000806 __ Ldr(temp, StackOperandFrom(source));
807 __ Str(temp, StackOperandFrom(destination));
808 }
809 }
810}
811
Alexandre Rames3e69f162014-12-10 10:36:50 +0000812void CodeGeneratorARM64::SwapLocations(Location loc1, Location loc2) {
813 DCHECK(!loc1.IsConstant());
814 DCHECK(!loc2.IsConstant());
815
816 if (loc1.Equals(loc2)) {
817 return;
818 }
819
820 UseScratchRegisterScope temps(GetAssembler()->vixl_masm_);
821
822 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
823 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
824 bool is_fp_reg1 = loc1.IsFpuRegister();
825 bool is_fp_reg2 = loc2.IsFpuRegister();
826
827 if (loc2.IsRegister() && loc1.IsRegister()) {
828 Register r1 = XRegisterFrom(loc1);
829 Register r2 = XRegisterFrom(loc2);
830 Register tmp = temps.AcquireSameSizeAs(r1);
831 __ Mov(tmp, r2);
832 __ Mov(r2, r1);
833 __ Mov(r1, tmp);
834 } else if (is_fp_reg2 && is_fp_reg1) {
835 FPRegister r1 = DRegisterFrom(loc1);
836 FPRegister r2 = DRegisterFrom(loc2);
837 FPRegister tmp = temps.AcquireSameSizeAs(r1);
838 __ Fmov(tmp, r2);
839 __ Fmov(r2, r1);
840 __ Fmov(r1, tmp);
841 } else if (is_slot1 != is_slot2) {
842 MemOperand mem = StackOperandFrom(is_slot1 ? loc1 : loc2);
843 Location reg_loc = is_slot1 ? loc2 : loc1;
844 CPURegister reg, tmp;
845 if (reg_loc.IsFpuRegister()) {
846 reg = DRegisterFrom(reg_loc);
847 tmp = temps.AcquireD();
848 } else {
849 reg = XRegisterFrom(reg_loc);
850 tmp = temps.AcquireX();
851 }
852 __ Ldr(tmp, mem);
853 __ Str(reg, mem);
854 if (reg_loc.IsFpuRegister()) {
855 __ Fmov(FPRegister(reg), FPRegister(tmp));
856 } else {
857 __ Mov(Register(reg), Register(tmp));
858 }
859 } else if (is_slot1 && is_slot2) {
860 MemOperand mem1 = StackOperandFrom(loc1);
861 MemOperand mem2 = StackOperandFrom(loc2);
862 Register tmp1 = loc1.IsStackSlot() ? temps.AcquireW() : temps.AcquireX();
863 Register tmp2 = temps.AcquireSameSizeAs(tmp1);
864 __ Ldr(tmp1, mem1);
865 __ Ldr(tmp2, mem2);
866 __ Str(tmp1, mem2);
867 __ Str(tmp2, mem1);
868 } else {
869 LOG(FATAL) << "Unimplemented";
870 }
871}
872
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000873void CodeGeneratorARM64::Load(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000874 CPURegister dst,
875 const MemOperand& src) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000876 switch (type) {
877 case Primitive::kPrimBoolean:
Alexandre Rames67555f72014-11-18 10:55:16 +0000878 __ Ldrb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000879 break;
880 case Primitive::kPrimByte:
Alexandre Rames67555f72014-11-18 10:55:16 +0000881 __ Ldrsb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000882 break;
883 case Primitive::kPrimShort:
Alexandre Rames67555f72014-11-18 10:55:16 +0000884 __ Ldrsh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000885 break;
886 case Primitive::kPrimChar:
Alexandre Rames67555f72014-11-18 10:55:16 +0000887 __ Ldrh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000888 break;
889 case Primitive::kPrimInt:
890 case Primitive::kPrimNot:
891 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000892 case Primitive::kPrimFloat:
893 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000894 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Rames67555f72014-11-18 10:55:16 +0000895 __ Ldr(dst, src);
896 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000897 case Primitive::kPrimVoid:
898 LOG(FATAL) << "Unreachable type " << type;
899 }
900}
901
Calin Juravle77520bc2015-01-12 18:45:46 +0000902void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000903 CPURegister dst,
904 const MemOperand& src) {
905 UseScratchRegisterScope temps(GetVIXLAssembler());
906 Register temp_base = temps.AcquireX();
Calin Juravle77520bc2015-01-12 18:45:46 +0000907 Primitive::Type type = instruction->GetType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000908
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000909 DCHECK(!src.IsPreIndex());
910 DCHECK(!src.IsPostIndex());
911
912 // TODO(vixl): Let the MacroAssembler handle MemOperand.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800913 __ Add(temp_base, src.base(), OperandFromMemOperand(src));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000914 MemOperand base = MemOperand(temp_base);
915 switch (type) {
916 case Primitive::kPrimBoolean:
917 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000918 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000919 break;
920 case Primitive::kPrimByte:
921 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000922 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000923 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
924 break;
925 case Primitive::kPrimChar:
926 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000927 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000928 break;
929 case Primitive::kPrimShort:
930 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000931 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000932 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
933 break;
934 case Primitive::kPrimInt:
935 case Primitive::kPrimNot:
936 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000937 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000938 __ Ldar(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000939 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000940 break;
941 case Primitive::kPrimFloat:
942 case Primitive::kPrimDouble: {
943 DCHECK(dst.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000944 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000945
946 Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
947 __ Ldar(temp, base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000948 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000949 __ Fmov(FPRegister(dst), temp);
950 break;
951 }
952 case Primitive::kPrimVoid:
953 LOG(FATAL) << "Unreachable type " << type;
954 }
955}
956
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000957void CodeGeneratorARM64::Store(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000958 CPURegister src,
959 const MemOperand& dst) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000960 switch (type) {
961 case Primitive::kPrimBoolean:
962 case Primitive::kPrimByte:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000963 __ Strb(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000964 break;
965 case Primitive::kPrimChar:
966 case Primitive::kPrimShort:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000967 __ Strh(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000968 break;
969 case Primitive::kPrimInt:
970 case Primitive::kPrimNot:
971 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000972 case Primitive::kPrimFloat:
973 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000974 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000975 __ Str(src, dst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000976 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000977 case Primitive::kPrimVoid:
978 LOG(FATAL) << "Unreachable type " << type;
979 }
980}
981
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000982void CodeGeneratorARM64::StoreRelease(Primitive::Type type,
983 CPURegister src,
984 const MemOperand& dst) {
985 UseScratchRegisterScope temps(GetVIXLAssembler());
986 Register temp_base = temps.AcquireX();
987
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000988 DCHECK(!dst.IsPreIndex());
989 DCHECK(!dst.IsPostIndex());
990
991 // TODO(vixl): Let the MacroAssembler handle this.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800992 Operand op = OperandFromMemOperand(dst);
993 __ Add(temp_base, dst.base(), op);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000994 MemOperand base = MemOperand(temp_base);
995 switch (type) {
996 case Primitive::kPrimBoolean:
997 case Primitive::kPrimByte:
998 __ Stlrb(Register(src), base);
999 break;
1000 case Primitive::kPrimChar:
1001 case Primitive::kPrimShort:
1002 __ Stlrh(Register(src), base);
1003 break;
1004 case Primitive::kPrimInt:
1005 case Primitive::kPrimNot:
1006 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +00001007 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001008 __ Stlr(Register(src), base);
1009 break;
1010 case Primitive::kPrimFloat:
1011 case Primitive::kPrimDouble: {
1012 DCHECK(src.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +00001013 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001014
1015 Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
1016 __ Fmov(temp, FPRegister(src));
1017 __ Stlr(temp, base);
1018 break;
1019 }
1020 case Primitive::kPrimVoid:
1021 LOG(FATAL) << "Unreachable type " << type;
1022 }
1023}
1024
Alexandre Rames67555f72014-11-18 10:55:16 +00001025void CodeGeneratorARM64::LoadCurrentMethod(vixl::Register current_method) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001026 DCHECK(RequiresCurrentMethod());
Alexandre Rames67555f72014-11-18 10:55:16 +00001027 DCHECK(current_method.IsW());
1028 __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset));
1029}
1030
1031void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset,
1032 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001033 uint32_t dex_pc,
1034 SlowPathCode* slow_path) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001035 __ Ldr(lr, MemOperand(tr, entry_point_offset));
1036 __ Blr(lr);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001037 if (instruction != nullptr) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001038 RecordPcInfo(instruction, dex_pc, slow_path);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001039 DCHECK(instruction->IsSuspendCheck()
1040 || instruction->IsBoundsCheck()
1041 || instruction->IsNullCheck()
1042 || instruction->IsDivZeroCheck()
1043 || !IsLeafMethod());
1044 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001045}
1046
1047void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path,
1048 vixl::Register class_reg) {
1049 UseScratchRegisterScope temps(GetVIXLAssembler());
1050 Register temp = temps.AcquireW();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001051 size_t status_offset = mirror::Class::StatusOffset().SizeValue();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001052 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001053
Serban Constantinescu02164b32014-11-13 14:05:07 +00001054 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
Serban Constantinescu579885a2015-02-22 20:51:33 +00001055 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001056 // TODO(vixl): Let the MacroAssembler handle MemOperand.
1057 __ Add(temp, class_reg, status_offset);
1058 __ Ldar(temp, HeapOperand(temp));
1059 __ Cmp(temp, mirror::Class::kStatusInitialized);
1060 __ B(lt, slow_path->GetEntryLabel());
1061 } else {
1062 __ Ldr(temp, HeapOperand(class_reg, status_offset));
1063 __ Cmp(temp, mirror::Class::kStatusInitialized);
1064 __ B(lt, slow_path->GetEntryLabel());
1065 __ Dmb(InnerShareable, BarrierReads);
1066 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001067 __ Bind(slow_path->GetExitLabel());
1068}
Alexandre Rames5319def2014-10-23 10:03:10 +01001069
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001070void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) {
1071 BarrierType type = BarrierAll;
1072
1073 switch (kind) {
1074 case MemBarrierKind::kAnyAny:
1075 case MemBarrierKind::kAnyStore: {
1076 type = BarrierAll;
1077 break;
1078 }
1079 case MemBarrierKind::kLoadAny: {
1080 type = BarrierReads;
1081 break;
1082 }
1083 case MemBarrierKind::kStoreStore: {
1084 type = BarrierWrites;
1085 break;
1086 }
1087 default:
1088 LOG(FATAL) << "Unexpected memory barrier " << kind;
1089 }
1090 __ Dmb(InnerShareable, type);
1091}
1092
Serban Constantinescu02164b32014-11-13 14:05:07 +00001093void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction,
1094 HBasicBlock* successor) {
1095 SuspendCheckSlowPathARM64* slow_path =
1096 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor);
1097 codegen_->AddSlowPath(slow_path);
1098 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
1099 Register temp = temps.AcquireW();
1100
1101 __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue()));
1102 if (successor == nullptr) {
1103 __ Cbnz(temp, slow_path->GetEntryLabel());
1104 __ Bind(slow_path->GetReturnLabel());
1105 } else {
1106 __ Cbz(temp, codegen_->GetLabelOf(successor));
1107 __ B(slow_path->GetEntryLabel());
1108 // slow_path will return to GetLabelOf(successor).
1109 }
1110}
1111
Alexandre Rames5319def2014-10-23 10:03:10 +01001112InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
1113 CodeGeneratorARM64* codegen)
1114 : HGraphVisitor(graph),
1115 assembler_(codegen->GetAssembler()),
1116 codegen_(codegen) {}
1117
1118#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Alexandre Rames3e69f162014-12-10 10:36:50 +00001119 /* No unimplemented IR. */
Alexandre Rames5319def2014-10-23 10:03:10 +01001120
1121#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
1122
1123enum UnimplementedInstructionBreakCode {
Alexandre Rames67555f72014-11-18 10:55:16 +00001124 // Using a base helps identify when we hit such breakpoints.
1125 UnimplementedInstructionBreakCodeBaseCode = 0x900,
Alexandre Rames5319def2014-10-23 10:03:10 +01001126#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
1127 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
1128#undef ENUM_UNIMPLEMENTED_INSTRUCTION
1129};
1130
1131#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
1132 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001133 UNUSED(instr); \
Alexandre Rames5319def2014-10-23 10:03:10 +01001134 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
1135 } \
1136 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
1137 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
1138 locations->SetOut(Location::Any()); \
1139 }
1140 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
1141#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
1142
1143#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
Alexandre Rames67555f72014-11-18 10:55:16 +00001144#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
Alexandre Rames5319def2014-10-23 10:03:10 +01001145
Alexandre Rames67555f72014-11-18 10:55:16 +00001146void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001147 DCHECK_EQ(instr->InputCount(), 2U);
1148 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1149 Primitive::Type type = instr->GetResultType();
1150 switch (type) {
1151 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001152 case Primitive::kPrimLong:
Alexandre Rames5319def2014-10-23 10:03:10 +01001153 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001154 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr));
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001155 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001156 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001157
1158 case Primitive::kPrimFloat:
1159 case Primitive::kPrimDouble:
1160 locations->SetInAt(0, Location::RequiresFpuRegister());
1161 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001162 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001163 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001164
Alexandre Rames5319def2014-10-23 10:03:10 +01001165 default:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001166 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001167 }
1168}
1169
Alexandre Rames67555f72014-11-18 10:55:16 +00001170void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001171 Primitive::Type type = instr->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001172
1173 switch (type) {
1174 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001175 case Primitive::kPrimLong: {
1176 Register dst = OutputRegister(instr);
1177 Register lhs = InputRegisterAt(instr, 0);
1178 Operand rhs = InputOperandAt(instr, 1);
Alexandre Rames5319def2014-10-23 10:03:10 +01001179 if (instr->IsAdd()) {
1180 __ Add(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001181 } else if (instr->IsAnd()) {
1182 __ And(dst, lhs, rhs);
1183 } else if (instr->IsOr()) {
1184 __ Orr(dst, lhs, rhs);
1185 } else if (instr->IsSub()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001186 __ Sub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001187 } else {
1188 DCHECK(instr->IsXor());
1189 __ Eor(dst, lhs, rhs);
Alexandre Rames5319def2014-10-23 10:03:10 +01001190 }
1191 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001192 }
1193 case Primitive::kPrimFloat:
1194 case Primitive::kPrimDouble: {
1195 FPRegister dst = OutputFPRegister(instr);
1196 FPRegister lhs = InputFPRegisterAt(instr, 0);
1197 FPRegister rhs = InputFPRegisterAt(instr, 1);
1198 if (instr->IsAdd()) {
1199 __ Fadd(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001200 } else if (instr->IsSub()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001201 __ Fsub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001202 } else {
1203 LOG(FATAL) << "Unexpected floating-point binary operation";
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001204 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001205 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001206 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001207 default:
Alexandre Rames67555f72014-11-18 10:55:16 +00001208 LOG(FATAL) << "Unexpected binary operation type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001209 }
1210}
1211
Serban Constantinescu02164b32014-11-13 14:05:07 +00001212void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) {
1213 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1214
1215 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1216 Primitive::Type type = instr->GetResultType();
1217 switch (type) {
1218 case Primitive::kPrimInt:
1219 case Primitive::kPrimLong: {
1220 locations->SetInAt(0, Location::RequiresRegister());
1221 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1222 locations->SetOut(Location::RequiresRegister());
1223 break;
1224 }
1225 default:
1226 LOG(FATAL) << "Unexpected shift type " << type;
1227 }
1228}
1229
1230void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) {
1231 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1232
1233 Primitive::Type type = instr->GetType();
1234 switch (type) {
1235 case Primitive::kPrimInt:
1236 case Primitive::kPrimLong: {
1237 Register dst = OutputRegister(instr);
1238 Register lhs = InputRegisterAt(instr, 0);
1239 Operand rhs = InputOperandAt(instr, 1);
1240 if (rhs.IsImmediate()) {
1241 uint32_t shift_value = (type == Primitive::kPrimInt)
1242 ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue)
1243 : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue);
1244 if (instr->IsShl()) {
1245 __ Lsl(dst, lhs, shift_value);
1246 } else if (instr->IsShr()) {
1247 __ Asr(dst, lhs, shift_value);
1248 } else {
1249 __ Lsr(dst, lhs, shift_value);
1250 }
1251 } else {
1252 Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W();
1253
1254 if (instr->IsShl()) {
1255 __ Lsl(dst, lhs, rhs_reg);
1256 } else if (instr->IsShr()) {
1257 __ Asr(dst, lhs, rhs_reg);
1258 } else {
1259 __ Lsr(dst, lhs, rhs_reg);
1260 }
1261 }
1262 break;
1263 }
1264 default:
1265 LOG(FATAL) << "Unexpected shift operation type " << type;
1266 }
1267}
1268
Alexandre Rames5319def2014-10-23 10:03:10 +01001269void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001270 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001271}
1272
1273void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001274 HandleBinaryOp(instruction);
1275}
1276
1277void LocationsBuilderARM64::VisitAnd(HAnd* instruction) {
1278 HandleBinaryOp(instruction);
1279}
1280
1281void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) {
1282 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001283}
1284
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001285void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) {
1286 LocationSummary* locations =
1287 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1288 locations->SetInAt(0, Location::RequiresRegister());
1289 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1290 locations->SetOut(Location::RequiresRegister());
1291}
1292
1293void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) {
1294 LocationSummary* locations = instruction->GetLocations();
1295 Primitive::Type type = instruction->GetType();
1296 Register obj = InputRegisterAt(instruction, 0);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001297 Location index = locations->InAt(1);
1298 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001299 MemOperand source = HeapOperand(obj);
Alexandre Rames67555f72014-11-18 10:55:16 +00001300 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001301
1302 if (index.IsConstant()) {
1303 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001304 source = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001305 } else {
1306 Register temp = temps.AcquireSameSizeAs(obj);
1307 Register index_reg = RegisterFrom(index, Primitive::kPrimInt);
1308 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001309 source = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001310 }
1311
Alexandre Rames67555f72014-11-18 10:55:16 +00001312 codegen_->Load(type, OutputCPURegister(instruction), source);
Calin Juravle77520bc2015-01-12 18:45:46 +00001313 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001314}
1315
Alexandre Rames5319def2014-10-23 10:03:10 +01001316void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
1317 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1318 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001319 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001320}
1321
1322void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
1323 __ Ldr(OutputRegister(instruction),
1324 HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset()));
Calin Juravle77520bc2015-01-12 18:45:46 +00001325 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001326}
1327
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001328void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) {
1329 Primitive::Type value_type = instruction->GetComponentType();
1330 bool is_object = value_type == Primitive::kPrimNot;
1331 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1332 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1333 if (is_object) {
1334 InvokeRuntimeCallingConvention calling_convention;
1335 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1336 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1337 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1338 } else {
1339 locations->SetInAt(0, Location::RequiresRegister());
1340 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1341 locations->SetInAt(2, Location::RequiresRegister());
1342 }
1343}
1344
1345void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) {
1346 Primitive::Type value_type = instruction->GetComponentType();
1347 if (value_type == Primitive::kPrimNot) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001348 codegen_->InvokeRuntime(
1349 QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001350 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001351 } else {
1352 LocationSummary* locations = instruction->GetLocations();
1353 Register obj = InputRegisterAt(instruction, 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00001354 CPURegister value = InputCPURegisterAt(instruction, 2);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001355 Location index = locations->InAt(1);
1356 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001357 MemOperand destination = HeapOperand(obj);
Alexandre Rames67555f72014-11-18 10:55:16 +00001358 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001359
1360 if (index.IsConstant()) {
1361 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001362 destination = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001363 } else {
1364 Register temp = temps.AcquireSameSizeAs(obj);
1365 Register index_reg = InputRegisterAt(instruction, 1);
1366 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001367 destination = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001368 }
1369
1370 codegen_->Store(value_type, value, destination);
Calin Juravle77520bc2015-01-12 18:45:46 +00001371 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001372 }
1373}
1374
Alexandre Rames67555f72014-11-18 10:55:16 +00001375void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1376 LocationSummary* locations =
1377 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1378 locations->SetInAt(0, Location::RequiresRegister());
1379 locations->SetInAt(1, Location::RequiresRegister());
1380 if (instruction->HasUses()) {
1381 locations->SetOut(Location::SameAsFirstInput());
1382 }
1383}
1384
1385void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001386 LocationSummary* locations = instruction->GetLocations();
1387 BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(
1388 instruction, locations->InAt(0), locations->InAt(1));
Alexandre Rames67555f72014-11-18 10:55:16 +00001389 codegen_->AddSlowPath(slow_path);
1390
1391 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
1392 __ B(slow_path->GetEntryLabel(), hs);
1393}
1394
1395void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) {
1396 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1397 instruction, LocationSummary::kCallOnSlowPath);
1398 locations->SetInAt(0, Location::RequiresRegister());
1399 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001400 locations->AddTemp(Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001401}
1402
1403void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001404 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames67555f72014-11-18 10:55:16 +00001405 Register obj = InputRegisterAt(instruction, 0);;
1406 Register cls = InputRegisterAt(instruction, 1);;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001407 Register obj_cls = WRegisterFrom(instruction->GetLocations()->GetTemp(0));
Alexandre Rames67555f72014-11-18 10:55:16 +00001408
Alexandre Rames3e69f162014-12-10 10:36:50 +00001409 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1410 instruction, locations->InAt(1), LocationFrom(obj_cls), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001411 codegen_->AddSlowPath(slow_path);
1412
1413 // TODO: avoid this check if we know obj is not null.
1414 __ Cbz(obj, slow_path->GetExitLabel());
1415 // Compare the class of `obj` with `cls`.
Alexandre Rames3e69f162014-12-10 10:36:50 +00001416 __ Ldr(obj_cls, HeapOperand(obj, mirror::Object::ClassOffset()));
1417 __ Cmp(obj_cls, cls);
Alexandre Rames67555f72014-11-18 10:55:16 +00001418 __ B(ne, slow_path->GetEntryLabel());
1419 __ Bind(slow_path->GetExitLabel());
1420}
1421
1422void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) {
1423 LocationSummary* locations =
1424 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1425 locations->SetInAt(0, Location::RequiresRegister());
1426 if (check->HasUses()) {
1427 locations->SetOut(Location::SameAsFirstInput());
1428 }
1429}
1430
1431void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) {
1432 // We assume the class is not null.
1433 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
1434 check->GetLoadClass(), check, check->GetDexPc(), true);
1435 codegen_->AddSlowPath(slow_path);
1436 GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0));
1437}
1438
Serban Constantinescu02164b32014-11-13 14:05:07 +00001439void LocationsBuilderARM64::VisitCompare(HCompare* compare) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001440 LocationSummary* locations =
Serban Constantinescu02164b32014-11-13 14:05:07 +00001441 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
1442 Primitive::Type in_type = compare->InputAt(0)->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001443 switch (in_type) {
1444 case Primitive::kPrimLong: {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001445 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001446 locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001447 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1448 break;
1449 }
1450 case Primitive::kPrimFloat:
1451 case Primitive::kPrimDouble: {
1452 locations->SetInAt(0, Location::RequiresFpuRegister());
Alexandre Rames93415462015-02-17 15:08:20 +00001453 HInstruction* right = compare->InputAt(1);
1454 if ((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1455 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))) {
1456 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1457 } else {
1458 locations->SetInAt(1, Location::RequiresFpuRegister());
1459 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001460 locations->SetOut(Location::RequiresRegister());
1461 break;
1462 }
1463 default:
1464 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1465 }
1466}
1467
1468void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) {
1469 Primitive::Type in_type = compare->InputAt(0)->GetType();
1470
1471 // 0 if: left == right
1472 // 1 if: left > right
1473 // -1 if: left < right
1474 switch (in_type) {
1475 case Primitive::kPrimLong: {
1476 Register result = OutputRegister(compare);
1477 Register left = InputRegisterAt(compare, 0);
1478 Operand right = InputOperandAt(compare, 1);
1479
1480 __ Cmp(left, right);
1481 __ Cset(result, ne);
1482 __ Cneg(result, result, lt);
1483 break;
1484 }
1485 case Primitive::kPrimFloat:
1486 case Primitive::kPrimDouble: {
1487 Register result = OutputRegister(compare);
1488 FPRegister left = InputFPRegisterAt(compare, 0);
Alexandre Rames93415462015-02-17 15:08:20 +00001489 if (compare->GetLocations()->InAt(1).IsConstant()) {
1490 if (kIsDebugBuild) {
1491 HInstruction* right = compare->GetLocations()->InAt(1).GetConstant();
1492 DCHECK((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1493 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0)));
1494 }
1495 // 0.0 is the only immediate that can be encoded directly in a FCMP instruction.
1496 __ Fcmp(left, 0.0);
1497 } else {
1498 __ Fcmp(left, InputFPRegisterAt(compare, 1));
1499 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001500 if (compare->IsGtBias()) {
1501 __ Cset(result, ne);
1502 } else {
1503 __ Csetm(result, ne);
1504 }
1505 __ Cneg(result, result, compare->IsGtBias() ? mi : gt);
Alexandre Rames5319def2014-10-23 10:03:10 +01001506 break;
1507 }
1508 default:
1509 LOG(FATAL) << "Unimplemented compare type " << in_type;
1510 }
1511}
1512
1513void LocationsBuilderARM64::VisitCondition(HCondition* instruction) {
1514 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1515 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001516 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames5319def2014-10-23 10:03:10 +01001517 if (instruction->NeedsMaterialization()) {
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001518 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001519 }
1520}
1521
1522void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) {
1523 if (!instruction->NeedsMaterialization()) {
1524 return;
1525 }
1526
1527 LocationSummary* locations = instruction->GetLocations();
1528 Register lhs = InputRegisterAt(instruction, 0);
1529 Operand rhs = InputOperandAt(instruction, 1);
1530 Register res = RegisterFrom(locations->Out(), instruction->GetType());
1531 Condition cond = ARM64Condition(instruction->GetCondition());
1532
1533 __ Cmp(lhs, rhs);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001534 __ Cset(res, cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001535}
1536
1537#define FOR_EACH_CONDITION_INSTRUCTION(M) \
1538 M(Equal) \
1539 M(NotEqual) \
1540 M(LessThan) \
1541 M(LessThanOrEqual) \
1542 M(GreaterThan) \
1543 M(GreaterThanOrEqual)
1544#define DEFINE_CONDITION_VISITORS(Name) \
1545void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \
1546void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }
1547FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
Alexandre Rames67555f72014-11-18 10:55:16 +00001548#undef DEFINE_CONDITION_VISITORS
Alexandre Rames5319def2014-10-23 10:03:10 +01001549#undef FOR_EACH_CONDITION_INSTRUCTION
1550
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001551void LocationsBuilderARM64::VisitDiv(HDiv* div) {
1552 LocationSummary* locations =
1553 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1554 switch (div->GetResultType()) {
1555 case Primitive::kPrimInt:
1556 case Primitive::kPrimLong:
1557 locations->SetInAt(0, Location::RequiresRegister());
1558 locations->SetInAt(1, Location::RequiresRegister());
1559 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1560 break;
1561
1562 case Primitive::kPrimFloat:
1563 case Primitive::kPrimDouble:
1564 locations->SetInAt(0, Location::RequiresFpuRegister());
1565 locations->SetInAt(1, Location::RequiresFpuRegister());
1566 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1567 break;
1568
1569 default:
1570 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1571 }
1572}
1573
1574void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) {
1575 Primitive::Type type = div->GetResultType();
1576 switch (type) {
1577 case Primitive::kPrimInt:
1578 case Primitive::kPrimLong:
1579 __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1));
1580 break;
1581
1582 case Primitive::kPrimFloat:
1583 case Primitive::kPrimDouble:
1584 __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1));
1585 break;
1586
1587 default:
1588 LOG(FATAL) << "Unexpected div type " << type;
1589 }
1590}
1591
Alexandre Rames67555f72014-11-18 10:55:16 +00001592void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1593 LocationSummary* locations =
1594 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1595 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1596 if (instruction->HasUses()) {
1597 locations->SetOut(Location::SameAsFirstInput());
1598 }
1599}
1600
1601void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1602 SlowPathCodeARM64* slow_path =
1603 new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction);
1604 codegen_->AddSlowPath(slow_path);
1605 Location value = instruction->GetLocations()->InAt(0);
1606
Alexandre Rames3e69f162014-12-10 10:36:50 +00001607 Primitive::Type type = instruction->GetType();
1608
1609 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1610 LOG(FATAL) << "Unexpected type " << type << "for DivZeroCheck.";
1611 return;
1612 }
1613
Alexandre Rames67555f72014-11-18 10:55:16 +00001614 if (value.IsConstant()) {
1615 int64_t divisor = Int64ConstantFrom(value);
1616 if (divisor == 0) {
1617 __ B(slow_path->GetEntryLabel());
1618 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001619 // A division by a non-null constant is valid. We don't need to perform
1620 // any check, so simply fall through.
Alexandre Rames67555f72014-11-18 10:55:16 +00001621 }
1622 } else {
1623 __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel());
1624 }
1625}
1626
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001627void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1628 LocationSummary* locations =
1629 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1630 locations->SetOut(Location::ConstantLocation(constant));
1631}
1632
1633void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1634 UNUSED(constant);
1635 // Will be generated at use site.
1636}
1637
Alexandre Rames5319def2014-10-23 10:03:10 +01001638void LocationsBuilderARM64::VisitExit(HExit* exit) {
1639 exit->SetLocations(nullptr);
1640}
1641
1642void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001643 UNUSED(exit);
Alexandre Rames5319def2014-10-23 10:03:10 +01001644}
1645
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001646void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) {
1647 LocationSummary* locations =
1648 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1649 locations->SetOut(Location::ConstantLocation(constant));
1650}
1651
1652void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) {
1653 UNUSED(constant);
1654 // Will be generated at use site.
1655}
1656
Alexandre Rames5319def2014-10-23 10:03:10 +01001657void LocationsBuilderARM64::VisitGoto(HGoto* got) {
1658 got->SetLocations(nullptr);
1659}
1660
1661void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
1662 HBasicBlock* successor = got->GetSuccessor();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001663 DCHECK(!successor->IsExitBlock());
1664 HBasicBlock* block = got->GetBlock();
1665 HInstruction* previous = got->GetPrevious();
1666 HLoopInformation* info = block->GetLoopInformation();
1667
David Brazdil46e2a392015-03-16 17:31:52 +00001668 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001669 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1670 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1671 return;
1672 }
1673 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1674 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1675 }
1676 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001677 __ B(codegen_->GetLabelOf(successor));
1678 }
1679}
1680
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001681void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction,
1682 vixl::Label* true_target,
1683 vixl::Label* false_target,
1684 vixl::Label* always_true_target) {
1685 HInstruction* cond = instruction->InputAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001686 HCondition* condition = cond->AsCondition();
Alexandre Rames5319def2014-10-23 10:03:10 +01001687
Serban Constantinescu02164b32014-11-13 14:05:07 +00001688 if (cond->IsIntConstant()) {
1689 int32_t cond_value = cond->AsIntConstant()->GetValue();
1690 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001691 if (always_true_target != nullptr) {
1692 __ B(always_true_target);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001693 }
1694 return;
1695 } else {
1696 DCHECK_EQ(cond_value, 0);
1697 }
1698 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001699 // The condition instruction has been materialized, compare the output to 0.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001700 Location cond_val = instruction->GetLocations()->InAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001701 DCHECK(cond_val.IsRegister());
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001702 __ Cbnz(InputRegisterAt(instruction, 0), true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001703 } else {
1704 // The condition instruction has not been materialized, use its inputs as
1705 // the comparison and its condition as the branch condition.
1706 Register lhs = InputRegisterAt(condition, 0);
1707 Operand rhs = InputOperandAt(condition, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001708 Condition arm64_cond = ARM64Condition(condition->GetCondition());
Alexandre Rames4388dcc2015-02-03 10:28:33 +00001709 if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
1710 switch (arm64_cond) {
1711 case eq:
1712 __ Cbz(lhs, true_target);
1713 break;
1714 case ne:
1715 __ Cbnz(lhs, true_target);
1716 break;
1717 case lt:
1718 // Test the sign bit and branch accordingly.
1719 __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1720 break;
1721 case ge:
1722 // Test the sign bit and branch accordingly.
1723 __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1724 break;
1725 default:
1726 // Without the `static_cast` the compiler throws an error for
1727 // `-Werror=sign-promo`.
1728 LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001729 }
1730 } else {
1731 __ Cmp(lhs, rhs);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001732 __ B(arm64_cond, true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001733 }
1734 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001735 if (false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001736 __ B(false_target);
1737 }
1738}
1739
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001740void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
1741 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1742 HInstruction* cond = if_instr->InputAt(0);
1743 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1744 locations->SetInAt(0, Location::RequiresRegister());
1745 }
1746}
1747
1748void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
1749 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1750 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1751 vixl::Label* always_true_target = true_target;
1752 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1753 if_instr->IfTrueSuccessor())) {
1754 always_true_target = nullptr;
1755 }
1756 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1757 if_instr->IfFalseSuccessor())) {
1758 false_target = nullptr;
1759 }
1760 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1761}
1762
1763void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1764 LocationSummary* locations = new (GetGraph()->GetArena())
1765 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1766 HInstruction* cond = deoptimize->InputAt(0);
1767 DCHECK(cond->IsCondition());
1768 if (cond->AsCondition()->NeedsMaterialization()) {
1769 locations->SetInAt(0, Location::RequiresRegister());
1770 }
1771}
1772
1773void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1774 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
1775 DeoptimizationSlowPathARM64(deoptimize);
1776 codegen_->AddSlowPath(slow_path);
1777 vixl::Label* slow_path_entry = slow_path->GetEntryLabel();
1778 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1779}
1780
Alexandre Rames5319def2014-10-23 10:03:10 +01001781void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001782 LocationSummary* locations =
1783 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001784 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001785 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001786}
1787
1788void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001789 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00001790 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001791
1792 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001793 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00001794 // NB: LoadAcquire will record the pc info if needed.
1795 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001796 } else {
1797 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001798 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001799 // For IRIW sequential consistency kLoadAny is not sufficient.
1800 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1801 }
1802 } else {
1803 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001804 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001805 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001806}
1807
1808void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001809 LocationSummary* locations =
1810 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001811 locations->SetInAt(0, Location::RequiresRegister());
1812 locations->SetInAt(1, Location::RequiresRegister());
1813}
1814
1815void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001816 Register obj = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001817 CPURegister value = InputCPURegisterAt(instruction, 1);
1818 Offset offset = instruction->GetFieldOffset();
1819 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001820 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001821
1822 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001823 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001824 codegen_->StoreRelease(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001825 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001826 } else {
1827 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
1828 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001829 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001830 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1831 }
1832 } else {
1833 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001834 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001835 }
1836
1837 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001838 codegen_->MarkGCCard(obj, Register(value));
Alexandre Rames5319def2014-10-23 10:03:10 +01001839 }
1840}
1841
Alexandre Rames67555f72014-11-18 10:55:16 +00001842void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
1843 LocationSummary::CallKind call_kind =
1844 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
1845 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1846 locations->SetInAt(0, Location::RequiresRegister());
1847 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001848 // The output does overlap inputs.
1849 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexandre Rames67555f72014-11-18 10:55:16 +00001850}
1851
1852void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
1853 LocationSummary* locations = instruction->GetLocations();
1854 Register obj = InputRegisterAt(instruction, 0);;
1855 Register cls = InputRegisterAt(instruction, 1);;
1856 Register out = OutputRegister(instruction);
1857
1858 vixl::Label done;
1859
1860 // Return 0 if `obj` is null.
1861 // TODO: Avoid this check if we know `obj` is not null.
1862 __ Mov(out, 0);
1863 __ Cbz(obj, &done);
1864
1865 // Compare the class of `obj` with `cls`.
Serban Constantinescu02164b32014-11-13 14:05:07 +00001866 __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset()));
Alexandre Rames67555f72014-11-18 10:55:16 +00001867 __ Cmp(out, cls);
1868 if (instruction->IsClassFinal()) {
1869 // Classes must be equal for the instanceof to succeed.
1870 __ Cset(out, eq);
1871 } else {
1872 // If the classes are not equal, we go into a slow path.
1873 DCHECK(locations->OnlyCallsOnSlowPath());
1874 SlowPathCodeARM64* slow_path =
Alexandre Rames3e69f162014-12-10 10:36:50 +00001875 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1876 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001877 codegen_->AddSlowPath(slow_path);
1878 __ B(ne, slow_path->GetEntryLabel());
1879 __ Mov(out, 1);
1880 __ Bind(slow_path->GetExitLabel());
1881 }
1882
1883 __ Bind(&done);
1884}
1885
Alexandre Rames5319def2014-10-23 10:03:10 +01001886void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
1887 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1888 locations->SetOut(Location::ConstantLocation(constant));
1889}
1890
1891void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
1892 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001893 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01001894}
1895
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001896void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
1897 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1898 locations->SetOut(Location::ConstantLocation(constant));
1899}
1900
1901void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) {
1902 // Will be generated at use site.
1903 UNUSED(constant);
1904}
1905
Alexandre Rames5319def2014-10-23 10:03:10 +01001906void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
1907 LocationSummary* locations =
1908 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
1909 locations->AddTemp(LocationFrom(x0));
1910
1911 InvokeDexCallingConventionVisitor calling_convention_visitor;
1912 for (size_t i = 0; i < invoke->InputCount(); i++) {
1913 HInstruction* input = invoke->InputAt(i);
1914 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1915 }
1916
1917 Primitive::Type return_type = invoke->GetType();
1918 if (return_type != Primitive::kPrimVoid) {
1919 locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type));
1920 }
1921}
1922
Alexandre Rames67555f72014-11-18 10:55:16 +00001923void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1924 HandleInvoke(invoke);
1925}
1926
1927void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1928 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1929 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1930 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1931 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1932 Location receiver = invoke->GetLocations()->InAt(0);
1933 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001934 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00001935
1936 // The register ip1 is required to be used for the hidden argument in
1937 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
1938 UseScratchRegisterScope scratch_scope(GetVIXLAssembler());
1939 scratch_scope.Exclude(ip1);
1940 __ Mov(ip1, invoke->GetDexMethodIndex());
1941
1942 // temp = object->GetClass();
1943 if (receiver.IsStackSlot()) {
1944 __ Ldr(temp, StackOperandFrom(receiver));
1945 __ Ldr(temp, HeapOperand(temp, class_offset));
1946 } else {
1947 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
1948 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001949 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames67555f72014-11-18 10:55:16 +00001950 // temp = temp->GetImtEntryAt(method_offset);
1951 __ Ldr(temp, HeapOperand(temp, method_offset));
1952 // lr = temp->GetEntryPoint();
1953 __ Ldr(lr, HeapOperand(temp, entry_point));
1954 // lr();
1955 __ Blr(lr);
1956 DCHECK(!codegen_->IsLeafMethod());
1957 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1958}
1959
1960void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001961 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1962 if (intrinsic.TryDispatch(invoke)) {
1963 return;
1964 }
1965
Alexandre Rames67555f72014-11-18 10:55:16 +00001966 HandleInvoke(invoke);
1967}
1968
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001969void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001970 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1971 if (intrinsic.TryDispatch(invoke)) {
1972 return;
1973 }
1974
Alexandre Rames67555f72014-11-18 10:55:16 +00001975 HandleInvoke(invoke);
1976}
1977
Andreas Gampe878d58c2015-01-15 23:24:00 -08001978static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
1979 if (invoke->GetLocations()->Intrinsified()) {
1980 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
1981 intrinsic.Dispatch(invoke);
1982 return true;
1983 }
1984 return false;
1985}
1986
1987void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
1988 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
1989 DCHECK(temp.Is(kArtMethodRegister));
Alexandre Rames5319def2014-10-23 10:03:10 +01001990 size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() +
Andreas Gampe878d58c2015-01-15 23:24:00 -08001991 invoke->GetDexMethodIndex() * kHeapRefSize;
Alexandre Rames5319def2014-10-23 10:03:10 +01001992
1993 // TODO: Implement all kinds of calls:
1994 // 1) boot -> boot
1995 // 2) app -> boot
1996 // 3) app -> app
1997 //
1998 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1999
Nicolas Geoffray0a299b92015-01-29 11:39:44 +00002000 // temp = method;
2001 LoadCurrentMethod(temp);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002002 if (!invoke->IsRecursive()) {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002003 // temp = temp->dex_cache_resolved_methods_;
2004 __ Ldr(temp, HeapOperand(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset()));
2005 // temp = temp[index_in_cache];
2006 __ Ldr(temp, HeapOperand(temp, index_in_cache));
2007 // lr = temp->entry_point_from_quick_compiled_code_;
2008 __ Ldr(lr, HeapOperand(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2009 kArm64WordSize)));
2010 // lr();
2011 __ Blr(lr);
2012 } else {
2013 __ Bl(&frame_entry_label_);
2014 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002015
Andreas Gampe878d58c2015-01-15 23:24:00 -08002016 DCHECK(!IsLeafMethod());
2017}
2018
2019void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2020 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2021 return;
2022 }
2023
2024 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
2025 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00002026 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01002027}
2028
2029void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08002030 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2031 return;
2032 }
2033
Alexandre Rames5319def2014-10-23 10:03:10 +01002034 LocationSummary* locations = invoke->GetLocations();
2035 Location receiver = locations->InAt(0);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002036 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002037 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
2038 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
2039 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00002040 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames5319def2014-10-23 10:03:10 +01002041
2042 // temp = object->GetClass();
2043 if (receiver.IsStackSlot()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002044 __ Ldr(temp, MemOperand(sp, receiver.GetStackIndex()));
2045 __ Ldr(temp, HeapOperand(temp, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002046 } else {
2047 DCHECK(receiver.IsRegister());
Serban Constantinescu02164b32014-11-13 14:05:07 +00002048 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002049 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002050 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames5319def2014-10-23 10:03:10 +01002051 // temp = temp->GetMethodAt(method_offset);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002052 __ Ldr(temp, HeapOperand(temp, method_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002053 // lr = temp->GetEntryPoint();
Serban Constantinescu02164b32014-11-13 14:05:07 +00002054 __ Ldr(lr, HeapOperand(temp, entry_point.SizeValue()));
Alexandre Rames5319def2014-10-23 10:03:10 +01002055 // lr();
2056 __ Blr(lr);
2057 DCHECK(!codegen_->IsLeafMethod());
2058 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2059}
2060
Alexandre Rames67555f72014-11-18 10:55:16 +00002061void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
2062 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2063 : LocationSummary::kNoCall;
2064 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2065 locations->SetOut(Location::RequiresRegister());
2066}
2067
2068void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
2069 Register out = OutputRegister(cls);
2070 if (cls->IsReferrersClass()) {
2071 DCHECK(!cls->CanCallRuntime());
2072 DCHECK(!cls->MustGenerateClinitCheck());
2073 codegen_->LoadCurrentMethod(out);
2074 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2075 } else {
2076 DCHECK(cls->CanCallRuntime());
2077 codegen_->LoadCurrentMethod(out);
2078 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DexCacheResolvedTypesOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002079 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002080
2081 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2082 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2083 codegen_->AddSlowPath(slow_path);
2084 __ Cbz(out, slow_path->GetEntryLabel());
2085 if (cls->MustGenerateClinitCheck()) {
2086 GenerateClassInitializationCheck(slow_path, out);
2087 } else {
2088 __ Bind(slow_path->GetExitLabel());
2089 }
2090 }
2091}
2092
2093void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
2094 LocationSummary* locations =
2095 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2096 locations->SetOut(Location::RequiresRegister());
2097}
2098
2099void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
2100 MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value());
2101 __ Ldr(OutputRegister(instruction), exception);
2102 __ Str(wzr, exception);
2103}
2104
Alexandre Rames5319def2014-10-23 10:03:10 +01002105void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
2106 load->SetLocations(nullptr);
2107}
2108
2109void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
2110 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002111 UNUSED(load);
Alexandre Rames5319def2014-10-23 10:03:10 +01002112}
2113
Alexandre Rames67555f72014-11-18 10:55:16 +00002114void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
2115 LocationSummary* locations =
2116 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2117 locations->SetOut(Location::RequiresRegister());
2118}
2119
2120void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
2121 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load);
2122 codegen_->AddSlowPath(slow_path);
2123
2124 Register out = OutputRegister(load);
2125 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08002126 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2127 __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002128 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002129 __ Cbz(out, slow_path->GetEntryLabel());
2130 __ Bind(slow_path->GetExitLabel());
2131}
2132
Alexandre Rames5319def2014-10-23 10:03:10 +01002133void LocationsBuilderARM64::VisitLocal(HLocal* local) {
2134 local->SetLocations(nullptr);
2135}
2136
2137void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
2138 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2139}
2140
2141void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
2142 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2143 locations->SetOut(Location::ConstantLocation(constant));
2144}
2145
2146void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
2147 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002148 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002149}
2150
Alexandre Rames67555f72014-11-18 10:55:16 +00002151void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2152 LocationSummary* locations =
2153 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2154 InvokeRuntimeCallingConvention calling_convention;
2155 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2156}
2157
2158void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2159 codegen_->InvokeRuntime(instruction->IsEnter()
2160 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2161 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002162 instruction->GetDexPc(),
2163 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002164 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002165}
2166
Alexandre Rames42d641b2014-10-27 14:00:51 +00002167void LocationsBuilderARM64::VisitMul(HMul* mul) {
2168 LocationSummary* locations =
2169 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2170 switch (mul->GetResultType()) {
2171 case Primitive::kPrimInt:
2172 case Primitive::kPrimLong:
2173 locations->SetInAt(0, Location::RequiresRegister());
2174 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002175 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002176 break;
2177
2178 case Primitive::kPrimFloat:
2179 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002180 locations->SetInAt(0, Location::RequiresFpuRegister());
2181 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002182 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002183 break;
2184
2185 default:
2186 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2187 }
2188}
2189
2190void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
2191 switch (mul->GetResultType()) {
2192 case Primitive::kPrimInt:
2193 case Primitive::kPrimLong:
2194 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
2195 break;
2196
2197 case Primitive::kPrimFloat:
2198 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002199 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00002200 break;
2201
2202 default:
2203 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2204 }
2205}
2206
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002207void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
2208 LocationSummary* locations =
2209 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2210 switch (neg->GetResultType()) {
2211 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00002212 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002213 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00002214 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002215 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002216
2217 case Primitive::kPrimFloat:
2218 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002219 locations->SetInAt(0, Location::RequiresFpuRegister());
2220 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002221 break;
2222
2223 default:
2224 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2225 }
2226}
2227
2228void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
2229 switch (neg->GetResultType()) {
2230 case Primitive::kPrimInt:
2231 case Primitive::kPrimLong:
2232 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
2233 break;
2234
2235 case Primitive::kPrimFloat:
2236 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002237 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002238 break;
2239
2240 default:
2241 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2242 }
2243}
2244
2245void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
2246 LocationSummary* locations =
2247 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2248 InvokeRuntimeCallingConvention calling_convention;
2249 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002250 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002251 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002252 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
2253 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2254 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002255}
2256
2257void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
2258 LocationSummary* locations = instruction->GetLocations();
2259 InvokeRuntimeCallingConvention calling_convention;
2260 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2261 DCHECK(type_index.Is(w0));
2262 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002263 DCHECK(current_method.Is(w2));
Alexandre Rames67555f72014-11-18 10:55:16 +00002264 codegen_->LoadCurrentMethod(current_method);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002265 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002266 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002267 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2268 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002269 instruction->GetDexPc(),
2270 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002271 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2272 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002273}
2274
Alexandre Rames5319def2014-10-23 10:03:10 +01002275void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
2276 LocationSummary* locations =
2277 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2278 InvokeRuntimeCallingConvention calling_convention;
2279 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2280 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2281 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002282 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002283}
2284
2285void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
2286 LocationSummary* locations = instruction->GetLocations();
2287 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2288 DCHECK(type_index.Is(w0));
2289 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
2290 DCHECK(current_method.Is(w1));
Alexandre Rames67555f72014-11-18 10:55:16 +00002291 codegen_->LoadCurrentMethod(current_method);
Alexandre Rames5319def2014-10-23 10:03:10 +01002292 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002293 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002294 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2295 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002296 instruction->GetDexPc(),
2297 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002298 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002299}
2300
2301void LocationsBuilderARM64::VisitNot(HNot* instruction) {
2302 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00002303 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002304 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002305}
2306
2307void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002308 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002309 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002310 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01002311 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002312 break;
2313
2314 default:
2315 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2316 }
2317}
2318
2319void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
2320 LocationSummary* locations =
2321 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2322 locations->SetInAt(0, Location::RequiresRegister());
2323 if (instruction->HasUses()) {
2324 locations->SetOut(Location::SameAsFirstInput());
2325 }
2326}
2327
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002328void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002329 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2330 return;
2331 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002332 Location obj = instruction->GetLocations()->InAt(0);
2333
2334 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
2335 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2336}
2337
2338void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002339 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
2340 codegen_->AddSlowPath(slow_path);
2341
2342 LocationSummary* locations = instruction->GetLocations();
2343 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002344
2345 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01002346}
2347
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002348void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
2349 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2350 GenerateImplicitNullCheck(instruction);
2351 } else {
2352 GenerateExplicitNullCheck(instruction);
2353 }
2354}
2355
Alexandre Rames67555f72014-11-18 10:55:16 +00002356void LocationsBuilderARM64::VisitOr(HOr* instruction) {
2357 HandleBinaryOp(instruction);
2358}
2359
2360void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
2361 HandleBinaryOp(instruction);
2362}
2363
Alexandre Rames3e69f162014-12-10 10:36:50 +00002364void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2365 LOG(FATAL) << "Unreachable";
2366}
2367
2368void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
2369 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2370}
2371
Alexandre Rames5319def2014-10-23 10:03:10 +01002372void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
2373 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2374 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2375 if (location.IsStackSlot()) {
2376 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2377 } else if (location.IsDoubleStackSlot()) {
2378 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2379 }
2380 locations->SetOut(location);
2381}
2382
2383void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) {
2384 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002385 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002386}
2387
2388void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
2389 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2390 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2391 locations->SetInAt(i, Location::Any());
2392 }
2393 locations->SetOut(Location::Any());
2394}
2395
2396void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002397 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002398 LOG(FATAL) << "Unreachable";
2399}
2400
Serban Constantinescu02164b32014-11-13 14:05:07 +00002401void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002402 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00002403 LocationSummary::CallKind call_kind =
2404 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002405 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2406
2407 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002408 case Primitive::kPrimInt:
2409 case Primitive::kPrimLong:
2410 locations->SetInAt(0, Location::RequiresRegister());
2411 locations->SetInAt(1, Location::RequiresRegister());
2412 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2413 break;
2414
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002415 case Primitive::kPrimFloat:
2416 case Primitive::kPrimDouble: {
2417 InvokeRuntimeCallingConvention calling_convention;
2418 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
2419 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
2420 locations->SetOut(calling_convention.GetReturnLocation(type));
2421
2422 break;
2423 }
2424
Serban Constantinescu02164b32014-11-13 14:05:07 +00002425 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002426 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00002427 }
2428}
2429
2430void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
2431 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002432
Serban Constantinescu02164b32014-11-13 14:05:07 +00002433 switch (type) {
2434 case Primitive::kPrimInt:
2435 case Primitive::kPrimLong: {
2436 UseScratchRegisterScope temps(GetVIXLAssembler());
2437 Register dividend = InputRegisterAt(rem, 0);
2438 Register divisor = InputRegisterAt(rem, 1);
2439 Register output = OutputRegister(rem);
2440 Register temp = temps.AcquireSameSizeAs(output);
2441
2442 __ Sdiv(temp, dividend, divisor);
2443 __ Msub(output, temp, divisor, dividend);
2444 break;
2445 }
2446
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002447 case Primitive::kPrimFloat:
2448 case Primitive::kPrimDouble: {
2449 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2450 : QUICK_ENTRY_POINT(pFmod);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002451 codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002452 break;
2453 }
2454
Serban Constantinescu02164b32014-11-13 14:05:07 +00002455 default:
2456 LOG(FATAL) << "Unexpected rem type " << type;
2457 }
2458}
2459
Alexandre Rames5319def2014-10-23 10:03:10 +01002460void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
2461 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2462 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002463 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01002464}
2465
2466void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002467 UNUSED(instruction);
David Srbeckyc6b4dd82015-04-07 20:32:43 +01002468 GetAssembler()->cfi().RememberState();
Alexandre Rames5319def2014-10-23 10:03:10 +01002469 codegen_->GenerateFrameExit();
Alexandre Rames3e69f162014-12-10 10:36:50 +00002470 __ Ret();
David Srbeckyc6b4dd82015-04-07 20:32:43 +01002471 GetAssembler()->cfi().RestoreState();
2472 GetAssembler()->cfi().DefCFAOffset(codegen_->GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +01002473}
2474
2475void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
2476 instruction->SetLocations(nullptr);
2477}
2478
2479void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002480 UNUSED(instruction);
David Srbeckyc6b4dd82015-04-07 20:32:43 +01002481 GetAssembler()->cfi().RememberState();
Alexandre Rames5319def2014-10-23 10:03:10 +01002482 codegen_->GenerateFrameExit();
Alexandre Rames3e69f162014-12-10 10:36:50 +00002483 __ Ret();
David Srbeckyc6b4dd82015-04-07 20:32:43 +01002484 GetAssembler()->cfi().RestoreState();
2485 GetAssembler()->cfi().DefCFAOffset(codegen_->GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +01002486}
2487
Serban Constantinescu02164b32014-11-13 14:05:07 +00002488void LocationsBuilderARM64::VisitShl(HShl* shl) {
2489 HandleShift(shl);
2490}
2491
2492void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
2493 HandleShift(shl);
2494}
2495
2496void LocationsBuilderARM64::VisitShr(HShr* shr) {
2497 HandleShift(shr);
2498}
2499
2500void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
2501 HandleShift(shr);
2502}
2503
Alexandre Rames5319def2014-10-23 10:03:10 +01002504void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
2505 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2506 Primitive::Type field_type = store->InputAt(1)->GetType();
2507 switch (field_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002508 case Primitive::kPrimNot:
Alexandre Rames5319def2014-10-23 10:03:10 +01002509 case Primitive::kPrimBoolean:
2510 case Primitive::kPrimByte:
2511 case Primitive::kPrimChar:
2512 case Primitive::kPrimShort:
2513 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002514 case Primitive::kPrimFloat:
Alexandre Rames5319def2014-10-23 10:03:10 +01002515 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2516 break;
2517
2518 case Primitive::kPrimLong:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002519 case Primitive::kPrimDouble:
Alexandre Rames5319def2014-10-23 10:03:10 +01002520 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2521 break;
2522
2523 default:
2524 LOG(FATAL) << "Unimplemented local type " << field_type;
2525 }
2526}
2527
2528void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002529 UNUSED(store);
Alexandre Rames5319def2014-10-23 10:03:10 +01002530}
2531
2532void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002533 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002534}
2535
2536void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002537 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002538}
2539
Alexandre Rames67555f72014-11-18 10:55:16 +00002540void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2541 LocationSummary* locations =
2542 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2543 locations->SetInAt(0, Location::RequiresRegister());
2544 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2545}
2546
2547void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002548 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00002549 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002550
2551 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002552 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002553 // NB: LoadAcquire will record the pc info if needed.
2554 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002555 } else {
2556 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2557 // For IRIW sequential consistency kLoadAny is not sufficient.
2558 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2559 }
2560 } else {
2561 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2562 }
Alexandre Rames67555f72014-11-18 10:55:16 +00002563}
2564
2565void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002566 LocationSummary* locations =
2567 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2568 locations->SetInAt(0, Location::RequiresRegister());
2569 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames5319def2014-10-23 10:03:10 +01002570}
2571
Alexandre Rames67555f72014-11-18 10:55:16 +00002572void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002573 Register cls = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002574 CPURegister value = InputCPURegisterAt(instruction, 1);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002575 Offset offset = instruction->GetFieldOffset();
Alexandre Rames67555f72014-11-18 10:55:16 +00002576 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00002577 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Alexandre Rames5319def2014-10-23 10:03:10 +01002578
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002579 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002580 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002581 codegen_->StoreRelease(field_type, value, HeapOperand(cls, offset));
2582 } else {
2583 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2584 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2585 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2586 }
2587 } else {
2588 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2589 }
2590
2591 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002592 codegen_->MarkGCCard(cls, Register(value));
2593 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002594}
2595
2596void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
2597 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2598}
2599
2600void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002601 HBasicBlock* block = instruction->GetBlock();
2602 if (block->GetLoopInformation() != nullptr) {
2603 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2604 // The back edge will generate the suspend check.
2605 return;
2606 }
2607 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2608 // The goto will generate the suspend check.
2609 return;
2610 }
2611 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01002612}
2613
2614void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
2615 temp->SetLocations(nullptr);
2616}
2617
2618void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
2619 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002620 UNUSED(temp);
Alexandre Rames5319def2014-10-23 10:03:10 +01002621}
2622
Alexandre Rames67555f72014-11-18 10:55:16 +00002623void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
2624 LocationSummary* locations =
2625 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2626 InvokeRuntimeCallingConvention calling_convention;
2627 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2628}
2629
2630void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
2631 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002632 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002633 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002634}
2635
2636void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
2637 LocationSummary* locations =
2638 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
2639 Primitive::Type input_type = conversion->GetInputType();
2640 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002641 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00002642 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
2643 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
2644 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
2645 }
2646
Alexandre Rames542361f2015-01-29 16:57:31 +00002647 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002648 locations->SetInAt(0, Location::RequiresFpuRegister());
2649 } else {
2650 locations->SetInAt(0, Location::RequiresRegister());
2651 }
2652
Alexandre Rames542361f2015-01-29 16:57:31 +00002653 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002654 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2655 } else {
2656 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2657 }
2658}
2659
2660void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
2661 Primitive::Type result_type = conversion->GetResultType();
2662 Primitive::Type input_type = conversion->GetInputType();
2663
2664 DCHECK_NE(input_type, result_type);
2665
Alexandre Rames542361f2015-01-29 16:57:31 +00002666 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002667 int result_size = Primitive::ComponentSize(result_type);
2668 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002669 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002670 Register output = OutputRegister(conversion);
2671 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002672 if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) {
2673 __ Ubfx(output, source, 0, result_size * kBitsPerByte);
2674 } else if ((result_type == Primitive::kPrimChar) ||
2675 ((input_type == Primitive::kPrimChar) && (result_size > input_size))) {
2676 __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002677 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00002678 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002679 }
Alexandre Rames542361f2015-01-29 16:57:31 +00002680 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002681 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002682 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002683 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
2684 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002685 } else if (Primitive::IsFloatingPointType(result_type) &&
2686 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002687 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
2688 } else {
2689 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
2690 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00002691 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00002692}
Alexandre Rames67555f72014-11-18 10:55:16 +00002693
Serban Constantinescu02164b32014-11-13 14:05:07 +00002694void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
2695 HandleShift(ushr);
2696}
2697
2698void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
2699 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00002700}
2701
2702void LocationsBuilderARM64::VisitXor(HXor* instruction) {
2703 HandleBinaryOp(instruction);
2704}
2705
2706void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
2707 HandleBinaryOp(instruction);
2708}
2709
Calin Juravleb1498f62015-02-16 13:13:29 +00002710void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) {
2711 // Nothing to do, this should be removed during prepare for register allocator.
2712 UNUSED(instruction);
2713 LOG(FATAL) << "Unreachable";
2714}
2715
2716void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) {
2717 // Nothing to do, this should be removed during prepare for register allocator.
2718 UNUSED(instruction);
2719 LOG(FATAL) << "Unreachable";
2720}
2721
Alexandre Rames67555f72014-11-18 10:55:16 +00002722#undef __
2723#undef QUICK_ENTRY_POINT
2724
Alexandre Rames5319def2014-10-23 10:03:10 +01002725} // namespace arm64
2726} // namespace art