blob: a4e8ee6511f2a5f67a64a59c375803e29b6dd909 [file] [log] [blame]
Alexandre Rames5319def2014-10-23 10:03:10 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_arm64.h"
18
Serban Constantinescu579885a2015-02-22 20:51:33 +000019#include "arch/arm64/instruction_set_features_arm64.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080020#include "common_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010021#include "entrypoints/quick/quick_entrypoints.h"
Andreas Gampe1cc7dba2014-12-17 18:43:01 -080022#include "entrypoints/quick/quick_entrypoints_enum.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010023#include "gc/accounting/card_table.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080024#include "intrinsics.h"
25#include "intrinsics_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010026#include "mirror/array-inl.h"
27#include "mirror/art_method.h"
28#include "mirror/class.h"
Calin Juravlecd6dffe2015-01-08 17:35:35 +000029#include "offsets.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010030#include "thread.h"
31#include "utils/arm64/assembler_arm64.h"
32#include "utils/assembler.h"
33#include "utils/stack_checks.h"
34
35
36using namespace vixl; // NOLINT(build/namespaces)
37
38#ifdef __
39#error "ARM64 Codegen VIXL macro-assembler macro already defined."
40#endif
41
Alexandre Rames5319def2014-10-23 10:03:10 +010042namespace art {
43
44namespace arm64 {
45
Andreas Gampe878d58c2015-01-15 23:24:00 -080046using helpers::CPURegisterFrom;
47using helpers::DRegisterFrom;
48using helpers::FPRegisterFrom;
49using helpers::HeapOperand;
50using helpers::HeapOperandFrom;
51using helpers::InputCPURegisterAt;
52using helpers::InputFPRegisterAt;
53using helpers::InputRegisterAt;
54using helpers::InputOperandAt;
55using helpers::Int64ConstantFrom;
Andreas Gampe878d58c2015-01-15 23:24:00 -080056using helpers::LocationFrom;
57using helpers::OperandFromMemOperand;
58using helpers::OutputCPURegister;
59using helpers::OutputFPRegister;
60using helpers::OutputRegister;
61using helpers::RegisterFrom;
62using helpers::StackOperandFrom;
63using helpers::VIXLRegCodeFromART;
64using helpers::WRegisterFrom;
65using helpers::XRegisterFrom;
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +000066using helpers::ARM64EncodableConstantOrRegister;
Andreas Gampe878d58c2015-01-15 23:24:00 -080067
Alexandre Rames5319def2014-10-23 10:03:10 +010068static constexpr size_t kHeapRefSize = sizeof(mirror::HeapReference<mirror::Object>);
69static constexpr int kCurrentMethodStackOffset = 0;
70
Alexandre Rames5319def2014-10-23 10:03:10 +010071inline Condition ARM64Condition(IfCondition cond) {
72 switch (cond) {
73 case kCondEQ: return eq;
74 case kCondNE: return ne;
75 case kCondLT: return lt;
76 case kCondLE: return le;
77 case kCondGT: return gt;
78 case kCondGE: return ge;
79 default:
80 LOG(FATAL) << "Unknown if condition";
81 }
82 return nv; // Unreachable.
83}
84
Alexandre Ramesa89086e2014-11-07 17:13:25 +000085Location ARM64ReturnLocation(Primitive::Type return_type) {
86 DCHECK_NE(return_type, Primitive::kPrimVoid);
87 // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the
88 // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`,
89 // but we use the exact registers for clarity.
90 if (return_type == Primitive::kPrimFloat) {
91 return LocationFrom(s0);
92 } else if (return_type == Primitive::kPrimDouble) {
93 return LocationFrom(d0);
94 } else if (return_type == Primitive::kPrimLong) {
95 return LocationFrom(x0);
96 } else {
97 return LocationFrom(w0);
98 }
99}
100
Alexandre Rames5319def2014-10-23 10:03:10 +0100101Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000102 return ARM64ReturnLocation(return_type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100103}
104
Alexandre Rames67555f72014-11-18 10:55:16 +0000105#define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()->
106#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value()
Alexandre Rames5319def2014-10-23 10:03:10 +0100107
Alexandre Rames5319def2014-10-23 10:03:10 +0100108class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 {
109 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000110 BoundsCheckSlowPathARM64(HBoundsCheck* instruction,
111 Location index_location,
112 Location length_location)
113 : instruction_(instruction),
114 index_location_(index_location),
115 length_location_(length_location) {}
116
Alexandre Rames5319def2014-10-23 10:03:10 +0100117
Alexandre Rames67555f72014-11-18 10:55:16 +0000118 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000119 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100120 __ Bind(GetEntryLabel());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000121 // We're moving two locations to locations that could overlap, so we need a parallel
122 // move resolver.
123 InvokeRuntimeCallingConvention calling_convention;
124 codegen->EmitParallelMoves(
Nicolas Geoffray90218252015-04-15 11:56:51 +0100125 index_location_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt,
126 length_location_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000127 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000128 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800129 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100130 }
131
132 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000133 HBoundsCheck* const instruction_;
134 const Location index_location_;
135 const Location length_location_;
136
Alexandre Rames5319def2014-10-23 10:03:10 +0100137 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64);
138};
139
Alexandre Rames67555f72014-11-18 10:55:16 +0000140class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 {
141 public:
142 explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : instruction_(instruction) {}
143
144 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
145 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
146 __ Bind(GetEntryLabel());
147 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000148 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800149 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000150 }
151
152 private:
153 HDivZeroCheck* const instruction_;
154 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64);
155};
156
157class LoadClassSlowPathARM64 : public SlowPathCodeARM64 {
158 public:
159 LoadClassSlowPathARM64(HLoadClass* cls,
160 HInstruction* at,
161 uint32_t dex_pc,
162 bool do_clinit)
163 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
164 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
165 }
166
167 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
168 LocationSummary* locations = at_->GetLocations();
169 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
170
171 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000172 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000173
174 InvokeRuntimeCallingConvention calling_convention;
175 __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex());
176 arm64_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1).W());
177 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
178 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000179 arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800180 if (do_clinit_) {
181 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t, mirror::ArtMethod*>();
182 } else {
183 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t, mirror::ArtMethod*>();
184 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000185
186 // Move the class to the desired location.
187 Location out = locations->Out();
188 if (out.IsValid()) {
189 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
190 Primitive::Type type = at_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000191 arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000192 }
193
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000194 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000195 __ B(GetExitLabel());
196 }
197
198 private:
199 // The class this slow path will load.
200 HLoadClass* const cls_;
201
202 // The instruction where this slow path is happening.
203 // (Might be the load class or an initialization check).
204 HInstruction* const at_;
205
206 // The dex PC of `at_`.
207 const uint32_t dex_pc_;
208
209 // Whether to initialize the class.
210 const bool do_clinit_;
211
212 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64);
213};
214
215class LoadStringSlowPathARM64 : public SlowPathCodeARM64 {
216 public:
217 explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {}
218
219 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
220 LocationSummary* locations = instruction_->GetLocations();
221 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
222 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
223
224 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000225 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000226
227 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800228 arm64_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1).W());
229 __ Mov(calling_convention.GetRegisterAt(0).W(), instruction_->GetStringIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +0000230 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000231 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800232 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000233 Primitive::Type type = instruction_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000234 arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000235
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000236 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000237 __ B(GetExitLabel());
238 }
239
240 private:
241 HLoadString* const instruction_;
242
243 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64);
244};
245
Alexandre Rames5319def2014-10-23 10:03:10 +0100246class NullCheckSlowPathARM64 : public SlowPathCodeARM64 {
247 public:
248 explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {}
249
Alexandre Rames67555f72014-11-18 10:55:16 +0000250 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
251 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100252 __ Bind(GetEntryLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000253 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000254 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800255 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100256 }
257
258 private:
259 HNullCheck* const instruction_;
260
261 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64);
262};
263
264class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 {
265 public:
266 explicit SuspendCheckSlowPathARM64(HSuspendCheck* instruction,
267 HBasicBlock* successor)
268 : instruction_(instruction), successor_(successor) {}
269
Alexandre Rames67555f72014-11-18 10:55:16 +0000270 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
271 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100272 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000273 SaveLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000274 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000275 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800276 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000277 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000278 if (successor_ == nullptr) {
279 __ B(GetReturnLabel());
280 } else {
281 __ B(arm64_codegen->GetLabelOf(successor_));
282 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100283 }
284
285 vixl::Label* GetReturnLabel() {
286 DCHECK(successor_ == nullptr);
287 return &return_label_;
288 }
289
Alexandre Rames5319def2014-10-23 10:03:10 +0100290 private:
291 HSuspendCheck* const instruction_;
292 // If not null, the block to branch to after the suspend check.
293 HBasicBlock* const successor_;
294
295 // If `successor_` is null, the label to branch to after the suspend check.
296 vixl::Label return_label_;
297
298 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64);
299};
300
Alexandre Rames67555f72014-11-18 10:55:16 +0000301class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 {
302 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000303 TypeCheckSlowPathARM64(HInstruction* instruction,
304 Location class_to_check,
305 Location object_class,
306 uint32_t dex_pc)
307 : instruction_(instruction),
308 class_to_check_(class_to_check),
309 object_class_(object_class),
310 dex_pc_(dex_pc) {}
Alexandre Rames67555f72014-11-18 10:55:16 +0000311
312 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000313 LocationSummary* locations = instruction_->GetLocations();
314 DCHECK(instruction_->IsCheckCast()
315 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
316 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
317
Alexandre Rames67555f72014-11-18 10:55:16 +0000318 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000319 SaveLiveRegisters(codegen, locations);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000320
321 // We're moving two locations to locations that could overlap, so we need a parallel
322 // move resolver.
323 InvokeRuntimeCallingConvention calling_convention;
324 codegen->EmitParallelMoves(
Nicolas Geoffray90218252015-04-15 11:56:51 +0100325 class_to_check_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot,
326 object_class_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000327
328 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000329 arm64_codegen->InvokeRuntime(
330 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000331 Primitive::Type ret_type = instruction_->GetType();
332 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
333 arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800334 CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t,
335 const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000336 } else {
337 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000338 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800339 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000340 }
341
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000342 RestoreLiveRegisters(codegen, locations);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000343 __ B(GetExitLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000344 }
345
346 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000347 HInstruction* const instruction_;
348 const Location class_to_check_;
349 const Location object_class_;
350 uint32_t dex_pc_;
351
Alexandre Rames67555f72014-11-18 10:55:16 +0000352 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64);
353};
354
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700355class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 {
356 public:
357 explicit DeoptimizationSlowPathARM64(HInstruction* instruction)
358 : instruction_(instruction) {}
359
360 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
361 __ Bind(GetEntryLabel());
362 SaveLiveRegisters(codegen, instruction_->GetLocations());
363 DCHECK(instruction_->IsDeoptimize());
364 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
365 uint32_t dex_pc = deoptimize->GetDexPc();
366 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
367 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
368 }
369
370 private:
371 HInstruction* const instruction_;
372 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64);
373};
374
Alexandre Rames5319def2014-10-23 10:03:10 +0100375#undef __
376
377Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
378 Location next_location;
379 if (type == Primitive::kPrimVoid) {
380 LOG(FATAL) << "Unreachable type " << type;
381 }
382
Alexandre Rames542361f2015-01-29 16:57:31 +0000383 if (Primitive::IsFloatingPointType(type) &&
384 (fp_index_ < calling_convention.GetNumberOfFpuRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000385 next_location = LocationFrom(calling_convention.GetFpuRegisterAt(fp_index_++));
Alexandre Rames542361f2015-01-29 16:57:31 +0000386 } else if (!Primitive::IsFloatingPointType(type) &&
387 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000388 next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++));
389 } else {
390 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Alexandre Rames542361f2015-01-29 16:57:31 +0000391 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
392 : Location::StackSlot(stack_offset);
Alexandre Rames5319def2014-10-23 10:03:10 +0100393 }
394
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000395 // Space on the stack is reserved for all arguments.
Alexandre Rames542361f2015-01-29 16:57:31 +0000396 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
Alexandre Rames5319def2014-10-23 10:03:10 +0100397 return next_location;
398}
399
Serban Constantinescu579885a2015-02-22 20:51:33 +0000400CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph,
401 const Arm64InstructionSetFeatures& isa_features,
402 const CompilerOptions& compiler_options)
Alexandre Rames5319def2014-10-23 10:03:10 +0100403 : CodeGenerator(graph,
404 kNumberOfAllocatableRegisters,
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000405 kNumberOfAllocatableFPRegisters,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000406 kNumberOfAllocatableRegisterPairs,
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000407 callee_saved_core_registers.list(),
408 callee_saved_fp_registers.list(),
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000409 compiler_options),
Alexandre Rames5319def2014-10-23 10:03:10 +0100410 block_labels_(nullptr),
411 location_builder_(graph, this),
Alexandre Rames3e69f162014-12-10 10:36:50 +0000412 instruction_visitor_(graph, this),
Serban Constantinescu579885a2015-02-22 20:51:33 +0000413 move_resolver_(graph->GetArena(), this),
414 isa_features_(isa_features) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000415 // Save the link register (containing the return address) to mimic Quick.
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000416 AddAllocatedRegister(LocationFrom(lr));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000417}
Alexandre Rames5319def2014-10-23 10:03:10 +0100418
Alexandre Rames67555f72014-11-18 10:55:16 +0000419#undef __
420#define __ GetVIXLAssembler()->
Alexandre Rames5319def2014-10-23 10:03:10 +0100421
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000422void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) {
423 // Ensure we emit the literal pool.
424 __ FinalizeCode();
425 CodeGenerator::Finalize(allocator);
426}
427
Alexandre Rames3e69f162014-12-10 10:36:50 +0000428void ParallelMoveResolverARM64::EmitMove(size_t index) {
429 MoveOperands* move = moves_.Get(index);
430 codegen_->MoveLocation(move->GetDestination(), move->GetSource());
431}
432
433void ParallelMoveResolverARM64::EmitSwap(size_t index) {
434 MoveOperands* move = moves_.Get(index);
435 codegen_->SwapLocations(move->GetDestination(), move->GetSource());
436}
437
438void ParallelMoveResolverARM64::RestoreScratch(int reg) {
439 __ Pop(Register(VIXLRegCodeFromART(reg), kXRegSize));
440}
441
442void ParallelMoveResolverARM64::SpillScratch(int reg) {
443 __ Push(Register(VIXLRegCodeFromART(reg), kXRegSize));
444}
445
Alexandre Rames5319def2014-10-23 10:03:10 +0100446void CodeGeneratorARM64::GenerateFrameEntry() {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100447 MacroAssembler* masm = GetVIXLAssembler();
448 BlockPoolsScope block_pools(masm);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000449 __ Bind(&frame_entry_label_);
450
Serban Constantinescu02164b32014-11-13 14:05:07 +0000451 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod();
452 if (do_overflow_check) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100453 UseScratchRegisterScope temps(masm);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000454 Register temp = temps.AcquireX();
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000455 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000456 __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64)));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000457 __ Ldr(wzr, MemOperand(temp, 0));
458 RecordPcInfo(nullptr, 0);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000459 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100460
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000461 if (!HasEmptyFrame()) {
462 int frame_size = GetFrameSize();
463 // Stack layout:
464 // sp[frame_size - 8] : lr.
465 // ... : other preserved core registers.
466 // ... : other preserved fp registers.
467 // ... : reserved frame space.
468 // sp[0] : current method.
469 __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100470 GetAssembler()->cfi().AdjustCFAOffset(frame_size);
Zheng Xu69a50302015-04-14 20:04:41 +0800471 GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(),
472 frame_size - GetCoreSpillSize());
473 GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(),
474 frame_size - FrameEntrySpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000475 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100476}
477
478void CodeGeneratorARM64::GenerateFrameExit() {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100479 BlockPoolsScope block_pools(GetVIXLAssembler());
David Srbeckyc34dc932015-04-12 09:27:43 +0100480 GetAssembler()->cfi().RememberState();
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000481 if (!HasEmptyFrame()) {
482 int frame_size = GetFrameSize();
Zheng Xu69a50302015-04-14 20:04:41 +0800483 GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(),
484 frame_size - FrameEntrySpillSize());
485 GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(),
486 frame_size - GetCoreSpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000487 __ Drop(frame_size);
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100488 GetAssembler()->cfi().AdjustCFAOffset(-frame_size);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000489 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100490 __ Ret();
491 GetAssembler()->cfi().RestoreState();
492 GetAssembler()->cfi().DefCFAOffset(GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +0100493}
494
495void CodeGeneratorARM64::Bind(HBasicBlock* block) {
496 __ Bind(GetLabelOf(block));
497}
498
Alexandre Rames5319def2014-10-23 10:03:10 +0100499void CodeGeneratorARM64::Move(HInstruction* instruction,
500 Location location,
501 HInstruction* move_for) {
502 LocationSummary* locations = instruction->GetLocations();
503 if (locations != nullptr && locations->Out().Equals(location)) {
504 return;
505 }
506
507 Primitive::Type type = instruction->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000508 DCHECK_NE(type, Primitive::kPrimVoid);
Alexandre Rames5319def2014-10-23 10:03:10 +0100509
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000510 if (instruction->IsIntConstant()
511 || instruction->IsLongConstant()
512 || instruction->IsNullConstant()) {
513 int64_t value = GetInt64ValueOf(instruction->AsConstant());
Alexandre Rames5319def2014-10-23 10:03:10 +0100514 if (location.IsRegister()) {
515 Register dst = RegisterFrom(location, type);
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000516 DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) ||
Alexandre Rames5319def2014-10-23 10:03:10 +0100517 (instruction->IsLongConstant() && dst.Is64Bits()));
518 __ Mov(dst, value);
519 } else {
520 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000521 UseScratchRegisterScope temps(GetVIXLAssembler());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000522 Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant())
523 ? temps.AcquireW()
524 : temps.AcquireX();
Alexandre Rames5319def2014-10-23 10:03:10 +0100525 __ Mov(temp, value);
526 __ Str(temp, StackOperandFrom(location));
527 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000528 } else if (instruction->IsTemporary()) {
529 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000530 MoveLocation(location, temp_location, type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100531 } else if (instruction->IsLoadLocal()) {
532 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Alexandre Rames542361f2015-01-29 16:57:31 +0000533 if (Primitive::Is64BitType(type)) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000534 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000535 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000536 MoveLocation(location, Location::StackSlot(stack_slot), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100537 }
538
539 } else {
540 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000541 MoveLocation(location, locations->Out(), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100542 }
543}
544
Alexandre Rames5319def2014-10-23 10:03:10 +0100545Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const {
546 Primitive::Type type = load->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000547
Alexandre Rames5319def2014-10-23 10:03:10 +0100548 switch (type) {
549 case Primitive::kPrimNot:
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000550 case Primitive::kPrimInt:
551 case Primitive::kPrimFloat:
552 return Location::StackSlot(GetStackSlot(load->GetLocal()));
553
554 case Primitive::kPrimLong:
555 case Primitive::kPrimDouble:
556 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
557
Alexandre Rames5319def2014-10-23 10:03:10 +0100558 case Primitive::kPrimBoolean:
559 case Primitive::kPrimByte:
560 case Primitive::kPrimChar:
561 case Primitive::kPrimShort:
Alexandre Rames5319def2014-10-23 10:03:10 +0100562 case Primitive::kPrimVoid:
Alexandre Rames5319def2014-10-23 10:03:10 +0100563 LOG(FATAL) << "Unexpected type " << type;
564 }
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000565
Alexandre Rames5319def2014-10-23 10:03:10 +0100566 LOG(FATAL) << "Unreachable";
567 return Location::NoLocation();
568}
569
570void CodeGeneratorARM64::MarkGCCard(Register object, Register value) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000571 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +0100572 Register card = temps.AcquireX();
Serban Constantinescu02164b32014-11-13 14:05:07 +0000573 Register temp = temps.AcquireW(); // Index within the CardTable - 32bit.
Alexandre Rames5319def2014-10-23 10:03:10 +0100574 vixl::Label done;
575 __ Cbz(value, &done);
576 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value()));
577 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000578 __ Strb(card, MemOperand(card, temp.X()));
Alexandre Rames5319def2014-10-23 10:03:10 +0100579 __ Bind(&done);
580}
581
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000582void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const {
583 // Blocked core registers:
584 // lr : Runtime reserved.
585 // tr : Runtime reserved.
586 // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it.
587 // ip1 : VIXL core temp.
588 // ip0 : VIXL core temp.
589 //
590 // Blocked fp registers:
591 // d31 : VIXL fp temp.
Alexandre Rames5319def2014-10-23 10:03:10 +0100592 CPURegList reserved_core_registers = vixl_reserved_core_registers;
593 reserved_core_registers.Combine(runtime_reserved_core_registers);
Alexandre Rames5319def2014-10-23 10:03:10 +0100594 while (!reserved_core_registers.IsEmpty()) {
595 blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true;
596 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000597
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000598 CPURegList reserved_fp_registers = vixl_reserved_fp_registers;
Zheng Xua3ec3942015-02-15 18:39:46 +0800599 while (!reserved_fp_registers.IsEmpty()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000600 blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true;
601 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000602
603 if (is_baseline) {
604 CPURegList reserved_core_baseline_registers = callee_saved_core_registers;
605 while (!reserved_core_baseline_registers.IsEmpty()) {
606 blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true;
607 }
608
609 CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers;
610 while (!reserved_fp_baseline_registers.IsEmpty()) {
611 blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true;
612 }
613 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100614}
615
616Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const {
617 if (type == Primitive::kPrimVoid) {
618 LOG(FATAL) << "Unreachable type " << type;
619 }
620
Alexandre Rames542361f2015-01-29 16:57:31 +0000621 if (Primitive::IsFloatingPointType(type)) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000622 ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters);
623 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100624 return Location::FpuRegisterLocation(reg);
625 } else {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000626 ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters);
627 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100628 return Location::RegisterLocation(reg);
629 }
630}
631
Alexandre Rames3e69f162014-12-10 10:36:50 +0000632size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
633 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
634 __ Str(reg, MemOperand(sp, stack_index));
635 return kArm64WordSize;
636}
637
638size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
639 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
640 __ Ldr(reg, MemOperand(sp, stack_index));
641 return kArm64WordSize;
642}
643
644size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
645 FPRegister reg = FPRegister(reg_id, kDRegSize);
646 __ Str(reg, MemOperand(sp, stack_index));
647 return kArm64WordSize;
648}
649
650size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
651 FPRegister reg = FPRegister(reg_id, kDRegSize);
652 __ Ldr(reg, MemOperand(sp, stack_index));
653 return kArm64WordSize;
654}
655
Alexandre Rames5319def2014-10-23 10:03:10 +0100656void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
657 stream << Arm64ManagedRegister::FromXRegister(XRegister(reg));
658}
659
660void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
661 stream << Arm64ManagedRegister::FromDRegister(DRegister(reg));
662}
663
Alexandre Rames67555f72014-11-18 10:55:16 +0000664void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000665 if (constant->IsIntConstant()) {
666 __ Mov(Register(destination), constant->AsIntConstant()->GetValue());
667 } else if (constant->IsLongConstant()) {
668 __ Mov(Register(destination), constant->AsLongConstant()->GetValue());
669 } else if (constant->IsNullConstant()) {
670 __ Mov(Register(destination), 0);
Alexandre Rames67555f72014-11-18 10:55:16 +0000671 } else if (constant->IsFloatConstant()) {
672 __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue());
673 } else {
674 DCHECK(constant->IsDoubleConstant());
675 __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue());
676 }
677}
678
Alexandre Rames3e69f162014-12-10 10:36:50 +0000679
680static bool CoherentConstantAndType(Location constant, Primitive::Type type) {
681 DCHECK(constant.IsConstant());
682 HConstant* cst = constant.GetConstant();
683 return (cst->IsIntConstant() && type == Primitive::kPrimInt) ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000684 // Null is mapped to a core W register, which we associate with kPrimInt.
685 (cst->IsNullConstant() && type == Primitive::kPrimInt) ||
Alexandre Rames3e69f162014-12-10 10:36:50 +0000686 (cst->IsLongConstant() && type == Primitive::kPrimLong) ||
687 (cst->IsFloatConstant() && type == Primitive::kPrimFloat) ||
688 (cst->IsDoubleConstant() && type == Primitive::kPrimDouble);
689}
690
691void CodeGeneratorARM64::MoveLocation(Location destination, Location source, Primitive::Type type) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000692 if (source.Equals(destination)) {
693 return;
694 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000695
696 // A valid move can always be inferred from the destination and source
697 // locations. When moving from and to a register, the argument type can be
698 // used to generate 32bit instead of 64bit moves. In debug mode we also
699 // checks the coherency of the locations and the type.
700 bool unspecified_type = (type == Primitive::kPrimVoid);
701
702 if (destination.IsRegister() || destination.IsFpuRegister()) {
703 if (unspecified_type) {
704 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
705 if (source.IsStackSlot() ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000706 (src_cst != nullptr && (src_cst->IsIntConstant()
707 || src_cst->IsFloatConstant()
708 || src_cst->IsNullConstant()))) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000709 // For stack slots and 32bit constants, a 64bit type is appropriate.
710 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexandre Rames67555f72014-11-18 10:55:16 +0000711 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000712 // If the source is a double stack slot or a 64bit constant, a 64bit
713 // type is appropriate. Else the source is a register, and since the
714 // type has not been specified, we chose a 64bit type to force a 64bit
715 // move.
716 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexandre Rames67555f72014-11-18 10:55:16 +0000717 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000718 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000719 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
720 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000721 CPURegister dst = CPURegisterFrom(destination, type);
722 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
723 DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot());
724 __ Ldr(dst, StackOperandFrom(source));
725 } else if (source.IsConstant()) {
726 DCHECK(CoherentConstantAndType(source, type));
727 MoveConstant(dst, source.GetConstant());
728 } else {
729 if (destination.IsRegister()) {
730 __ Mov(Register(dst), RegisterFrom(source, type));
731 } else {
732 __ Fmov(FPRegister(dst), FPRegisterFrom(source, type));
733 }
734 }
735
736 } else { // The destination is not a register. It must be a stack slot.
737 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
738 if (source.IsRegister() || source.IsFpuRegister()) {
739 if (unspecified_type) {
740 if (source.IsRegister()) {
741 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
742 } else {
743 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
744 }
745 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000746 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
747 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000748 __ Str(CPURegisterFrom(source, type), StackOperandFrom(destination));
749 } else if (source.IsConstant()) {
750 DCHECK(unspecified_type || CoherentConstantAndType(source, type));
751 UseScratchRegisterScope temps(GetVIXLAssembler());
752 HConstant* src_cst = source.GetConstant();
753 CPURegister temp;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000754 if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000755 temp = temps.AcquireW();
756 } else if (src_cst->IsLongConstant()) {
757 temp = temps.AcquireX();
758 } else if (src_cst->IsFloatConstant()) {
759 temp = temps.AcquireS();
760 } else {
761 DCHECK(src_cst->IsDoubleConstant());
762 temp = temps.AcquireD();
763 }
764 MoveConstant(temp, src_cst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000765 __ Str(temp, StackOperandFrom(destination));
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000766 } else {
Alexandre Rames67555f72014-11-18 10:55:16 +0000767 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000768 DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000769 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000770 // There is generally less pressure on FP registers.
771 FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS();
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000772 __ Ldr(temp, StackOperandFrom(source));
773 __ Str(temp, StackOperandFrom(destination));
774 }
775 }
776}
777
Alexandre Rames3e69f162014-12-10 10:36:50 +0000778void CodeGeneratorARM64::SwapLocations(Location loc1, Location loc2) {
779 DCHECK(!loc1.IsConstant());
780 DCHECK(!loc2.IsConstant());
781
782 if (loc1.Equals(loc2)) {
783 return;
784 }
785
786 UseScratchRegisterScope temps(GetAssembler()->vixl_masm_);
787
788 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
789 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
790 bool is_fp_reg1 = loc1.IsFpuRegister();
791 bool is_fp_reg2 = loc2.IsFpuRegister();
792
793 if (loc2.IsRegister() && loc1.IsRegister()) {
794 Register r1 = XRegisterFrom(loc1);
795 Register r2 = XRegisterFrom(loc2);
796 Register tmp = temps.AcquireSameSizeAs(r1);
797 __ Mov(tmp, r2);
798 __ Mov(r2, r1);
799 __ Mov(r1, tmp);
800 } else if (is_fp_reg2 && is_fp_reg1) {
801 FPRegister r1 = DRegisterFrom(loc1);
802 FPRegister r2 = DRegisterFrom(loc2);
803 FPRegister tmp = temps.AcquireSameSizeAs(r1);
804 __ Fmov(tmp, r2);
805 __ Fmov(r2, r1);
806 __ Fmov(r1, tmp);
807 } else if (is_slot1 != is_slot2) {
808 MemOperand mem = StackOperandFrom(is_slot1 ? loc1 : loc2);
809 Location reg_loc = is_slot1 ? loc2 : loc1;
810 CPURegister reg, tmp;
811 if (reg_loc.IsFpuRegister()) {
812 reg = DRegisterFrom(reg_loc);
813 tmp = temps.AcquireD();
814 } else {
815 reg = XRegisterFrom(reg_loc);
816 tmp = temps.AcquireX();
817 }
818 __ Ldr(tmp, mem);
819 __ Str(reg, mem);
820 if (reg_loc.IsFpuRegister()) {
821 __ Fmov(FPRegister(reg), FPRegister(tmp));
822 } else {
823 __ Mov(Register(reg), Register(tmp));
824 }
825 } else if (is_slot1 && is_slot2) {
826 MemOperand mem1 = StackOperandFrom(loc1);
827 MemOperand mem2 = StackOperandFrom(loc2);
828 Register tmp1 = loc1.IsStackSlot() ? temps.AcquireW() : temps.AcquireX();
829 Register tmp2 = temps.AcquireSameSizeAs(tmp1);
830 __ Ldr(tmp1, mem1);
831 __ Ldr(tmp2, mem2);
832 __ Str(tmp1, mem2);
833 __ Str(tmp2, mem1);
834 } else {
835 LOG(FATAL) << "Unimplemented";
836 }
837}
838
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000839void CodeGeneratorARM64::Load(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000840 CPURegister dst,
841 const MemOperand& src) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000842 switch (type) {
843 case Primitive::kPrimBoolean:
Alexandre Rames67555f72014-11-18 10:55:16 +0000844 __ Ldrb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000845 break;
846 case Primitive::kPrimByte:
Alexandre Rames67555f72014-11-18 10:55:16 +0000847 __ Ldrsb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000848 break;
849 case Primitive::kPrimShort:
Alexandre Rames67555f72014-11-18 10:55:16 +0000850 __ Ldrsh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000851 break;
852 case Primitive::kPrimChar:
Alexandre Rames67555f72014-11-18 10:55:16 +0000853 __ Ldrh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000854 break;
855 case Primitive::kPrimInt:
856 case Primitive::kPrimNot:
857 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000858 case Primitive::kPrimFloat:
859 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000860 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Rames67555f72014-11-18 10:55:16 +0000861 __ Ldr(dst, src);
862 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000863 case Primitive::kPrimVoid:
864 LOG(FATAL) << "Unreachable type " << type;
865 }
866}
867
Calin Juravle77520bc2015-01-12 18:45:46 +0000868void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000869 CPURegister dst,
870 const MemOperand& src) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100871 MacroAssembler* masm = GetVIXLAssembler();
872 BlockPoolsScope block_pools(masm);
873 UseScratchRegisterScope temps(masm);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000874 Register temp_base = temps.AcquireX();
Calin Juravle77520bc2015-01-12 18:45:46 +0000875 Primitive::Type type = instruction->GetType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000876
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000877 DCHECK(!src.IsPreIndex());
878 DCHECK(!src.IsPostIndex());
879
880 // TODO(vixl): Let the MacroAssembler handle MemOperand.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800881 __ Add(temp_base, src.base(), OperandFromMemOperand(src));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000882 MemOperand base = MemOperand(temp_base);
883 switch (type) {
884 case Primitive::kPrimBoolean:
885 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000886 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000887 break;
888 case Primitive::kPrimByte:
889 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000890 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000891 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
892 break;
893 case Primitive::kPrimChar:
894 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000895 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000896 break;
897 case Primitive::kPrimShort:
898 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000899 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000900 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
901 break;
902 case Primitive::kPrimInt:
903 case Primitive::kPrimNot:
904 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000905 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000906 __ Ldar(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000907 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000908 break;
909 case Primitive::kPrimFloat:
910 case Primitive::kPrimDouble: {
911 DCHECK(dst.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000912 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000913
914 Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
915 __ Ldar(temp, base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000916 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000917 __ Fmov(FPRegister(dst), temp);
918 break;
919 }
920 case Primitive::kPrimVoid:
921 LOG(FATAL) << "Unreachable type " << type;
922 }
923}
924
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000925void CodeGeneratorARM64::Store(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000926 CPURegister src,
927 const MemOperand& dst) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000928 switch (type) {
929 case Primitive::kPrimBoolean:
930 case Primitive::kPrimByte:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000931 __ Strb(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000932 break;
933 case Primitive::kPrimChar:
934 case Primitive::kPrimShort:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000935 __ Strh(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000936 break;
937 case Primitive::kPrimInt:
938 case Primitive::kPrimNot:
939 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000940 case Primitive::kPrimFloat:
941 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000942 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000943 __ Str(src, dst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000944 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000945 case Primitive::kPrimVoid:
946 LOG(FATAL) << "Unreachable type " << type;
947 }
948}
949
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000950void CodeGeneratorARM64::StoreRelease(Primitive::Type type,
951 CPURegister src,
952 const MemOperand& dst) {
953 UseScratchRegisterScope temps(GetVIXLAssembler());
954 Register temp_base = temps.AcquireX();
955
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000956 DCHECK(!dst.IsPreIndex());
957 DCHECK(!dst.IsPostIndex());
958
959 // TODO(vixl): Let the MacroAssembler handle this.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800960 Operand op = OperandFromMemOperand(dst);
961 __ Add(temp_base, dst.base(), op);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000962 MemOperand base = MemOperand(temp_base);
963 switch (type) {
964 case Primitive::kPrimBoolean:
965 case Primitive::kPrimByte:
966 __ Stlrb(Register(src), base);
967 break;
968 case Primitive::kPrimChar:
969 case Primitive::kPrimShort:
970 __ Stlrh(Register(src), base);
971 break;
972 case Primitive::kPrimInt:
973 case Primitive::kPrimNot:
974 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000975 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000976 __ Stlr(Register(src), base);
977 break;
978 case Primitive::kPrimFloat:
979 case Primitive::kPrimDouble: {
980 DCHECK(src.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000981 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000982
983 Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
984 __ Fmov(temp, FPRegister(src));
985 __ Stlr(temp, base);
986 break;
987 }
988 case Primitive::kPrimVoid:
989 LOG(FATAL) << "Unreachable type " << type;
990 }
991}
992
Alexandre Rames67555f72014-11-18 10:55:16 +0000993void CodeGeneratorARM64::LoadCurrentMethod(vixl::Register current_method) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000994 DCHECK(RequiresCurrentMethod());
Alexandre Rames67555f72014-11-18 10:55:16 +0000995 DCHECK(current_method.IsW());
996 __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset));
997}
998
999void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset,
1000 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001001 uint32_t dex_pc,
1002 SlowPathCode* slow_path) {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001003 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames67555f72014-11-18 10:55:16 +00001004 __ Ldr(lr, MemOperand(tr, entry_point_offset));
1005 __ Blr(lr);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001006 if (instruction != nullptr) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001007 RecordPcInfo(instruction, dex_pc, slow_path);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001008 DCHECK(instruction->IsSuspendCheck()
1009 || instruction->IsBoundsCheck()
1010 || instruction->IsNullCheck()
1011 || instruction->IsDivZeroCheck()
1012 || !IsLeafMethod());
1013 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001014}
1015
1016void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path,
1017 vixl::Register class_reg) {
1018 UseScratchRegisterScope temps(GetVIXLAssembler());
1019 Register temp = temps.AcquireW();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001020 size_t status_offset = mirror::Class::StatusOffset().SizeValue();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001021 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001022
Serban Constantinescu02164b32014-11-13 14:05:07 +00001023 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
Serban Constantinescu579885a2015-02-22 20:51:33 +00001024 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001025 // TODO(vixl): Let the MacroAssembler handle MemOperand.
1026 __ Add(temp, class_reg, status_offset);
1027 __ Ldar(temp, HeapOperand(temp));
1028 __ Cmp(temp, mirror::Class::kStatusInitialized);
1029 __ B(lt, slow_path->GetEntryLabel());
1030 } else {
1031 __ Ldr(temp, HeapOperand(class_reg, status_offset));
1032 __ Cmp(temp, mirror::Class::kStatusInitialized);
1033 __ B(lt, slow_path->GetEntryLabel());
1034 __ Dmb(InnerShareable, BarrierReads);
1035 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001036 __ Bind(slow_path->GetExitLabel());
1037}
Alexandre Rames5319def2014-10-23 10:03:10 +01001038
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001039void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) {
1040 BarrierType type = BarrierAll;
1041
1042 switch (kind) {
1043 case MemBarrierKind::kAnyAny:
1044 case MemBarrierKind::kAnyStore: {
1045 type = BarrierAll;
1046 break;
1047 }
1048 case MemBarrierKind::kLoadAny: {
1049 type = BarrierReads;
1050 break;
1051 }
1052 case MemBarrierKind::kStoreStore: {
1053 type = BarrierWrites;
1054 break;
1055 }
1056 default:
1057 LOG(FATAL) << "Unexpected memory barrier " << kind;
1058 }
1059 __ Dmb(InnerShareable, type);
1060}
1061
Serban Constantinescu02164b32014-11-13 14:05:07 +00001062void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction,
1063 HBasicBlock* successor) {
1064 SuspendCheckSlowPathARM64* slow_path =
1065 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor);
1066 codegen_->AddSlowPath(slow_path);
1067 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
1068 Register temp = temps.AcquireW();
1069
1070 __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue()));
1071 if (successor == nullptr) {
1072 __ Cbnz(temp, slow_path->GetEntryLabel());
1073 __ Bind(slow_path->GetReturnLabel());
1074 } else {
1075 __ Cbz(temp, codegen_->GetLabelOf(successor));
1076 __ B(slow_path->GetEntryLabel());
1077 // slow_path will return to GetLabelOf(successor).
1078 }
1079}
1080
Alexandre Rames5319def2014-10-23 10:03:10 +01001081InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
1082 CodeGeneratorARM64* codegen)
1083 : HGraphVisitor(graph),
1084 assembler_(codegen->GetAssembler()),
1085 codegen_(codegen) {}
1086
1087#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Alexandre Rames3e69f162014-12-10 10:36:50 +00001088 /* No unimplemented IR. */
Alexandre Rames5319def2014-10-23 10:03:10 +01001089
1090#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
1091
1092enum UnimplementedInstructionBreakCode {
Alexandre Rames67555f72014-11-18 10:55:16 +00001093 // Using a base helps identify when we hit such breakpoints.
1094 UnimplementedInstructionBreakCodeBaseCode = 0x900,
Alexandre Rames5319def2014-10-23 10:03:10 +01001095#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
1096 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
1097#undef ENUM_UNIMPLEMENTED_INSTRUCTION
1098};
1099
1100#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
1101 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001102 UNUSED(instr); \
Alexandre Rames5319def2014-10-23 10:03:10 +01001103 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
1104 } \
1105 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
1106 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
1107 locations->SetOut(Location::Any()); \
1108 }
1109 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
1110#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
1111
1112#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
Alexandre Rames67555f72014-11-18 10:55:16 +00001113#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
Alexandre Rames5319def2014-10-23 10:03:10 +01001114
Alexandre Rames67555f72014-11-18 10:55:16 +00001115void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001116 DCHECK_EQ(instr->InputCount(), 2U);
1117 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1118 Primitive::Type type = instr->GetResultType();
1119 switch (type) {
1120 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001121 case Primitive::kPrimLong:
Alexandre Rames5319def2014-10-23 10:03:10 +01001122 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001123 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr));
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001124 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001125 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001126
1127 case Primitive::kPrimFloat:
1128 case Primitive::kPrimDouble:
1129 locations->SetInAt(0, Location::RequiresFpuRegister());
1130 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001131 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001132 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001133
Alexandre Rames5319def2014-10-23 10:03:10 +01001134 default:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001135 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001136 }
1137}
1138
Alexandre Rames09a99962015-04-15 11:47:56 +01001139void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) {
1140 LocationSummary* locations =
1141 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1142 locations->SetInAt(0, Location::RequiresRegister());
1143 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1144 locations->SetOut(Location::RequiresFpuRegister());
1145 } else {
1146 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1147 }
1148}
1149
1150void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction,
1151 const FieldInfo& field_info) {
1152 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Alexandre Ramesd921d642015-04-16 15:07:16 +01001153 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001154
1155 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset());
1156 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
1157
1158 if (field_info.IsVolatile()) {
1159 if (use_acquire_release) {
1160 // NB: LoadAcquire will record the pc info if needed.
1161 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
1162 } else {
1163 codegen_->Load(field_info.GetFieldType(), OutputCPURegister(instruction), field);
1164 codegen_->MaybeRecordImplicitNullCheck(instruction);
1165 // For IRIW sequential consistency kLoadAny is not sufficient.
1166 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1167 }
1168 } else {
1169 codegen_->Load(field_info.GetFieldType(), OutputCPURegister(instruction), field);
1170 codegen_->MaybeRecordImplicitNullCheck(instruction);
1171 }
1172}
1173
1174void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) {
1175 LocationSummary* locations =
1176 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1177 locations->SetInAt(0, Location::RequiresRegister());
1178 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
1179 locations->SetInAt(1, Location::RequiresFpuRegister());
1180 } else {
1181 locations->SetInAt(1, Location::RequiresRegister());
1182 }
1183}
1184
1185void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction,
1186 const FieldInfo& field_info) {
1187 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
Alexandre Ramesd921d642015-04-16 15:07:16 +01001188 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001189
1190 Register obj = InputRegisterAt(instruction, 0);
1191 CPURegister value = InputCPURegisterAt(instruction, 1);
1192 Offset offset = field_info.GetFieldOffset();
1193 Primitive::Type field_type = field_info.GetFieldType();
1194 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
1195
1196 if (field_info.IsVolatile()) {
1197 if (use_acquire_release) {
1198 codegen_->StoreRelease(field_type, value, HeapOperand(obj, offset));
1199 codegen_->MaybeRecordImplicitNullCheck(instruction);
1200 } else {
1201 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
1202 codegen_->Store(field_type, value, HeapOperand(obj, offset));
1203 codegen_->MaybeRecordImplicitNullCheck(instruction);
1204 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1205 }
1206 } else {
1207 codegen_->Store(field_type, value, HeapOperand(obj, offset));
1208 codegen_->MaybeRecordImplicitNullCheck(instruction);
1209 }
1210
1211 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
1212 codegen_->MarkGCCard(obj, Register(value));
1213 }
1214}
1215
Alexandre Rames67555f72014-11-18 10:55:16 +00001216void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001217 Primitive::Type type = instr->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001218
1219 switch (type) {
1220 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001221 case Primitive::kPrimLong: {
1222 Register dst = OutputRegister(instr);
1223 Register lhs = InputRegisterAt(instr, 0);
1224 Operand rhs = InputOperandAt(instr, 1);
Alexandre Rames5319def2014-10-23 10:03:10 +01001225 if (instr->IsAdd()) {
1226 __ Add(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001227 } else if (instr->IsAnd()) {
1228 __ And(dst, lhs, rhs);
1229 } else if (instr->IsOr()) {
1230 __ Orr(dst, lhs, rhs);
1231 } else if (instr->IsSub()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001232 __ Sub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001233 } else {
1234 DCHECK(instr->IsXor());
1235 __ Eor(dst, lhs, rhs);
Alexandre Rames5319def2014-10-23 10:03:10 +01001236 }
1237 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001238 }
1239 case Primitive::kPrimFloat:
1240 case Primitive::kPrimDouble: {
1241 FPRegister dst = OutputFPRegister(instr);
1242 FPRegister lhs = InputFPRegisterAt(instr, 0);
1243 FPRegister rhs = InputFPRegisterAt(instr, 1);
1244 if (instr->IsAdd()) {
1245 __ Fadd(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001246 } else if (instr->IsSub()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001247 __ Fsub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001248 } else {
1249 LOG(FATAL) << "Unexpected floating-point binary operation";
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001250 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001251 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001252 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001253 default:
Alexandre Rames67555f72014-11-18 10:55:16 +00001254 LOG(FATAL) << "Unexpected binary operation type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001255 }
1256}
1257
Serban Constantinescu02164b32014-11-13 14:05:07 +00001258void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) {
1259 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1260
1261 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1262 Primitive::Type type = instr->GetResultType();
1263 switch (type) {
1264 case Primitive::kPrimInt:
1265 case Primitive::kPrimLong: {
1266 locations->SetInAt(0, Location::RequiresRegister());
1267 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1268 locations->SetOut(Location::RequiresRegister());
1269 break;
1270 }
1271 default:
1272 LOG(FATAL) << "Unexpected shift type " << type;
1273 }
1274}
1275
1276void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) {
1277 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1278
1279 Primitive::Type type = instr->GetType();
1280 switch (type) {
1281 case Primitive::kPrimInt:
1282 case Primitive::kPrimLong: {
1283 Register dst = OutputRegister(instr);
1284 Register lhs = InputRegisterAt(instr, 0);
1285 Operand rhs = InputOperandAt(instr, 1);
1286 if (rhs.IsImmediate()) {
1287 uint32_t shift_value = (type == Primitive::kPrimInt)
1288 ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue)
1289 : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue);
1290 if (instr->IsShl()) {
1291 __ Lsl(dst, lhs, shift_value);
1292 } else if (instr->IsShr()) {
1293 __ Asr(dst, lhs, shift_value);
1294 } else {
1295 __ Lsr(dst, lhs, shift_value);
1296 }
1297 } else {
1298 Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W();
1299
1300 if (instr->IsShl()) {
1301 __ Lsl(dst, lhs, rhs_reg);
1302 } else if (instr->IsShr()) {
1303 __ Asr(dst, lhs, rhs_reg);
1304 } else {
1305 __ Lsr(dst, lhs, rhs_reg);
1306 }
1307 }
1308 break;
1309 }
1310 default:
1311 LOG(FATAL) << "Unexpected shift operation type " << type;
1312 }
1313}
1314
Alexandre Rames5319def2014-10-23 10:03:10 +01001315void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001316 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001317}
1318
1319void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001320 HandleBinaryOp(instruction);
1321}
1322
1323void LocationsBuilderARM64::VisitAnd(HAnd* instruction) {
1324 HandleBinaryOp(instruction);
1325}
1326
1327void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) {
1328 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001329}
1330
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001331void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) {
1332 LocationSummary* locations =
1333 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1334 locations->SetInAt(0, Location::RequiresRegister());
1335 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01001336 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1337 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1338 } else {
1339 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1340 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001341}
1342
1343void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) {
1344 LocationSummary* locations = instruction->GetLocations();
1345 Primitive::Type type = instruction->GetType();
1346 Register obj = InputRegisterAt(instruction, 0);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001347 Location index = locations->InAt(1);
1348 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001349 MemOperand source = HeapOperand(obj);
Alexandre Ramesd921d642015-04-16 15:07:16 +01001350 MacroAssembler* masm = GetVIXLAssembler();
1351 UseScratchRegisterScope temps(masm);
1352 BlockPoolsScope block_pools(masm);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001353
1354 if (index.IsConstant()) {
1355 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001356 source = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001357 } else {
1358 Register temp = temps.AcquireSameSizeAs(obj);
1359 Register index_reg = RegisterFrom(index, Primitive::kPrimInt);
1360 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001361 source = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001362 }
1363
Alexandre Rames67555f72014-11-18 10:55:16 +00001364 codegen_->Load(type, OutputCPURegister(instruction), source);
Calin Juravle77520bc2015-01-12 18:45:46 +00001365 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001366}
1367
Alexandre Rames5319def2014-10-23 10:03:10 +01001368void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
1369 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1370 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001371 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001372}
1373
1374void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001375 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +01001376 __ Ldr(OutputRegister(instruction),
1377 HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset()));
Calin Juravle77520bc2015-01-12 18:45:46 +00001378 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001379}
1380
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001381void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) {
1382 Primitive::Type value_type = instruction->GetComponentType();
1383 bool is_object = value_type == Primitive::kPrimNot;
1384 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1385 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1386 if (is_object) {
1387 InvokeRuntimeCallingConvention calling_convention;
1388 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1389 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1390 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1391 } else {
1392 locations->SetInAt(0, Location::RequiresRegister());
1393 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01001394 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1395 locations->SetInAt(2, Location::RequiresFpuRegister());
1396 } else {
1397 locations->SetInAt(2, Location::RequiresRegister());
1398 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001399 }
1400}
1401
1402void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) {
1403 Primitive::Type value_type = instruction->GetComponentType();
1404 if (value_type == Primitive::kPrimNot) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001405 codegen_->InvokeRuntime(
1406 QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001407 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001408 } else {
1409 LocationSummary* locations = instruction->GetLocations();
1410 Register obj = InputRegisterAt(instruction, 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00001411 CPURegister value = InputCPURegisterAt(instruction, 2);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001412 Location index = locations->InAt(1);
1413 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001414 MemOperand destination = HeapOperand(obj);
Alexandre Ramesd921d642015-04-16 15:07:16 +01001415 MacroAssembler* masm = GetVIXLAssembler();
1416 UseScratchRegisterScope temps(masm);
1417 BlockPoolsScope block_pools(masm);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001418
1419 if (index.IsConstant()) {
1420 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001421 destination = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001422 } else {
1423 Register temp = temps.AcquireSameSizeAs(obj);
1424 Register index_reg = InputRegisterAt(instruction, 1);
1425 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001426 destination = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001427 }
1428
1429 codegen_->Store(value_type, value, destination);
Calin Juravle77520bc2015-01-12 18:45:46 +00001430 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001431 }
1432}
1433
Alexandre Rames67555f72014-11-18 10:55:16 +00001434void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1435 LocationSummary* locations =
1436 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1437 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu760d8ef2015-03-28 18:09:56 +00001438 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames67555f72014-11-18 10:55:16 +00001439 if (instruction->HasUses()) {
1440 locations->SetOut(Location::SameAsFirstInput());
1441 }
1442}
1443
1444void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001445 LocationSummary* locations = instruction->GetLocations();
1446 BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(
1447 instruction, locations->InAt(0), locations->InAt(1));
Alexandre Rames67555f72014-11-18 10:55:16 +00001448 codegen_->AddSlowPath(slow_path);
1449
1450 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
1451 __ B(slow_path->GetEntryLabel(), hs);
1452}
1453
1454void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) {
1455 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1456 instruction, LocationSummary::kCallOnSlowPath);
1457 locations->SetInAt(0, Location::RequiresRegister());
1458 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001459 locations->AddTemp(Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001460}
1461
1462void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001463 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames67555f72014-11-18 10:55:16 +00001464 Register obj = InputRegisterAt(instruction, 0);;
1465 Register cls = InputRegisterAt(instruction, 1);;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001466 Register obj_cls = WRegisterFrom(instruction->GetLocations()->GetTemp(0));
Alexandre Rames67555f72014-11-18 10:55:16 +00001467
Alexandre Rames3e69f162014-12-10 10:36:50 +00001468 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1469 instruction, locations->InAt(1), LocationFrom(obj_cls), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001470 codegen_->AddSlowPath(slow_path);
1471
1472 // TODO: avoid this check if we know obj is not null.
1473 __ Cbz(obj, slow_path->GetExitLabel());
1474 // Compare the class of `obj` with `cls`.
Alexandre Rames3e69f162014-12-10 10:36:50 +00001475 __ Ldr(obj_cls, HeapOperand(obj, mirror::Object::ClassOffset()));
1476 __ Cmp(obj_cls, cls);
Alexandre Rames67555f72014-11-18 10:55:16 +00001477 __ B(ne, slow_path->GetEntryLabel());
1478 __ Bind(slow_path->GetExitLabel());
1479}
1480
1481void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) {
1482 LocationSummary* locations =
1483 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1484 locations->SetInAt(0, Location::RequiresRegister());
1485 if (check->HasUses()) {
1486 locations->SetOut(Location::SameAsFirstInput());
1487 }
1488}
1489
1490void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) {
1491 // We assume the class is not null.
1492 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
1493 check->GetLoadClass(), check, check->GetDexPc(), true);
1494 codegen_->AddSlowPath(slow_path);
1495 GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0));
1496}
1497
Serban Constantinescu02164b32014-11-13 14:05:07 +00001498void LocationsBuilderARM64::VisitCompare(HCompare* compare) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001499 LocationSummary* locations =
Serban Constantinescu02164b32014-11-13 14:05:07 +00001500 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
1501 Primitive::Type in_type = compare->InputAt(0)->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001502 switch (in_type) {
1503 case Primitive::kPrimLong: {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001504 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001505 locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001506 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1507 break;
1508 }
1509 case Primitive::kPrimFloat:
1510 case Primitive::kPrimDouble: {
1511 locations->SetInAt(0, Location::RequiresFpuRegister());
Alexandre Rames93415462015-02-17 15:08:20 +00001512 HInstruction* right = compare->InputAt(1);
1513 if ((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1514 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))) {
1515 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1516 } else {
1517 locations->SetInAt(1, Location::RequiresFpuRegister());
1518 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001519 locations->SetOut(Location::RequiresRegister());
1520 break;
1521 }
1522 default:
1523 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1524 }
1525}
1526
1527void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) {
1528 Primitive::Type in_type = compare->InputAt(0)->GetType();
1529
1530 // 0 if: left == right
1531 // 1 if: left > right
1532 // -1 if: left < right
1533 switch (in_type) {
1534 case Primitive::kPrimLong: {
1535 Register result = OutputRegister(compare);
1536 Register left = InputRegisterAt(compare, 0);
1537 Operand right = InputOperandAt(compare, 1);
1538
1539 __ Cmp(left, right);
1540 __ Cset(result, ne);
1541 __ Cneg(result, result, lt);
1542 break;
1543 }
1544 case Primitive::kPrimFloat:
1545 case Primitive::kPrimDouble: {
1546 Register result = OutputRegister(compare);
1547 FPRegister left = InputFPRegisterAt(compare, 0);
Alexandre Rames93415462015-02-17 15:08:20 +00001548 if (compare->GetLocations()->InAt(1).IsConstant()) {
1549 if (kIsDebugBuild) {
1550 HInstruction* right = compare->GetLocations()->InAt(1).GetConstant();
1551 DCHECK((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1552 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0)));
1553 }
1554 // 0.0 is the only immediate that can be encoded directly in a FCMP instruction.
1555 __ Fcmp(left, 0.0);
1556 } else {
1557 __ Fcmp(left, InputFPRegisterAt(compare, 1));
1558 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001559 if (compare->IsGtBias()) {
1560 __ Cset(result, ne);
1561 } else {
1562 __ Csetm(result, ne);
1563 }
1564 __ Cneg(result, result, compare->IsGtBias() ? mi : gt);
Alexandre Rames5319def2014-10-23 10:03:10 +01001565 break;
1566 }
1567 default:
1568 LOG(FATAL) << "Unimplemented compare type " << in_type;
1569 }
1570}
1571
1572void LocationsBuilderARM64::VisitCondition(HCondition* instruction) {
1573 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1574 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001575 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames5319def2014-10-23 10:03:10 +01001576 if (instruction->NeedsMaterialization()) {
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001577 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001578 }
1579}
1580
1581void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) {
1582 if (!instruction->NeedsMaterialization()) {
1583 return;
1584 }
1585
1586 LocationSummary* locations = instruction->GetLocations();
1587 Register lhs = InputRegisterAt(instruction, 0);
1588 Operand rhs = InputOperandAt(instruction, 1);
1589 Register res = RegisterFrom(locations->Out(), instruction->GetType());
1590 Condition cond = ARM64Condition(instruction->GetCondition());
1591
1592 __ Cmp(lhs, rhs);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001593 __ Cset(res, cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001594}
1595
1596#define FOR_EACH_CONDITION_INSTRUCTION(M) \
1597 M(Equal) \
1598 M(NotEqual) \
1599 M(LessThan) \
1600 M(LessThanOrEqual) \
1601 M(GreaterThan) \
1602 M(GreaterThanOrEqual)
1603#define DEFINE_CONDITION_VISITORS(Name) \
1604void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \
1605void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }
1606FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
Alexandre Rames67555f72014-11-18 10:55:16 +00001607#undef DEFINE_CONDITION_VISITORS
Alexandre Rames5319def2014-10-23 10:03:10 +01001608#undef FOR_EACH_CONDITION_INSTRUCTION
1609
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001610void LocationsBuilderARM64::VisitDiv(HDiv* div) {
1611 LocationSummary* locations =
1612 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1613 switch (div->GetResultType()) {
1614 case Primitive::kPrimInt:
1615 case Primitive::kPrimLong:
1616 locations->SetInAt(0, Location::RequiresRegister());
1617 locations->SetInAt(1, Location::RequiresRegister());
1618 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1619 break;
1620
1621 case Primitive::kPrimFloat:
1622 case Primitive::kPrimDouble:
1623 locations->SetInAt(0, Location::RequiresFpuRegister());
1624 locations->SetInAt(1, Location::RequiresFpuRegister());
1625 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1626 break;
1627
1628 default:
1629 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1630 }
1631}
1632
1633void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) {
1634 Primitive::Type type = div->GetResultType();
1635 switch (type) {
1636 case Primitive::kPrimInt:
1637 case Primitive::kPrimLong:
1638 __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1));
1639 break;
1640
1641 case Primitive::kPrimFloat:
1642 case Primitive::kPrimDouble:
1643 __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1));
1644 break;
1645
1646 default:
1647 LOG(FATAL) << "Unexpected div type " << type;
1648 }
1649}
1650
Alexandre Rames67555f72014-11-18 10:55:16 +00001651void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1652 LocationSummary* locations =
1653 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1654 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1655 if (instruction->HasUses()) {
1656 locations->SetOut(Location::SameAsFirstInput());
1657 }
1658}
1659
1660void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1661 SlowPathCodeARM64* slow_path =
1662 new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction);
1663 codegen_->AddSlowPath(slow_path);
1664 Location value = instruction->GetLocations()->InAt(0);
1665
Alexandre Rames3e69f162014-12-10 10:36:50 +00001666 Primitive::Type type = instruction->GetType();
1667
1668 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1669 LOG(FATAL) << "Unexpected type " << type << "for DivZeroCheck.";
1670 return;
1671 }
1672
Alexandre Rames67555f72014-11-18 10:55:16 +00001673 if (value.IsConstant()) {
1674 int64_t divisor = Int64ConstantFrom(value);
1675 if (divisor == 0) {
1676 __ B(slow_path->GetEntryLabel());
1677 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001678 // A division by a non-null constant is valid. We don't need to perform
1679 // any check, so simply fall through.
Alexandre Rames67555f72014-11-18 10:55:16 +00001680 }
1681 } else {
1682 __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel());
1683 }
1684}
1685
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001686void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1687 LocationSummary* locations =
1688 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1689 locations->SetOut(Location::ConstantLocation(constant));
1690}
1691
1692void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1693 UNUSED(constant);
1694 // Will be generated at use site.
1695}
1696
Alexandre Rames5319def2014-10-23 10:03:10 +01001697void LocationsBuilderARM64::VisitExit(HExit* exit) {
1698 exit->SetLocations(nullptr);
1699}
1700
1701void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001702 UNUSED(exit);
Alexandre Rames5319def2014-10-23 10:03:10 +01001703}
1704
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001705void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) {
1706 LocationSummary* locations =
1707 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1708 locations->SetOut(Location::ConstantLocation(constant));
1709}
1710
1711void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) {
1712 UNUSED(constant);
1713 // Will be generated at use site.
1714}
1715
Alexandre Rames5319def2014-10-23 10:03:10 +01001716void LocationsBuilderARM64::VisitGoto(HGoto* got) {
1717 got->SetLocations(nullptr);
1718}
1719
1720void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
1721 HBasicBlock* successor = got->GetSuccessor();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001722 DCHECK(!successor->IsExitBlock());
1723 HBasicBlock* block = got->GetBlock();
1724 HInstruction* previous = got->GetPrevious();
1725 HLoopInformation* info = block->GetLoopInformation();
1726
David Brazdil46e2a392015-03-16 17:31:52 +00001727 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001728 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1729 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1730 return;
1731 }
1732 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1733 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1734 }
1735 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001736 __ B(codegen_->GetLabelOf(successor));
1737 }
1738}
1739
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001740void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction,
1741 vixl::Label* true_target,
1742 vixl::Label* false_target,
1743 vixl::Label* always_true_target) {
1744 HInstruction* cond = instruction->InputAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001745 HCondition* condition = cond->AsCondition();
Alexandre Rames5319def2014-10-23 10:03:10 +01001746
Serban Constantinescu02164b32014-11-13 14:05:07 +00001747 if (cond->IsIntConstant()) {
1748 int32_t cond_value = cond->AsIntConstant()->GetValue();
1749 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001750 if (always_true_target != nullptr) {
1751 __ B(always_true_target);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001752 }
1753 return;
1754 } else {
1755 DCHECK_EQ(cond_value, 0);
1756 }
1757 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001758 // The condition instruction has been materialized, compare the output to 0.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001759 Location cond_val = instruction->GetLocations()->InAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001760 DCHECK(cond_val.IsRegister());
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001761 __ Cbnz(InputRegisterAt(instruction, 0), true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001762 } else {
1763 // The condition instruction has not been materialized, use its inputs as
1764 // the comparison and its condition as the branch condition.
1765 Register lhs = InputRegisterAt(condition, 0);
1766 Operand rhs = InputOperandAt(condition, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001767 Condition arm64_cond = ARM64Condition(condition->GetCondition());
Alexandre Rames4388dcc2015-02-03 10:28:33 +00001768 if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
1769 switch (arm64_cond) {
1770 case eq:
1771 __ Cbz(lhs, true_target);
1772 break;
1773 case ne:
1774 __ Cbnz(lhs, true_target);
1775 break;
1776 case lt:
1777 // Test the sign bit and branch accordingly.
1778 __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1779 break;
1780 case ge:
1781 // Test the sign bit and branch accordingly.
1782 __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1783 break;
1784 default:
1785 // Without the `static_cast` the compiler throws an error for
1786 // `-Werror=sign-promo`.
1787 LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001788 }
1789 } else {
1790 __ Cmp(lhs, rhs);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001791 __ B(arm64_cond, true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001792 }
1793 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001794 if (false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001795 __ B(false_target);
1796 }
1797}
1798
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001799void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
1800 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1801 HInstruction* cond = if_instr->InputAt(0);
1802 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1803 locations->SetInAt(0, Location::RequiresRegister());
1804 }
1805}
1806
1807void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
1808 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1809 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1810 vixl::Label* always_true_target = true_target;
1811 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1812 if_instr->IfTrueSuccessor())) {
1813 always_true_target = nullptr;
1814 }
1815 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1816 if_instr->IfFalseSuccessor())) {
1817 false_target = nullptr;
1818 }
1819 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1820}
1821
1822void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1823 LocationSummary* locations = new (GetGraph()->GetArena())
1824 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1825 HInstruction* cond = deoptimize->InputAt(0);
1826 DCHECK(cond->IsCondition());
1827 if (cond->AsCondition()->NeedsMaterialization()) {
1828 locations->SetInAt(0, Location::RequiresRegister());
1829 }
1830}
1831
1832void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1833 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
1834 DeoptimizationSlowPathARM64(deoptimize);
1835 codegen_->AddSlowPath(slow_path);
1836 vixl::Label* slow_path_entry = slow_path->GetEntryLabel();
1837 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1838}
1839
Alexandre Rames5319def2014-10-23 10:03:10 +01001840void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001841 HandleFieldGet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001842}
1843
1844void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001845 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01001846}
1847
1848void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001849 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001850}
1851
1852void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001853 HandleFieldSet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01001854}
1855
Alexandre Rames67555f72014-11-18 10:55:16 +00001856void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
1857 LocationSummary::CallKind call_kind =
1858 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
1859 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1860 locations->SetInAt(0, Location::RequiresRegister());
1861 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001862 // The output does overlap inputs.
1863 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexandre Rames67555f72014-11-18 10:55:16 +00001864}
1865
1866void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
1867 LocationSummary* locations = instruction->GetLocations();
1868 Register obj = InputRegisterAt(instruction, 0);;
1869 Register cls = InputRegisterAt(instruction, 1);;
1870 Register out = OutputRegister(instruction);
1871
1872 vixl::Label done;
1873
1874 // Return 0 if `obj` is null.
1875 // TODO: Avoid this check if we know `obj` is not null.
1876 __ Mov(out, 0);
1877 __ Cbz(obj, &done);
1878
1879 // Compare the class of `obj` with `cls`.
Serban Constantinescu02164b32014-11-13 14:05:07 +00001880 __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset()));
Alexandre Rames67555f72014-11-18 10:55:16 +00001881 __ Cmp(out, cls);
1882 if (instruction->IsClassFinal()) {
1883 // Classes must be equal for the instanceof to succeed.
1884 __ Cset(out, eq);
1885 } else {
1886 // If the classes are not equal, we go into a slow path.
1887 DCHECK(locations->OnlyCallsOnSlowPath());
1888 SlowPathCodeARM64* slow_path =
Alexandre Rames3e69f162014-12-10 10:36:50 +00001889 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1890 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001891 codegen_->AddSlowPath(slow_path);
1892 __ B(ne, slow_path->GetEntryLabel());
1893 __ Mov(out, 1);
1894 __ Bind(slow_path->GetExitLabel());
1895 }
1896
1897 __ Bind(&done);
1898}
1899
Alexandre Rames5319def2014-10-23 10:03:10 +01001900void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
1901 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1902 locations->SetOut(Location::ConstantLocation(constant));
1903}
1904
1905void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
1906 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001907 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01001908}
1909
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001910void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
1911 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1912 locations->SetOut(Location::ConstantLocation(constant));
1913}
1914
1915void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) {
1916 // Will be generated at use site.
1917 UNUSED(constant);
1918}
1919
Alexandre Rames5319def2014-10-23 10:03:10 +01001920void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
1921 LocationSummary* locations =
1922 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
1923 locations->AddTemp(LocationFrom(x0));
1924
1925 InvokeDexCallingConventionVisitor calling_convention_visitor;
1926 for (size_t i = 0; i < invoke->InputCount(); i++) {
1927 HInstruction* input = invoke->InputAt(i);
1928 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1929 }
1930
1931 Primitive::Type return_type = invoke->GetType();
1932 if (return_type != Primitive::kPrimVoid) {
1933 locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type));
1934 }
1935}
1936
Alexandre Rames67555f72014-11-18 10:55:16 +00001937void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1938 HandleInvoke(invoke);
1939}
1940
1941void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1942 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1943 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1944 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1945 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1946 Location receiver = invoke->GetLocations()->InAt(0);
1947 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001948 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00001949
1950 // The register ip1 is required to be used for the hidden argument in
1951 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
Alexandre Ramesd921d642015-04-16 15:07:16 +01001952 MacroAssembler* masm = GetVIXLAssembler();
1953 UseScratchRegisterScope scratch_scope(masm);
1954 BlockPoolsScope block_pools(masm);
Alexandre Rames67555f72014-11-18 10:55:16 +00001955 scratch_scope.Exclude(ip1);
1956 __ Mov(ip1, invoke->GetDexMethodIndex());
1957
1958 // temp = object->GetClass();
1959 if (receiver.IsStackSlot()) {
1960 __ Ldr(temp, StackOperandFrom(receiver));
1961 __ Ldr(temp, HeapOperand(temp, class_offset));
1962 } else {
1963 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
1964 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001965 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames67555f72014-11-18 10:55:16 +00001966 // temp = temp->GetImtEntryAt(method_offset);
1967 __ Ldr(temp, HeapOperand(temp, method_offset));
1968 // lr = temp->GetEntryPoint();
1969 __ Ldr(lr, HeapOperand(temp, entry_point));
1970 // lr();
1971 __ Blr(lr);
1972 DCHECK(!codegen_->IsLeafMethod());
1973 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1974}
1975
1976void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001977 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1978 if (intrinsic.TryDispatch(invoke)) {
1979 return;
1980 }
1981
Alexandre Rames67555f72014-11-18 10:55:16 +00001982 HandleInvoke(invoke);
1983}
1984
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001985void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001986 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1987 if (intrinsic.TryDispatch(invoke)) {
1988 return;
1989 }
1990
Alexandre Rames67555f72014-11-18 10:55:16 +00001991 HandleInvoke(invoke);
1992}
1993
Andreas Gampe878d58c2015-01-15 23:24:00 -08001994static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
1995 if (invoke->GetLocations()->Intrinsified()) {
1996 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
1997 intrinsic.Dispatch(invoke);
1998 return true;
1999 }
2000 return false;
2001}
2002
2003void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
2004 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
2005 DCHECK(temp.Is(kArtMethodRegister));
Alexandre Rames5319def2014-10-23 10:03:10 +01002006 size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() +
Andreas Gampe878d58c2015-01-15 23:24:00 -08002007 invoke->GetDexMethodIndex() * kHeapRefSize;
Alexandre Rames5319def2014-10-23 10:03:10 +01002008
2009 // TODO: Implement all kinds of calls:
2010 // 1) boot -> boot
2011 // 2) app -> boot
2012 // 3) app -> app
2013 //
2014 // Currently we implement the app -> app logic, which looks up in the resolve cache.
2015
Nicolas Geoffray0a299b92015-01-29 11:39:44 +00002016 // temp = method;
2017 LoadCurrentMethod(temp);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002018 if (!invoke->IsRecursive()) {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002019 // temp = temp->dex_cache_resolved_methods_;
2020 __ Ldr(temp, HeapOperand(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset()));
2021 // temp = temp[index_in_cache];
2022 __ Ldr(temp, HeapOperand(temp, index_in_cache));
2023 // lr = temp->entry_point_from_quick_compiled_code_;
2024 __ Ldr(lr, HeapOperand(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2025 kArm64WordSize)));
2026 // lr();
2027 __ Blr(lr);
2028 } else {
2029 __ Bl(&frame_entry_label_);
2030 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002031
Andreas Gampe878d58c2015-01-15 23:24:00 -08002032 DCHECK(!IsLeafMethod());
2033}
2034
2035void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2036 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2037 return;
2038 }
2039
Alexandre Ramesd921d642015-04-16 15:07:16 +01002040 BlockPoolsScope block_pools(GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -08002041 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
2042 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00002043 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01002044}
2045
2046void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08002047 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2048 return;
2049 }
2050
Alexandre Rames5319def2014-10-23 10:03:10 +01002051 LocationSummary* locations = invoke->GetLocations();
2052 Location receiver = locations->InAt(0);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002053 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002054 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
2055 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
2056 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00002057 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames5319def2014-10-23 10:03:10 +01002058
Alexandre Ramesd921d642015-04-16 15:07:16 +01002059 BlockPoolsScope block_pools(GetVIXLAssembler());
2060
Alexandre Rames5319def2014-10-23 10:03:10 +01002061 // temp = object->GetClass();
2062 if (receiver.IsStackSlot()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002063 __ Ldr(temp, MemOperand(sp, receiver.GetStackIndex()));
2064 __ Ldr(temp, HeapOperand(temp, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002065 } else {
2066 DCHECK(receiver.IsRegister());
Serban Constantinescu02164b32014-11-13 14:05:07 +00002067 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002068 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002069 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames5319def2014-10-23 10:03:10 +01002070 // temp = temp->GetMethodAt(method_offset);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002071 __ Ldr(temp, HeapOperand(temp, method_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002072 // lr = temp->GetEntryPoint();
Serban Constantinescu02164b32014-11-13 14:05:07 +00002073 __ Ldr(lr, HeapOperand(temp, entry_point.SizeValue()));
Alexandre Rames5319def2014-10-23 10:03:10 +01002074 // lr();
2075 __ Blr(lr);
2076 DCHECK(!codegen_->IsLeafMethod());
2077 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2078}
2079
Alexandre Rames67555f72014-11-18 10:55:16 +00002080void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
2081 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2082 : LocationSummary::kNoCall;
2083 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2084 locations->SetOut(Location::RequiresRegister());
2085}
2086
2087void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
2088 Register out = OutputRegister(cls);
2089 if (cls->IsReferrersClass()) {
2090 DCHECK(!cls->CanCallRuntime());
2091 DCHECK(!cls->MustGenerateClinitCheck());
2092 codegen_->LoadCurrentMethod(out);
2093 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2094 } else {
2095 DCHECK(cls->CanCallRuntime());
2096 codegen_->LoadCurrentMethod(out);
2097 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DexCacheResolvedTypesOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002098 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002099
2100 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2101 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2102 codegen_->AddSlowPath(slow_path);
2103 __ Cbz(out, slow_path->GetEntryLabel());
2104 if (cls->MustGenerateClinitCheck()) {
2105 GenerateClassInitializationCheck(slow_path, out);
2106 } else {
2107 __ Bind(slow_path->GetExitLabel());
2108 }
2109 }
2110}
2111
2112void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
2113 LocationSummary* locations =
2114 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2115 locations->SetOut(Location::RequiresRegister());
2116}
2117
2118void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
2119 MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value());
2120 __ Ldr(OutputRegister(instruction), exception);
2121 __ Str(wzr, exception);
2122}
2123
Alexandre Rames5319def2014-10-23 10:03:10 +01002124void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
2125 load->SetLocations(nullptr);
2126}
2127
2128void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
2129 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002130 UNUSED(load);
Alexandre Rames5319def2014-10-23 10:03:10 +01002131}
2132
Alexandre Rames67555f72014-11-18 10:55:16 +00002133void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
2134 LocationSummary* locations =
2135 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2136 locations->SetOut(Location::RequiresRegister());
2137}
2138
2139void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
2140 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load);
2141 codegen_->AddSlowPath(slow_path);
2142
2143 Register out = OutputRegister(load);
2144 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08002145 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2146 __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002147 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002148 __ Cbz(out, slow_path->GetEntryLabel());
2149 __ Bind(slow_path->GetExitLabel());
2150}
2151
Alexandre Rames5319def2014-10-23 10:03:10 +01002152void LocationsBuilderARM64::VisitLocal(HLocal* local) {
2153 local->SetLocations(nullptr);
2154}
2155
2156void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
2157 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2158}
2159
2160void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
2161 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2162 locations->SetOut(Location::ConstantLocation(constant));
2163}
2164
2165void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
2166 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002167 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002168}
2169
Alexandre Rames67555f72014-11-18 10:55:16 +00002170void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2171 LocationSummary* locations =
2172 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2173 InvokeRuntimeCallingConvention calling_convention;
2174 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2175}
2176
2177void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2178 codegen_->InvokeRuntime(instruction->IsEnter()
2179 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2180 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002181 instruction->GetDexPc(),
2182 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002183 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002184}
2185
Alexandre Rames42d641b2014-10-27 14:00:51 +00002186void LocationsBuilderARM64::VisitMul(HMul* mul) {
2187 LocationSummary* locations =
2188 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2189 switch (mul->GetResultType()) {
2190 case Primitive::kPrimInt:
2191 case Primitive::kPrimLong:
2192 locations->SetInAt(0, Location::RequiresRegister());
2193 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002194 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002195 break;
2196
2197 case Primitive::kPrimFloat:
2198 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002199 locations->SetInAt(0, Location::RequiresFpuRegister());
2200 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002201 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002202 break;
2203
2204 default:
2205 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2206 }
2207}
2208
2209void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
2210 switch (mul->GetResultType()) {
2211 case Primitive::kPrimInt:
2212 case Primitive::kPrimLong:
2213 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
2214 break;
2215
2216 case Primitive::kPrimFloat:
2217 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002218 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00002219 break;
2220
2221 default:
2222 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2223 }
2224}
2225
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002226void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
2227 LocationSummary* locations =
2228 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2229 switch (neg->GetResultType()) {
2230 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00002231 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002232 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00002233 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002234 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002235
2236 case Primitive::kPrimFloat:
2237 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002238 locations->SetInAt(0, Location::RequiresFpuRegister());
2239 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002240 break;
2241
2242 default:
2243 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2244 }
2245}
2246
2247void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
2248 switch (neg->GetResultType()) {
2249 case Primitive::kPrimInt:
2250 case Primitive::kPrimLong:
2251 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
2252 break;
2253
2254 case Primitive::kPrimFloat:
2255 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002256 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002257 break;
2258
2259 default:
2260 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2261 }
2262}
2263
2264void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
2265 LocationSummary* locations =
2266 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2267 InvokeRuntimeCallingConvention calling_convention;
2268 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002269 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002270 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002271 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
2272 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2273 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002274}
2275
2276void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
2277 LocationSummary* locations = instruction->GetLocations();
2278 InvokeRuntimeCallingConvention calling_convention;
2279 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2280 DCHECK(type_index.Is(w0));
2281 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002282 DCHECK(current_method.Is(w2));
Alexandre Rames67555f72014-11-18 10:55:16 +00002283 codegen_->LoadCurrentMethod(current_method);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002284 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002285 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002286 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2287 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002288 instruction->GetDexPc(),
2289 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002290 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2291 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002292}
2293
Alexandre Rames5319def2014-10-23 10:03:10 +01002294void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
2295 LocationSummary* locations =
2296 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2297 InvokeRuntimeCallingConvention calling_convention;
2298 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2299 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2300 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002301 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002302}
2303
2304void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
2305 LocationSummary* locations = instruction->GetLocations();
2306 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2307 DCHECK(type_index.Is(w0));
2308 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
2309 DCHECK(current_method.Is(w1));
Alexandre Rames67555f72014-11-18 10:55:16 +00002310 codegen_->LoadCurrentMethod(current_method);
Alexandre Rames5319def2014-10-23 10:03:10 +01002311 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002312 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002313 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2314 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002315 instruction->GetDexPc(),
2316 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002317 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002318}
2319
2320void LocationsBuilderARM64::VisitNot(HNot* instruction) {
2321 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00002322 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002323 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002324}
2325
2326void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002327 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002328 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002329 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01002330 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002331 break;
2332
2333 default:
2334 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2335 }
2336}
2337
David Brazdil66d126e2015-04-03 16:02:44 +01002338void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) {
2339 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2340 locations->SetInAt(0, Location::RequiresRegister());
2341 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2342}
2343
2344void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) {
David Brazdil66d126e2015-04-03 16:02:44 +01002345 __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1));
2346}
2347
Alexandre Rames5319def2014-10-23 10:03:10 +01002348void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
2349 LocationSummary* locations =
2350 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2351 locations->SetInAt(0, Location::RequiresRegister());
2352 if (instruction->HasUses()) {
2353 locations->SetOut(Location::SameAsFirstInput());
2354 }
2355}
2356
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002357void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002358 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2359 return;
2360 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002361
Alexandre Ramesd921d642015-04-16 15:07:16 +01002362 BlockPoolsScope block_pools(GetVIXLAssembler());
2363 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002364 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
2365 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2366}
2367
2368void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002369 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
2370 codegen_->AddSlowPath(slow_path);
2371
2372 LocationSummary* locations = instruction->GetLocations();
2373 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002374
2375 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01002376}
2377
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002378void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
2379 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2380 GenerateImplicitNullCheck(instruction);
2381 } else {
2382 GenerateExplicitNullCheck(instruction);
2383 }
2384}
2385
Alexandre Rames67555f72014-11-18 10:55:16 +00002386void LocationsBuilderARM64::VisitOr(HOr* instruction) {
2387 HandleBinaryOp(instruction);
2388}
2389
2390void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
2391 HandleBinaryOp(instruction);
2392}
2393
Alexandre Rames3e69f162014-12-10 10:36:50 +00002394void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2395 LOG(FATAL) << "Unreachable";
2396}
2397
2398void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
2399 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2400}
2401
Alexandre Rames5319def2014-10-23 10:03:10 +01002402void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
2403 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2404 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2405 if (location.IsStackSlot()) {
2406 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2407 } else if (location.IsDoubleStackSlot()) {
2408 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2409 }
2410 locations->SetOut(location);
2411}
2412
2413void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) {
2414 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002415 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002416}
2417
2418void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
2419 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2420 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2421 locations->SetInAt(i, Location::Any());
2422 }
2423 locations->SetOut(Location::Any());
2424}
2425
2426void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002427 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002428 LOG(FATAL) << "Unreachable";
2429}
2430
Serban Constantinescu02164b32014-11-13 14:05:07 +00002431void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002432 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00002433 LocationSummary::CallKind call_kind =
2434 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002435 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2436
2437 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002438 case Primitive::kPrimInt:
2439 case Primitive::kPrimLong:
2440 locations->SetInAt(0, Location::RequiresRegister());
2441 locations->SetInAt(1, Location::RequiresRegister());
2442 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2443 break;
2444
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002445 case Primitive::kPrimFloat:
2446 case Primitive::kPrimDouble: {
2447 InvokeRuntimeCallingConvention calling_convention;
2448 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
2449 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
2450 locations->SetOut(calling_convention.GetReturnLocation(type));
2451
2452 break;
2453 }
2454
Serban Constantinescu02164b32014-11-13 14:05:07 +00002455 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002456 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00002457 }
2458}
2459
2460void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
2461 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002462
Serban Constantinescu02164b32014-11-13 14:05:07 +00002463 switch (type) {
2464 case Primitive::kPrimInt:
2465 case Primitive::kPrimLong: {
2466 UseScratchRegisterScope temps(GetVIXLAssembler());
2467 Register dividend = InputRegisterAt(rem, 0);
2468 Register divisor = InputRegisterAt(rem, 1);
2469 Register output = OutputRegister(rem);
2470 Register temp = temps.AcquireSameSizeAs(output);
2471
2472 __ Sdiv(temp, dividend, divisor);
2473 __ Msub(output, temp, divisor, dividend);
2474 break;
2475 }
2476
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002477 case Primitive::kPrimFloat:
2478 case Primitive::kPrimDouble: {
2479 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2480 : QUICK_ENTRY_POINT(pFmod);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002481 codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002482 break;
2483 }
2484
Serban Constantinescu02164b32014-11-13 14:05:07 +00002485 default:
2486 LOG(FATAL) << "Unexpected rem type " << type;
2487 }
2488}
2489
Alexandre Rames5319def2014-10-23 10:03:10 +01002490void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
2491 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2492 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002493 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01002494}
2495
2496void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002497 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002498 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002499}
2500
2501void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
2502 instruction->SetLocations(nullptr);
2503}
2504
2505void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002506 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002507 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002508}
2509
Serban Constantinescu02164b32014-11-13 14:05:07 +00002510void LocationsBuilderARM64::VisitShl(HShl* shl) {
2511 HandleShift(shl);
2512}
2513
2514void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
2515 HandleShift(shl);
2516}
2517
2518void LocationsBuilderARM64::VisitShr(HShr* shr) {
2519 HandleShift(shr);
2520}
2521
2522void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
2523 HandleShift(shr);
2524}
2525
Alexandre Rames5319def2014-10-23 10:03:10 +01002526void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
2527 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2528 Primitive::Type field_type = store->InputAt(1)->GetType();
2529 switch (field_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002530 case Primitive::kPrimNot:
Alexandre Rames5319def2014-10-23 10:03:10 +01002531 case Primitive::kPrimBoolean:
2532 case Primitive::kPrimByte:
2533 case Primitive::kPrimChar:
2534 case Primitive::kPrimShort:
2535 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002536 case Primitive::kPrimFloat:
Alexandre Rames5319def2014-10-23 10:03:10 +01002537 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2538 break;
2539
2540 case Primitive::kPrimLong:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002541 case Primitive::kPrimDouble:
Alexandre Rames5319def2014-10-23 10:03:10 +01002542 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2543 break;
2544
2545 default:
2546 LOG(FATAL) << "Unimplemented local type " << field_type;
2547 }
2548}
2549
2550void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002551 UNUSED(store);
Alexandre Rames5319def2014-10-23 10:03:10 +01002552}
2553
2554void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002555 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002556}
2557
2558void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002559 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002560}
2561
Alexandre Rames67555f72014-11-18 10:55:16 +00002562void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002563 HandleFieldGet(instruction);
Alexandre Rames67555f72014-11-18 10:55:16 +00002564}
2565
2566void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002567 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames67555f72014-11-18 10:55:16 +00002568}
2569
2570void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002571 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002572}
2573
Alexandre Rames67555f72014-11-18 10:55:16 +00002574void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002575 HandleFieldSet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01002576}
2577
2578void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
2579 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2580}
2581
2582void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002583 HBasicBlock* block = instruction->GetBlock();
2584 if (block->GetLoopInformation() != nullptr) {
2585 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2586 // The back edge will generate the suspend check.
2587 return;
2588 }
2589 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2590 // The goto will generate the suspend check.
2591 return;
2592 }
2593 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01002594}
2595
2596void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
2597 temp->SetLocations(nullptr);
2598}
2599
2600void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
2601 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002602 UNUSED(temp);
Alexandre Rames5319def2014-10-23 10:03:10 +01002603}
2604
Alexandre Rames67555f72014-11-18 10:55:16 +00002605void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
2606 LocationSummary* locations =
2607 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2608 InvokeRuntimeCallingConvention calling_convention;
2609 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2610}
2611
2612void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
2613 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002614 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002615 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002616}
2617
2618void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
2619 LocationSummary* locations =
2620 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
2621 Primitive::Type input_type = conversion->GetInputType();
2622 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002623 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00002624 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
2625 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
2626 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
2627 }
2628
Alexandre Rames542361f2015-01-29 16:57:31 +00002629 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002630 locations->SetInAt(0, Location::RequiresFpuRegister());
2631 } else {
2632 locations->SetInAt(0, Location::RequiresRegister());
2633 }
2634
Alexandre Rames542361f2015-01-29 16:57:31 +00002635 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002636 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2637 } else {
2638 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2639 }
2640}
2641
2642void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
2643 Primitive::Type result_type = conversion->GetResultType();
2644 Primitive::Type input_type = conversion->GetInputType();
2645
2646 DCHECK_NE(input_type, result_type);
2647
Alexandre Rames542361f2015-01-29 16:57:31 +00002648 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002649 int result_size = Primitive::ComponentSize(result_type);
2650 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002651 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002652 Register output = OutputRegister(conversion);
2653 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002654 if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) {
2655 __ Ubfx(output, source, 0, result_size * kBitsPerByte);
2656 } else if ((result_type == Primitive::kPrimChar) ||
2657 ((input_type == Primitive::kPrimChar) && (result_size > input_size))) {
2658 __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002659 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00002660 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002661 }
Alexandre Rames542361f2015-01-29 16:57:31 +00002662 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002663 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002664 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002665 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
2666 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002667 } else if (Primitive::IsFloatingPointType(result_type) &&
2668 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002669 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
2670 } else {
2671 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
2672 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00002673 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00002674}
Alexandre Rames67555f72014-11-18 10:55:16 +00002675
Serban Constantinescu02164b32014-11-13 14:05:07 +00002676void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
2677 HandleShift(ushr);
2678}
2679
2680void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
2681 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00002682}
2683
2684void LocationsBuilderARM64::VisitXor(HXor* instruction) {
2685 HandleBinaryOp(instruction);
2686}
2687
2688void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
2689 HandleBinaryOp(instruction);
2690}
2691
Calin Juravleb1498f62015-02-16 13:13:29 +00002692void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) {
2693 // Nothing to do, this should be removed during prepare for register allocator.
2694 UNUSED(instruction);
2695 LOG(FATAL) << "Unreachable";
2696}
2697
2698void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) {
2699 // Nothing to do, this should be removed during prepare for register allocator.
2700 UNUSED(instruction);
2701 LOG(FATAL) << "Unreachable";
2702}
2703
Alexandre Rames67555f72014-11-18 10:55:16 +00002704#undef __
2705#undef QUICK_ENTRY_POINT
2706
Alexandre Rames5319def2014-10-23 10:03:10 +01002707} // namespace arm64
2708} // namespace art