blob: 12eb0c78ea6a6f2706b9e06600ddfae0899d88b5 [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());
1709 if ((arm64_cond == eq || arm64_cond == ne) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
1710 if (arm64_cond == eq) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001711 __ Cbz(lhs, true_target);
1712 } else {
1713 __ Cbnz(lhs, true_target);
1714 }
1715 } else {
1716 __ Cmp(lhs, rhs);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001717 __ B(arm64_cond, true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001718 }
1719 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001720 if (false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001721 __ B(false_target);
1722 }
1723}
1724
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001725void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
1726 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1727 HInstruction* cond = if_instr->InputAt(0);
1728 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1729 locations->SetInAt(0, Location::RequiresRegister());
1730 }
1731}
1732
1733void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
1734 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1735 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1736 vixl::Label* always_true_target = true_target;
1737 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1738 if_instr->IfTrueSuccessor())) {
1739 always_true_target = nullptr;
1740 }
1741 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1742 if_instr->IfFalseSuccessor())) {
1743 false_target = nullptr;
1744 }
1745 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1746}
1747
1748void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1749 LocationSummary* locations = new (GetGraph()->GetArena())
1750 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1751 HInstruction* cond = deoptimize->InputAt(0);
1752 DCHECK(cond->IsCondition());
1753 if (cond->AsCondition()->NeedsMaterialization()) {
1754 locations->SetInAt(0, Location::RequiresRegister());
1755 }
1756}
1757
1758void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1759 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
1760 DeoptimizationSlowPathARM64(deoptimize);
1761 codegen_->AddSlowPath(slow_path);
1762 vixl::Label* slow_path_entry = slow_path->GetEntryLabel();
1763 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1764}
1765
Alexandre Rames5319def2014-10-23 10:03:10 +01001766void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001767 LocationSummary* locations =
1768 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001769 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001770 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001771}
1772
1773void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001774 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00001775 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001776
1777 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001778 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00001779 // NB: LoadAcquire will record the pc info if needed.
1780 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001781 } else {
1782 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001783 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001784 // For IRIW sequential consistency kLoadAny is not sufficient.
1785 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1786 }
1787 } else {
1788 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001789 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001790 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001791}
1792
1793void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001794 LocationSummary* locations =
1795 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001796 locations->SetInAt(0, Location::RequiresRegister());
1797 locations->SetInAt(1, Location::RequiresRegister());
1798}
1799
1800void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001801 Register obj = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001802 CPURegister value = InputCPURegisterAt(instruction, 1);
1803 Offset offset = instruction->GetFieldOffset();
1804 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001805 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001806
1807 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001808 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001809 codegen_->StoreRelease(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001810 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001811 } else {
1812 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
1813 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001814 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001815 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1816 }
1817 } else {
1818 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001819 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001820 }
1821
1822 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001823 codegen_->MarkGCCard(obj, Register(value));
Alexandre Rames5319def2014-10-23 10:03:10 +01001824 }
1825}
1826
Alexandre Rames67555f72014-11-18 10:55:16 +00001827void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
1828 LocationSummary::CallKind call_kind =
1829 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
1830 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1831 locations->SetInAt(0, Location::RequiresRegister());
1832 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001833 // The output does overlap inputs.
1834 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexandre Rames67555f72014-11-18 10:55:16 +00001835}
1836
1837void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
1838 LocationSummary* locations = instruction->GetLocations();
1839 Register obj = InputRegisterAt(instruction, 0);;
1840 Register cls = InputRegisterAt(instruction, 1);;
1841 Register out = OutputRegister(instruction);
1842
1843 vixl::Label done;
1844
1845 // Return 0 if `obj` is null.
1846 // TODO: Avoid this check if we know `obj` is not null.
1847 __ Mov(out, 0);
1848 __ Cbz(obj, &done);
1849
1850 // Compare the class of `obj` with `cls`.
Serban Constantinescu02164b32014-11-13 14:05:07 +00001851 __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset()));
Alexandre Rames67555f72014-11-18 10:55:16 +00001852 __ Cmp(out, cls);
1853 if (instruction->IsClassFinal()) {
1854 // Classes must be equal for the instanceof to succeed.
1855 __ Cset(out, eq);
1856 } else {
1857 // If the classes are not equal, we go into a slow path.
1858 DCHECK(locations->OnlyCallsOnSlowPath());
1859 SlowPathCodeARM64* slow_path =
Alexandre Rames3e69f162014-12-10 10:36:50 +00001860 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1861 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001862 codegen_->AddSlowPath(slow_path);
1863 __ B(ne, slow_path->GetEntryLabel());
1864 __ Mov(out, 1);
1865 __ Bind(slow_path->GetExitLabel());
1866 }
1867
1868 __ Bind(&done);
1869}
1870
Alexandre Rames5319def2014-10-23 10:03:10 +01001871void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
1872 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1873 locations->SetOut(Location::ConstantLocation(constant));
1874}
1875
1876void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
1877 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001878 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01001879}
1880
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001881void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
1882 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1883 locations->SetOut(Location::ConstantLocation(constant));
1884}
1885
1886void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) {
1887 // Will be generated at use site.
1888 UNUSED(constant);
1889}
1890
Alexandre Rames5319def2014-10-23 10:03:10 +01001891void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
1892 LocationSummary* locations =
1893 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
1894 locations->AddTemp(LocationFrom(x0));
1895
1896 InvokeDexCallingConventionVisitor calling_convention_visitor;
1897 for (size_t i = 0; i < invoke->InputCount(); i++) {
1898 HInstruction* input = invoke->InputAt(i);
1899 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1900 }
1901
1902 Primitive::Type return_type = invoke->GetType();
1903 if (return_type != Primitive::kPrimVoid) {
1904 locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type));
1905 }
1906}
1907
Alexandre Rames67555f72014-11-18 10:55:16 +00001908void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1909 HandleInvoke(invoke);
1910}
1911
1912void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1913 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1914 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1915 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1916 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1917 Location receiver = invoke->GetLocations()->InAt(0);
1918 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001919 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00001920
1921 // The register ip1 is required to be used for the hidden argument in
1922 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
1923 UseScratchRegisterScope scratch_scope(GetVIXLAssembler());
1924 scratch_scope.Exclude(ip1);
1925 __ Mov(ip1, invoke->GetDexMethodIndex());
1926
1927 // temp = object->GetClass();
1928 if (receiver.IsStackSlot()) {
1929 __ Ldr(temp, StackOperandFrom(receiver));
1930 __ Ldr(temp, HeapOperand(temp, class_offset));
1931 } else {
1932 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
1933 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001934 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames67555f72014-11-18 10:55:16 +00001935 // temp = temp->GetImtEntryAt(method_offset);
1936 __ Ldr(temp, HeapOperand(temp, method_offset));
1937 // lr = temp->GetEntryPoint();
1938 __ Ldr(lr, HeapOperand(temp, entry_point));
1939 // lr();
1940 __ Blr(lr);
1941 DCHECK(!codegen_->IsLeafMethod());
1942 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1943}
1944
1945void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001946 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1947 if (intrinsic.TryDispatch(invoke)) {
1948 return;
1949 }
1950
Alexandre Rames67555f72014-11-18 10:55:16 +00001951 HandleInvoke(invoke);
1952}
1953
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001954void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001955 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1956 if (intrinsic.TryDispatch(invoke)) {
1957 return;
1958 }
1959
Alexandre Rames67555f72014-11-18 10:55:16 +00001960 HandleInvoke(invoke);
1961}
1962
Andreas Gampe878d58c2015-01-15 23:24:00 -08001963static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
1964 if (invoke->GetLocations()->Intrinsified()) {
1965 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
1966 intrinsic.Dispatch(invoke);
1967 return true;
1968 }
1969 return false;
1970}
1971
1972void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
1973 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
1974 DCHECK(temp.Is(kArtMethodRegister));
Alexandre Rames5319def2014-10-23 10:03:10 +01001975 size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() +
Andreas Gampe878d58c2015-01-15 23:24:00 -08001976 invoke->GetDexMethodIndex() * kHeapRefSize;
Alexandre Rames5319def2014-10-23 10:03:10 +01001977
1978 // TODO: Implement all kinds of calls:
1979 // 1) boot -> boot
1980 // 2) app -> boot
1981 // 3) app -> app
1982 //
1983 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1984
Nicolas Geoffray0a299b92015-01-29 11:39:44 +00001985 // temp = method;
1986 LoadCurrentMethod(temp);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001987 if (!invoke->IsRecursive()) {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001988 // temp = temp->dex_cache_resolved_methods_;
1989 __ Ldr(temp, HeapOperand(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset()));
1990 // temp = temp[index_in_cache];
1991 __ Ldr(temp, HeapOperand(temp, index_in_cache));
1992 // lr = temp->entry_point_from_quick_compiled_code_;
1993 __ Ldr(lr, HeapOperand(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1994 kArm64WordSize)));
1995 // lr();
1996 __ Blr(lr);
1997 } else {
1998 __ Bl(&frame_entry_label_);
1999 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002000
Andreas Gampe878d58c2015-01-15 23:24:00 -08002001 DCHECK(!IsLeafMethod());
2002}
2003
2004void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2005 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2006 return;
2007 }
2008
2009 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
2010 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00002011 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01002012}
2013
2014void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08002015 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2016 return;
2017 }
2018
Alexandre Rames5319def2014-10-23 10:03:10 +01002019 LocationSummary* locations = invoke->GetLocations();
2020 Location receiver = locations->InAt(0);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002021 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002022 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
2023 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
2024 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00002025 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames5319def2014-10-23 10:03:10 +01002026
2027 // temp = object->GetClass();
2028 if (receiver.IsStackSlot()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002029 __ Ldr(temp, MemOperand(sp, receiver.GetStackIndex()));
2030 __ Ldr(temp, HeapOperand(temp, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002031 } else {
2032 DCHECK(receiver.IsRegister());
Serban Constantinescu02164b32014-11-13 14:05:07 +00002033 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002034 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002035 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames5319def2014-10-23 10:03:10 +01002036 // temp = temp->GetMethodAt(method_offset);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002037 __ Ldr(temp, HeapOperand(temp, method_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002038 // lr = temp->GetEntryPoint();
Serban Constantinescu02164b32014-11-13 14:05:07 +00002039 __ Ldr(lr, HeapOperand(temp, entry_point.SizeValue()));
Alexandre Rames5319def2014-10-23 10:03:10 +01002040 // lr();
2041 __ Blr(lr);
2042 DCHECK(!codegen_->IsLeafMethod());
2043 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2044}
2045
Alexandre Rames67555f72014-11-18 10:55:16 +00002046void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
2047 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2048 : LocationSummary::kNoCall;
2049 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2050 locations->SetOut(Location::RequiresRegister());
2051}
2052
2053void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
2054 Register out = OutputRegister(cls);
2055 if (cls->IsReferrersClass()) {
2056 DCHECK(!cls->CanCallRuntime());
2057 DCHECK(!cls->MustGenerateClinitCheck());
2058 codegen_->LoadCurrentMethod(out);
2059 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2060 } else {
2061 DCHECK(cls->CanCallRuntime());
2062 codegen_->LoadCurrentMethod(out);
2063 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DexCacheResolvedTypesOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002064 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002065
2066 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2067 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2068 codegen_->AddSlowPath(slow_path);
2069 __ Cbz(out, slow_path->GetEntryLabel());
2070 if (cls->MustGenerateClinitCheck()) {
2071 GenerateClassInitializationCheck(slow_path, out);
2072 } else {
2073 __ Bind(slow_path->GetExitLabel());
2074 }
2075 }
2076}
2077
2078void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
2079 LocationSummary* locations =
2080 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2081 locations->SetOut(Location::RequiresRegister());
2082}
2083
2084void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
2085 MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value());
2086 __ Ldr(OutputRegister(instruction), exception);
2087 __ Str(wzr, exception);
2088}
2089
Alexandre Rames5319def2014-10-23 10:03:10 +01002090void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
2091 load->SetLocations(nullptr);
2092}
2093
2094void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
2095 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002096 UNUSED(load);
Alexandre Rames5319def2014-10-23 10:03:10 +01002097}
2098
Alexandre Rames67555f72014-11-18 10:55:16 +00002099void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
2100 LocationSummary* locations =
2101 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2102 locations->SetOut(Location::RequiresRegister());
2103}
2104
2105void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
2106 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load);
2107 codegen_->AddSlowPath(slow_path);
2108
2109 Register out = OutputRegister(load);
2110 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08002111 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2112 __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002113 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002114 __ Cbz(out, slow_path->GetEntryLabel());
2115 __ Bind(slow_path->GetExitLabel());
2116}
2117
Alexandre Rames5319def2014-10-23 10:03:10 +01002118void LocationsBuilderARM64::VisitLocal(HLocal* local) {
2119 local->SetLocations(nullptr);
2120}
2121
2122void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
2123 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2124}
2125
2126void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
2127 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2128 locations->SetOut(Location::ConstantLocation(constant));
2129}
2130
2131void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
2132 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002133 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002134}
2135
Alexandre Rames67555f72014-11-18 10:55:16 +00002136void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2137 LocationSummary* locations =
2138 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2139 InvokeRuntimeCallingConvention calling_convention;
2140 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2141}
2142
2143void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2144 codegen_->InvokeRuntime(instruction->IsEnter()
2145 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2146 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002147 instruction->GetDexPc(),
2148 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002149 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002150}
2151
Alexandre Rames42d641b2014-10-27 14:00:51 +00002152void LocationsBuilderARM64::VisitMul(HMul* mul) {
2153 LocationSummary* locations =
2154 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2155 switch (mul->GetResultType()) {
2156 case Primitive::kPrimInt:
2157 case Primitive::kPrimLong:
2158 locations->SetInAt(0, Location::RequiresRegister());
2159 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002160 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002161 break;
2162
2163 case Primitive::kPrimFloat:
2164 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002165 locations->SetInAt(0, Location::RequiresFpuRegister());
2166 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002167 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002168 break;
2169
2170 default:
2171 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2172 }
2173}
2174
2175void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
2176 switch (mul->GetResultType()) {
2177 case Primitive::kPrimInt:
2178 case Primitive::kPrimLong:
2179 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
2180 break;
2181
2182 case Primitive::kPrimFloat:
2183 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002184 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00002185 break;
2186
2187 default:
2188 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2189 }
2190}
2191
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002192void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
2193 LocationSummary* locations =
2194 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2195 switch (neg->GetResultType()) {
2196 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00002197 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002198 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00002199 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002200 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002201
2202 case Primitive::kPrimFloat:
2203 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002204 locations->SetInAt(0, Location::RequiresFpuRegister());
2205 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002206 break;
2207
2208 default:
2209 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2210 }
2211}
2212
2213void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
2214 switch (neg->GetResultType()) {
2215 case Primitive::kPrimInt:
2216 case Primitive::kPrimLong:
2217 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
2218 break;
2219
2220 case Primitive::kPrimFloat:
2221 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002222 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002223 break;
2224
2225 default:
2226 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2227 }
2228}
2229
2230void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
2231 LocationSummary* locations =
2232 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2233 InvokeRuntimeCallingConvention calling_convention;
2234 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002235 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002236 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002237 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
2238 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2239 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002240}
2241
2242void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
2243 LocationSummary* locations = instruction->GetLocations();
2244 InvokeRuntimeCallingConvention calling_convention;
2245 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2246 DCHECK(type_index.Is(w0));
2247 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002248 DCHECK(current_method.Is(w2));
Alexandre Rames67555f72014-11-18 10:55:16 +00002249 codegen_->LoadCurrentMethod(current_method);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002250 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002251 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002252 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2253 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002254 instruction->GetDexPc(),
2255 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002256 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2257 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002258}
2259
Alexandre Rames5319def2014-10-23 10:03:10 +01002260void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
2261 LocationSummary* locations =
2262 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2263 InvokeRuntimeCallingConvention calling_convention;
2264 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2265 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2266 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002267 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002268}
2269
2270void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
2271 LocationSummary* locations = instruction->GetLocations();
2272 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2273 DCHECK(type_index.Is(w0));
2274 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
2275 DCHECK(current_method.Is(w1));
Alexandre Rames67555f72014-11-18 10:55:16 +00002276 codegen_->LoadCurrentMethod(current_method);
Alexandre Rames5319def2014-10-23 10:03:10 +01002277 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002278 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002279 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2280 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002281 instruction->GetDexPc(),
2282 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002283 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002284}
2285
2286void LocationsBuilderARM64::VisitNot(HNot* instruction) {
2287 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00002288 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002289 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002290}
2291
2292void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002293 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002294 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002295 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01002296 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002297 break;
2298
2299 default:
2300 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2301 }
2302}
2303
2304void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
2305 LocationSummary* locations =
2306 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2307 locations->SetInAt(0, Location::RequiresRegister());
2308 if (instruction->HasUses()) {
2309 locations->SetOut(Location::SameAsFirstInput());
2310 }
2311}
2312
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002313void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002314 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2315 return;
2316 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002317 Location obj = instruction->GetLocations()->InAt(0);
2318
2319 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
2320 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2321}
2322
2323void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002324 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
2325 codegen_->AddSlowPath(slow_path);
2326
2327 LocationSummary* locations = instruction->GetLocations();
2328 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002329
2330 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01002331}
2332
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002333void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
2334 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2335 GenerateImplicitNullCheck(instruction);
2336 } else {
2337 GenerateExplicitNullCheck(instruction);
2338 }
2339}
2340
Alexandre Rames67555f72014-11-18 10:55:16 +00002341void LocationsBuilderARM64::VisitOr(HOr* instruction) {
2342 HandleBinaryOp(instruction);
2343}
2344
2345void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
2346 HandleBinaryOp(instruction);
2347}
2348
Alexandre Rames3e69f162014-12-10 10:36:50 +00002349void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2350 LOG(FATAL) << "Unreachable";
2351}
2352
2353void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
2354 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2355}
2356
Alexandre Rames5319def2014-10-23 10:03:10 +01002357void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
2358 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2359 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2360 if (location.IsStackSlot()) {
2361 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2362 } else if (location.IsDoubleStackSlot()) {
2363 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2364 }
2365 locations->SetOut(location);
2366}
2367
2368void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) {
2369 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002370 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002371}
2372
2373void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
2374 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2375 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2376 locations->SetInAt(i, Location::Any());
2377 }
2378 locations->SetOut(Location::Any());
2379}
2380
2381void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002382 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002383 LOG(FATAL) << "Unreachable";
2384}
2385
Serban Constantinescu02164b32014-11-13 14:05:07 +00002386void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002387 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00002388 LocationSummary::CallKind call_kind =
2389 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002390 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2391
2392 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002393 case Primitive::kPrimInt:
2394 case Primitive::kPrimLong:
2395 locations->SetInAt(0, Location::RequiresRegister());
2396 locations->SetInAt(1, Location::RequiresRegister());
2397 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2398 break;
2399
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002400 case Primitive::kPrimFloat:
2401 case Primitive::kPrimDouble: {
2402 InvokeRuntimeCallingConvention calling_convention;
2403 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
2404 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
2405 locations->SetOut(calling_convention.GetReturnLocation(type));
2406
2407 break;
2408 }
2409
Serban Constantinescu02164b32014-11-13 14:05:07 +00002410 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002411 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00002412 }
2413}
2414
2415void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
2416 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002417
Serban Constantinescu02164b32014-11-13 14:05:07 +00002418 switch (type) {
2419 case Primitive::kPrimInt:
2420 case Primitive::kPrimLong: {
2421 UseScratchRegisterScope temps(GetVIXLAssembler());
2422 Register dividend = InputRegisterAt(rem, 0);
2423 Register divisor = InputRegisterAt(rem, 1);
2424 Register output = OutputRegister(rem);
2425 Register temp = temps.AcquireSameSizeAs(output);
2426
2427 __ Sdiv(temp, dividend, divisor);
2428 __ Msub(output, temp, divisor, dividend);
2429 break;
2430 }
2431
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002432 case Primitive::kPrimFloat:
2433 case Primitive::kPrimDouble: {
2434 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2435 : QUICK_ENTRY_POINT(pFmod);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002436 codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002437 break;
2438 }
2439
Serban Constantinescu02164b32014-11-13 14:05:07 +00002440 default:
2441 LOG(FATAL) << "Unexpected rem type " << type;
2442 }
2443}
2444
Alexandre Rames5319def2014-10-23 10:03:10 +01002445void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
2446 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2447 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002448 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01002449}
2450
2451void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002452 UNUSED(instruction);
David Srbeckyc6b4dd82015-04-07 20:32:43 +01002453 GetAssembler()->cfi().RememberState();
Alexandre Rames5319def2014-10-23 10:03:10 +01002454 codegen_->GenerateFrameExit();
Alexandre Rames3e69f162014-12-10 10:36:50 +00002455 __ Ret();
David Srbeckyc6b4dd82015-04-07 20:32:43 +01002456 GetAssembler()->cfi().RestoreState();
2457 GetAssembler()->cfi().DefCFAOffset(codegen_->GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +01002458}
2459
2460void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
2461 instruction->SetLocations(nullptr);
2462}
2463
2464void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002465 UNUSED(instruction);
David Srbeckyc6b4dd82015-04-07 20:32:43 +01002466 GetAssembler()->cfi().RememberState();
Alexandre Rames5319def2014-10-23 10:03:10 +01002467 codegen_->GenerateFrameExit();
Alexandre Rames3e69f162014-12-10 10:36:50 +00002468 __ Ret();
David Srbeckyc6b4dd82015-04-07 20:32:43 +01002469 GetAssembler()->cfi().RestoreState();
2470 GetAssembler()->cfi().DefCFAOffset(codegen_->GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +01002471}
2472
Serban Constantinescu02164b32014-11-13 14:05:07 +00002473void LocationsBuilderARM64::VisitShl(HShl* shl) {
2474 HandleShift(shl);
2475}
2476
2477void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
2478 HandleShift(shl);
2479}
2480
2481void LocationsBuilderARM64::VisitShr(HShr* shr) {
2482 HandleShift(shr);
2483}
2484
2485void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
2486 HandleShift(shr);
2487}
2488
Alexandre Rames5319def2014-10-23 10:03:10 +01002489void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
2490 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2491 Primitive::Type field_type = store->InputAt(1)->GetType();
2492 switch (field_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002493 case Primitive::kPrimNot:
Alexandre Rames5319def2014-10-23 10:03:10 +01002494 case Primitive::kPrimBoolean:
2495 case Primitive::kPrimByte:
2496 case Primitive::kPrimChar:
2497 case Primitive::kPrimShort:
2498 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002499 case Primitive::kPrimFloat:
Alexandre Rames5319def2014-10-23 10:03:10 +01002500 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2501 break;
2502
2503 case Primitive::kPrimLong:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002504 case Primitive::kPrimDouble:
Alexandre Rames5319def2014-10-23 10:03:10 +01002505 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2506 break;
2507
2508 default:
2509 LOG(FATAL) << "Unimplemented local type " << field_type;
2510 }
2511}
2512
2513void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002514 UNUSED(store);
Alexandre Rames5319def2014-10-23 10:03:10 +01002515}
2516
2517void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002518 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002519}
2520
2521void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002522 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002523}
2524
Alexandre Rames67555f72014-11-18 10:55:16 +00002525void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2526 LocationSummary* locations =
2527 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2528 locations->SetInAt(0, Location::RequiresRegister());
2529 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2530}
2531
2532void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002533 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00002534 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002535
2536 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002537 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002538 // NB: LoadAcquire will record the pc info if needed.
2539 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002540 } else {
2541 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2542 // For IRIW sequential consistency kLoadAny is not sufficient.
2543 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2544 }
2545 } else {
2546 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2547 }
Alexandre Rames67555f72014-11-18 10:55:16 +00002548}
2549
2550void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002551 LocationSummary* locations =
2552 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2553 locations->SetInAt(0, Location::RequiresRegister());
2554 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames5319def2014-10-23 10:03:10 +01002555}
2556
Alexandre Rames67555f72014-11-18 10:55:16 +00002557void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002558 Register cls = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002559 CPURegister value = InputCPURegisterAt(instruction, 1);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002560 Offset offset = instruction->GetFieldOffset();
Alexandre Rames67555f72014-11-18 10:55:16 +00002561 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00002562 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Alexandre Rames5319def2014-10-23 10:03:10 +01002563
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002564 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002565 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002566 codegen_->StoreRelease(field_type, value, HeapOperand(cls, offset));
2567 } else {
2568 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2569 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2570 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2571 }
2572 } else {
2573 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2574 }
2575
2576 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002577 codegen_->MarkGCCard(cls, Register(value));
2578 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002579}
2580
2581void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
2582 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2583}
2584
2585void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002586 HBasicBlock* block = instruction->GetBlock();
2587 if (block->GetLoopInformation() != nullptr) {
2588 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2589 // The back edge will generate the suspend check.
2590 return;
2591 }
2592 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2593 // The goto will generate the suspend check.
2594 return;
2595 }
2596 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01002597}
2598
2599void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
2600 temp->SetLocations(nullptr);
2601}
2602
2603void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
2604 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002605 UNUSED(temp);
Alexandre Rames5319def2014-10-23 10:03:10 +01002606}
2607
Alexandre Rames67555f72014-11-18 10:55:16 +00002608void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
2609 LocationSummary* locations =
2610 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2611 InvokeRuntimeCallingConvention calling_convention;
2612 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2613}
2614
2615void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
2616 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002617 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002618 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002619}
2620
2621void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
2622 LocationSummary* locations =
2623 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
2624 Primitive::Type input_type = conversion->GetInputType();
2625 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002626 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00002627 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
2628 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
2629 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
2630 }
2631
Alexandre Rames542361f2015-01-29 16:57:31 +00002632 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002633 locations->SetInAt(0, Location::RequiresFpuRegister());
2634 } else {
2635 locations->SetInAt(0, Location::RequiresRegister());
2636 }
2637
Alexandre Rames542361f2015-01-29 16:57:31 +00002638 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002639 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2640 } else {
2641 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2642 }
2643}
2644
2645void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
2646 Primitive::Type result_type = conversion->GetResultType();
2647 Primitive::Type input_type = conversion->GetInputType();
2648
2649 DCHECK_NE(input_type, result_type);
2650
Alexandre Rames542361f2015-01-29 16:57:31 +00002651 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002652 int result_size = Primitive::ComponentSize(result_type);
2653 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002654 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002655 Register output = OutputRegister(conversion);
2656 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002657 if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) {
2658 __ Ubfx(output, source, 0, result_size * kBitsPerByte);
2659 } else if ((result_type == Primitive::kPrimChar) ||
2660 ((input_type == Primitive::kPrimChar) && (result_size > input_size))) {
2661 __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002662 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00002663 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002664 }
Alexandre Rames542361f2015-01-29 16:57:31 +00002665 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002666 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002667 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002668 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
2669 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002670 } else if (Primitive::IsFloatingPointType(result_type) &&
2671 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002672 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
2673 } else {
2674 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
2675 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00002676 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00002677}
Alexandre Rames67555f72014-11-18 10:55:16 +00002678
Serban Constantinescu02164b32014-11-13 14:05:07 +00002679void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
2680 HandleShift(ushr);
2681}
2682
2683void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
2684 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00002685}
2686
2687void LocationsBuilderARM64::VisitXor(HXor* instruction) {
2688 HandleBinaryOp(instruction);
2689}
2690
2691void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
2692 HandleBinaryOp(instruction);
2693}
2694
Calin Juravleb1498f62015-02-16 13:13:29 +00002695void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) {
2696 // Nothing to do, this should be removed during prepare for register allocator.
2697 UNUSED(instruction);
2698 LOG(FATAL) << "Unreachable";
2699}
2700
2701void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) {
2702 // Nothing to do, this should be removed during prepare for register allocator.
2703 UNUSED(instruction);
2704 LOG(FATAL) << "Unreachable";
2705}
2706
Alexandre Rames67555f72014-11-18 10:55:16 +00002707#undef __
2708#undef QUICK_ENTRY_POINT
2709
Alexandre Rames5319def2014-10-23 10:03:10 +01002710} // namespace arm64
2711} // namespace art