blob: 3619656c1860484185b29a8264ee80face509458 [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(
Nicolas Geoffray90218252015-04-15 11:56:51 +0100125 index_location_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt,
126 length_location_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000127 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(
Nicolas Geoffray90218252015-04-15 11:56:51 +0100325 class_to_check_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot,
326 object_class_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000327
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);
Zheng Xu69a50302015-04-14 20:04:41 +0800469 GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(),
470 frame_size - GetCoreSpillSize());
471 GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(),
472 frame_size - FrameEntrySpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000473 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100474}
475
476void CodeGeneratorARM64::GenerateFrameExit() {
David Srbeckyc34dc932015-04-12 09:27:43 +0100477 GetAssembler()->cfi().RememberState();
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000478 if (!HasEmptyFrame()) {
479 int frame_size = GetFrameSize();
Zheng Xu69a50302015-04-14 20:04:41 +0800480 GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(),
481 frame_size - FrameEntrySpillSize());
482 GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(),
483 frame_size - GetCoreSpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000484 __ Drop(frame_size);
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100485 GetAssembler()->cfi().AdjustCFAOffset(-frame_size);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000486 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100487 __ Ret();
488 GetAssembler()->cfi().RestoreState();
489 GetAssembler()->cfi().DefCFAOffset(GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +0100490}
491
492void CodeGeneratorARM64::Bind(HBasicBlock* block) {
493 __ Bind(GetLabelOf(block));
494}
495
Alexandre Rames5319def2014-10-23 10:03:10 +0100496void CodeGeneratorARM64::Move(HInstruction* instruction,
497 Location location,
498 HInstruction* move_for) {
499 LocationSummary* locations = instruction->GetLocations();
500 if (locations != nullptr && locations->Out().Equals(location)) {
501 return;
502 }
503
504 Primitive::Type type = instruction->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000505 DCHECK_NE(type, Primitive::kPrimVoid);
Alexandre Rames5319def2014-10-23 10:03:10 +0100506
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000507 if (instruction->IsIntConstant()
508 || instruction->IsLongConstant()
509 || instruction->IsNullConstant()) {
510 int64_t value = GetInt64ValueOf(instruction->AsConstant());
Alexandre Rames5319def2014-10-23 10:03:10 +0100511 if (location.IsRegister()) {
512 Register dst = RegisterFrom(location, type);
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000513 DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) ||
Alexandre Rames5319def2014-10-23 10:03:10 +0100514 (instruction->IsLongConstant() && dst.Is64Bits()));
515 __ Mov(dst, value);
516 } else {
517 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000518 UseScratchRegisterScope temps(GetVIXLAssembler());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000519 Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant())
520 ? temps.AcquireW()
521 : temps.AcquireX();
Alexandre Rames5319def2014-10-23 10:03:10 +0100522 __ Mov(temp, value);
523 __ Str(temp, StackOperandFrom(location));
524 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000525 } else if (instruction->IsTemporary()) {
526 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000527 MoveLocation(location, temp_location, type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100528 } else if (instruction->IsLoadLocal()) {
529 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Alexandre Rames542361f2015-01-29 16:57:31 +0000530 if (Primitive::Is64BitType(type)) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000531 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000532 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000533 MoveLocation(location, Location::StackSlot(stack_slot), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100534 }
535
536 } else {
537 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000538 MoveLocation(location, locations->Out(), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100539 }
540}
541
Alexandre Rames5319def2014-10-23 10:03:10 +0100542Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const {
543 Primitive::Type type = load->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000544
Alexandre Rames5319def2014-10-23 10:03:10 +0100545 switch (type) {
546 case Primitive::kPrimNot:
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000547 case Primitive::kPrimInt:
548 case Primitive::kPrimFloat:
549 return Location::StackSlot(GetStackSlot(load->GetLocal()));
550
551 case Primitive::kPrimLong:
552 case Primitive::kPrimDouble:
553 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
554
Alexandre Rames5319def2014-10-23 10:03:10 +0100555 case Primitive::kPrimBoolean:
556 case Primitive::kPrimByte:
557 case Primitive::kPrimChar:
558 case Primitive::kPrimShort:
Alexandre Rames5319def2014-10-23 10:03:10 +0100559 case Primitive::kPrimVoid:
Alexandre Rames5319def2014-10-23 10:03:10 +0100560 LOG(FATAL) << "Unexpected type " << type;
561 }
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000562
Alexandre Rames5319def2014-10-23 10:03:10 +0100563 LOG(FATAL) << "Unreachable";
564 return Location::NoLocation();
565}
566
567void CodeGeneratorARM64::MarkGCCard(Register object, Register value) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000568 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +0100569 Register card = temps.AcquireX();
Serban Constantinescu02164b32014-11-13 14:05:07 +0000570 Register temp = temps.AcquireW(); // Index within the CardTable - 32bit.
Alexandre Rames5319def2014-10-23 10:03:10 +0100571 vixl::Label done;
572 __ Cbz(value, &done);
573 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value()));
574 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000575 __ Strb(card, MemOperand(card, temp.X()));
Alexandre Rames5319def2014-10-23 10:03:10 +0100576 __ Bind(&done);
577}
578
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000579void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const {
580 // Blocked core registers:
581 // lr : Runtime reserved.
582 // tr : Runtime reserved.
583 // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it.
584 // ip1 : VIXL core temp.
585 // ip0 : VIXL core temp.
586 //
587 // Blocked fp registers:
588 // d31 : VIXL fp temp.
Alexandre Rames5319def2014-10-23 10:03:10 +0100589 CPURegList reserved_core_registers = vixl_reserved_core_registers;
590 reserved_core_registers.Combine(runtime_reserved_core_registers);
Alexandre Rames5319def2014-10-23 10:03:10 +0100591 while (!reserved_core_registers.IsEmpty()) {
592 blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true;
593 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000594
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000595 CPURegList reserved_fp_registers = vixl_reserved_fp_registers;
Zheng Xua3ec3942015-02-15 18:39:46 +0800596 while (!reserved_fp_registers.IsEmpty()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000597 blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true;
598 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000599
600 if (is_baseline) {
601 CPURegList reserved_core_baseline_registers = callee_saved_core_registers;
602 while (!reserved_core_baseline_registers.IsEmpty()) {
603 blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true;
604 }
605
606 CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers;
607 while (!reserved_fp_baseline_registers.IsEmpty()) {
608 blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true;
609 }
610 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100611}
612
613Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const {
614 if (type == Primitive::kPrimVoid) {
615 LOG(FATAL) << "Unreachable type " << type;
616 }
617
Alexandre Rames542361f2015-01-29 16:57:31 +0000618 if (Primitive::IsFloatingPointType(type)) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000619 ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters);
620 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100621 return Location::FpuRegisterLocation(reg);
622 } else {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000623 ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters);
624 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100625 return Location::RegisterLocation(reg);
626 }
627}
628
Alexandre Rames3e69f162014-12-10 10:36:50 +0000629size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
630 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
631 __ Str(reg, MemOperand(sp, stack_index));
632 return kArm64WordSize;
633}
634
635size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
636 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
637 __ Ldr(reg, MemOperand(sp, stack_index));
638 return kArm64WordSize;
639}
640
641size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
642 FPRegister reg = FPRegister(reg_id, kDRegSize);
643 __ Str(reg, MemOperand(sp, stack_index));
644 return kArm64WordSize;
645}
646
647size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
648 FPRegister reg = FPRegister(reg_id, kDRegSize);
649 __ Ldr(reg, MemOperand(sp, stack_index));
650 return kArm64WordSize;
651}
652
Alexandre Rames5319def2014-10-23 10:03:10 +0100653void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
654 stream << Arm64ManagedRegister::FromXRegister(XRegister(reg));
655}
656
657void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
658 stream << Arm64ManagedRegister::FromDRegister(DRegister(reg));
659}
660
Alexandre Rames67555f72014-11-18 10:55:16 +0000661void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000662 if (constant->IsIntConstant()) {
663 __ Mov(Register(destination), constant->AsIntConstant()->GetValue());
664 } else if (constant->IsLongConstant()) {
665 __ Mov(Register(destination), constant->AsLongConstant()->GetValue());
666 } else if (constant->IsNullConstant()) {
667 __ Mov(Register(destination), 0);
Alexandre Rames67555f72014-11-18 10:55:16 +0000668 } else if (constant->IsFloatConstant()) {
669 __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue());
670 } else {
671 DCHECK(constant->IsDoubleConstant());
672 __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue());
673 }
674}
675
Alexandre Rames3e69f162014-12-10 10:36:50 +0000676
677static bool CoherentConstantAndType(Location constant, Primitive::Type type) {
678 DCHECK(constant.IsConstant());
679 HConstant* cst = constant.GetConstant();
680 return (cst->IsIntConstant() && type == Primitive::kPrimInt) ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000681 // Null is mapped to a core W register, which we associate with kPrimInt.
682 (cst->IsNullConstant() && type == Primitive::kPrimInt) ||
Alexandre Rames3e69f162014-12-10 10:36:50 +0000683 (cst->IsLongConstant() && type == Primitive::kPrimLong) ||
684 (cst->IsFloatConstant() && type == Primitive::kPrimFloat) ||
685 (cst->IsDoubleConstant() && type == Primitive::kPrimDouble);
686}
687
688void CodeGeneratorARM64::MoveLocation(Location destination, Location source, Primitive::Type type) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000689 if (source.Equals(destination)) {
690 return;
691 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000692
693 // A valid move can always be inferred from the destination and source
694 // locations. When moving from and to a register, the argument type can be
695 // used to generate 32bit instead of 64bit moves. In debug mode we also
696 // checks the coherency of the locations and the type.
697 bool unspecified_type = (type == Primitive::kPrimVoid);
698
699 if (destination.IsRegister() || destination.IsFpuRegister()) {
700 if (unspecified_type) {
701 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
702 if (source.IsStackSlot() ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000703 (src_cst != nullptr && (src_cst->IsIntConstant()
704 || src_cst->IsFloatConstant()
705 || src_cst->IsNullConstant()))) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000706 // For stack slots and 32bit constants, a 64bit type is appropriate.
707 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexandre Rames67555f72014-11-18 10:55:16 +0000708 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000709 // If the source is a double stack slot or a 64bit constant, a 64bit
710 // type is appropriate. Else the source is a register, and since the
711 // type has not been specified, we chose a 64bit type to force a 64bit
712 // move.
713 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexandre Rames67555f72014-11-18 10:55:16 +0000714 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000715 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000716 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
717 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000718 CPURegister dst = CPURegisterFrom(destination, type);
719 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
720 DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot());
721 __ Ldr(dst, StackOperandFrom(source));
722 } else if (source.IsConstant()) {
723 DCHECK(CoherentConstantAndType(source, type));
724 MoveConstant(dst, source.GetConstant());
725 } else {
726 if (destination.IsRegister()) {
727 __ Mov(Register(dst), RegisterFrom(source, type));
728 } else {
729 __ Fmov(FPRegister(dst), FPRegisterFrom(source, type));
730 }
731 }
732
733 } else { // The destination is not a register. It must be a stack slot.
734 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
735 if (source.IsRegister() || source.IsFpuRegister()) {
736 if (unspecified_type) {
737 if (source.IsRegister()) {
738 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
739 } else {
740 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
741 }
742 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000743 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
744 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000745 __ Str(CPURegisterFrom(source, type), StackOperandFrom(destination));
746 } else if (source.IsConstant()) {
747 DCHECK(unspecified_type || CoherentConstantAndType(source, type));
748 UseScratchRegisterScope temps(GetVIXLAssembler());
749 HConstant* src_cst = source.GetConstant();
750 CPURegister temp;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000751 if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000752 temp = temps.AcquireW();
753 } else if (src_cst->IsLongConstant()) {
754 temp = temps.AcquireX();
755 } else if (src_cst->IsFloatConstant()) {
756 temp = temps.AcquireS();
757 } else {
758 DCHECK(src_cst->IsDoubleConstant());
759 temp = temps.AcquireD();
760 }
761 MoveConstant(temp, src_cst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000762 __ Str(temp, StackOperandFrom(destination));
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000763 } else {
Alexandre Rames67555f72014-11-18 10:55:16 +0000764 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000765 DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000766 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000767 // There is generally less pressure on FP registers.
768 FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS();
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000769 __ Ldr(temp, StackOperandFrom(source));
770 __ Str(temp, StackOperandFrom(destination));
771 }
772 }
773}
774
Alexandre Rames3e69f162014-12-10 10:36:50 +0000775void CodeGeneratorARM64::SwapLocations(Location loc1, Location loc2) {
776 DCHECK(!loc1.IsConstant());
777 DCHECK(!loc2.IsConstant());
778
779 if (loc1.Equals(loc2)) {
780 return;
781 }
782
783 UseScratchRegisterScope temps(GetAssembler()->vixl_masm_);
784
785 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
786 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
787 bool is_fp_reg1 = loc1.IsFpuRegister();
788 bool is_fp_reg2 = loc2.IsFpuRegister();
789
790 if (loc2.IsRegister() && loc1.IsRegister()) {
791 Register r1 = XRegisterFrom(loc1);
792 Register r2 = XRegisterFrom(loc2);
793 Register tmp = temps.AcquireSameSizeAs(r1);
794 __ Mov(tmp, r2);
795 __ Mov(r2, r1);
796 __ Mov(r1, tmp);
797 } else if (is_fp_reg2 && is_fp_reg1) {
798 FPRegister r1 = DRegisterFrom(loc1);
799 FPRegister r2 = DRegisterFrom(loc2);
800 FPRegister tmp = temps.AcquireSameSizeAs(r1);
801 __ Fmov(tmp, r2);
802 __ Fmov(r2, r1);
803 __ Fmov(r1, tmp);
804 } else if (is_slot1 != is_slot2) {
805 MemOperand mem = StackOperandFrom(is_slot1 ? loc1 : loc2);
806 Location reg_loc = is_slot1 ? loc2 : loc1;
807 CPURegister reg, tmp;
808 if (reg_loc.IsFpuRegister()) {
809 reg = DRegisterFrom(reg_loc);
810 tmp = temps.AcquireD();
811 } else {
812 reg = XRegisterFrom(reg_loc);
813 tmp = temps.AcquireX();
814 }
815 __ Ldr(tmp, mem);
816 __ Str(reg, mem);
817 if (reg_loc.IsFpuRegister()) {
818 __ Fmov(FPRegister(reg), FPRegister(tmp));
819 } else {
820 __ Mov(Register(reg), Register(tmp));
821 }
822 } else if (is_slot1 && is_slot2) {
823 MemOperand mem1 = StackOperandFrom(loc1);
824 MemOperand mem2 = StackOperandFrom(loc2);
825 Register tmp1 = loc1.IsStackSlot() ? temps.AcquireW() : temps.AcquireX();
826 Register tmp2 = temps.AcquireSameSizeAs(tmp1);
827 __ Ldr(tmp1, mem1);
828 __ Ldr(tmp2, mem2);
829 __ Str(tmp1, mem2);
830 __ Str(tmp2, mem1);
831 } else {
832 LOG(FATAL) << "Unimplemented";
833 }
834}
835
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000836void CodeGeneratorARM64::Load(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000837 CPURegister dst,
838 const MemOperand& src) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000839 switch (type) {
840 case Primitive::kPrimBoolean:
Alexandre Rames67555f72014-11-18 10:55:16 +0000841 __ Ldrb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000842 break;
843 case Primitive::kPrimByte:
Alexandre Rames67555f72014-11-18 10:55:16 +0000844 __ Ldrsb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000845 break;
846 case Primitive::kPrimShort:
Alexandre Rames67555f72014-11-18 10:55:16 +0000847 __ Ldrsh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000848 break;
849 case Primitive::kPrimChar:
Alexandre Rames67555f72014-11-18 10:55:16 +0000850 __ Ldrh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000851 break;
852 case Primitive::kPrimInt:
853 case Primitive::kPrimNot:
854 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000855 case Primitive::kPrimFloat:
856 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000857 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Rames67555f72014-11-18 10:55:16 +0000858 __ Ldr(dst, src);
859 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000860 case Primitive::kPrimVoid:
861 LOG(FATAL) << "Unreachable type " << type;
862 }
863}
864
Calin Juravle77520bc2015-01-12 18:45:46 +0000865void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000866 CPURegister dst,
867 const MemOperand& src) {
868 UseScratchRegisterScope temps(GetVIXLAssembler());
869 Register temp_base = temps.AcquireX();
Calin Juravle77520bc2015-01-12 18:45:46 +0000870 Primitive::Type type = instruction->GetType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000871
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000872 DCHECK(!src.IsPreIndex());
873 DCHECK(!src.IsPostIndex());
874
875 // TODO(vixl): Let the MacroAssembler handle MemOperand.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800876 __ Add(temp_base, src.base(), OperandFromMemOperand(src));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000877 MemOperand base = MemOperand(temp_base);
878 switch (type) {
879 case Primitive::kPrimBoolean:
880 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000881 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000882 break;
883 case Primitive::kPrimByte:
884 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000885 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000886 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
887 break;
888 case Primitive::kPrimChar:
889 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000890 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000891 break;
892 case Primitive::kPrimShort:
893 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000894 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000895 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
896 break;
897 case Primitive::kPrimInt:
898 case Primitive::kPrimNot:
899 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000900 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000901 __ Ldar(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000902 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000903 break;
904 case Primitive::kPrimFloat:
905 case Primitive::kPrimDouble: {
906 DCHECK(dst.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000907 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000908
909 Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
910 __ Ldar(temp, base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000911 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000912 __ Fmov(FPRegister(dst), temp);
913 break;
914 }
915 case Primitive::kPrimVoid:
916 LOG(FATAL) << "Unreachable type " << type;
917 }
918}
919
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000920void CodeGeneratorARM64::Store(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000921 CPURegister src,
922 const MemOperand& dst) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000923 switch (type) {
924 case Primitive::kPrimBoolean:
925 case Primitive::kPrimByte:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000926 __ Strb(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000927 break;
928 case Primitive::kPrimChar:
929 case Primitive::kPrimShort:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000930 __ Strh(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000931 break;
932 case Primitive::kPrimInt:
933 case Primitive::kPrimNot:
934 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000935 case Primitive::kPrimFloat:
936 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000937 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000938 __ Str(src, dst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000939 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000940 case Primitive::kPrimVoid:
941 LOG(FATAL) << "Unreachable type " << type;
942 }
943}
944
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000945void CodeGeneratorARM64::StoreRelease(Primitive::Type type,
946 CPURegister src,
947 const MemOperand& dst) {
948 UseScratchRegisterScope temps(GetVIXLAssembler());
949 Register temp_base = temps.AcquireX();
950
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000951 DCHECK(!dst.IsPreIndex());
952 DCHECK(!dst.IsPostIndex());
953
954 // TODO(vixl): Let the MacroAssembler handle this.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800955 Operand op = OperandFromMemOperand(dst);
956 __ Add(temp_base, dst.base(), op);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000957 MemOperand base = MemOperand(temp_base);
958 switch (type) {
959 case Primitive::kPrimBoolean:
960 case Primitive::kPrimByte:
961 __ Stlrb(Register(src), base);
962 break;
963 case Primitive::kPrimChar:
964 case Primitive::kPrimShort:
965 __ Stlrh(Register(src), base);
966 break;
967 case Primitive::kPrimInt:
968 case Primitive::kPrimNot:
969 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000970 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000971 __ Stlr(Register(src), base);
972 break;
973 case Primitive::kPrimFloat:
974 case Primitive::kPrimDouble: {
975 DCHECK(src.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000976 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000977
978 Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
979 __ Fmov(temp, FPRegister(src));
980 __ Stlr(temp, base);
981 break;
982 }
983 case Primitive::kPrimVoid:
984 LOG(FATAL) << "Unreachable type " << type;
985 }
986}
987
Alexandre Rames67555f72014-11-18 10:55:16 +0000988void CodeGeneratorARM64::LoadCurrentMethod(vixl::Register current_method) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000989 DCHECK(RequiresCurrentMethod());
Alexandre Rames67555f72014-11-18 10:55:16 +0000990 DCHECK(current_method.IsW());
991 __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset));
992}
993
994void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset,
995 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000996 uint32_t dex_pc,
997 SlowPathCode* slow_path) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000998 __ Ldr(lr, MemOperand(tr, entry_point_offset));
999 __ Blr(lr);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001000 if (instruction != nullptr) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001001 RecordPcInfo(instruction, dex_pc, slow_path);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001002 DCHECK(instruction->IsSuspendCheck()
1003 || instruction->IsBoundsCheck()
1004 || instruction->IsNullCheck()
1005 || instruction->IsDivZeroCheck()
1006 || !IsLeafMethod());
1007 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001008}
1009
1010void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path,
1011 vixl::Register class_reg) {
1012 UseScratchRegisterScope temps(GetVIXLAssembler());
1013 Register temp = temps.AcquireW();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001014 size_t status_offset = mirror::Class::StatusOffset().SizeValue();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001015 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001016
Serban Constantinescu02164b32014-11-13 14:05:07 +00001017 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
Serban Constantinescu579885a2015-02-22 20:51:33 +00001018 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001019 // TODO(vixl): Let the MacroAssembler handle MemOperand.
1020 __ Add(temp, class_reg, status_offset);
1021 __ Ldar(temp, HeapOperand(temp));
1022 __ Cmp(temp, mirror::Class::kStatusInitialized);
1023 __ B(lt, slow_path->GetEntryLabel());
1024 } else {
1025 __ Ldr(temp, HeapOperand(class_reg, status_offset));
1026 __ Cmp(temp, mirror::Class::kStatusInitialized);
1027 __ B(lt, slow_path->GetEntryLabel());
1028 __ Dmb(InnerShareable, BarrierReads);
1029 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001030 __ Bind(slow_path->GetExitLabel());
1031}
Alexandre Rames5319def2014-10-23 10:03:10 +01001032
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001033void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) {
1034 BarrierType type = BarrierAll;
1035
1036 switch (kind) {
1037 case MemBarrierKind::kAnyAny:
1038 case MemBarrierKind::kAnyStore: {
1039 type = BarrierAll;
1040 break;
1041 }
1042 case MemBarrierKind::kLoadAny: {
1043 type = BarrierReads;
1044 break;
1045 }
1046 case MemBarrierKind::kStoreStore: {
1047 type = BarrierWrites;
1048 break;
1049 }
1050 default:
1051 LOG(FATAL) << "Unexpected memory barrier " << kind;
1052 }
1053 __ Dmb(InnerShareable, type);
1054}
1055
Serban Constantinescu02164b32014-11-13 14:05:07 +00001056void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction,
1057 HBasicBlock* successor) {
1058 SuspendCheckSlowPathARM64* slow_path =
1059 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor);
1060 codegen_->AddSlowPath(slow_path);
1061 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
1062 Register temp = temps.AcquireW();
1063
1064 __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue()));
1065 if (successor == nullptr) {
1066 __ Cbnz(temp, slow_path->GetEntryLabel());
1067 __ Bind(slow_path->GetReturnLabel());
1068 } else {
1069 __ Cbz(temp, codegen_->GetLabelOf(successor));
1070 __ B(slow_path->GetEntryLabel());
1071 // slow_path will return to GetLabelOf(successor).
1072 }
1073}
1074
Alexandre Rames5319def2014-10-23 10:03:10 +01001075InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
1076 CodeGeneratorARM64* codegen)
1077 : HGraphVisitor(graph),
1078 assembler_(codegen->GetAssembler()),
1079 codegen_(codegen) {}
1080
1081#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Alexandre Rames3e69f162014-12-10 10:36:50 +00001082 /* No unimplemented IR. */
Alexandre Rames5319def2014-10-23 10:03:10 +01001083
1084#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
1085
1086enum UnimplementedInstructionBreakCode {
Alexandre Rames67555f72014-11-18 10:55:16 +00001087 // Using a base helps identify when we hit such breakpoints.
1088 UnimplementedInstructionBreakCodeBaseCode = 0x900,
Alexandre Rames5319def2014-10-23 10:03:10 +01001089#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
1090 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
1091#undef ENUM_UNIMPLEMENTED_INSTRUCTION
1092};
1093
1094#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
1095 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001096 UNUSED(instr); \
Alexandre Rames5319def2014-10-23 10:03:10 +01001097 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
1098 } \
1099 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
1100 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
1101 locations->SetOut(Location::Any()); \
1102 }
1103 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
1104#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
1105
1106#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
Alexandre Rames67555f72014-11-18 10:55:16 +00001107#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
Alexandre Rames5319def2014-10-23 10:03:10 +01001108
Alexandre Rames67555f72014-11-18 10:55:16 +00001109void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001110 DCHECK_EQ(instr->InputCount(), 2U);
1111 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1112 Primitive::Type type = instr->GetResultType();
1113 switch (type) {
1114 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001115 case Primitive::kPrimLong:
Alexandre Rames5319def2014-10-23 10:03:10 +01001116 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001117 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr));
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001118 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001119 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001120
1121 case Primitive::kPrimFloat:
1122 case Primitive::kPrimDouble:
1123 locations->SetInAt(0, Location::RequiresFpuRegister());
1124 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001125 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001126 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001127
Alexandre Rames5319def2014-10-23 10:03:10 +01001128 default:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001129 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001130 }
1131}
1132
Alexandre Rames67555f72014-11-18 10:55:16 +00001133void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001134 Primitive::Type type = instr->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001135
1136 switch (type) {
1137 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001138 case Primitive::kPrimLong: {
1139 Register dst = OutputRegister(instr);
1140 Register lhs = InputRegisterAt(instr, 0);
1141 Operand rhs = InputOperandAt(instr, 1);
Alexandre Rames5319def2014-10-23 10:03:10 +01001142 if (instr->IsAdd()) {
1143 __ Add(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001144 } else if (instr->IsAnd()) {
1145 __ And(dst, lhs, rhs);
1146 } else if (instr->IsOr()) {
1147 __ Orr(dst, lhs, rhs);
1148 } else if (instr->IsSub()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001149 __ Sub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001150 } else {
1151 DCHECK(instr->IsXor());
1152 __ Eor(dst, lhs, rhs);
Alexandre Rames5319def2014-10-23 10:03:10 +01001153 }
1154 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001155 }
1156 case Primitive::kPrimFloat:
1157 case Primitive::kPrimDouble: {
1158 FPRegister dst = OutputFPRegister(instr);
1159 FPRegister lhs = InputFPRegisterAt(instr, 0);
1160 FPRegister rhs = InputFPRegisterAt(instr, 1);
1161 if (instr->IsAdd()) {
1162 __ Fadd(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001163 } else if (instr->IsSub()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001164 __ Fsub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001165 } else {
1166 LOG(FATAL) << "Unexpected floating-point binary operation";
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001167 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001168 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001169 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001170 default:
Alexandre Rames67555f72014-11-18 10:55:16 +00001171 LOG(FATAL) << "Unexpected binary operation type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001172 }
1173}
1174
Serban Constantinescu02164b32014-11-13 14:05:07 +00001175void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) {
1176 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1177
1178 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1179 Primitive::Type type = instr->GetResultType();
1180 switch (type) {
1181 case Primitive::kPrimInt:
1182 case Primitive::kPrimLong: {
1183 locations->SetInAt(0, Location::RequiresRegister());
1184 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1185 locations->SetOut(Location::RequiresRegister());
1186 break;
1187 }
1188 default:
1189 LOG(FATAL) << "Unexpected shift type " << type;
1190 }
1191}
1192
1193void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) {
1194 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1195
1196 Primitive::Type type = instr->GetType();
1197 switch (type) {
1198 case Primitive::kPrimInt:
1199 case Primitive::kPrimLong: {
1200 Register dst = OutputRegister(instr);
1201 Register lhs = InputRegisterAt(instr, 0);
1202 Operand rhs = InputOperandAt(instr, 1);
1203 if (rhs.IsImmediate()) {
1204 uint32_t shift_value = (type == Primitive::kPrimInt)
1205 ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue)
1206 : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue);
1207 if (instr->IsShl()) {
1208 __ Lsl(dst, lhs, shift_value);
1209 } else if (instr->IsShr()) {
1210 __ Asr(dst, lhs, shift_value);
1211 } else {
1212 __ Lsr(dst, lhs, shift_value);
1213 }
1214 } else {
1215 Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W();
1216
1217 if (instr->IsShl()) {
1218 __ Lsl(dst, lhs, rhs_reg);
1219 } else if (instr->IsShr()) {
1220 __ Asr(dst, lhs, rhs_reg);
1221 } else {
1222 __ Lsr(dst, lhs, rhs_reg);
1223 }
1224 }
1225 break;
1226 }
1227 default:
1228 LOG(FATAL) << "Unexpected shift operation type " << type;
1229 }
1230}
1231
Alexandre Rames5319def2014-10-23 10:03:10 +01001232void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001233 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001234}
1235
1236void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001237 HandleBinaryOp(instruction);
1238}
1239
1240void LocationsBuilderARM64::VisitAnd(HAnd* instruction) {
1241 HandleBinaryOp(instruction);
1242}
1243
1244void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) {
1245 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001246}
1247
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001248void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) {
1249 LocationSummary* locations =
1250 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1251 locations->SetInAt(0, Location::RequiresRegister());
1252 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1253 locations->SetOut(Location::RequiresRegister());
1254}
1255
1256void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) {
1257 LocationSummary* locations = instruction->GetLocations();
1258 Primitive::Type type = instruction->GetType();
1259 Register obj = InputRegisterAt(instruction, 0);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001260 Location index = locations->InAt(1);
1261 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001262 MemOperand source = HeapOperand(obj);
Alexandre Rames67555f72014-11-18 10:55:16 +00001263 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001264
1265 if (index.IsConstant()) {
1266 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001267 source = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001268 } else {
1269 Register temp = temps.AcquireSameSizeAs(obj);
1270 Register index_reg = RegisterFrom(index, Primitive::kPrimInt);
1271 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001272 source = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001273 }
1274
Alexandre Rames67555f72014-11-18 10:55:16 +00001275 codegen_->Load(type, OutputCPURegister(instruction), source);
Calin Juravle77520bc2015-01-12 18:45:46 +00001276 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001277}
1278
Alexandre Rames5319def2014-10-23 10:03:10 +01001279void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
1280 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1281 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001282 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001283}
1284
1285void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
1286 __ Ldr(OutputRegister(instruction),
1287 HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset()));
Calin Juravle77520bc2015-01-12 18:45:46 +00001288 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001289}
1290
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001291void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) {
1292 Primitive::Type value_type = instruction->GetComponentType();
1293 bool is_object = value_type == Primitive::kPrimNot;
1294 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1295 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1296 if (is_object) {
1297 InvokeRuntimeCallingConvention calling_convention;
1298 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1299 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1300 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1301 } else {
1302 locations->SetInAt(0, Location::RequiresRegister());
1303 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1304 locations->SetInAt(2, Location::RequiresRegister());
1305 }
1306}
1307
1308void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) {
1309 Primitive::Type value_type = instruction->GetComponentType();
1310 if (value_type == Primitive::kPrimNot) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001311 codegen_->InvokeRuntime(
1312 QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001313 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001314 } else {
1315 LocationSummary* locations = instruction->GetLocations();
1316 Register obj = InputRegisterAt(instruction, 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00001317 CPURegister value = InputCPURegisterAt(instruction, 2);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001318 Location index = locations->InAt(1);
1319 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001320 MemOperand destination = HeapOperand(obj);
Alexandre Rames67555f72014-11-18 10:55:16 +00001321 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001322
1323 if (index.IsConstant()) {
1324 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001325 destination = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001326 } else {
1327 Register temp = temps.AcquireSameSizeAs(obj);
1328 Register index_reg = InputRegisterAt(instruction, 1);
1329 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001330 destination = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001331 }
1332
1333 codegen_->Store(value_type, value, destination);
Calin Juravle77520bc2015-01-12 18:45:46 +00001334 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001335 }
1336}
1337
Alexandre Rames67555f72014-11-18 10:55:16 +00001338void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1339 LocationSummary* locations =
1340 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1341 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu760d8ef2015-03-28 18:09:56 +00001342 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames67555f72014-11-18 10:55:16 +00001343 if (instruction->HasUses()) {
1344 locations->SetOut(Location::SameAsFirstInput());
1345 }
1346}
1347
1348void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001349 LocationSummary* locations = instruction->GetLocations();
1350 BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(
1351 instruction, locations->InAt(0), locations->InAt(1));
Alexandre Rames67555f72014-11-18 10:55:16 +00001352 codegen_->AddSlowPath(slow_path);
1353
1354 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
1355 __ B(slow_path->GetEntryLabel(), hs);
1356}
1357
1358void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) {
1359 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1360 instruction, LocationSummary::kCallOnSlowPath);
1361 locations->SetInAt(0, Location::RequiresRegister());
1362 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001363 locations->AddTemp(Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001364}
1365
1366void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001367 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames67555f72014-11-18 10:55:16 +00001368 Register obj = InputRegisterAt(instruction, 0);;
1369 Register cls = InputRegisterAt(instruction, 1);;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001370 Register obj_cls = WRegisterFrom(instruction->GetLocations()->GetTemp(0));
Alexandre Rames67555f72014-11-18 10:55:16 +00001371
Alexandre Rames3e69f162014-12-10 10:36:50 +00001372 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1373 instruction, locations->InAt(1), LocationFrom(obj_cls), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001374 codegen_->AddSlowPath(slow_path);
1375
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01001376 // Avoid null check if we know obj is not null.
1377 if (instruction->MustDoNullCheck()) {
1378 __ Cbz(obj, slow_path->GetExitLabel());
1379 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001380 // Compare the class of `obj` with `cls`.
Alexandre Rames3e69f162014-12-10 10:36:50 +00001381 __ Ldr(obj_cls, HeapOperand(obj, mirror::Object::ClassOffset()));
1382 __ Cmp(obj_cls, cls);
Alexandre Rames67555f72014-11-18 10:55:16 +00001383 __ B(ne, slow_path->GetEntryLabel());
1384 __ Bind(slow_path->GetExitLabel());
1385}
1386
1387void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) {
1388 LocationSummary* locations =
1389 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1390 locations->SetInAt(0, Location::RequiresRegister());
1391 if (check->HasUses()) {
1392 locations->SetOut(Location::SameAsFirstInput());
1393 }
1394}
1395
1396void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) {
1397 // We assume the class is not null.
1398 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
1399 check->GetLoadClass(), check, check->GetDexPc(), true);
1400 codegen_->AddSlowPath(slow_path);
1401 GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0));
1402}
1403
Serban Constantinescu02164b32014-11-13 14:05:07 +00001404void LocationsBuilderARM64::VisitCompare(HCompare* compare) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001405 LocationSummary* locations =
Serban Constantinescu02164b32014-11-13 14:05:07 +00001406 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
1407 Primitive::Type in_type = compare->InputAt(0)->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001408 switch (in_type) {
1409 case Primitive::kPrimLong: {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001410 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001411 locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001412 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1413 break;
1414 }
1415 case Primitive::kPrimFloat:
1416 case Primitive::kPrimDouble: {
1417 locations->SetInAt(0, Location::RequiresFpuRegister());
Alexandre Rames93415462015-02-17 15:08:20 +00001418 HInstruction* right = compare->InputAt(1);
1419 if ((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1420 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))) {
1421 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1422 } else {
1423 locations->SetInAt(1, Location::RequiresFpuRegister());
1424 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001425 locations->SetOut(Location::RequiresRegister());
1426 break;
1427 }
1428 default:
1429 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1430 }
1431}
1432
1433void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) {
1434 Primitive::Type in_type = compare->InputAt(0)->GetType();
1435
1436 // 0 if: left == right
1437 // 1 if: left > right
1438 // -1 if: left < right
1439 switch (in_type) {
1440 case Primitive::kPrimLong: {
1441 Register result = OutputRegister(compare);
1442 Register left = InputRegisterAt(compare, 0);
1443 Operand right = InputOperandAt(compare, 1);
1444
1445 __ Cmp(left, right);
1446 __ Cset(result, ne);
1447 __ Cneg(result, result, lt);
1448 break;
1449 }
1450 case Primitive::kPrimFloat:
1451 case Primitive::kPrimDouble: {
1452 Register result = OutputRegister(compare);
1453 FPRegister left = InputFPRegisterAt(compare, 0);
Alexandre Rames93415462015-02-17 15:08:20 +00001454 if (compare->GetLocations()->InAt(1).IsConstant()) {
1455 if (kIsDebugBuild) {
1456 HInstruction* right = compare->GetLocations()->InAt(1).GetConstant();
1457 DCHECK((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1458 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0)));
1459 }
1460 // 0.0 is the only immediate that can be encoded directly in a FCMP instruction.
1461 __ Fcmp(left, 0.0);
1462 } else {
1463 __ Fcmp(left, InputFPRegisterAt(compare, 1));
1464 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001465 if (compare->IsGtBias()) {
1466 __ Cset(result, ne);
1467 } else {
1468 __ Csetm(result, ne);
1469 }
1470 __ Cneg(result, result, compare->IsGtBias() ? mi : gt);
Alexandre Rames5319def2014-10-23 10:03:10 +01001471 break;
1472 }
1473 default:
1474 LOG(FATAL) << "Unimplemented compare type " << in_type;
1475 }
1476}
1477
1478void LocationsBuilderARM64::VisitCondition(HCondition* instruction) {
1479 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1480 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001481 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames5319def2014-10-23 10:03:10 +01001482 if (instruction->NeedsMaterialization()) {
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001483 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001484 }
1485}
1486
1487void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) {
1488 if (!instruction->NeedsMaterialization()) {
1489 return;
1490 }
1491
1492 LocationSummary* locations = instruction->GetLocations();
1493 Register lhs = InputRegisterAt(instruction, 0);
1494 Operand rhs = InputOperandAt(instruction, 1);
1495 Register res = RegisterFrom(locations->Out(), instruction->GetType());
1496 Condition cond = ARM64Condition(instruction->GetCondition());
1497
1498 __ Cmp(lhs, rhs);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001499 __ Cset(res, cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001500}
1501
1502#define FOR_EACH_CONDITION_INSTRUCTION(M) \
1503 M(Equal) \
1504 M(NotEqual) \
1505 M(LessThan) \
1506 M(LessThanOrEqual) \
1507 M(GreaterThan) \
1508 M(GreaterThanOrEqual)
1509#define DEFINE_CONDITION_VISITORS(Name) \
1510void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \
1511void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }
1512FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
Alexandre Rames67555f72014-11-18 10:55:16 +00001513#undef DEFINE_CONDITION_VISITORS
Alexandre Rames5319def2014-10-23 10:03:10 +01001514#undef FOR_EACH_CONDITION_INSTRUCTION
1515
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001516void LocationsBuilderARM64::VisitDiv(HDiv* div) {
1517 LocationSummary* locations =
1518 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1519 switch (div->GetResultType()) {
1520 case Primitive::kPrimInt:
1521 case Primitive::kPrimLong:
1522 locations->SetInAt(0, Location::RequiresRegister());
1523 locations->SetInAt(1, Location::RequiresRegister());
1524 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1525 break;
1526
1527 case Primitive::kPrimFloat:
1528 case Primitive::kPrimDouble:
1529 locations->SetInAt(0, Location::RequiresFpuRegister());
1530 locations->SetInAt(1, Location::RequiresFpuRegister());
1531 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1532 break;
1533
1534 default:
1535 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1536 }
1537}
1538
1539void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) {
1540 Primitive::Type type = div->GetResultType();
1541 switch (type) {
1542 case Primitive::kPrimInt:
1543 case Primitive::kPrimLong:
1544 __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1));
1545 break;
1546
1547 case Primitive::kPrimFloat:
1548 case Primitive::kPrimDouble:
1549 __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1));
1550 break;
1551
1552 default:
1553 LOG(FATAL) << "Unexpected div type " << type;
1554 }
1555}
1556
Alexandre Rames67555f72014-11-18 10:55:16 +00001557void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1558 LocationSummary* locations =
1559 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1560 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1561 if (instruction->HasUses()) {
1562 locations->SetOut(Location::SameAsFirstInput());
1563 }
1564}
1565
1566void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1567 SlowPathCodeARM64* slow_path =
1568 new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction);
1569 codegen_->AddSlowPath(slow_path);
1570 Location value = instruction->GetLocations()->InAt(0);
1571
Alexandre Rames3e69f162014-12-10 10:36:50 +00001572 Primitive::Type type = instruction->GetType();
1573
1574 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1575 LOG(FATAL) << "Unexpected type " << type << "for DivZeroCheck.";
1576 return;
1577 }
1578
Alexandre Rames67555f72014-11-18 10:55:16 +00001579 if (value.IsConstant()) {
1580 int64_t divisor = Int64ConstantFrom(value);
1581 if (divisor == 0) {
1582 __ B(slow_path->GetEntryLabel());
1583 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001584 // A division by a non-null constant is valid. We don't need to perform
1585 // any check, so simply fall through.
Alexandre Rames67555f72014-11-18 10:55:16 +00001586 }
1587 } else {
1588 __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel());
1589 }
1590}
1591
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001592void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1593 LocationSummary* locations =
1594 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1595 locations->SetOut(Location::ConstantLocation(constant));
1596}
1597
1598void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1599 UNUSED(constant);
1600 // Will be generated at use site.
1601}
1602
Alexandre Rames5319def2014-10-23 10:03:10 +01001603void LocationsBuilderARM64::VisitExit(HExit* exit) {
1604 exit->SetLocations(nullptr);
1605}
1606
1607void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001608 UNUSED(exit);
Alexandre Rames5319def2014-10-23 10:03:10 +01001609}
1610
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001611void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) {
1612 LocationSummary* locations =
1613 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1614 locations->SetOut(Location::ConstantLocation(constant));
1615}
1616
1617void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) {
1618 UNUSED(constant);
1619 // Will be generated at use site.
1620}
1621
Alexandre Rames5319def2014-10-23 10:03:10 +01001622void LocationsBuilderARM64::VisitGoto(HGoto* got) {
1623 got->SetLocations(nullptr);
1624}
1625
1626void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
1627 HBasicBlock* successor = got->GetSuccessor();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001628 DCHECK(!successor->IsExitBlock());
1629 HBasicBlock* block = got->GetBlock();
1630 HInstruction* previous = got->GetPrevious();
1631 HLoopInformation* info = block->GetLoopInformation();
1632
David Brazdil46e2a392015-03-16 17:31:52 +00001633 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001634 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1635 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1636 return;
1637 }
1638 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1639 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1640 }
1641 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001642 __ B(codegen_->GetLabelOf(successor));
1643 }
1644}
1645
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001646void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction,
1647 vixl::Label* true_target,
1648 vixl::Label* false_target,
1649 vixl::Label* always_true_target) {
1650 HInstruction* cond = instruction->InputAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001651 HCondition* condition = cond->AsCondition();
Alexandre Rames5319def2014-10-23 10:03:10 +01001652
Serban Constantinescu02164b32014-11-13 14:05:07 +00001653 if (cond->IsIntConstant()) {
1654 int32_t cond_value = cond->AsIntConstant()->GetValue();
1655 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001656 if (always_true_target != nullptr) {
1657 __ B(always_true_target);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001658 }
1659 return;
1660 } else {
1661 DCHECK_EQ(cond_value, 0);
1662 }
1663 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001664 // The condition instruction has been materialized, compare the output to 0.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001665 Location cond_val = instruction->GetLocations()->InAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001666 DCHECK(cond_val.IsRegister());
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001667 __ Cbnz(InputRegisterAt(instruction, 0), true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001668 } else {
1669 // The condition instruction has not been materialized, use its inputs as
1670 // the comparison and its condition as the branch condition.
1671 Register lhs = InputRegisterAt(condition, 0);
1672 Operand rhs = InputOperandAt(condition, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001673 Condition arm64_cond = ARM64Condition(condition->GetCondition());
Alexandre Rames4388dcc2015-02-03 10:28:33 +00001674 if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
1675 switch (arm64_cond) {
1676 case eq:
1677 __ Cbz(lhs, true_target);
1678 break;
1679 case ne:
1680 __ Cbnz(lhs, true_target);
1681 break;
1682 case lt:
1683 // Test the sign bit and branch accordingly.
1684 __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1685 break;
1686 case ge:
1687 // Test the sign bit and branch accordingly.
1688 __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1689 break;
1690 default:
1691 // Without the `static_cast` the compiler throws an error for
1692 // `-Werror=sign-promo`.
1693 LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001694 }
1695 } else {
1696 __ Cmp(lhs, rhs);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001697 __ B(arm64_cond, true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001698 }
1699 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001700 if (false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001701 __ B(false_target);
1702 }
1703}
1704
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001705void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
1706 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1707 HInstruction* cond = if_instr->InputAt(0);
1708 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1709 locations->SetInAt(0, Location::RequiresRegister());
1710 }
1711}
1712
1713void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
1714 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1715 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1716 vixl::Label* always_true_target = true_target;
1717 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1718 if_instr->IfTrueSuccessor())) {
1719 always_true_target = nullptr;
1720 }
1721 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1722 if_instr->IfFalseSuccessor())) {
1723 false_target = nullptr;
1724 }
1725 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1726}
1727
1728void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1729 LocationSummary* locations = new (GetGraph()->GetArena())
1730 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1731 HInstruction* cond = deoptimize->InputAt(0);
1732 DCHECK(cond->IsCondition());
1733 if (cond->AsCondition()->NeedsMaterialization()) {
1734 locations->SetInAt(0, Location::RequiresRegister());
1735 }
1736}
1737
1738void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1739 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
1740 DeoptimizationSlowPathARM64(deoptimize);
1741 codegen_->AddSlowPath(slow_path);
1742 vixl::Label* slow_path_entry = slow_path->GetEntryLabel();
1743 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1744}
1745
Alexandre Rames5319def2014-10-23 10:03:10 +01001746void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001747 LocationSummary* locations =
1748 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001749 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001750 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001751}
1752
1753void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001754 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00001755 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001756
1757 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001758 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00001759 // NB: LoadAcquire will record the pc info if needed.
1760 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001761 } else {
1762 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001763 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001764 // For IRIW sequential consistency kLoadAny is not sufficient.
1765 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1766 }
1767 } else {
1768 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001769 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001770 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001771}
1772
1773void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001774 LocationSummary* locations =
1775 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001776 locations->SetInAt(0, Location::RequiresRegister());
1777 locations->SetInAt(1, Location::RequiresRegister());
1778}
1779
1780void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001781 Register obj = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001782 CPURegister value = InputCPURegisterAt(instruction, 1);
1783 Offset offset = instruction->GetFieldOffset();
1784 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001785 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001786
1787 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001788 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001789 codegen_->StoreRelease(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001790 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001791 } else {
1792 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
1793 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001794 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001795 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1796 }
1797 } else {
1798 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001799 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001800 }
1801
1802 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001803 codegen_->MarkGCCard(obj, Register(value));
Alexandre Rames5319def2014-10-23 10:03:10 +01001804 }
1805}
1806
Alexandre Rames67555f72014-11-18 10:55:16 +00001807void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
1808 LocationSummary::CallKind call_kind =
1809 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
1810 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1811 locations->SetInAt(0, Location::RequiresRegister());
1812 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001813 // The output does overlap inputs.
1814 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexandre Rames67555f72014-11-18 10:55:16 +00001815}
1816
1817void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
1818 LocationSummary* locations = instruction->GetLocations();
1819 Register obj = InputRegisterAt(instruction, 0);;
1820 Register cls = InputRegisterAt(instruction, 1);;
1821 Register out = OutputRegister(instruction);
1822
1823 vixl::Label done;
1824
1825 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01001826 // Avoid null check if we know `obj` is not null.
1827 if (instruction->MustDoNullCheck()) {
1828 __ Mov(out, 0);
1829 __ Cbz(obj, &done);
1830 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001831
1832 // Compare the class of `obj` with `cls`.
Serban Constantinescu02164b32014-11-13 14:05:07 +00001833 __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset()));
Alexandre Rames67555f72014-11-18 10:55:16 +00001834 __ Cmp(out, cls);
1835 if (instruction->IsClassFinal()) {
1836 // Classes must be equal for the instanceof to succeed.
1837 __ Cset(out, eq);
1838 } else {
1839 // If the classes are not equal, we go into a slow path.
1840 DCHECK(locations->OnlyCallsOnSlowPath());
1841 SlowPathCodeARM64* slow_path =
Alexandre Rames3e69f162014-12-10 10:36:50 +00001842 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1843 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001844 codegen_->AddSlowPath(slow_path);
1845 __ B(ne, slow_path->GetEntryLabel());
1846 __ Mov(out, 1);
1847 __ Bind(slow_path->GetExitLabel());
1848 }
1849
1850 __ Bind(&done);
1851}
1852
Alexandre Rames5319def2014-10-23 10:03:10 +01001853void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
1854 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1855 locations->SetOut(Location::ConstantLocation(constant));
1856}
1857
1858void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
1859 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001860 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01001861}
1862
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001863void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
1864 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1865 locations->SetOut(Location::ConstantLocation(constant));
1866}
1867
1868void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) {
1869 // Will be generated at use site.
1870 UNUSED(constant);
1871}
1872
Alexandre Rames5319def2014-10-23 10:03:10 +01001873void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
1874 LocationSummary* locations =
1875 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
1876 locations->AddTemp(LocationFrom(x0));
1877
1878 InvokeDexCallingConventionVisitor calling_convention_visitor;
1879 for (size_t i = 0; i < invoke->InputCount(); i++) {
1880 HInstruction* input = invoke->InputAt(i);
1881 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1882 }
1883
1884 Primitive::Type return_type = invoke->GetType();
1885 if (return_type != Primitive::kPrimVoid) {
1886 locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type));
1887 }
1888}
1889
Alexandre Rames67555f72014-11-18 10:55:16 +00001890void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1891 HandleInvoke(invoke);
1892}
1893
1894void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1895 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1896 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1897 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1898 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1899 Location receiver = invoke->GetLocations()->InAt(0);
1900 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001901 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00001902
1903 // The register ip1 is required to be used for the hidden argument in
1904 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
1905 UseScratchRegisterScope scratch_scope(GetVIXLAssembler());
1906 scratch_scope.Exclude(ip1);
1907 __ Mov(ip1, invoke->GetDexMethodIndex());
1908
1909 // temp = object->GetClass();
1910 if (receiver.IsStackSlot()) {
1911 __ Ldr(temp, StackOperandFrom(receiver));
1912 __ Ldr(temp, HeapOperand(temp, class_offset));
1913 } else {
1914 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
1915 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001916 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames67555f72014-11-18 10:55:16 +00001917 // temp = temp->GetImtEntryAt(method_offset);
1918 __ Ldr(temp, HeapOperand(temp, method_offset));
1919 // lr = temp->GetEntryPoint();
1920 __ Ldr(lr, HeapOperand(temp, entry_point));
1921 // lr();
1922 __ Blr(lr);
1923 DCHECK(!codegen_->IsLeafMethod());
1924 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1925}
1926
1927void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001928 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1929 if (intrinsic.TryDispatch(invoke)) {
1930 return;
1931 }
1932
Alexandre Rames67555f72014-11-18 10:55:16 +00001933 HandleInvoke(invoke);
1934}
1935
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001936void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001937 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1938 if (intrinsic.TryDispatch(invoke)) {
1939 return;
1940 }
1941
Alexandre Rames67555f72014-11-18 10:55:16 +00001942 HandleInvoke(invoke);
1943}
1944
Andreas Gampe878d58c2015-01-15 23:24:00 -08001945static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
1946 if (invoke->GetLocations()->Intrinsified()) {
1947 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
1948 intrinsic.Dispatch(invoke);
1949 return true;
1950 }
1951 return false;
1952}
1953
1954void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
1955 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
1956 DCHECK(temp.Is(kArtMethodRegister));
Alexandre Rames5319def2014-10-23 10:03:10 +01001957 size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() +
Andreas Gampe878d58c2015-01-15 23:24:00 -08001958 invoke->GetDexMethodIndex() * kHeapRefSize;
Alexandre Rames5319def2014-10-23 10:03:10 +01001959
1960 // TODO: Implement all kinds of calls:
1961 // 1) boot -> boot
1962 // 2) app -> boot
1963 // 3) app -> app
1964 //
1965 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1966
Nicolas Geoffray0a299b92015-01-29 11:39:44 +00001967 // temp = method;
1968 LoadCurrentMethod(temp);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001969 if (!invoke->IsRecursive()) {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001970 // temp = temp->dex_cache_resolved_methods_;
1971 __ Ldr(temp, HeapOperand(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset()));
1972 // temp = temp[index_in_cache];
1973 __ Ldr(temp, HeapOperand(temp, index_in_cache));
1974 // lr = temp->entry_point_from_quick_compiled_code_;
1975 __ Ldr(lr, HeapOperand(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1976 kArm64WordSize)));
1977 // lr();
1978 __ Blr(lr);
1979 } else {
1980 __ Bl(&frame_entry_label_);
1981 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001982
Andreas Gampe878d58c2015-01-15 23:24:00 -08001983 DCHECK(!IsLeafMethod());
1984}
1985
1986void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
1987 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1988 return;
1989 }
1990
1991 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1992 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001993 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01001994}
1995
1996void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001997 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1998 return;
1999 }
2000
Alexandre Rames5319def2014-10-23 10:03:10 +01002001 LocationSummary* locations = invoke->GetLocations();
2002 Location receiver = locations->InAt(0);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002003 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002004 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
2005 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
2006 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00002007 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames5319def2014-10-23 10:03:10 +01002008
2009 // temp = object->GetClass();
2010 if (receiver.IsStackSlot()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002011 __ Ldr(temp, MemOperand(sp, receiver.GetStackIndex()));
2012 __ Ldr(temp, HeapOperand(temp, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002013 } else {
2014 DCHECK(receiver.IsRegister());
Serban Constantinescu02164b32014-11-13 14:05:07 +00002015 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002016 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002017 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames5319def2014-10-23 10:03:10 +01002018 // temp = temp->GetMethodAt(method_offset);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002019 __ Ldr(temp, HeapOperand(temp, method_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002020 // lr = temp->GetEntryPoint();
Serban Constantinescu02164b32014-11-13 14:05:07 +00002021 __ Ldr(lr, HeapOperand(temp, entry_point.SizeValue()));
Alexandre Rames5319def2014-10-23 10:03:10 +01002022 // lr();
2023 __ Blr(lr);
2024 DCHECK(!codegen_->IsLeafMethod());
2025 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2026}
2027
Alexandre Rames67555f72014-11-18 10:55:16 +00002028void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
2029 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2030 : LocationSummary::kNoCall;
2031 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2032 locations->SetOut(Location::RequiresRegister());
2033}
2034
2035void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
2036 Register out = OutputRegister(cls);
2037 if (cls->IsReferrersClass()) {
2038 DCHECK(!cls->CanCallRuntime());
2039 DCHECK(!cls->MustGenerateClinitCheck());
2040 codegen_->LoadCurrentMethod(out);
2041 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2042 } else {
2043 DCHECK(cls->CanCallRuntime());
2044 codegen_->LoadCurrentMethod(out);
2045 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DexCacheResolvedTypesOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002046 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002047
2048 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2049 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2050 codegen_->AddSlowPath(slow_path);
2051 __ Cbz(out, slow_path->GetEntryLabel());
2052 if (cls->MustGenerateClinitCheck()) {
2053 GenerateClassInitializationCheck(slow_path, out);
2054 } else {
2055 __ Bind(slow_path->GetExitLabel());
2056 }
2057 }
2058}
2059
2060void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
2061 LocationSummary* locations =
2062 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2063 locations->SetOut(Location::RequiresRegister());
2064}
2065
2066void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
2067 MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value());
2068 __ Ldr(OutputRegister(instruction), exception);
2069 __ Str(wzr, exception);
2070}
2071
Alexandre Rames5319def2014-10-23 10:03:10 +01002072void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
2073 load->SetLocations(nullptr);
2074}
2075
2076void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
2077 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002078 UNUSED(load);
Alexandre Rames5319def2014-10-23 10:03:10 +01002079}
2080
Alexandre Rames67555f72014-11-18 10:55:16 +00002081void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
2082 LocationSummary* locations =
2083 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2084 locations->SetOut(Location::RequiresRegister());
2085}
2086
2087void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
2088 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load);
2089 codegen_->AddSlowPath(slow_path);
2090
2091 Register out = OutputRegister(load);
2092 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08002093 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2094 __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002095 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002096 __ Cbz(out, slow_path->GetEntryLabel());
2097 __ Bind(slow_path->GetExitLabel());
2098}
2099
Alexandre Rames5319def2014-10-23 10:03:10 +01002100void LocationsBuilderARM64::VisitLocal(HLocal* local) {
2101 local->SetLocations(nullptr);
2102}
2103
2104void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
2105 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2106}
2107
2108void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
2109 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2110 locations->SetOut(Location::ConstantLocation(constant));
2111}
2112
2113void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
2114 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002115 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002116}
2117
Alexandre Rames67555f72014-11-18 10:55:16 +00002118void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2119 LocationSummary* locations =
2120 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2121 InvokeRuntimeCallingConvention calling_convention;
2122 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2123}
2124
2125void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2126 codegen_->InvokeRuntime(instruction->IsEnter()
2127 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2128 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002129 instruction->GetDexPc(),
2130 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002131 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002132}
2133
Alexandre Rames42d641b2014-10-27 14:00:51 +00002134void LocationsBuilderARM64::VisitMul(HMul* mul) {
2135 LocationSummary* locations =
2136 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2137 switch (mul->GetResultType()) {
2138 case Primitive::kPrimInt:
2139 case Primitive::kPrimLong:
2140 locations->SetInAt(0, Location::RequiresRegister());
2141 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002142 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002143 break;
2144
2145 case Primitive::kPrimFloat:
2146 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002147 locations->SetInAt(0, Location::RequiresFpuRegister());
2148 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002149 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002150 break;
2151
2152 default:
2153 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2154 }
2155}
2156
2157void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
2158 switch (mul->GetResultType()) {
2159 case Primitive::kPrimInt:
2160 case Primitive::kPrimLong:
2161 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
2162 break;
2163
2164 case Primitive::kPrimFloat:
2165 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002166 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00002167 break;
2168
2169 default:
2170 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2171 }
2172}
2173
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002174void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
2175 LocationSummary* locations =
2176 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2177 switch (neg->GetResultType()) {
2178 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00002179 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002180 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00002181 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002182 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002183
2184 case Primitive::kPrimFloat:
2185 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002186 locations->SetInAt(0, Location::RequiresFpuRegister());
2187 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002188 break;
2189
2190 default:
2191 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2192 }
2193}
2194
2195void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
2196 switch (neg->GetResultType()) {
2197 case Primitive::kPrimInt:
2198 case Primitive::kPrimLong:
2199 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
2200 break;
2201
2202 case Primitive::kPrimFloat:
2203 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002204 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002205 break;
2206
2207 default:
2208 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2209 }
2210}
2211
2212void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
2213 LocationSummary* locations =
2214 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2215 InvokeRuntimeCallingConvention calling_convention;
2216 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002217 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002218 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002219 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
2220 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2221 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002222}
2223
2224void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
2225 LocationSummary* locations = instruction->GetLocations();
2226 InvokeRuntimeCallingConvention calling_convention;
2227 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2228 DCHECK(type_index.Is(w0));
2229 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002230 DCHECK(current_method.Is(w2));
Alexandre Rames67555f72014-11-18 10:55:16 +00002231 codegen_->LoadCurrentMethod(current_method);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002232 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002233 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002234 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2235 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002236 instruction->GetDexPc(),
2237 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002238 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2239 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002240}
2241
Alexandre Rames5319def2014-10-23 10:03:10 +01002242void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
2243 LocationSummary* locations =
2244 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2245 InvokeRuntimeCallingConvention calling_convention;
2246 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2247 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2248 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002249 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002250}
2251
2252void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
2253 LocationSummary* locations = instruction->GetLocations();
2254 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2255 DCHECK(type_index.Is(w0));
2256 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
2257 DCHECK(current_method.Is(w1));
Alexandre Rames67555f72014-11-18 10:55:16 +00002258 codegen_->LoadCurrentMethod(current_method);
Alexandre Rames5319def2014-10-23 10:03:10 +01002259 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002260 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002261 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2262 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002263 instruction->GetDexPc(),
2264 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002265 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002266}
2267
2268void LocationsBuilderARM64::VisitNot(HNot* instruction) {
2269 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00002270 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002271 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002272}
2273
2274void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002275 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002276 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002277 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01002278 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002279 break;
2280
2281 default:
2282 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2283 }
2284}
2285
David Brazdil66d126e2015-04-03 16:02:44 +01002286void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) {
2287 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2288 locations->SetInAt(0, Location::RequiresRegister());
2289 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2290}
2291
2292void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) {
2293 DCHECK_EQ(instruction->InputAt(0)->GetType(), Primitive::kPrimBoolean);
2294 __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1));
2295}
2296
Alexandre Rames5319def2014-10-23 10:03:10 +01002297void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
2298 LocationSummary* locations =
2299 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2300 locations->SetInAt(0, Location::RequiresRegister());
2301 if (instruction->HasUses()) {
2302 locations->SetOut(Location::SameAsFirstInput());
2303 }
2304}
2305
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002306void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002307 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2308 return;
2309 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002310 Location obj = instruction->GetLocations()->InAt(0);
2311
2312 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
2313 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2314}
2315
2316void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002317 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
2318 codegen_->AddSlowPath(slow_path);
2319
2320 LocationSummary* locations = instruction->GetLocations();
2321 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002322
2323 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01002324}
2325
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002326void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
2327 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2328 GenerateImplicitNullCheck(instruction);
2329 } else {
2330 GenerateExplicitNullCheck(instruction);
2331 }
2332}
2333
Alexandre Rames67555f72014-11-18 10:55:16 +00002334void LocationsBuilderARM64::VisitOr(HOr* instruction) {
2335 HandleBinaryOp(instruction);
2336}
2337
2338void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
2339 HandleBinaryOp(instruction);
2340}
2341
Alexandre Rames3e69f162014-12-10 10:36:50 +00002342void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2343 LOG(FATAL) << "Unreachable";
2344}
2345
2346void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
2347 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2348}
2349
Alexandre Rames5319def2014-10-23 10:03:10 +01002350void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
2351 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2352 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2353 if (location.IsStackSlot()) {
2354 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2355 } else if (location.IsDoubleStackSlot()) {
2356 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2357 }
2358 locations->SetOut(location);
2359}
2360
2361void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) {
2362 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002363 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002364}
2365
2366void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
2367 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2368 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2369 locations->SetInAt(i, Location::Any());
2370 }
2371 locations->SetOut(Location::Any());
2372}
2373
2374void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002375 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002376 LOG(FATAL) << "Unreachable";
2377}
2378
Serban Constantinescu02164b32014-11-13 14:05:07 +00002379void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002380 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00002381 LocationSummary::CallKind call_kind =
2382 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002383 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2384
2385 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002386 case Primitive::kPrimInt:
2387 case Primitive::kPrimLong:
2388 locations->SetInAt(0, Location::RequiresRegister());
2389 locations->SetInAt(1, Location::RequiresRegister());
2390 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2391 break;
2392
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002393 case Primitive::kPrimFloat:
2394 case Primitive::kPrimDouble: {
2395 InvokeRuntimeCallingConvention calling_convention;
2396 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
2397 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
2398 locations->SetOut(calling_convention.GetReturnLocation(type));
2399
2400 break;
2401 }
2402
Serban Constantinescu02164b32014-11-13 14:05:07 +00002403 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002404 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00002405 }
2406}
2407
2408void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
2409 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002410
Serban Constantinescu02164b32014-11-13 14:05:07 +00002411 switch (type) {
2412 case Primitive::kPrimInt:
2413 case Primitive::kPrimLong: {
2414 UseScratchRegisterScope temps(GetVIXLAssembler());
2415 Register dividend = InputRegisterAt(rem, 0);
2416 Register divisor = InputRegisterAt(rem, 1);
2417 Register output = OutputRegister(rem);
2418 Register temp = temps.AcquireSameSizeAs(output);
2419
2420 __ Sdiv(temp, dividend, divisor);
2421 __ Msub(output, temp, divisor, dividend);
2422 break;
2423 }
2424
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002425 case Primitive::kPrimFloat:
2426 case Primitive::kPrimDouble: {
2427 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2428 : QUICK_ENTRY_POINT(pFmod);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002429 codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002430 break;
2431 }
2432
Serban Constantinescu02164b32014-11-13 14:05:07 +00002433 default:
2434 LOG(FATAL) << "Unexpected rem type " << type;
2435 }
2436}
2437
Alexandre Rames5319def2014-10-23 10:03:10 +01002438void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
2439 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2440 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002441 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01002442}
2443
2444void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002445 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002446 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002447}
2448
2449void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
2450 instruction->SetLocations(nullptr);
2451}
2452
2453void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002454 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002455 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002456}
2457
Serban Constantinescu02164b32014-11-13 14:05:07 +00002458void LocationsBuilderARM64::VisitShl(HShl* shl) {
2459 HandleShift(shl);
2460}
2461
2462void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
2463 HandleShift(shl);
2464}
2465
2466void LocationsBuilderARM64::VisitShr(HShr* shr) {
2467 HandleShift(shr);
2468}
2469
2470void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
2471 HandleShift(shr);
2472}
2473
Alexandre Rames5319def2014-10-23 10:03:10 +01002474void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
2475 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2476 Primitive::Type field_type = store->InputAt(1)->GetType();
2477 switch (field_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002478 case Primitive::kPrimNot:
Alexandre Rames5319def2014-10-23 10:03:10 +01002479 case Primitive::kPrimBoolean:
2480 case Primitive::kPrimByte:
2481 case Primitive::kPrimChar:
2482 case Primitive::kPrimShort:
2483 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002484 case Primitive::kPrimFloat:
Alexandre Rames5319def2014-10-23 10:03:10 +01002485 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2486 break;
2487
2488 case Primitive::kPrimLong:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002489 case Primitive::kPrimDouble:
Alexandre Rames5319def2014-10-23 10:03:10 +01002490 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2491 break;
2492
2493 default:
2494 LOG(FATAL) << "Unimplemented local type " << field_type;
2495 }
2496}
2497
2498void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002499 UNUSED(store);
Alexandre Rames5319def2014-10-23 10:03:10 +01002500}
2501
2502void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002503 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002504}
2505
2506void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002507 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002508}
2509
Alexandre Rames67555f72014-11-18 10:55:16 +00002510void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2511 LocationSummary* locations =
2512 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2513 locations->SetInAt(0, Location::RequiresRegister());
2514 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2515}
2516
2517void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002518 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00002519 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002520
2521 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002522 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002523 // NB: LoadAcquire will record the pc info if needed.
2524 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002525 } else {
2526 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2527 // For IRIW sequential consistency kLoadAny is not sufficient.
2528 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2529 }
2530 } else {
2531 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2532 }
Alexandre Rames67555f72014-11-18 10:55:16 +00002533}
2534
2535void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002536 LocationSummary* locations =
2537 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2538 locations->SetInAt(0, Location::RequiresRegister());
2539 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames5319def2014-10-23 10:03:10 +01002540}
2541
Alexandre Rames67555f72014-11-18 10:55:16 +00002542void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002543 Register cls = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002544 CPURegister value = InputCPURegisterAt(instruction, 1);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002545 Offset offset = instruction->GetFieldOffset();
Alexandre Rames67555f72014-11-18 10:55:16 +00002546 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00002547 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Alexandre Rames5319def2014-10-23 10:03:10 +01002548
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002549 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002550 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002551 codegen_->StoreRelease(field_type, value, HeapOperand(cls, offset));
2552 } else {
2553 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2554 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2555 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2556 }
2557 } else {
2558 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2559 }
2560
2561 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002562 codegen_->MarkGCCard(cls, Register(value));
2563 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002564}
2565
2566void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
2567 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2568}
2569
2570void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002571 HBasicBlock* block = instruction->GetBlock();
2572 if (block->GetLoopInformation() != nullptr) {
2573 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2574 // The back edge will generate the suspend check.
2575 return;
2576 }
2577 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2578 // The goto will generate the suspend check.
2579 return;
2580 }
2581 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01002582}
2583
2584void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
2585 temp->SetLocations(nullptr);
2586}
2587
2588void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
2589 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002590 UNUSED(temp);
Alexandre Rames5319def2014-10-23 10:03:10 +01002591}
2592
Alexandre Rames67555f72014-11-18 10:55:16 +00002593void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
2594 LocationSummary* locations =
2595 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2596 InvokeRuntimeCallingConvention calling_convention;
2597 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2598}
2599
2600void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
2601 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002602 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002603 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002604}
2605
2606void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
2607 LocationSummary* locations =
2608 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
2609 Primitive::Type input_type = conversion->GetInputType();
2610 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002611 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00002612 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
2613 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
2614 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
2615 }
2616
Alexandre Rames542361f2015-01-29 16:57:31 +00002617 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002618 locations->SetInAt(0, Location::RequiresFpuRegister());
2619 } else {
2620 locations->SetInAt(0, Location::RequiresRegister());
2621 }
2622
Alexandre Rames542361f2015-01-29 16:57:31 +00002623 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002624 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2625 } else {
2626 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2627 }
2628}
2629
2630void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
2631 Primitive::Type result_type = conversion->GetResultType();
2632 Primitive::Type input_type = conversion->GetInputType();
2633
2634 DCHECK_NE(input_type, result_type);
2635
Alexandre Rames542361f2015-01-29 16:57:31 +00002636 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002637 int result_size = Primitive::ComponentSize(result_type);
2638 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002639 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002640 Register output = OutputRegister(conversion);
2641 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002642 if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) {
2643 __ Ubfx(output, source, 0, result_size * kBitsPerByte);
2644 } else if ((result_type == Primitive::kPrimChar) ||
2645 ((input_type == Primitive::kPrimChar) && (result_size > input_size))) {
2646 __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002647 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00002648 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002649 }
Alexandre Rames542361f2015-01-29 16:57:31 +00002650 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002651 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002652 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002653 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
2654 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002655 } else if (Primitive::IsFloatingPointType(result_type) &&
2656 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002657 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
2658 } else {
2659 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
2660 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00002661 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00002662}
Alexandre Rames67555f72014-11-18 10:55:16 +00002663
Serban Constantinescu02164b32014-11-13 14:05:07 +00002664void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
2665 HandleShift(ushr);
2666}
2667
2668void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
2669 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00002670}
2671
2672void LocationsBuilderARM64::VisitXor(HXor* instruction) {
2673 HandleBinaryOp(instruction);
2674}
2675
2676void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
2677 HandleBinaryOp(instruction);
2678}
2679
Calin Juravleb1498f62015-02-16 13:13:29 +00002680void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) {
2681 // Nothing to do, this should be removed during prepare for register allocator.
2682 UNUSED(instruction);
2683 LOG(FATAL) << "Unreachable";
2684}
2685
2686void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) {
2687 // Nothing to do, this should be removed during prepare for register allocator.
2688 UNUSED(instruction);
2689 LOG(FATAL) << "Unreachable";
2690}
2691
Alexandre Rames67555f72014-11-18 10:55:16 +00002692#undef __
2693#undef QUICK_ENTRY_POINT
2694
Alexandre Rames5319def2014-10-23 10:03:10 +01002695} // namespace arm64
2696} // namespace art