blob: 33eacbaf08ad3c0cccc70711afdc1f67883d84bb [file] [log] [blame]
Alexandre Rames5319def2014-10-23 10:03:10 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_arm64.h"
18
Serban Constantinescu579885a2015-02-22 20:51:33 +000019#include "arch/arm64/instruction_set_features_arm64.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080020#include "common_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010021#include "entrypoints/quick/quick_entrypoints.h"
Andreas Gampe1cc7dba2014-12-17 18:43:01 -080022#include "entrypoints/quick/quick_entrypoints_enum.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010023#include "gc/accounting/card_table.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080024#include "intrinsics.h"
25#include "intrinsics_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010026#include "mirror/array-inl.h"
27#include "mirror/art_method.h"
28#include "mirror/class.h"
Calin Juravlecd6dffe2015-01-08 17:35:35 +000029#include "offsets.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010030#include "thread.h"
31#include "utils/arm64/assembler_arm64.h"
32#include "utils/assembler.h"
33#include "utils/stack_checks.h"
34
35
36using namespace vixl; // NOLINT(build/namespaces)
37
38#ifdef __
39#error "ARM64 Codegen VIXL macro-assembler macro already defined."
40#endif
41
Alexandre Rames5319def2014-10-23 10:03:10 +010042namespace art {
43
44namespace arm64 {
45
Andreas Gampe878d58c2015-01-15 23:24:00 -080046using helpers::CPURegisterFrom;
47using helpers::DRegisterFrom;
48using helpers::FPRegisterFrom;
49using helpers::HeapOperand;
50using helpers::HeapOperandFrom;
51using helpers::InputCPURegisterAt;
52using helpers::InputFPRegisterAt;
53using helpers::InputRegisterAt;
54using helpers::InputOperandAt;
55using helpers::Int64ConstantFrom;
Andreas Gampe878d58c2015-01-15 23:24:00 -080056using helpers::LocationFrom;
57using helpers::OperandFromMemOperand;
58using helpers::OutputCPURegister;
59using helpers::OutputFPRegister;
60using helpers::OutputRegister;
61using helpers::RegisterFrom;
62using helpers::StackOperandFrom;
63using helpers::VIXLRegCodeFromART;
64using helpers::WRegisterFrom;
65using helpers::XRegisterFrom;
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +000066using helpers::ARM64EncodableConstantOrRegister;
Andreas Gampe878d58c2015-01-15 23:24:00 -080067
Alexandre Rames5319def2014-10-23 10:03:10 +010068static constexpr size_t kHeapRefSize = sizeof(mirror::HeapReference<mirror::Object>);
69static constexpr int kCurrentMethodStackOffset = 0;
70
Alexandre Rames5319def2014-10-23 10:03:10 +010071inline Condition ARM64Condition(IfCondition cond) {
72 switch (cond) {
73 case kCondEQ: return eq;
74 case kCondNE: return ne;
75 case kCondLT: return lt;
76 case kCondLE: return le;
77 case kCondGT: return gt;
78 case kCondGE: return ge;
79 default:
80 LOG(FATAL) << "Unknown if condition";
81 }
82 return nv; // Unreachable.
83}
84
Alexandre Ramesa89086e2014-11-07 17:13:25 +000085Location ARM64ReturnLocation(Primitive::Type return_type) {
86 DCHECK_NE(return_type, Primitive::kPrimVoid);
87 // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the
88 // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`,
89 // but we use the exact registers for clarity.
90 if (return_type == Primitive::kPrimFloat) {
91 return LocationFrom(s0);
92 } else if (return_type == Primitive::kPrimDouble) {
93 return LocationFrom(d0);
94 } else if (return_type == Primitive::kPrimLong) {
95 return LocationFrom(x0);
96 } else {
97 return LocationFrom(w0);
98 }
99}
100
Alexandre Rames5319def2014-10-23 10:03:10 +0100101Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000102 return ARM64ReturnLocation(return_type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100103}
104
Alexandre Rames67555f72014-11-18 10:55:16 +0000105#define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()->
106#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value()
Alexandre Rames5319def2014-10-23 10:03:10 +0100107
Alexandre Rames5319def2014-10-23 10:03:10 +0100108class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 {
109 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000110 BoundsCheckSlowPathARM64(HBoundsCheck* instruction,
111 Location index_location,
112 Location length_location)
113 : instruction_(instruction),
114 index_location_(index_location),
115 length_location_(length_location) {}
116
Alexandre Rames5319def2014-10-23 10:03:10 +0100117
Alexandre Rames67555f72014-11-18 10:55:16 +0000118 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000119 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100120 __ Bind(GetEntryLabel());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000121 // We're moving two locations to locations that could overlap, so we need a parallel
122 // move resolver.
123 InvokeRuntimeCallingConvention calling_convention;
124 codegen->EmitParallelMoves(
125 index_location_, LocationFrom(calling_convention.GetRegisterAt(0)),
126 length_location_, LocationFrom(calling_convention.GetRegisterAt(1)));
127 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000128 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800129 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100130 }
131
132 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000133 HBoundsCheck* const instruction_;
134 const Location index_location_;
135 const Location length_location_;
136
Alexandre Rames5319def2014-10-23 10:03:10 +0100137 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64);
138};
139
Alexandre Rames67555f72014-11-18 10:55:16 +0000140class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 {
141 public:
142 explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : instruction_(instruction) {}
143
144 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
145 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
146 __ Bind(GetEntryLabel());
147 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000148 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800149 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000150 }
151
152 private:
153 HDivZeroCheck* const instruction_;
154 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64);
155};
156
157class LoadClassSlowPathARM64 : public SlowPathCodeARM64 {
158 public:
159 LoadClassSlowPathARM64(HLoadClass* cls,
160 HInstruction* at,
161 uint32_t dex_pc,
162 bool do_clinit)
163 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
164 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
165 }
166
167 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
168 LocationSummary* locations = at_->GetLocations();
169 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
170
171 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000172 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000173
174 InvokeRuntimeCallingConvention calling_convention;
175 __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex());
176 arm64_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1).W());
177 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
178 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000179 arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800180 if (do_clinit_) {
181 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t, mirror::ArtMethod*>();
182 } else {
183 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t, mirror::ArtMethod*>();
184 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000185
186 // Move the class to the desired location.
187 Location out = locations->Out();
188 if (out.IsValid()) {
189 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
190 Primitive::Type type = at_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000191 arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000192 }
193
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000194 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000195 __ B(GetExitLabel());
196 }
197
198 private:
199 // The class this slow path will load.
200 HLoadClass* const cls_;
201
202 // The instruction where this slow path is happening.
203 // (Might be the load class or an initialization check).
204 HInstruction* const at_;
205
206 // The dex PC of `at_`.
207 const uint32_t dex_pc_;
208
209 // Whether to initialize the class.
210 const bool do_clinit_;
211
212 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64);
213};
214
215class LoadStringSlowPathARM64 : public SlowPathCodeARM64 {
216 public:
217 explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {}
218
219 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
220 LocationSummary* locations = instruction_->GetLocations();
221 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
222 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
223
224 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000225 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000226
227 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800228 arm64_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1).W());
229 __ Mov(calling_convention.GetRegisterAt(0).W(), instruction_->GetStringIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +0000230 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000231 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800232 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000233 Primitive::Type type = instruction_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000234 arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000235
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000236 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000237 __ B(GetExitLabel());
238 }
239
240 private:
241 HLoadString* const instruction_;
242
243 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64);
244};
245
Alexandre Rames5319def2014-10-23 10:03:10 +0100246class NullCheckSlowPathARM64 : public SlowPathCodeARM64 {
247 public:
248 explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {}
249
Alexandre Rames67555f72014-11-18 10:55:16 +0000250 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
251 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100252 __ Bind(GetEntryLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000253 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000254 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800255 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100256 }
257
258 private:
259 HNullCheck* const instruction_;
260
261 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64);
262};
263
264class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 {
265 public:
266 explicit SuspendCheckSlowPathARM64(HSuspendCheck* instruction,
267 HBasicBlock* successor)
268 : instruction_(instruction), successor_(successor) {}
269
Alexandre Rames67555f72014-11-18 10:55:16 +0000270 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
271 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100272 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000273 SaveLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000274 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000275 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800276 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000277 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000278 if (successor_ == nullptr) {
279 __ B(GetReturnLabel());
280 } else {
281 __ B(arm64_codegen->GetLabelOf(successor_));
282 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100283 }
284
285 vixl::Label* GetReturnLabel() {
286 DCHECK(successor_ == nullptr);
287 return &return_label_;
288 }
289
Alexandre Rames5319def2014-10-23 10:03:10 +0100290 private:
291 HSuspendCheck* const instruction_;
292 // If not null, the block to branch to after the suspend check.
293 HBasicBlock* const successor_;
294
295 // If `successor_` is null, the label to branch to after the suspend check.
296 vixl::Label return_label_;
297
298 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64);
299};
300
Alexandre Rames67555f72014-11-18 10:55:16 +0000301class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 {
302 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000303 TypeCheckSlowPathARM64(HInstruction* instruction,
304 Location class_to_check,
305 Location object_class,
306 uint32_t dex_pc)
307 : instruction_(instruction),
308 class_to_check_(class_to_check),
309 object_class_(object_class),
310 dex_pc_(dex_pc) {}
Alexandre Rames67555f72014-11-18 10:55:16 +0000311
312 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000313 LocationSummary* locations = instruction_->GetLocations();
314 DCHECK(instruction_->IsCheckCast()
315 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
316 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
317
Alexandre Rames67555f72014-11-18 10:55:16 +0000318 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000319 SaveLiveRegisters(codegen, locations);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000320
321 // We're moving two locations to locations that could overlap, so we need a parallel
322 // move resolver.
323 InvokeRuntimeCallingConvention calling_convention;
324 codegen->EmitParallelMoves(
325 class_to_check_, LocationFrom(calling_convention.GetRegisterAt(0)),
326 object_class_, LocationFrom(calling_convention.GetRegisterAt(1)));
327
328 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000329 arm64_codegen->InvokeRuntime(
330 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000331 Primitive::Type ret_type = instruction_->GetType();
332 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
333 arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800334 CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t,
335 const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000336 } else {
337 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000338 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800339 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000340 }
341
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000342 RestoreLiveRegisters(codegen, locations);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000343 __ B(GetExitLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000344 }
345
346 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000347 HInstruction* const instruction_;
348 const Location class_to_check_;
349 const Location object_class_;
350 uint32_t dex_pc_;
351
Alexandre Rames67555f72014-11-18 10:55:16 +0000352 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64);
353};
354
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700355class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 {
356 public:
357 explicit DeoptimizationSlowPathARM64(HInstruction* instruction)
358 : instruction_(instruction) {}
359
360 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
361 __ Bind(GetEntryLabel());
362 SaveLiveRegisters(codegen, instruction_->GetLocations());
363 DCHECK(instruction_->IsDeoptimize());
364 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
365 uint32_t dex_pc = deoptimize->GetDexPc();
366 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
367 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
368 }
369
370 private:
371 HInstruction* const instruction_;
372 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64);
373};
374
Alexandre Rames5319def2014-10-23 10:03:10 +0100375#undef __
376
377Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
378 Location next_location;
379 if (type == Primitive::kPrimVoid) {
380 LOG(FATAL) << "Unreachable type " << type;
381 }
382
Alexandre Rames542361f2015-01-29 16:57:31 +0000383 if (Primitive::IsFloatingPointType(type) &&
384 (fp_index_ < calling_convention.GetNumberOfFpuRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000385 next_location = LocationFrom(calling_convention.GetFpuRegisterAt(fp_index_++));
Alexandre Rames542361f2015-01-29 16:57:31 +0000386 } else if (!Primitive::IsFloatingPointType(type) &&
387 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000388 next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++));
389 } else {
390 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Alexandre Rames542361f2015-01-29 16:57:31 +0000391 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
392 : Location::StackSlot(stack_offset);
Alexandre Rames5319def2014-10-23 10:03:10 +0100393 }
394
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000395 // Space on the stack is reserved for all arguments.
Alexandre Rames542361f2015-01-29 16:57:31 +0000396 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
Alexandre Rames5319def2014-10-23 10:03:10 +0100397 return next_location;
398}
399
Serban Constantinescu579885a2015-02-22 20:51:33 +0000400CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph,
401 const Arm64InstructionSetFeatures& isa_features,
402 const CompilerOptions& compiler_options)
Alexandre Rames5319def2014-10-23 10:03:10 +0100403 : CodeGenerator(graph,
404 kNumberOfAllocatableRegisters,
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000405 kNumberOfAllocatableFPRegisters,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000406 kNumberOfAllocatableRegisterPairs,
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000407 callee_saved_core_registers.list(),
408 callee_saved_fp_registers.list(),
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000409 compiler_options),
Alexandre Rames5319def2014-10-23 10:03:10 +0100410 block_labels_(nullptr),
411 location_builder_(graph, this),
Alexandre Rames3e69f162014-12-10 10:36:50 +0000412 instruction_visitor_(graph, this),
Serban Constantinescu579885a2015-02-22 20:51:33 +0000413 move_resolver_(graph->GetArena(), this),
414 isa_features_(isa_features) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000415 // Save the link register (containing the return address) to mimic Quick.
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000416 AddAllocatedRegister(LocationFrom(lr));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000417}
Alexandre Rames5319def2014-10-23 10:03:10 +0100418
Alexandre Rames67555f72014-11-18 10:55:16 +0000419#undef __
420#define __ GetVIXLAssembler()->
Alexandre Rames5319def2014-10-23 10:03:10 +0100421
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000422void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) {
423 // Ensure we emit the literal pool.
424 __ FinalizeCode();
425 CodeGenerator::Finalize(allocator);
426}
427
Alexandre Rames3e69f162014-12-10 10:36:50 +0000428void ParallelMoveResolverARM64::EmitMove(size_t index) {
429 MoveOperands* move = moves_.Get(index);
430 codegen_->MoveLocation(move->GetDestination(), move->GetSource());
431}
432
433void ParallelMoveResolverARM64::EmitSwap(size_t index) {
434 MoveOperands* move = moves_.Get(index);
435 codegen_->SwapLocations(move->GetDestination(), move->GetSource());
436}
437
438void ParallelMoveResolverARM64::RestoreScratch(int reg) {
439 __ Pop(Register(VIXLRegCodeFromART(reg), kXRegSize));
440}
441
442void ParallelMoveResolverARM64::SpillScratch(int reg) {
443 __ Push(Register(VIXLRegCodeFromART(reg), kXRegSize));
444}
445
Alexandre Rames5319def2014-10-23 10:03:10 +0100446void CodeGeneratorARM64::GenerateFrameEntry() {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000447 __ Bind(&frame_entry_label_);
448
Serban Constantinescu02164b32014-11-13 14:05:07 +0000449 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod();
450 if (do_overflow_check) {
451 UseScratchRegisterScope temps(GetVIXLAssembler());
452 Register temp = temps.AcquireX();
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000453 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000454 __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64)));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000455 __ Ldr(wzr, MemOperand(temp, 0));
456 RecordPcInfo(nullptr, 0);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000457 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100458
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000459 if (!HasEmptyFrame()) {
460 int frame_size = GetFrameSize();
461 // Stack layout:
462 // sp[frame_size - 8] : lr.
463 // ... : other preserved core registers.
464 // ... : other preserved fp registers.
465 // ... : reserved frame space.
466 // sp[0] : current method.
467 __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100468 GetAssembler()->cfi().AdjustCFAOffset(frame_size);
469 SpillRegisters(GetFramePreservedCoreRegisters(), frame_size - GetCoreSpillSize());
470 SpillRegisters(GetFramePreservedFPRegisters(), frame_size - FrameEntrySpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000471 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100472}
473
474void CodeGeneratorARM64::GenerateFrameExit() {
David Srbeckyc34dc932015-04-12 09:27:43 +0100475 GetAssembler()->cfi().RememberState();
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000476 if (!HasEmptyFrame()) {
477 int frame_size = GetFrameSize();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100478 UnspillRegisters(GetFramePreservedFPRegisters(), frame_size - FrameEntrySpillSize());
479 UnspillRegisters(GetFramePreservedCoreRegisters(), frame_size - GetCoreSpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000480 __ Drop(frame_size);
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100481 GetAssembler()->cfi().AdjustCFAOffset(-frame_size);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000482 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100483 __ Ret();
484 GetAssembler()->cfi().RestoreState();
485 GetAssembler()->cfi().DefCFAOffset(GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +0100486}
487
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100488static inline dwarf::Reg DWARFReg(CPURegister reg) {
489 if (reg.IsFPRegister()) {
490 return dwarf::Reg::Arm64Fp(reg.code());
491 } else {
492 DCHECK_LT(reg.code(), 31u); // X0 - X30.
493 return dwarf::Reg::Arm64Core(reg.code());
494 }
495}
496
497void CodeGeneratorARM64::SpillRegisters(vixl::CPURegList registers, int offset) {
498 int size = registers.RegisterSizeInBytes();
499 while (registers.Count() >= 2) {
500 const CPURegister& dst0 = registers.PopLowestIndex();
501 const CPURegister& dst1 = registers.PopLowestIndex();
502 __ Stp(dst0, dst1, MemOperand(__ StackPointer(), offset));
503 GetAssembler()->cfi().RelOffset(DWARFReg(dst0), offset);
504 GetAssembler()->cfi().RelOffset(DWARFReg(dst1), offset + size);
505 offset += 2 * size;
506 }
507 if (!registers.IsEmpty()) {
508 const CPURegister& dst0 = registers.PopLowestIndex();
509 __ Str(dst0, MemOperand(__ StackPointer(), offset));
510 GetAssembler()->cfi().RelOffset(DWARFReg(dst0), offset);
511 }
512 DCHECK(registers.IsEmpty());
513}
514
515void CodeGeneratorARM64::UnspillRegisters(vixl::CPURegList registers, int offset) {
516 int size = registers.RegisterSizeInBytes();
517 while (registers.Count() >= 2) {
518 const CPURegister& dst0 = registers.PopLowestIndex();
519 const CPURegister& dst1 = registers.PopLowestIndex();
520 __ Ldp(dst0, dst1, MemOperand(__ StackPointer(), offset));
521 GetAssembler()->cfi().Restore(DWARFReg(dst0));
522 GetAssembler()->cfi().Restore(DWARFReg(dst1));
523 offset += 2 * size;
524 }
525 if (!registers.IsEmpty()) {
526 const CPURegister& dst0 = registers.PopLowestIndex();
527 __ Ldr(dst0, MemOperand(__ StackPointer(), offset));
528 GetAssembler()->cfi().Restore(DWARFReg(dst0));
529 }
530 DCHECK(registers.IsEmpty());
531}
532
Alexandre Rames5319def2014-10-23 10:03:10 +0100533void CodeGeneratorARM64::Bind(HBasicBlock* block) {
534 __ Bind(GetLabelOf(block));
535}
536
Alexandre Rames5319def2014-10-23 10:03:10 +0100537void CodeGeneratorARM64::Move(HInstruction* instruction,
538 Location location,
539 HInstruction* move_for) {
540 LocationSummary* locations = instruction->GetLocations();
541 if (locations != nullptr && locations->Out().Equals(location)) {
542 return;
543 }
544
545 Primitive::Type type = instruction->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000546 DCHECK_NE(type, Primitive::kPrimVoid);
Alexandre Rames5319def2014-10-23 10:03:10 +0100547
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000548 if (instruction->IsIntConstant()
549 || instruction->IsLongConstant()
550 || instruction->IsNullConstant()) {
551 int64_t value = GetInt64ValueOf(instruction->AsConstant());
Alexandre Rames5319def2014-10-23 10:03:10 +0100552 if (location.IsRegister()) {
553 Register dst = RegisterFrom(location, type);
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000554 DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) ||
Alexandre Rames5319def2014-10-23 10:03:10 +0100555 (instruction->IsLongConstant() && dst.Is64Bits()));
556 __ Mov(dst, value);
557 } else {
558 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000559 UseScratchRegisterScope temps(GetVIXLAssembler());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000560 Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant())
561 ? temps.AcquireW()
562 : temps.AcquireX();
Alexandre Rames5319def2014-10-23 10:03:10 +0100563 __ Mov(temp, value);
564 __ Str(temp, StackOperandFrom(location));
565 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000566 } else if (instruction->IsTemporary()) {
567 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000568 MoveLocation(location, temp_location, type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100569 } else if (instruction->IsLoadLocal()) {
570 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Alexandre Rames542361f2015-01-29 16:57:31 +0000571 if (Primitive::Is64BitType(type)) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000572 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000573 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000574 MoveLocation(location, Location::StackSlot(stack_slot), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100575 }
576
577 } else {
578 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000579 MoveLocation(location, locations->Out(), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100580 }
581}
582
Alexandre Rames5319def2014-10-23 10:03:10 +0100583Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const {
584 Primitive::Type type = load->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000585
Alexandre Rames5319def2014-10-23 10:03:10 +0100586 switch (type) {
587 case Primitive::kPrimNot:
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000588 case Primitive::kPrimInt:
589 case Primitive::kPrimFloat:
590 return Location::StackSlot(GetStackSlot(load->GetLocal()));
591
592 case Primitive::kPrimLong:
593 case Primitive::kPrimDouble:
594 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
595
Alexandre Rames5319def2014-10-23 10:03:10 +0100596 case Primitive::kPrimBoolean:
597 case Primitive::kPrimByte:
598 case Primitive::kPrimChar:
599 case Primitive::kPrimShort:
Alexandre Rames5319def2014-10-23 10:03:10 +0100600 case Primitive::kPrimVoid:
Alexandre Rames5319def2014-10-23 10:03:10 +0100601 LOG(FATAL) << "Unexpected type " << type;
602 }
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000603
Alexandre Rames5319def2014-10-23 10:03:10 +0100604 LOG(FATAL) << "Unreachable";
605 return Location::NoLocation();
606}
607
608void CodeGeneratorARM64::MarkGCCard(Register object, Register value) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000609 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +0100610 Register card = temps.AcquireX();
Serban Constantinescu02164b32014-11-13 14:05:07 +0000611 Register temp = temps.AcquireW(); // Index within the CardTable - 32bit.
Alexandre Rames5319def2014-10-23 10:03:10 +0100612 vixl::Label done;
613 __ Cbz(value, &done);
614 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value()));
615 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000616 __ Strb(card, MemOperand(card, temp.X()));
Alexandre Rames5319def2014-10-23 10:03:10 +0100617 __ Bind(&done);
618}
619
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000620void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const {
621 // Blocked core registers:
622 // lr : Runtime reserved.
623 // tr : Runtime reserved.
624 // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it.
625 // ip1 : VIXL core temp.
626 // ip0 : VIXL core temp.
627 //
628 // Blocked fp registers:
629 // d31 : VIXL fp temp.
Alexandre Rames5319def2014-10-23 10:03:10 +0100630 CPURegList reserved_core_registers = vixl_reserved_core_registers;
631 reserved_core_registers.Combine(runtime_reserved_core_registers);
Alexandre Rames5319def2014-10-23 10:03:10 +0100632 while (!reserved_core_registers.IsEmpty()) {
633 blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true;
634 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000635
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000636 CPURegList reserved_fp_registers = vixl_reserved_fp_registers;
Zheng Xua3ec3942015-02-15 18:39:46 +0800637 while (!reserved_fp_registers.IsEmpty()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000638 blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true;
639 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000640
641 if (is_baseline) {
642 CPURegList reserved_core_baseline_registers = callee_saved_core_registers;
643 while (!reserved_core_baseline_registers.IsEmpty()) {
644 blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true;
645 }
646
647 CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers;
648 while (!reserved_fp_baseline_registers.IsEmpty()) {
649 blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true;
650 }
651 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100652}
653
654Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const {
655 if (type == Primitive::kPrimVoid) {
656 LOG(FATAL) << "Unreachable type " << type;
657 }
658
Alexandre Rames542361f2015-01-29 16:57:31 +0000659 if (Primitive::IsFloatingPointType(type)) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000660 ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters);
661 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100662 return Location::FpuRegisterLocation(reg);
663 } else {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000664 ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters);
665 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100666 return Location::RegisterLocation(reg);
667 }
668}
669
Alexandre Rames3e69f162014-12-10 10:36:50 +0000670size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
671 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
672 __ Str(reg, MemOperand(sp, stack_index));
673 return kArm64WordSize;
674}
675
676size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
677 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
678 __ Ldr(reg, MemOperand(sp, stack_index));
679 return kArm64WordSize;
680}
681
682size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
683 FPRegister reg = FPRegister(reg_id, kDRegSize);
684 __ Str(reg, MemOperand(sp, stack_index));
685 return kArm64WordSize;
686}
687
688size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
689 FPRegister reg = FPRegister(reg_id, kDRegSize);
690 __ Ldr(reg, MemOperand(sp, stack_index));
691 return kArm64WordSize;
692}
693
Alexandre Rames5319def2014-10-23 10:03:10 +0100694void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
695 stream << Arm64ManagedRegister::FromXRegister(XRegister(reg));
696}
697
698void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
699 stream << Arm64ManagedRegister::FromDRegister(DRegister(reg));
700}
701
Alexandre Rames67555f72014-11-18 10:55:16 +0000702void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000703 if (constant->IsIntConstant()) {
704 __ Mov(Register(destination), constant->AsIntConstant()->GetValue());
705 } else if (constant->IsLongConstant()) {
706 __ Mov(Register(destination), constant->AsLongConstant()->GetValue());
707 } else if (constant->IsNullConstant()) {
708 __ Mov(Register(destination), 0);
Alexandre Rames67555f72014-11-18 10:55:16 +0000709 } else if (constant->IsFloatConstant()) {
710 __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue());
711 } else {
712 DCHECK(constant->IsDoubleConstant());
713 __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue());
714 }
715}
716
Alexandre Rames3e69f162014-12-10 10:36:50 +0000717
718static bool CoherentConstantAndType(Location constant, Primitive::Type type) {
719 DCHECK(constant.IsConstant());
720 HConstant* cst = constant.GetConstant();
721 return (cst->IsIntConstant() && type == Primitive::kPrimInt) ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000722 // Null is mapped to a core W register, which we associate with kPrimInt.
723 (cst->IsNullConstant() && type == Primitive::kPrimInt) ||
Alexandre Rames3e69f162014-12-10 10:36:50 +0000724 (cst->IsLongConstant() && type == Primitive::kPrimLong) ||
725 (cst->IsFloatConstant() && type == Primitive::kPrimFloat) ||
726 (cst->IsDoubleConstant() && type == Primitive::kPrimDouble);
727}
728
729void CodeGeneratorARM64::MoveLocation(Location destination, Location source, Primitive::Type type) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000730 if (source.Equals(destination)) {
731 return;
732 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000733
734 // A valid move can always be inferred from the destination and source
735 // locations. When moving from and to a register, the argument type can be
736 // used to generate 32bit instead of 64bit moves. In debug mode we also
737 // checks the coherency of the locations and the type.
738 bool unspecified_type = (type == Primitive::kPrimVoid);
739
740 if (destination.IsRegister() || destination.IsFpuRegister()) {
741 if (unspecified_type) {
742 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
743 if (source.IsStackSlot() ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000744 (src_cst != nullptr && (src_cst->IsIntConstant()
745 || src_cst->IsFloatConstant()
746 || src_cst->IsNullConstant()))) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000747 // For stack slots and 32bit constants, a 64bit type is appropriate.
748 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexandre Rames67555f72014-11-18 10:55:16 +0000749 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000750 // If the source is a double stack slot or a 64bit constant, a 64bit
751 // type is appropriate. Else the source is a register, and since the
752 // type has not been specified, we chose a 64bit type to force a 64bit
753 // move.
754 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexandre Rames67555f72014-11-18 10:55:16 +0000755 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000756 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000757 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
758 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000759 CPURegister dst = CPURegisterFrom(destination, type);
760 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
761 DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot());
762 __ Ldr(dst, StackOperandFrom(source));
763 } else if (source.IsConstant()) {
764 DCHECK(CoherentConstantAndType(source, type));
765 MoveConstant(dst, source.GetConstant());
766 } else {
767 if (destination.IsRegister()) {
768 __ Mov(Register(dst), RegisterFrom(source, type));
769 } else {
770 __ Fmov(FPRegister(dst), FPRegisterFrom(source, type));
771 }
772 }
773
774 } else { // The destination is not a register. It must be a stack slot.
775 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
776 if (source.IsRegister() || source.IsFpuRegister()) {
777 if (unspecified_type) {
778 if (source.IsRegister()) {
779 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
780 } else {
781 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
782 }
783 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000784 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
785 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000786 __ Str(CPURegisterFrom(source, type), StackOperandFrom(destination));
787 } else if (source.IsConstant()) {
788 DCHECK(unspecified_type || CoherentConstantAndType(source, type));
789 UseScratchRegisterScope temps(GetVIXLAssembler());
790 HConstant* src_cst = source.GetConstant();
791 CPURegister temp;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000792 if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000793 temp = temps.AcquireW();
794 } else if (src_cst->IsLongConstant()) {
795 temp = temps.AcquireX();
796 } else if (src_cst->IsFloatConstant()) {
797 temp = temps.AcquireS();
798 } else {
799 DCHECK(src_cst->IsDoubleConstant());
800 temp = temps.AcquireD();
801 }
802 MoveConstant(temp, src_cst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000803 __ Str(temp, StackOperandFrom(destination));
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000804 } else {
Alexandre Rames67555f72014-11-18 10:55:16 +0000805 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000806 DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000807 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000808 // There is generally less pressure on FP registers.
809 FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS();
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000810 __ Ldr(temp, StackOperandFrom(source));
811 __ Str(temp, StackOperandFrom(destination));
812 }
813 }
814}
815
Alexandre Rames3e69f162014-12-10 10:36:50 +0000816void CodeGeneratorARM64::SwapLocations(Location loc1, Location loc2) {
817 DCHECK(!loc1.IsConstant());
818 DCHECK(!loc2.IsConstant());
819
820 if (loc1.Equals(loc2)) {
821 return;
822 }
823
824 UseScratchRegisterScope temps(GetAssembler()->vixl_masm_);
825
826 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
827 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
828 bool is_fp_reg1 = loc1.IsFpuRegister();
829 bool is_fp_reg2 = loc2.IsFpuRegister();
830
831 if (loc2.IsRegister() && loc1.IsRegister()) {
832 Register r1 = XRegisterFrom(loc1);
833 Register r2 = XRegisterFrom(loc2);
834 Register tmp = temps.AcquireSameSizeAs(r1);
835 __ Mov(tmp, r2);
836 __ Mov(r2, r1);
837 __ Mov(r1, tmp);
838 } else if (is_fp_reg2 && is_fp_reg1) {
839 FPRegister r1 = DRegisterFrom(loc1);
840 FPRegister r2 = DRegisterFrom(loc2);
841 FPRegister tmp = temps.AcquireSameSizeAs(r1);
842 __ Fmov(tmp, r2);
843 __ Fmov(r2, r1);
844 __ Fmov(r1, tmp);
845 } else if (is_slot1 != is_slot2) {
846 MemOperand mem = StackOperandFrom(is_slot1 ? loc1 : loc2);
847 Location reg_loc = is_slot1 ? loc2 : loc1;
848 CPURegister reg, tmp;
849 if (reg_loc.IsFpuRegister()) {
850 reg = DRegisterFrom(reg_loc);
851 tmp = temps.AcquireD();
852 } else {
853 reg = XRegisterFrom(reg_loc);
854 tmp = temps.AcquireX();
855 }
856 __ Ldr(tmp, mem);
857 __ Str(reg, mem);
858 if (reg_loc.IsFpuRegister()) {
859 __ Fmov(FPRegister(reg), FPRegister(tmp));
860 } else {
861 __ Mov(Register(reg), Register(tmp));
862 }
863 } else if (is_slot1 && is_slot2) {
864 MemOperand mem1 = StackOperandFrom(loc1);
865 MemOperand mem2 = StackOperandFrom(loc2);
866 Register tmp1 = loc1.IsStackSlot() ? temps.AcquireW() : temps.AcquireX();
867 Register tmp2 = temps.AcquireSameSizeAs(tmp1);
868 __ Ldr(tmp1, mem1);
869 __ Ldr(tmp2, mem2);
870 __ Str(tmp1, mem2);
871 __ Str(tmp2, mem1);
872 } else {
873 LOG(FATAL) << "Unimplemented";
874 }
875}
876
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000877void CodeGeneratorARM64::Load(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000878 CPURegister dst,
879 const MemOperand& src) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000880 switch (type) {
881 case Primitive::kPrimBoolean:
Alexandre Rames67555f72014-11-18 10:55:16 +0000882 __ Ldrb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000883 break;
884 case Primitive::kPrimByte:
Alexandre Rames67555f72014-11-18 10:55:16 +0000885 __ Ldrsb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000886 break;
887 case Primitive::kPrimShort:
Alexandre Rames67555f72014-11-18 10:55:16 +0000888 __ Ldrsh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000889 break;
890 case Primitive::kPrimChar:
Alexandre Rames67555f72014-11-18 10:55:16 +0000891 __ Ldrh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000892 break;
893 case Primitive::kPrimInt:
894 case Primitive::kPrimNot:
895 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000896 case Primitive::kPrimFloat:
897 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000898 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Rames67555f72014-11-18 10:55:16 +0000899 __ Ldr(dst, src);
900 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000901 case Primitive::kPrimVoid:
902 LOG(FATAL) << "Unreachable type " << type;
903 }
904}
905
Calin Juravle77520bc2015-01-12 18:45:46 +0000906void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000907 CPURegister dst,
908 const MemOperand& src) {
909 UseScratchRegisterScope temps(GetVIXLAssembler());
910 Register temp_base = temps.AcquireX();
Calin Juravle77520bc2015-01-12 18:45:46 +0000911 Primitive::Type type = instruction->GetType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000912
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000913 DCHECK(!src.IsPreIndex());
914 DCHECK(!src.IsPostIndex());
915
916 // TODO(vixl): Let the MacroAssembler handle MemOperand.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800917 __ Add(temp_base, src.base(), OperandFromMemOperand(src));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000918 MemOperand base = MemOperand(temp_base);
919 switch (type) {
920 case Primitive::kPrimBoolean:
921 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000922 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000923 break;
924 case Primitive::kPrimByte:
925 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000926 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000927 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
928 break;
929 case Primitive::kPrimChar:
930 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000931 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000932 break;
933 case Primitive::kPrimShort:
934 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000935 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000936 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
937 break;
938 case Primitive::kPrimInt:
939 case Primitive::kPrimNot:
940 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000941 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000942 __ Ldar(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000943 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000944 break;
945 case Primitive::kPrimFloat:
946 case Primitive::kPrimDouble: {
947 DCHECK(dst.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000948 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000949
950 Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
951 __ Ldar(temp, base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000952 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000953 __ Fmov(FPRegister(dst), temp);
954 break;
955 }
956 case Primitive::kPrimVoid:
957 LOG(FATAL) << "Unreachable type " << type;
958 }
959}
960
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000961void CodeGeneratorARM64::Store(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000962 CPURegister src,
963 const MemOperand& dst) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000964 switch (type) {
965 case Primitive::kPrimBoolean:
966 case Primitive::kPrimByte:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000967 __ Strb(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000968 break;
969 case Primitive::kPrimChar:
970 case Primitive::kPrimShort:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000971 __ Strh(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000972 break;
973 case Primitive::kPrimInt:
974 case Primitive::kPrimNot:
975 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000976 case Primitive::kPrimFloat:
977 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000978 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000979 __ Str(src, dst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000980 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000981 case Primitive::kPrimVoid:
982 LOG(FATAL) << "Unreachable type " << type;
983 }
984}
985
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000986void CodeGeneratorARM64::StoreRelease(Primitive::Type type,
987 CPURegister src,
988 const MemOperand& dst) {
989 UseScratchRegisterScope temps(GetVIXLAssembler());
990 Register temp_base = temps.AcquireX();
991
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000992 DCHECK(!dst.IsPreIndex());
993 DCHECK(!dst.IsPostIndex());
994
995 // TODO(vixl): Let the MacroAssembler handle this.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800996 Operand op = OperandFromMemOperand(dst);
997 __ Add(temp_base, dst.base(), op);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000998 MemOperand base = MemOperand(temp_base);
999 switch (type) {
1000 case Primitive::kPrimBoolean:
1001 case Primitive::kPrimByte:
1002 __ Stlrb(Register(src), base);
1003 break;
1004 case Primitive::kPrimChar:
1005 case Primitive::kPrimShort:
1006 __ Stlrh(Register(src), base);
1007 break;
1008 case Primitive::kPrimInt:
1009 case Primitive::kPrimNot:
1010 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +00001011 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001012 __ Stlr(Register(src), base);
1013 break;
1014 case Primitive::kPrimFloat:
1015 case Primitive::kPrimDouble: {
1016 DCHECK(src.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +00001017 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001018
1019 Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
1020 __ Fmov(temp, FPRegister(src));
1021 __ Stlr(temp, base);
1022 break;
1023 }
1024 case Primitive::kPrimVoid:
1025 LOG(FATAL) << "Unreachable type " << type;
1026 }
1027}
1028
Alexandre Rames67555f72014-11-18 10:55:16 +00001029void CodeGeneratorARM64::LoadCurrentMethod(vixl::Register current_method) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001030 DCHECK(RequiresCurrentMethod());
Alexandre Rames67555f72014-11-18 10:55:16 +00001031 DCHECK(current_method.IsW());
1032 __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset));
1033}
1034
1035void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset,
1036 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001037 uint32_t dex_pc,
1038 SlowPathCode* slow_path) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001039 __ Ldr(lr, MemOperand(tr, entry_point_offset));
1040 __ Blr(lr);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001041 if (instruction != nullptr) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001042 RecordPcInfo(instruction, dex_pc, slow_path);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001043 DCHECK(instruction->IsSuspendCheck()
1044 || instruction->IsBoundsCheck()
1045 || instruction->IsNullCheck()
1046 || instruction->IsDivZeroCheck()
1047 || !IsLeafMethod());
1048 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001049}
1050
1051void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path,
1052 vixl::Register class_reg) {
1053 UseScratchRegisterScope temps(GetVIXLAssembler());
1054 Register temp = temps.AcquireW();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001055 size_t status_offset = mirror::Class::StatusOffset().SizeValue();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001056 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001057
Serban Constantinescu02164b32014-11-13 14:05:07 +00001058 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
Serban Constantinescu579885a2015-02-22 20:51:33 +00001059 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001060 // TODO(vixl): Let the MacroAssembler handle MemOperand.
1061 __ Add(temp, class_reg, status_offset);
1062 __ Ldar(temp, HeapOperand(temp));
1063 __ Cmp(temp, mirror::Class::kStatusInitialized);
1064 __ B(lt, slow_path->GetEntryLabel());
1065 } else {
1066 __ Ldr(temp, HeapOperand(class_reg, status_offset));
1067 __ Cmp(temp, mirror::Class::kStatusInitialized);
1068 __ B(lt, slow_path->GetEntryLabel());
1069 __ Dmb(InnerShareable, BarrierReads);
1070 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001071 __ Bind(slow_path->GetExitLabel());
1072}
Alexandre Rames5319def2014-10-23 10:03:10 +01001073
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001074void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) {
1075 BarrierType type = BarrierAll;
1076
1077 switch (kind) {
1078 case MemBarrierKind::kAnyAny:
1079 case MemBarrierKind::kAnyStore: {
1080 type = BarrierAll;
1081 break;
1082 }
1083 case MemBarrierKind::kLoadAny: {
1084 type = BarrierReads;
1085 break;
1086 }
1087 case MemBarrierKind::kStoreStore: {
1088 type = BarrierWrites;
1089 break;
1090 }
1091 default:
1092 LOG(FATAL) << "Unexpected memory barrier " << kind;
1093 }
1094 __ Dmb(InnerShareable, type);
1095}
1096
Serban Constantinescu02164b32014-11-13 14:05:07 +00001097void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction,
1098 HBasicBlock* successor) {
1099 SuspendCheckSlowPathARM64* slow_path =
1100 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor);
1101 codegen_->AddSlowPath(slow_path);
1102 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
1103 Register temp = temps.AcquireW();
1104
1105 __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue()));
1106 if (successor == nullptr) {
1107 __ Cbnz(temp, slow_path->GetEntryLabel());
1108 __ Bind(slow_path->GetReturnLabel());
1109 } else {
1110 __ Cbz(temp, codegen_->GetLabelOf(successor));
1111 __ B(slow_path->GetEntryLabel());
1112 // slow_path will return to GetLabelOf(successor).
1113 }
1114}
1115
Alexandre Rames5319def2014-10-23 10:03:10 +01001116InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
1117 CodeGeneratorARM64* codegen)
1118 : HGraphVisitor(graph),
1119 assembler_(codegen->GetAssembler()),
1120 codegen_(codegen) {}
1121
1122#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Alexandre Rames3e69f162014-12-10 10:36:50 +00001123 /* No unimplemented IR. */
Alexandre Rames5319def2014-10-23 10:03:10 +01001124
1125#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
1126
1127enum UnimplementedInstructionBreakCode {
Alexandre Rames67555f72014-11-18 10:55:16 +00001128 // Using a base helps identify when we hit such breakpoints.
1129 UnimplementedInstructionBreakCodeBaseCode = 0x900,
Alexandre Rames5319def2014-10-23 10:03:10 +01001130#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
1131 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
1132#undef ENUM_UNIMPLEMENTED_INSTRUCTION
1133};
1134
1135#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
1136 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001137 UNUSED(instr); \
Alexandre Rames5319def2014-10-23 10:03:10 +01001138 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
1139 } \
1140 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
1141 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
1142 locations->SetOut(Location::Any()); \
1143 }
1144 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
1145#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
1146
1147#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
Alexandre Rames67555f72014-11-18 10:55:16 +00001148#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
Alexandre Rames5319def2014-10-23 10:03:10 +01001149
Alexandre Rames67555f72014-11-18 10:55:16 +00001150void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001151 DCHECK_EQ(instr->InputCount(), 2U);
1152 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1153 Primitive::Type type = instr->GetResultType();
1154 switch (type) {
1155 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001156 case Primitive::kPrimLong:
Alexandre Rames5319def2014-10-23 10:03:10 +01001157 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001158 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr));
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001159 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001160 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001161
1162 case Primitive::kPrimFloat:
1163 case Primitive::kPrimDouble:
1164 locations->SetInAt(0, Location::RequiresFpuRegister());
1165 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001166 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001167 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001168
Alexandre Rames5319def2014-10-23 10:03:10 +01001169 default:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001170 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001171 }
1172}
1173
Alexandre Rames67555f72014-11-18 10:55:16 +00001174void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001175 Primitive::Type type = instr->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001176
1177 switch (type) {
1178 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001179 case Primitive::kPrimLong: {
1180 Register dst = OutputRegister(instr);
1181 Register lhs = InputRegisterAt(instr, 0);
1182 Operand rhs = InputOperandAt(instr, 1);
Alexandre Rames5319def2014-10-23 10:03:10 +01001183 if (instr->IsAdd()) {
1184 __ Add(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001185 } else if (instr->IsAnd()) {
1186 __ And(dst, lhs, rhs);
1187 } else if (instr->IsOr()) {
1188 __ Orr(dst, lhs, rhs);
1189 } else if (instr->IsSub()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001190 __ Sub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001191 } else {
1192 DCHECK(instr->IsXor());
1193 __ Eor(dst, lhs, rhs);
Alexandre Rames5319def2014-10-23 10:03:10 +01001194 }
1195 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001196 }
1197 case Primitive::kPrimFloat:
1198 case Primitive::kPrimDouble: {
1199 FPRegister dst = OutputFPRegister(instr);
1200 FPRegister lhs = InputFPRegisterAt(instr, 0);
1201 FPRegister rhs = InputFPRegisterAt(instr, 1);
1202 if (instr->IsAdd()) {
1203 __ Fadd(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001204 } else if (instr->IsSub()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001205 __ Fsub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001206 } else {
1207 LOG(FATAL) << "Unexpected floating-point binary operation";
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001208 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001209 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001210 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001211 default:
Alexandre Rames67555f72014-11-18 10:55:16 +00001212 LOG(FATAL) << "Unexpected binary operation type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001213 }
1214}
1215
Serban Constantinescu02164b32014-11-13 14:05:07 +00001216void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) {
1217 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1218
1219 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1220 Primitive::Type type = instr->GetResultType();
1221 switch (type) {
1222 case Primitive::kPrimInt:
1223 case Primitive::kPrimLong: {
1224 locations->SetInAt(0, Location::RequiresRegister());
1225 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1226 locations->SetOut(Location::RequiresRegister());
1227 break;
1228 }
1229 default:
1230 LOG(FATAL) << "Unexpected shift type " << type;
1231 }
1232}
1233
1234void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) {
1235 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1236
1237 Primitive::Type type = instr->GetType();
1238 switch (type) {
1239 case Primitive::kPrimInt:
1240 case Primitive::kPrimLong: {
1241 Register dst = OutputRegister(instr);
1242 Register lhs = InputRegisterAt(instr, 0);
1243 Operand rhs = InputOperandAt(instr, 1);
1244 if (rhs.IsImmediate()) {
1245 uint32_t shift_value = (type == Primitive::kPrimInt)
1246 ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue)
1247 : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue);
1248 if (instr->IsShl()) {
1249 __ Lsl(dst, lhs, shift_value);
1250 } else if (instr->IsShr()) {
1251 __ Asr(dst, lhs, shift_value);
1252 } else {
1253 __ Lsr(dst, lhs, shift_value);
1254 }
1255 } else {
1256 Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W();
1257
1258 if (instr->IsShl()) {
1259 __ Lsl(dst, lhs, rhs_reg);
1260 } else if (instr->IsShr()) {
1261 __ Asr(dst, lhs, rhs_reg);
1262 } else {
1263 __ Lsr(dst, lhs, rhs_reg);
1264 }
1265 }
1266 break;
1267 }
1268 default:
1269 LOG(FATAL) << "Unexpected shift operation type " << type;
1270 }
1271}
1272
Alexandre Rames5319def2014-10-23 10:03:10 +01001273void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001274 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001275}
1276
1277void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001278 HandleBinaryOp(instruction);
1279}
1280
1281void LocationsBuilderARM64::VisitAnd(HAnd* instruction) {
1282 HandleBinaryOp(instruction);
1283}
1284
1285void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) {
1286 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001287}
1288
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001289void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) {
1290 LocationSummary* locations =
1291 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1292 locations->SetInAt(0, Location::RequiresRegister());
1293 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1294 locations->SetOut(Location::RequiresRegister());
1295}
1296
1297void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) {
1298 LocationSummary* locations = instruction->GetLocations();
1299 Primitive::Type type = instruction->GetType();
1300 Register obj = InputRegisterAt(instruction, 0);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001301 Location index = locations->InAt(1);
1302 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001303 MemOperand source = HeapOperand(obj);
Alexandre Rames67555f72014-11-18 10:55:16 +00001304 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001305
1306 if (index.IsConstant()) {
1307 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001308 source = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001309 } else {
1310 Register temp = temps.AcquireSameSizeAs(obj);
1311 Register index_reg = RegisterFrom(index, Primitive::kPrimInt);
1312 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001313 source = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001314 }
1315
Alexandre Rames67555f72014-11-18 10:55:16 +00001316 codegen_->Load(type, OutputCPURegister(instruction), source);
Calin Juravle77520bc2015-01-12 18:45:46 +00001317 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001318}
1319
Alexandre Rames5319def2014-10-23 10:03:10 +01001320void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
1321 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1322 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001323 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001324}
1325
1326void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
1327 __ Ldr(OutputRegister(instruction),
1328 HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset()));
Calin Juravle77520bc2015-01-12 18:45:46 +00001329 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001330}
1331
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001332void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) {
1333 Primitive::Type value_type = instruction->GetComponentType();
1334 bool is_object = value_type == Primitive::kPrimNot;
1335 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1336 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1337 if (is_object) {
1338 InvokeRuntimeCallingConvention calling_convention;
1339 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1340 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1341 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1342 } else {
1343 locations->SetInAt(0, Location::RequiresRegister());
1344 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1345 locations->SetInAt(2, Location::RequiresRegister());
1346 }
1347}
1348
1349void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) {
1350 Primitive::Type value_type = instruction->GetComponentType();
1351 if (value_type == Primitive::kPrimNot) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001352 codegen_->InvokeRuntime(
1353 QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001354 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001355 } else {
1356 LocationSummary* locations = instruction->GetLocations();
1357 Register obj = InputRegisterAt(instruction, 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00001358 CPURegister value = InputCPURegisterAt(instruction, 2);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001359 Location index = locations->InAt(1);
1360 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001361 MemOperand destination = HeapOperand(obj);
Alexandre Rames67555f72014-11-18 10:55:16 +00001362 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001363
1364 if (index.IsConstant()) {
1365 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001366 destination = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001367 } else {
1368 Register temp = temps.AcquireSameSizeAs(obj);
1369 Register index_reg = InputRegisterAt(instruction, 1);
1370 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001371 destination = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001372 }
1373
1374 codegen_->Store(value_type, value, destination);
Calin Juravle77520bc2015-01-12 18:45:46 +00001375 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001376 }
1377}
1378
Alexandre Rames67555f72014-11-18 10:55:16 +00001379void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1380 LocationSummary* locations =
1381 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1382 locations->SetInAt(0, Location::RequiresRegister());
1383 locations->SetInAt(1, Location::RequiresRegister());
1384 if (instruction->HasUses()) {
1385 locations->SetOut(Location::SameAsFirstInput());
1386 }
1387}
1388
1389void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001390 LocationSummary* locations = instruction->GetLocations();
1391 BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(
1392 instruction, locations->InAt(0), locations->InAt(1));
Alexandre Rames67555f72014-11-18 10:55:16 +00001393 codegen_->AddSlowPath(slow_path);
1394
1395 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
1396 __ B(slow_path->GetEntryLabel(), hs);
1397}
1398
1399void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) {
1400 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1401 instruction, LocationSummary::kCallOnSlowPath);
1402 locations->SetInAt(0, Location::RequiresRegister());
1403 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001404 locations->AddTemp(Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001405}
1406
1407void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001408 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames67555f72014-11-18 10:55:16 +00001409 Register obj = InputRegisterAt(instruction, 0);;
1410 Register cls = InputRegisterAt(instruction, 1);;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001411 Register obj_cls = WRegisterFrom(instruction->GetLocations()->GetTemp(0));
Alexandre Rames67555f72014-11-18 10:55:16 +00001412
Alexandre Rames3e69f162014-12-10 10:36:50 +00001413 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1414 instruction, locations->InAt(1), LocationFrom(obj_cls), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001415 codegen_->AddSlowPath(slow_path);
1416
1417 // TODO: avoid this check if we know obj is not null.
1418 __ Cbz(obj, slow_path->GetExitLabel());
1419 // Compare the class of `obj` with `cls`.
Alexandre Rames3e69f162014-12-10 10:36:50 +00001420 __ Ldr(obj_cls, HeapOperand(obj, mirror::Object::ClassOffset()));
1421 __ Cmp(obj_cls, cls);
Alexandre Rames67555f72014-11-18 10:55:16 +00001422 __ B(ne, slow_path->GetEntryLabel());
1423 __ Bind(slow_path->GetExitLabel());
1424}
1425
1426void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) {
1427 LocationSummary* locations =
1428 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1429 locations->SetInAt(0, Location::RequiresRegister());
1430 if (check->HasUses()) {
1431 locations->SetOut(Location::SameAsFirstInput());
1432 }
1433}
1434
1435void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) {
1436 // We assume the class is not null.
1437 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
1438 check->GetLoadClass(), check, check->GetDexPc(), true);
1439 codegen_->AddSlowPath(slow_path);
1440 GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0));
1441}
1442
Serban Constantinescu02164b32014-11-13 14:05:07 +00001443void LocationsBuilderARM64::VisitCompare(HCompare* compare) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001444 LocationSummary* locations =
Serban Constantinescu02164b32014-11-13 14:05:07 +00001445 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
1446 Primitive::Type in_type = compare->InputAt(0)->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001447 switch (in_type) {
1448 case Primitive::kPrimLong: {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001449 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001450 locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001451 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1452 break;
1453 }
1454 case Primitive::kPrimFloat:
1455 case Primitive::kPrimDouble: {
1456 locations->SetInAt(0, Location::RequiresFpuRegister());
Alexandre Rames93415462015-02-17 15:08:20 +00001457 HInstruction* right = compare->InputAt(1);
1458 if ((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1459 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))) {
1460 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1461 } else {
1462 locations->SetInAt(1, Location::RequiresFpuRegister());
1463 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001464 locations->SetOut(Location::RequiresRegister());
1465 break;
1466 }
1467 default:
1468 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1469 }
1470}
1471
1472void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) {
1473 Primitive::Type in_type = compare->InputAt(0)->GetType();
1474
1475 // 0 if: left == right
1476 // 1 if: left > right
1477 // -1 if: left < right
1478 switch (in_type) {
1479 case Primitive::kPrimLong: {
1480 Register result = OutputRegister(compare);
1481 Register left = InputRegisterAt(compare, 0);
1482 Operand right = InputOperandAt(compare, 1);
1483
1484 __ Cmp(left, right);
1485 __ Cset(result, ne);
1486 __ Cneg(result, result, lt);
1487 break;
1488 }
1489 case Primitive::kPrimFloat:
1490 case Primitive::kPrimDouble: {
1491 Register result = OutputRegister(compare);
1492 FPRegister left = InputFPRegisterAt(compare, 0);
Alexandre Rames93415462015-02-17 15:08:20 +00001493 if (compare->GetLocations()->InAt(1).IsConstant()) {
1494 if (kIsDebugBuild) {
1495 HInstruction* right = compare->GetLocations()->InAt(1).GetConstant();
1496 DCHECK((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1497 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0)));
1498 }
1499 // 0.0 is the only immediate that can be encoded directly in a FCMP instruction.
1500 __ Fcmp(left, 0.0);
1501 } else {
1502 __ Fcmp(left, InputFPRegisterAt(compare, 1));
1503 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001504 if (compare->IsGtBias()) {
1505 __ Cset(result, ne);
1506 } else {
1507 __ Csetm(result, ne);
1508 }
1509 __ Cneg(result, result, compare->IsGtBias() ? mi : gt);
Alexandre Rames5319def2014-10-23 10:03:10 +01001510 break;
1511 }
1512 default:
1513 LOG(FATAL) << "Unimplemented compare type " << in_type;
1514 }
1515}
1516
1517void LocationsBuilderARM64::VisitCondition(HCondition* instruction) {
1518 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1519 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001520 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames5319def2014-10-23 10:03:10 +01001521 if (instruction->NeedsMaterialization()) {
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001522 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001523 }
1524}
1525
1526void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) {
1527 if (!instruction->NeedsMaterialization()) {
1528 return;
1529 }
1530
1531 LocationSummary* locations = instruction->GetLocations();
1532 Register lhs = InputRegisterAt(instruction, 0);
1533 Operand rhs = InputOperandAt(instruction, 1);
1534 Register res = RegisterFrom(locations->Out(), instruction->GetType());
1535 Condition cond = ARM64Condition(instruction->GetCondition());
1536
1537 __ Cmp(lhs, rhs);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001538 __ Cset(res, cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001539}
1540
1541#define FOR_EACH_CONDITION_INSTRUCTION(M) \
1542 M(Equal) \
1543 M(NotEqual) \
1544 M(LessThan) \
1545 M(LessThanOrEqual) \
1546 M(GreaterThan) \
1547 M(GreaterThanOrEqual)
1548#define DEFINE_CONDITION_VISITORS(Name) \
1549void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \
1550void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }
1551FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
Alexandre Rames67555f72014-11-18 10:55:16 +00001552#undef DEFINE_CONDITION_VISITORS
Alexandre Rames5319def2014-10-23 10:03:10 +01001553#undef FOR_EACH_CONDITION_INSTRUCTION
1554
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001555void LocationsBuilderARM64::VisitDiv(HDiv* div) {
1556 LocationSummary* locations =
1557 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1558 switch (div->GetResultType()) {
1559 case Primitive::kPrimInt:
1560 case Primitive::kPrimLong:
1561 locations->SetInAt(0, Location::RequiresRegister());
1562 locations->SetInAt(1, Location::RequiresRegister());
1563 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1564 break;
1565
1566 case Primitive::kPrimFloat:
1567 case Primitive::kPrimDouble:
1568 locations->SetInAt(0, Location::RequiresFpuRegister());
1569 locations->SetInAt(1, Location::RequiresFpuRegister());
1570 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1571 break;
1572
1573 default:
1574 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1575 }
1576}
1577
1578void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) {
1579 Primitive::Type type = div->GetResultType();
1580 switch (type) {
1581 case Primitive::kPrimInt:
1582 case Primitive::kPrimLong:
1583 __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1));
1584 break;
1585
1586 case Primitive::kPrimFloat:
1587 case Primitive::kPrimDouble:
1588 __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1));
1589 break;
1590
1591 default:
1592 LOG(FATAL) << "Unexpected div type " << type;
1593 }
1594}
1595
Alexandre Rames67555f72014-11-18 10:55:16 +00001596void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1597 LocationSummary* locations =
1598 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1599 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1600 if (instruction->HasUses()) {
1601 locations->SetOut(Location::SameAsFirstInput());
1602 }
1603}
1604
1605void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1606 SlowPathCodeARM64* slow_path =
1607 new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction);
1608 codegen_->AddSlowPath(slow_path);
1609 Location value = instruction->GetLocations()->InAt(0);
1610
Alexandre Rames3e69f162014-12-10 10:36:50 +00001611 Primitive::Type type = instruction->GetType();
1612
1613 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1614 LOG(FATAL) << "Unexpected type " << type << "for DivZeroCheck.";
1615 return;
1616 }
1617
Alexandre Rames67555f72014-11-18 10:55:16 +00001618 if (value.IsConstant()) {
1619 int64_t divisor = Int64ConstantFrom(value);
1620 if (divisor == 0) {
1621 __ B(slow_path->GetEntryLabel());
1622 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001623 // A division by a non-null constant is valid. We don't need to perform
1624 // any check, so simply fall through.
Alexandre Rames67555f72014-11-18 10:55:16 +00001625 }
1626 } else {
1627 __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel());
1628 }
1629}
1630
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001631void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1632 LocationSummary* locations =
1633 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1634 locations->SetOut(Location::ConstantLocation(constant));
1635}
1636
1637void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1638 UNUSED(constant);
1639 // Will be generated at use site.
1640}
1641
Alexandre Rames5319def2014-10-23 10:03:10 +01001642void LocationsBuilderARM64::VisitExit(HExit* exit) {
1643 exit->SetLocations(nullptr);
1644}
1645
1646void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001647 UNUSED(exit);
Alexandre Rames5319def2014-10-23 10:03:10 +01001648}
1649
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001650void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) {
1651 LocationSummary* locations =
1652 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1653 locations->SetOut(Location::ConstantLocation(constant));
1654}
1655
1656void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) {
1657 UNUSED(constant);
1658 // Will be generated at use site.
1659}
1660
Alexandre Rames5319def2014-10-23 10:03:10 +01001661void LocationsBuilderARM64::VisitGoto(HGoto* got) {
1662 got->SetLocations(nullptr);
1663}
1664
1665void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
1666 HBasicBlock* successor = got->GetSuccessor();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001667 DCHECK(!successor->IsExitBlock());
1668 HBasicBlock* block = got->GetBlock();
1669 HInstruction* previous = got->GetPrevious();
1670 HLoopInformation* info = block->GetLoopInformation();
1671
David Brazdil46e2a392015-03-16 17:31:52 +00001672 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001673 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1674 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1675 return;
1676 }
1677 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1678 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1679 }
1680 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001681 __ B(codegen_->GetLabelOf(successor));
1682 }
1683}
1684
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001685void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction,
1686 vixl::Label* true_target,
1687 vixl::Label* false_target,
1688 vixl::Label* always_true_target) {
1689 HInstruction* cond = instruction->InputAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001690 HCondition* condition = cond->AsCondition();
Alexandre Rames5319def2014-10-23 10:03:10 +01001691
Serban Constantinescu02164b32014-11-13 14:05:07 +00001692 if (cond->IsIntConstant()) {
1693 int32_t cond_value = cond->AsIntConstant()->GetValue();
1694 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001695 if (always_true_target != nullptr) {
1696 __ B(always_true_target);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001697 }
1698 return;
1699 } else {
1700 DCHECK_EQ(cond_value, 0);
1701 }
1702 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001703 // The condition instruction has been materialized, compare the output to 0.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001704 Location cond_val = instruction->GetLocations()->InAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001705 DCHECK(cond_val.IsRegister());
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001706 __ Cbnz(InputRegisterAt(instruction, 0), true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001707 } else {
1708 // The condition instruction has not been materialized, use its inputs as
1709 // the comparison and its condition as the branch condition.
1710 Register lhs = InputRegisterAt(condition, 0);
1711 Operand rhs = InputOperandAt(condition, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001712 Condition arm64_cond = ARM64Condition(condition->GetCondition());
Alexandre Rames4388dcc2015-02-03 10:28:33 +00001713 if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
1714 switch (arm64_cond) {
1715 case eq:
1716 __ Cbz(lhs, true_target);
1717 break;
1718 case ne:
1719 __ Cbnz(lhs, true_target);
1720 break;
1721 case lt:
1722 // Test the sign bit and branch accordingly.
1723 __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1724 break;
1725 case ge:
1726 // Test the sign bit and branch accordingly.
1727 __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1728 break;
1729 default:
1730 // Without the `static_cast` the compiler throws an error for
1731 // `-Werror=sign-promo`.
1732 LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001733 }
1734 } else {
1735 __ Cmp(lhs, rhs);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001736 __ B(arm64_cond, true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001737 }
1738 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001739 if (false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001740 __ B(false_target);
1741 }
1742}
1743
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001744void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
1745 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1746 HInstruction* cond = if_instr->InputAt(0);
1747 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1748 locations->SetInAt(0, Location::RequiresRegister());
1749 }
1750}
1751
1752void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
1753 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1754 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1755 vixl::Label* always_true_target = true_target;
1756 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1757 if_instr->IfTrueSuccessor())) {
1758 always_true_target = nullptr;
1759 }
1760 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1761 if_instr->IfFalseSuccessor())) {
1762 false_target = nullptr;
1763 }
1764 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1765}
1766
1767void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1768 LocationSummary* locations = new (GetGraph()->GetArena())
1769 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1770 HInstruction* cond = deoptimize->InputAt(0);
1771 DCHECK(cond->IsCondition());
1772 if (cond->AsCondition()->NeedsMaterialization()) {
1773 locations->SetInAt(0, Location::RequiresRegister());
1774 }
1775}
1776
1777void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1778 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
1779 DeoptimizationSlowPathARM64(deoptimize);
1780 codegen_->AddSlowPath(slow_path);
1781 vixl::Label* slow_path_entry = slow_path->GetEntryLabel();
1782 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1783}
1784
Alexandre Rames5319def2014-10-23 10:03:10 +01001785void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001786 LocationSummary* locations =
1787 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001788 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001789 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001790}
1791
1792void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001793 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00001794 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001795
1796 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001797 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00001798 // NB: LoadAcquire will record the pc info if needed.
1799 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001800 } else {
1801 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001802 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001803 // For IRIW sequential consistency kLoadAny is not sufficient.
1804 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1805 }
1806 } else {
1807 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001808 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001809 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001810}
1811
1812void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001813 LocationSummary* locations =
1814 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001815 locations->SetInAt(0, Location::RequiresRegister());
1816 locations->SetInAt(1, Location::RequiresRegister());
1817}
1818
1819void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001820 Register obj = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001821 CPURegister value = InputCPURegisterAt(instruction, 1);
1822 Offset offset = instruction->GetFieldOffset();
1823 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001824 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001825
1826 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001827 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001828 codegen_->StoreRelease(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001829 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001830 } else {
1831 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
1832 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001833 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001834 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1835 }
1836 } else {
1837 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001838 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001839 }
1840
1841 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001842 codegen_->MarkGCCard(obj, Register(value));
Alexandre Rames5319def2014-10-23 10:03:10 +01001843 }
1844}
1845
Alexandre Rames67555f72014-11-18 10:55:16 +00001846void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
1847 LocationSummary::CallKind call_kind =
1848 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
1849 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1850 locations->SetInAt(0, Location::RequiresRegister());
1851 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001852 // The output does overlap inputs.
1853 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexandre Rames67555f72014-11-18 10:55:16 +00001854}
1855
1856void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
1857 LocationSummary* locations = instruction->GetLocations();
1858 Register obj = InputRegisterAt(instruction, 0);;
1859 Register cls = InputRegisterAt(instruction, 1);;
1860 Register out = OutputRegister(instruction);
1861
1862 vixl::Label done;
1863
1864 // Return 0 if `obj` is null.
1865 // TODO: Avoid this check if we know `obj` is not null.
1866 __ Mov(out, 0);
1867 __ Cbz(obj, &done);
1868
1869 // Compare the class of `obj` with `cls`.
Serban Constantinescu02164b32014-11-13 14:05:07 +00001870 __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset()));
Alexandre Rames67555f72014-11-18 10:55:16 +00001871 __ Cmp(out, cls);
1872 if (instruction->IsClassFinal()) {
1873 // Classes must be equal for the instanceof to succeed.
1874 __ Cset(out, eq);
1875 } else {
1876 // If the classes are not equal, we go into a slow path.
1877 DCHECK(locations->OnlyCallsOnSlowPath());
1878 SlowPathCodeARM64* slow_path =
Alexandre Rames3e69f162014-12-10 10:36:50 +00001879 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1880 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001881 codegen_->AddSlowPath(slow_path);
1882 __ B(ne, slow_path->GetEntryLabel());
1883 __ Mov(out, 1);
1884 __ Bind(slow_path->GetExitLabel());
1885 }
1886
1887 __ Bind(&done);
1888}
1889
Alexandre Rames5319def2014-10-23 10:03:10 +01001890void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
1891 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1892 locations->SetOut(Location::ConstantLocation(constant));
1893}
1894
1895void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
1896 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001897 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01001898}
1899
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001900void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
1901 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1902 locations->SetOut(Location::ConstantLocation(constant));
1903}
1904
1905void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) {
1906 // Will be generated at use site.
1907 UNUSED(constant);
1908}
1909
Alexandre Rames5319def2014-10-23 10:03:10 +01001910void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
1911 LocationSummary* locations =
1912 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
1913 locations->AddTemp(LocationFrom(x0));
1914
1915 InvokeDexCallingConventionVisitor calling_convention_visitor;
1916 for (size_t i = 0; i < invoke->InputCount(); i++) {
1917 HInstruction* input = invoke->InputAt(i);
1918 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1919 }
1920
1921 Primitive::Type return_type = invoke->GetType();
1922 if (return_type != Primitive::kPrimVoid) {
1923 locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type));
1924 }
1925}
1926
Alexandre Rames67555f72014-11-18 10:55:16 +00001927void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1928 HandleInvoke(invoke);
1929}
1930
1931void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1932 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1933 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1934 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1935 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1936 Location receiver = invoke->GetLocations()->InAt(0);
1937 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001938 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00001939
1940 // The register ip1 is required to be used for the hidden argument in
1941 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
1942 UseScratchRegisterScope scratch_scope(GetVIXLAssembler());
1943 scratch_scope.Exclude(ip1);
1944 __ Mov(ip1, invoke->GetDexMethodIndex());
1945
1946 // temp = object->GetClass();
1947 if (receiver.IsStackSlot()) {
1948 __ Ldr(temp, StackOperandFrom(receiver));
1949 __ Ldr(temp, HeapOperand(temp, class_offset));
1950 } else {
1951 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
1952 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001953 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames67555f72014-11-18 10:55:16 +00001954 // temp = temp->GetImtEntryAt(method_offset);
1955 __ Ldr(temp, HeapOperand(temp, method_offset));
1956 // lr = temp->GetEntryPoint();
1957 __ Ldr(lr, HeapOperand(temp, entry_point));
1958 // lr();
1959 __ Blr(lr);
1960 DCHECK(!codegen_->IsLeafMethod());
1961 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1962}
1963
1964void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001965 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1966 if (intrinsic.TryDispatch(invoke)) {
1967 return;
1968 }
1969
Alexandre Rames67555f72014-11-18 10:55:16 +00001970 HandleInvoke(invoke);
1971}
1972
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001973void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001974 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1975 if (intrinsic.TryDispatch(invoke)) {
1976 return;
1977 }
1978
Alexandre Rames67555f72014-11-18 10:55:16 +00001979 HandleInvoke(invoke);
1980}
1981
Andreas Gampe878d58c2015-01-15 23:24:00 -08001982static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
1983 if (invoke->GetLocations()->Intrinsified()) {
1984 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
1985 intrinsic.Dispatch(invoke);
1986 return true;
1987 }
1988 return false;
1989}
1990
1991void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
1992 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
1993 DCHECK(temp.Is(kArtMethodRegister));
Alexandre Rames5319def2014-10-23 10:03:10 +01001994 size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() +
Andreas Gampe878d58c2015-01-15 23:24:00 -08001995 invoke->GetDexMethodIndex() * kHeapRefSize;
Alexandre Rames5319def2014-10-23 10:03:10 +01001996
1997 // TODO: Implement all kinds of calls:
1998 // 1) boot -> boot
1999 // 2) app -> boot
2000 // 3) app -> app
2001 //
2002 // Currently we implement the app -> app logic, which looks up in the resolve cache.
2003
Nicolas Geoffray0a299b92015-01-29 11:39:44 +00002004 // temp = method;
2005 LoadCurrentMethod(temp);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002006 if (!invoke->IsRecursive()) {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002007 // temp = temp->dex_cache_resolved_methods_;
2008 __ Ldr(temp, HeapOperand(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset()));
2009 // temp = temp[index_in_cache];
2010 __ Ldr(temp, HeapOperand(temp, index_in_cache));
2011 // lr = temp->entry_point_from_quick_compiled_code_;
2012 __ Ldr(lr, HeapOperand(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2013 kArm64WordSize)));
2014 // lr();
2015 __ Blr(lr);
2016 } else {
2017 __ Bl(&frame_entry_label_);
2018 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002019
Andreas Gampe878d58c2015-01-15 23:24:00 -08002020 DCHECK(!IsLeafMethod());
2021}
2022
2023void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2024 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2025 return;
2026 }
2027
2028 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
2029 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00002030 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01002031}
2032
2033void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08002034 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2035 return;
2036 }
2037
Alexandre Rames5319def2014-10-23 10:03:10 +01002038 LocationSummary* locations = invoke->GetLocations();
2039 Location receiver = locations->InAt(0);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002040 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002041 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
2042 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
2043 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00002044 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames5319def2014-10-23 10:03:10 +01002045
2046 // temp = object->GetClass();
2047 if (receiver.IsStackSlot()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002048 __ Ldr(temp, MemOperand(sp, receiver.GetStackIndex()));
2049 __ Ldr(temp, HeapOperand(temp, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002050 } else {
2051 DCHECK(receiver.IsRegister());
Serban Constantinescu02164b32014-11-13 14:05:07 +00002052 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002053 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002054 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames5319def2014-10-23 10:03:10 +01002055 // temp = temp->GetMethodAt(method_offset);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002056 __ Ldr(temp, HeapOperand(temp, method_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002057 // lr = temp->GetEntryPoint();
Serban Constantinescu02164b32014-11-13 14:05:07 +00002058 __ Ldr(lr, HeapOperand(temp, entry_point.SizeValue()));
Alexandre Rames5319def2014-10-23 10:03:10 +01002059 // lr();
2060 __ Blr(lr);
2061 DCHECK(!codegen_->IsLeafMethod());
2062 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2063}
2064
Alexandre Rames67555f72014-11-18 10:55:16 +00002065void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
2066 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2067 : LocationSummary::kNoCall;
2068 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2069 locations->SetOut(Location::RequiresRegister());
2070}
2071
2072void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
2073 Register out = OutputRegister(cls);
2074 if (cls->IsReferrersClass()) {
2075 DCHECK(!cls->CanCallRuntime());
2076 DCHECK(!cls->MustGenerateClinitCheck());
2077 codegen_->LoadCurrentMethod(out);
2078 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2079 } else {
2080 DCHECK(cls->CanCallRuntime());
2081 codegen_->LoadCurrentMethod(out);
2082 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DexCacheResolvedTypesOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002083 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002084
2085 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2086 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2087 codegen_->AddSlowPath(slow_path);
2088 __ Cbz(out, slow_path->GetEntryLabel());
2089 if (cls->MustGenerateClinitCheck()) {
2090 GenerateClassInitializationCheck(slow_path, out);
2091 } else {
2092 __ Bind(slow_path->GetExitLabel());
2093 }
2094 }
2095}
2096
2097void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
2098 LocationSummary* locations =
2099 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2100 locations->SetOut(Location::RequiresRegister());
2101}
2102
2103void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
2104 MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value());
2105 __ Ldr(OutputRegister(instruction), exception);
2106 __ Str(wzr, exception);
2107}
2108
Alexandre Rames5319def2014-10-23 10:03:10 +01002109void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
2110 load->SetLocations(nullptr);
2111}
2112
2113void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
2114 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002115 UNUSED(load);
Alexandre Rames5319def2014-10-23 10:03:10 +01002116}
2117
Alexandre Rames67555f72014-11-18 10:55:16 +00002118void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
2119 LocationSummary* locations =
2120 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2121 locations->SetOut(Location::RequiresRegister());
2122}
2123
2124void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
2125 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load);
2126 codegen_->AddSlowPath(slow_path);
2127
2128 Register out = OutputRegister(load);
2129 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08002130 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2131 __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002132 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002133 __ Cbz(out, slow_path->GetEntryLabel());
2134 __ Bind(slow_path->GetExitLabel());
2135}
2136
Alexandre Rames5319def2014-10-23 10:03:10 +01002137void LocationsBuilderARM64::VisitLocal(HLocal* local) {
2138 local->SetLocations(nullptr);
2139}
2140
2141void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
2142 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2143}
2144
2145void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
2146 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2147 locations->SetOut(Location::ConstantLocation(constant));
2148}
2149
2150void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
2151 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002152 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002153}
2154
Alexandre Rames67555f72014-11-18 10:55:16 +00002155void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2156 LocationSummary* locations =
2157 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2158 InvokeRuntimeCallingConvention calling_convention;
2159 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2160}
2161
2162void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2163 codegen_->InvokeRuntime(instruction->IsEnter()
2164 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2165 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002166 instruction->GetDexPc(),
2167 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002168 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002169}
2170
Alexandre Rames42d641b2014-10-27 14:00:51 +00002171void LocationsBuilderARM64::VisitMul(HMul* mul) {
2172 LocationSummary* locations =
2173 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2174 switch (mul->GetResultType()) {
2175 case Primitive::kPrimInt:
2176 case Primitive::kPrimLong:
2177 locations->SetInAt(0, Location::RequiresRegister());
2178 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002179 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002180 break;
2181
2182 case Primitive::kPrimFloat:
2183 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002184 locations->SetInAt(0, Location::RequiresFpuRegister());
2185 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002186 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002187 break;
2188
2189 default:
2190 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2191 }
2192}
2193
2194void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
2195 switch (mul->GetResultType()) {
2196 case Primitive::kPrimInt:
2197 case Primitive::kPrimLong:
2198 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
2199 break;
2200
2201 case Primitive::kPrimFloat:
2202 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002203 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00002204 break;
2205
2206 default:
2207 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2208 }
2209}
2210
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002211void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
2212 LocationSummary* locations =
2213 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2214 switch (neg->GetResultType()) {
2215 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00002216 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002217 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00002218 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002219 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002220
2221 case Primitive::kPrimFloat:
2222 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002223 locations->SetInAt(0, Location::RequiresFpuRegister());
2224 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002225 break;
2226
2227 default:
2228 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2229 }
2230}
2231
2232void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
2233 switch (neg->GetResultType()) {
2234 case Primitive::kPrimInt:
2235 case Primitive::kPrimLong:
2236 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
2237 break;
2238
2239 case Primitive::kPrimFloat:
2240 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002241 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002242 break;
2243
2244 default:
2245 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2246 }
2247}
2248
2249void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
2250 LocationSummary* locations =
2251 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2252 InvokeRuntimeCallingConvention calling_convention;
2253 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002254 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002255 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002256 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
2257 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2258 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002259}
2260
2261void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
2262 LocationSummary* locations = instruction->GetLocations();
2263 InvokeRuntimeCallingConvention calling_convention;
2264 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2265 DCHECK(type_index.Is(w0));
2266 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002267 DCHECK(current_method.Is(w2));
Alexandre Rames67555f72014-11-18 10:55:16 +00002268 codegen_->LoadCurrentMethod(current_method);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002269 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002270 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002271 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2272 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002273 instruction->GetDexPc(),
2274 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002275 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2276 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002277}
2278
Alexandre Rames5319def2014-10-23 10:03:10 +01002279void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
2280 LocationSummary* locations =
2281 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2282 InvokeRuntimeCallingConvention calling_convention;
2283 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2284 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2285 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002286 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002287}
2288
2289void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
2290 LocationSummary* locations = instruction->GetLocations();
2291 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2292 DCHECK(type_index.Is(w0));
2293 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
2294 DCHECK(current_method.Is(w1));
Alexandre Rames67555f72014-11-18 10:55:16 +00002295 codegen_->LoadCurrentMethod(current_method);
Alexandre Rames5319def2014-10-23 10:03:10 +01002296 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002297 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002298 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2299 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002300 instruction->GetDexPc(),
2301 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002302 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002303}
2304
2305void LocationsBuilderARM64::VisitNot(HNot* instruction) {
2306 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00002307 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002308 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002309}
2310
2311void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002312 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002313 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002314 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01002315 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002316 break;
2317
2318 default:
2319 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2320 }
2321}
2322
2323void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
2324 LocationSummary* locations =
2325 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2326 locations->SetInAt(0, Location::RequiresRegister());
2327 if (instruction->HasUses()) {
2328 locations->SetOut(Location::SameAsFirstInput());
2329 }
2330}
2331
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002332void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002333 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2334 return;
2335 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002336 Location obj = instruction->GetLocations()->InAt(0);
2337
2338 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
2339 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2340}
2341
2342void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002343 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
2344 codegen_->AddSlowPath(slow_path);
2345
2346 LocationSummary* locations = instruction->GetLocations();
2347 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002348
2349 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01002350}
2351
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002352void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
2353 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2354 GenerateImplicitNullCheck(instruction);
2355 } else {
2356 GenerateExplicitNullCheck(instruction);
2357 }
2358}
2359
Alexandre Rames67555f72014-11-18 10:55:16 +00002360void LocationsBuilderARM64::VisitOr(HOr* instruction) {
2361 HandleBinaryOp(instruction);
2362}
2363
2364void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
2365 HandleBinaryOp(instruction);
2366}
2367
Alexandre Rames3e69f162014-12-10 10:36:50 +00002368void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2369 LOG(FATAL) << "Unreachable";
2370}
2371
2372void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
2373 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2374}
2375
Alexandre Rames5319def2014-10-23 10:03:10 +01002376void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
2377 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2378 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2379 if (location.IsStackSlot()) {
2380 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2381 } else if (location.IsDoubleStackSlot()) {
2382 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2383 }
2384 locations->SetOut(location);
2385}
2386
2387void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) {
2388 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002389 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002390}
2391
2392void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
2393 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2394 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2395 locations->SetInAt(i, Location::Any());
2396 }
2397 locations->SetOut(Location::Any());
2398}
2399
2400void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002401 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002402 LOG(FATAL) << "Unreachable";
2403}
2404
Serban Constantinescu02164b32014-11-13 14:05:07 +00002405void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002406 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00002407 LocationSummary::CallKind call_kind =
2408 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002409 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2410
2411 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002412 case Primitive::kPrimInt:
2413 case Primitive::kPrimLong:
2414 locations->SetInAt(0, Location::RequiresRegister());
2415 locations->SetInAt(1, Location::RequiresRegister());
2416 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2417 break;
2418
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002419 case Primitive::kPrimFloat:
2420 case Primitive::kPrimDouble: {
2421 InvokeRuntimeCallingConvention calling_convention;
2422 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
2423 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
2424 locations->SetOut(calling_convention.GetReturnLocation(type));
2425
2426 break;
2427 }
2428
Serban Constantinescu02164b32014-11-13 14:05:07 +00002429 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002430 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00002431 }
2432}
2433
2434void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
2435 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002436
Serban Constantinescu02164b32014-11-13 14:05:07 +00002437 switch (type) {
2438 case Primitive::kPrimInt:
2439 case Primitive::kPrimLong: {
2440 UseScratchRegisterScope temps(GetVIXLAssembler());
2441 Register dividend = InputRegisterAt(rem, 0);
2442 Register divisor = InputRegisterAt(rem, 1);
2443 Register output = OutputRegister(rem);
2444 Register temp = temps.AcquireSameSizeAs(output);
2445
2446 __ Sdiv(temp, dividend, divisor);
2447 __ Msub(output, temp, divisor, dividend);
2448 break;
2449 }
2450
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002451 case Primitive::kPrimFloat:
2452 case Primitive::kPrimDouble: {
2453 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2454 : QUICK_ENTRY_POINT(pFmod);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002455 codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002456 break;
2457 }
2458
Serban Constantinescu02164b32014-11-13 14:05:07 +00002459 default:
2460 LOG(FATAL) << "Unexpected rem type " << type;
2461 }
2462}
2463
Alexandre Rames5319def2014-10-23 10:03:10 +01002464void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
2465 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2466 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002467 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01002468}
2469
2470void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002471 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002472 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002473}
2474
2475void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
2476 instruction->SetLocations(nullptr);
2477}
2478
2479void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002480 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002481 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002482}
2483
Serban Constantinescu02164b32014-11-13 14:05:07 +00002484void LocationsBuilderARM64::VisitShl(HShl* shl) {
2485 HandleShift(shl);
2486}
2487
2488void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
2489 HandleShift(shl);
2490}
2491
2492void LocationsBuilderARM64::VisitShr(HShr* shr) {
2493 HandleShift(shr);
2494}
2495
2496void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
2497 HandleShift(shr);
2498}
2499
Alexandre Rames5319def2014-10-23 10:03:10 +01002500void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
2501 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2502 Primitive::Type field_type = store->InputAt(1)->GetType();
2503 switch (field_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002504 case Primitive::kPrimNot:
Alexandre Rames5319def2014-10-23 10:03:10 +01002505 case Primitive::kPrimBoolean:
2506 case Primitive::kPrimByte:
2507 case Primitive::kPrimChar:
2508 case Primitive::kPrimShort:
2509 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002510 case Primitive::kPrimFloat:
Alexandre Rames5319def2014-10-23 10:03:10 +01002511 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2512 break;
2513
2514 case Primitive::kPrimLong:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002515 case Primitive::kPrimDouble:
Alexandre Rames5319def2014-10-23 10:03:10 +01002516 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2517 break;
2518
2519 default:
2520 LOG(FATAL) << "Unimplemented local type " << field_type;
2521 }
2522}
2523
2524void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002525 UNUSED(store);
Alexandre Rames5319def2014-10-23 10:03:10 +01002526}
2527
2528void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002529 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002530}
2531
2532void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002533 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002534}
2535
Alexandre Rames67555f72014-11-18 10:55:16 +00002536void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2537 LocationSummary* locations =
2538 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2539 locations->SetInAt(0, Location::RequiresRegister());
2540 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2541}
2542
2543void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002544 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00002545 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002546
2547 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002548 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002549 // NB: LoadAcquire will record the pc info if needed.
2550 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002551 } else {
2552 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2553 // For IRIW sequential consistency kLoadAny is not sufficient.
2554 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2555 }
2556 } else {
2557 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2558 }
Alexandre Rames67555f72014-11-18 10:55:16 +00002559}
2560
2561void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002562 LocationSummary* locations =
2563 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2564 locations->SetInAt(0, Location::RequiresRegister());
2565 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames5319def2014-10-23 10:03:10 +01002566}
2567
Alexandre Rames67555f72014-11-18 10:55:16 +00002568void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002569 Register cls = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002570 CPURegister value = InputCPURegisterAt(instruction, 1);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002571 Offset offset = instruction->GetFieldOffset();
Alexandre Rames67555f72014-11-18 10:55:16 +00002572 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00002573 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Alexandre Rames5319def2014-10-23 10:03:10 +01002574
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002575 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002576 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002577 codegen_->StoreRelease(field_type, value, HeapOperand(cls, offset));
2578 } else {
2579 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2580 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2581 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2582 }
2583 } else {
2584 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2585 }
2586
2587 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002588 codegen_->MarkGCCard(cls, Register(value));
2589 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002590}
2591
2592void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
2593 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2594}
2595
2596void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002597 HBasicBlock* block = instruction->GetBlock();
2598 if (block->GetLoopInformation() != nullptr) {
2599 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2600 // The back edge will generate the suspend check.
2601 return;
2602 }
2603 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2604 // The goto will generate the suspend check.
2605 return;
2606 }
2607 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01002608}
2609
2610void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
2611 temp->SetLocations(nullptr);
2612}
2613
2614void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
2615 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002616 UNUSED(temp);
Alexandre Rames5319def2014-10-23 10:03:10 +01002617}
2618
Alexandre Rames67555f72014-11-18 10:55:16 +00002619void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
2620 LocationSummary* locations =
2621 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2622 InvokeRuntimeCallingConvention calling_convention;
2623 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2624}
2625
2626void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
2627 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002628 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002629 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002630}
2631
2632void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
2633 LocationSummary* locations =
2634 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
2635 Primitive::Type input_type = conversion->GetInputType();
2636 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002637 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00002638 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
2639 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
2640 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
2641 }
2642
Alexandre Rames542361f2015-01-29 16:57:31 +00002643 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002644 locations->SetInAt(0, Location::RequiresFpuRegister());
2645 } else {
2646 locations->SetInAt(0, Location::RequiresRegister());
2647 }
2648
Alexandre Rames542361f2015-01-29 16:57:31 +00002649 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002650 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2651 } else {
2652 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2653 }
2654}
2655
2656void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
2657 Primitive::Type result_type = conversion->GetResultType();
2658 Primitive::Type input_type = conversion->GetInputType();
2659
2660 DCHECK_NE(input_type, result_type);
2661
Alexandre Rames542361f2015-01-29 16:57:31 +00002662 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002663 int result_size = Primitive::ComponentSize(result_type);
2664 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002665 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002666 Register output = OutputRegister(conversion);
2667 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002668 if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) {
2669 __ Ubfx(output, source, 0, result_size * kBitsPerByte);
2670 } else if ((result_type == Primitive::kPrimChar) ||
2671 ((input_type == Primitive::kPrimChar) && (result_size > input_size))) {
2672 __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002673 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00002674 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002675 }
Alexandre Rames542361f2015-01-29 16:57:31 +00002676 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002677 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002678 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002679 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
2680 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002681 } else if (Primitive::IsFloatingPointType(result_type) &&
2682 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002683 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
2684 } else {
2685 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
2686 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00002687 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00002688}
Alexandre Rames67555f72014-11-18 10:55:16 +00002689
Serban Constantinescu02164b32014-11-13 14:05:07 +00002690void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
2691 HandleShift(ushr);
2692}
2693
2694void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
2695 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00002696}
2697
2698void LocationsBuilderARM64::VisitXor(HXor* instruction) {
2699 HandleBinaryOp(instruction);
2700}
2701
2702void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
2703 HandleBinaryOp(instruction);
2704}
2705
Calin Juravleb1498f62015-02-16 13:13:29 +00002706void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) {
2707 // Nothing to do, this should be removed during prepare for register allocator.
2708 UNUSED(instruction);
2709 LOG(FATAL) << "Unreachable";
2710}
2711
2712void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) {
2713 // Nothing to do, this should be removed during prepare for register allocator.
2714 UNUSED(instruction);
2715 LOG(FATAL) << "Unreachable";
2716}
2717
Alexandre Rames67555f72014-11-18 10:55:16 +00002718#undef __
2719#undef QUICK_ENTRY_POINT
2720
Alexandre Rames5319def2014-10-23 10:03:10 +01002721} // namespace arm64
2722} // namespace art