blob: 55ef66fa99800724dbb8de807f47d9a56e406120 [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"
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -070020#include "art_method.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080021#include "common_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010022#include "entrypoints/quick/quick_entrypoints.h"
Andreas Gampe1cc7dba2014-12-17 18:43:01 -080023#include "entrypoints/quick/quick_entrypoints_enum.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010024#include "gc/accounting/card_table.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080025#include "intrinsics.h"
26#include "intrinsics_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010027#include "mirror/array-inl.h"
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -070028#include "mirror/class-inl.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 int kCurrentMethodStackOffset = 0;
69
Alexandre Rames5319def2014-10-23 10:03:10 +010070inline Condition ARM64Condition(IfCondition cond) {
71 switch (cond) {
72 case kCondEQ: return eq;
73 case kCondNE: return ne;
74 case kCondLT: return lt;
75 case kCondLE: return le;
76 case kCondGT: return gt;
77 case kCondGE: return ge;
78 default:
79 LOG(FATAL) << "Unknown if condition";
80 }
81 return nv; // Unreachable.
82}
83
Alexandre Ramesa89086e2014-11-07 17:13:25 +000084Location ARM64ReturnLocation(Primitive::Type return_type) {
85 DCHECK_NE(return_type, Primitive::kPrimVoid);
86 // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the
87 // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`,
88 // but we use the exact registers for clarity.
89 if (return_type == Primitive::kPrimFloat) {
90 return LocationFrom(s0);
91 } else if (return_type == Primitive::kPrimDouble) {
92 return LocationFrom(d0);
93 } else if (return_type == Primitive::kPrimLong) {
94 return LocationFrom(x0);
95 } else {
96 return LocationFrom(w0);
97 }
98}
99
Alexandre Rames5319def2014-10-23 10:03:10 +0100100Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000101 return ARM64ReturnLocation(return_type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100102}
103
Alexandre Rames67555f72014-11-18 10:55:16 +0000104#define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()->
105#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value()
Alexandre Rames5319def2014-10-23 10:03:10 +0100106
Alexandre Rames5319def2014-10-23 10:03:10 +0100107class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 {
108 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000109 BoundsCheckSlowPathARM64(HBoundsCheck* instruction,
110 Location index_location,
111 Location length_location)
112 : instruction_(instruction),
113 index_location_(index_location),
114 length_location_(length_location) {}
115
Alexandre Rames5319def2014-10-23 10:03:10 +0100116
Alexandre Rames67555f72014-11-18 10:55:16 +0000117 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000118 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100119 __ Bind(GetEntryLabel());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000120 // We're moving two locations to locations that could overlap, so we need a parallel
121 // move resolver.
122 InvokeRuntimeCallingConvention calling_convention;
123 codegen->EmitParallelMoves(
Nicolas Geoffray90218252015-04-15 11:56:51 +0100124 index_location_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt,
125 length_location_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000126 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000127 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800128 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100129 }
130
131 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000132 HBoundsCheck* const instruction_;
133 const Location index_location_;
134 const Location length_location_;
135
Alexandre Rames5319def2014-10-23 10:03:10 +0100136 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64);
137};
138
Alexandre Rames67555f72014-11-18 10:55:16 +0000139class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 {
140 public:
141 explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : instruction_(instruction) {}
142
143 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
144 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
145 __ Bind(GetEntryLabel());
146 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000147 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800148 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000149 }
150
151 private:
152 HDivZeroCheck* const instruction_;
153 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64);
154};
155
156class LoadClassSlowPathARM64 : public SlowPathCodeARM64 {
157 public:
158 LoadClassSlowPathARM64(HLoadClass* cls,
159 HInstruction* at,
160 uint32_t dex_pc,
161 bool do_clinit)
162 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
163 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
164 }
165
166 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
167 LocationSummary* locations = at_->GetLocations();
168 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
169
170 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000171 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000172
173 InvokeRuntimeCallingConvention calling_convention;
174 __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +0000175 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
176 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000177 arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800178 if (do_clinit_) {
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100179 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800180 } else {
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100181 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800182 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000183
184 // Move the class to the desired location.
185 Location out = locations->Out();
186 if (out.IsValid()) {
187 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
188 Primitive::Type type = at_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000189 arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000190 }
191
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000192 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000193 __ B(GetExitLabel());
194 }
195
196 private:
197 // The class this slow path will load.
198 HLoadClass* const cls_;
199
200 // The instruction where this slow path is happening.
201 // (Might be the load class or an initialization check).
202 HInstruction* const at_;
203
204 // The dex PC of `at_`.
205 const uint32_t dex_pc_;
206
207 // Whether to initialize the class.
208 const bool do_clinit_;
209
210 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64);
211};
212
213class LoadStringSlowPathARM64 : public SlowPathCodeARM64 {
214 public:
215 explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {}
216
217 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
218 LocationSummary* locations = instruction_->GetLocations();
219 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
220 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
221
222 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000223 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000224
225 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800226 __ Mov(calling_convention.GetRegisterAt(0).W(), instruction_->GetStringIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +0000227 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000228 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100229 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000230 Primitive::Type type = instruction_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000231 arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000232
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000233 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000234 __ B(GetExitLabel());
235 }
236
237 private:
238 HLoadString* const instruction_;
239
240 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64);
241};
242
Alexandre Rames5319def2014-10-23 10:03:10 +0100243class NullCheckSlowPathARM64 : public SlowPathCodeARM64 {
244 public:
245 explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {}
246
Alexandre Rames67555f72014-11-18 10:55:16 +0000247 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
248 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100249 __ Bind(GetEntryLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000250 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000251 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800252 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100253 }
254
255 private:
256 HNullCheck* const instruction_;
257
258 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64);
259};
260
261class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 {
262 public:
263 explicit SuspendCheckSlowPathARM64(HSuspendCheck* instruction,
264 HBasicBlock* successor)
265 : instruction_(instruction), successor_(successor) {}
266
Alexandre Rames67555f72014-11-18 10:55:16 +0000267 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
268 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100269 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000270 SaveLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000271 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000272 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800273 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000274 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000275 if (successor_ == nullptr) {
276 __ B(GetReturnLabel());
277 } else {
278 __ B(arm64_codegen->GetLabelOf(successor_));
279 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100280 }
281
282 vixl::Label* GetReturnLabel() {
283 DCHECK(successor_ == nullptr);
284 return &return_label_;
285 }
286
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100287 HBasicBlock* GetSuccessor() const {
288 return successor_;
289 }
290
Alexandre Rames5319def2014-10-23 10:03:10 +0100291 private:
292 HSuspendCheck* const instruction_;
293 // If not null, the block to branch to after the suspend check.
294 HBasicBlock* const successor_;
295
296 // If `successor_` is null, the label to branch to after the suspend check.
297 vixl::Label return_label_;
298
299 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64);
300};
301
Alexandre Rames67555f72014-11-18 10:55:16 +0000302class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 {
303 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000304 TypeCheckSlowPathARM64(HInstruction* instruction,
305 Location class_to_check,
306 Location object_class,
307 uint32_t dex_pc)
308 : instruction_(instruction),
309 class_to_check_(class_to_check),
310 object_class_(object_class),
311 dex_pc_(dex_pc) {}
Alexandre Rames67555f72014-11-18 10:55:16 +0000312
313 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000314 LocationSummary* locations = instruction_->GetLocations();
315 DCHECK(instruction_->IsCheckCast()
316 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
317 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
318
Alexandre Rames67555f72014-11-18 10:55:16 +0000319 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000320 SaveLiveRegisters(codegen, locations);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000321
322 // We're moving two locations to locations that could overlap, so we need a parallel
323 // move resolver.
324 InvokeRuntimeCallingConvention calling_convention;
325 codegen->EmitParallelMoves(
Nicolas Geoffray90218252015-04-15 11:56:51 +0100326 class_to_check_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot,
327 object_class_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000328
329 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000330 arm64_codegen->InvokeRuntime(
331 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000332 Primitive::Type ret_type = instruction_->GetType();
333 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
334 arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800335 CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t,
336 const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000337 } else {
338 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000339 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800340 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000341 }
342
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000343 RestoreLiveRegisters(codegen, locations);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000344 __ B(GetExitLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000345 }
346
347 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000348 HInstruction* const instruction_;
349 const Location class_to_check_;
350 const Location object_class_;
351 uint32_t dex_pc_;
352
Alexandre Rames67555f72014-11-18 10:55:16 +0000353 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64);
354};
355
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700356class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 {
357 public:
358 explicit DeoptimizationSlowPathARM64(HInstruction* instruction)
359 : instruction_(instruction) {}
360
361 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
362 __ Bind(GetEntryLabel());
363 SaveLiveRegisters(codegen, instruction_->GetLocations());
364 DCHECK(instruction_->IsDeoptimize());
365 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
366 uint32_t dex_pc = deoptimize->GetDexPc();
367 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
368 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
369 }
370
371 private:
372 HInstruction* const instruction_;
373 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64);
374};
375
Alexandre Rames5319def2014-10-23 10:03:10 +0100376#undef __
377
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100378Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) {
Alexandre Rames5319def2014-10-23 10:03:10 +0100379 Location next_location;
380 if (type == Primitive::kPrimVoid) {
381 LOG(FATAL) << "Unreachable type " << type;
382 }
383
Alexandre Rames542361f2015-01-29 16:57:31 +0000384 if (Primitive::IsFloatingPointType(type) &&
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100385 (float_index_ < calling_convention.GetNumberOfFpuRegisters())) {
386 next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++));
Alexandre Rames542361f2015-01-29 16:57:31 +0000387 } else if (!Primitive::IsFloatingPointType(type) &&
388 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000389 next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++));
390 } else {
391 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Alexandre Rames542361f2015-01-29 16:57:31 +0000392 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
393 : Location::StackSlot(stack_offset);
Alexandre Rames5319def2014-10-23 10:03:10 +0100394 }
395
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000396 // Space on the stack is reserved for all arguments.
Alexandre Rames542361f2015-01-29 16:57:31 +0000397 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
Alexandre Rames5319def2014-10-23 10:03:10 +0100398 return next_location;
399}
400
Serban Constantinescu579885a2015-02-22 20:51:33 +0000401CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph,
402 const Arm64InstructionSetFeatures& isa_features,
403 const CompilerOptions& compiler_options)
Alexandre Rames5319def2014-10-23 10:03:10 +0100404 : CodeGenerator(graph,
405 kNumberOfAllocatableRegisters,
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000406 kNumberOfAllocatableFPRegisters,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000407 kNumberOfAllocatableRegisterPairs,
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000408 callee_saved_core_registers.list(),
409 callee_saved_fp_registers.list(),
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000410 compiler_options),
Alexandre Rames5319def2014-10-23 10:03:10 +0100411 block_labels_(nullptr),
412 location_builder_(graph, this),
Alexandre Rames3e69f162014-12-10 10:36:50 +0000413 instruction_visitor_(graph, this),
Serban Constantinescu579885a2015-02-22 20:51:33 +0000414 move_resolver_(graph->GetArena(), this),
415 isa_features_(isa_features) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000416 // Save the link register (containing the return address) to mimic Quick.
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000417 AddAllocatedRegister(LocationFrom(lr));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000418}
Alexandre Rames5319def2014-10-23 10:03:10 +0100419
Alexandre Rames67555f72014-11-18 10:55:16 +0000420#undef __
421#define __ GetVIXLAssembler()->
Alexandre Rames5319def2014-10-23 10:03:10 +0100422
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000423void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) {
424 // Ensure we emit the literal pool.
425 __ FinalizeCode();
426 CodeGenerator::Finalize(allocator);
427}
428
Zheng Xuad4450e2015-04-17 18:48:56 +0800429void ParallelMoveResolverARM64::PrepareForEmitNativeCode() {
430 // Note: There are 6 kinds of moves:
431 // 1. constant -> GPR/FPR (non-cycle)
432 // 2. constant -> stack (non-cycle)
433 // 3. GPR/FPR -> GPR/FPR
434 // 4. GPR/FPR -> stack
435 // 5. stack -> GPR/FPR
436 // 6. stack -> stack (non-cycle)
437 // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5
438 // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting
439 // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the
440 // dependency.
441 vixl_temps_.Open(GetVIXLAssembler());
442}
443
444void ParallelMoveResolverARM64::FinishEmitNativeCode() {
445 vixl_temps_.Close();
446}
447
448Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) {
449 DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister ||
450 kind == Location::kStackSlot || kind == Location::kDoubleStackSlot);
451 kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister;
452 Location scratch = GetScratchLocation(kind);
453 if (!scratch.Equals(Location::NoLocation())) {
454 return scratch;
455 }
456 // Allocate from VIXL temp registers.
457 if (kind == Location::kRegister) {
458 scratch = LocationFrom(vixl_temps_.AcquireX());
459 } else {
460 DCHECK(kind == Location::kFpuRegister);
461 scratch = LocationFrom(vixl_temps_.AcquireD());
462 }
463 AddScratchLocation(scratch);
464 return scratch;
465}
466
467void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) {
468 if (loc.IsRegister()) {
469 vixl_temps_.Release(XRegisterFrom(loc));
470 } else {
471 DCHECK(loc.IsFpuRegister());
472 vixl_temps_.Release(DRegisterFrom(loc));
473 }
474 RemoveScratchLocation(loc);
475}
476
Alexandre Rames3e69f162014-12-10 10:36:50 +0000477void ParallelMoveResolverARM64::EmitMove(size_t index) {
478 MoveOperands* move = moves_.Get(index);
479 codegen_->MoveLocation(move->GetDestination(), move->GetSource());
480}
481
Alexandre Rames5319def2014-10-23 10:03:10 +0100482void CodeGeneratorARM64::GenerateFrameEntry() {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100483 MacroAssembler* masm = GetVIXLAssembler();
484 BlockPoolsScope block_pools(masm);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000485 __ Bind(&frame_entry_label_);
486
Serban Constantinescu02164b32014-11-13 14:05:07 +0000487 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod();
488 if (do_overflow_check) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100489 UseScratchRegisterScope temps(masm);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000490 Register temp = temps.AcquireX();
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000491 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000492 __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64)));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000493 __ Ldr(wzr, MemOperand(temp, 0));
494 RecordPcInfo(nullptr, 0);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000495 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100496
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000497 if (!HasEmptyFrame()) {
498 int frame_size = GetFrameSize();
499 // Stack layout:
500 // sp[frame_size - 8] : lr.
501 // ... : other preserved core registers.
502 // ... : other preserved fp registers.
503 // ... : reserved frame space.
504 // sp[0] : current method.
505 __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100506 GetAssembler()->cfi().AdjustCFAOffset(frame_size);
Zheng Xu69a50302015-04-14 20:04:41 +0800507 GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(),
508 frame_size - GetCoreSpillSize());
509 GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(),
510 frame_size - FrameEntrySpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000511 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100512}
513
514void CodeGeneratorARM64::GenerateFrameExit() {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100515 BlockPoolsScope block_pools(GetVIXLAssembler());
David Srbeckyc34dc932015-04-12 09:27:43 +0100516 GetAssembler()->cfi().RememberState();
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000517 if (!HasEmptyFrame()) {
518 int frame_size = GetFrameSize();
Zheng Xu69a50302015-04-14 20:04:41 +0800519 GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(),
520 frame_size - FrameEntrySpillSize());
521 GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(),
522 frame_size - GetCoreSpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000523 __ Drop(frame_size);
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100524 GetAssembler()->cfi().AdjustCFAOffset(-frame_size);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000525 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100526 __ Ret();
527 GetAssembler()->cfi().RestoreState();
528 GetAssembler()->cfi().DefCFAOffset(GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +0100529}
530
531void CodeGeneratorARM64::Bind(HBasicBlock* block) {
532 __ Bind(GetLabelOf(block));
533}
534
Alexandre Rames5319def2014-10-23 10:03:10 +0100535void CodeGeneratorARM64::Move(HInstruction* instruction,
536 Location location,
537 HInstruction* move_for) {
538 LocationSummary* locations = instruction->GetLocations();
539 if (locations != nullptr && locations->Out().Equals(location)) {
540 return;
541 }
542
543 Primitive::Type type = instruction->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000544 DCHECK_NE(type, Primitive::kPrimVoid);
Alexandre Rames5319def2014-10-23 10:03:10 +0100545
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000546 if (instruction->IsIntConstant()
547 || instruction->IsLongConstant()
548 || instruction->IsNullConstant()) {
549 int64_t value = GetInt64ValueOf(instruction->AsConstant());
Alexandre Rames5319def2014-10-23 10:03:10 +0100550 if (location.IsRegister()) {
551 Register dst = RegisterFrom(location, type);
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000552 DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) ||
Alexandre Rames5319def2014-10-23 10:03:10 +0100553 (instruction->IsLongConstant() && dst.Is64Bits()));
554 __ Mov(dst, value);
555 } else {
556 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000557 UseScratchRegisterScope temps(GetVIXLAssembler());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000558 Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant())
559 ? temps.AcquireW()
560 : temps.AcquireX();
Alexandre Rames5319def2014-10-23 10:03:10 +0100561 __ Mov(temp, value);
562 __ Str(temp, StackOperandFrom(location));
563 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000564 } else if (instruction->IsTemporary()) {
565 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000566 MoveLocation(location, temp_location, type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100567 } else if (instruction->IsLoadLocal()) {
568 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Alexandre Rames542361f2015-01-29 16:57:31 +0000569 if (Primitive::Is64BitType(type)) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000570 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000571 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000572 MoveLocation(location, Location::StackSlot(stack_slot), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100573 }
574
575 } else {
576 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000577 MoveLocation(location, locations->Out(), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100578 }
579}
580
Alexandre Rames5319def2014-10-23 10:03:10 +0100581Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const {
582 Primitive::Type type = load->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000583
Alexandre Rames5319def2014-10-23 10:03:10 +0100584 switch (type) {
585 case Primitive::kPrimNot:
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000586 case Primitive::kPrimInt:
587 case Primitive::kPrimFloat:
588 return Location::StackSlot(GetStackSlot(load->GetLocal()));
589
590 case Primitive::kPrimLong:
591 case Primitive::kPrimDouble:
592 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
593
Alexandre Rames5319def2014-10-23 10:03:10 +0100594 case Primitive::kPrimBoolean:
595 case Primitive::kPrimByte:
596 case Primitive::kPrimChar:
597 case Primitive::kPrimShort:
Alexandre Rames5319def2014-10-23 10:03:10 +0100598 case Primitive::kPrimVoid:
Alexandre Rames5319def2014-10-23 10:03:10 +0100599 LOG(FATAL) << "Unexpected type " << type;
600 }
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000601
Alexandre Rames5319def2014-10-23 10:03:10 +0100602 LOG(FATAL) << "Unreachable";
603 return Location::NoLocation();
604}
605
606void CodeGeneratorARM64::MarkGCCard(Register object, Register value) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000607 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +0100608 Register card = temps.AcquireX();
Serban Constantinescu02164b32014-11-13 14:05:07 +0000609 Register temp = temps.AcquireW(); // Index within the CardTable - 32bit.
Alexandre Rames5319def2014-10-23 10:03:10 +0100610 vixl::Label done;
611 __ Cbz(value, &done);
612 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value()));
613 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000614 __ Strb(card, MemOperand(card, temp.X()));
Alexandre Rames5319def2014-10-23 10:03:10 +0100615 __ Bind(&done);
616}
617
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000618void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const {
619 // Blocked core registers:
620 // lr : Runtime reserved.
621 // tr : Runtime reserved.
622 // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it.
623 // ip1 : VIXL core temp.
624 // ip0 : VIXL core temp.
625 //
626 // Blocked fp registers:
627 // d31 : VIXL fp temp.
Alexandre Rames5319def2014-10-23 10:03:10 +0100628 CPURegList reserved_core_registers = vixl_reserved_core_registers;
629 reserved_core_registers.Combine(runtime_reserved_core_registers);
Alexandre Rames5319def2014-10-23 10:03:10 +0100630 while (!reserved_core_registers.IsEmpty()) {
631 blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true;
632 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000633
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000634 CPURegList reserved_fp_registers = vixl_reserved_fp_registers;
Zheng Xua3ec3942015-02-15 18:39:46 +0800635 while (!reserved_fp_registers.IsEmpty()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000636 blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true;
637 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000638
639 if (is_baseline) {
640 CPURegList reserved_core_baseline_registers = callee_saved_core_registers;
641 while (!reserved_core_baseline_registers.IsEmpty()) {
642 blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true;
643 }
644
645 CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers;
646 while (!reserved_fp_baseline_registers.IsEmpty()) {
647 blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true;
648 }
649 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100650}
651
652Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const {
653 if (type == Primitive::kPrimVoid) {
654 LOG(FATAL) << "Unreachable type " << type;
655 }
656
Alexandre Rames542361f2015-01-29 16:57:31 +0000657 if (Primitive::IsFloatingPointType(type)) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000658 ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters);
659 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100660 return Location::FpuRegisterLocation(reg);
661 } else {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000662 ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters);
663 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100664 return Location::RegisterLocation(reg);
665 }
666}
667
Alexandre Rames3e69f162014-12-10 10:36:50 +0000668size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
669 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
670 __ Str(reg, MemOperand(sp, stack_index));
671 return kArm64WordSize;
672}
673
674size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
675 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
676 __ Ldr(reg, MemOperand(sp, stack_index));
677 return kArm64WordSize;
678}
679
680size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
681 FPRegister reg = FPRegister(reg_id, kDRegSize);
682 __ Str(reg, MemOperand(sp, stack_index));
683 return kArm64WordSize;
684}
685
686size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
687 FPRegister reg = FPRegister(reg_id, kDRegSize);
688 __ Ldr(reg, MemOperand(sp, stack_index));
689 return kArm64WordSize;
690}
691
Alexandre Rames5319def2014-10-23 10:03:10 +0100692void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
693 stream << Arm64ManagedRegister::FromXRegister(XRegister(reg));
694}
695
696void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
697 stream << Arm64ManagedRegister::FromDRegister(DRegister(reg));
698}
699
Alexandre Rames67555f72014-11-18 10:55:16 +0000700void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000701 if (constant->IsIntConstant()) {
702 __ Mov(Register(destination), constant->AsIntConstant()->GetValue());
703 } else if (constant->IsLongConstant()) {
704 __ Mov(Register(destination), constant->AsLongConstant()->GetValue());
705 } else if (constant->IsNullConstant()) {
706 __ Mov(Register(destination), 0);
Alexandre Rames67555f72014-11-18 10:55:16 +0000707 } else if (constant->IsFloatConstant()) {
708 __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue());
709 } else {
710 DCHECK(constant->IsDoubleConstant());
711 __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue());
712 }
713}
714
Alexandre Rames3e69f162014-12-10 10:36:50 +0000715
716static bool CoherentConstantAndType(Location constant, Primitive::Type type) {
717 DCHECK(constant.IsConstant());
718 HConstant* cst = constant.GetConstant();
719 return (cst->IsIntConstant() && type == Primitive::kPrimInt) ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000720 // Null is mapped to a core W register, which we associate with kPrimInt.
721 (cst->IsNullConstant() && type == Primitive::kPrimInt) ||
Alexandre Rames3e69f162014-12-10 10:36:50 +0000722 (cst->IsLongConstant() && type == Primitive::kPrimLong) ||
723 (cst->IsFloatConstant() && type == Primitive::kPrimFloat) ||
724 (cst->IsDoubleConstant() && type == Primitive::kPrimDouble);
725}
726
727void CodeGeneratorARM64::MoveLocation(Location destination, Location source, Primitive::Type type) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000728 if (source.Equals(destination)) {
729 return;
730 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000731
732 // A valid move can always be inferred from the destination and source
733 // locations. When moving from and to a register, the argument type can be
734 // used to generate 32bit instead of 64bit moves. In debug mode we also
735 // checks the coherency of the locations and the type.
736 bool unspecified_type = (type == Primitive::kPrimVoid);
737
738 if (destination.IsRegister() || destination.IsFpuRegister()) {
739 if (unspecified_type) {
740 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
741 if (source.IsStackSlot() ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000742 (src_cst != nullptr && (src_cst->IsIntConstant()
743 || src_cst->IsFloatConstant()
744 || src_cst->IsNullConstant()))) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000745 // For stack slots and 32bit constants, a 64bit type is appropriate.
746 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexandre Rames67555f72014-11-18 10:55:16 +0000747 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000748 // If the source is a double stack slot or a 64bit constant, a 64bit
749 // type is appropriate. Else the source is a register, and since the
750 // type has not been specified, we chose a 64bit type to force a 64bit
751 // move.
752 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexandre Rames67555f72014-11-18 10:55:16 +0000753 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000754 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000755 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
756 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000757 CPURegister dst = CPURegisterFrom(destination, type);
758 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
759 DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot());
760 __ Ldr(dst, StackOperandFrom(source));
761 } else if (source.IsConstant()) {
762 DCHECK(CoherentConstantAndType(source, type));
763 MoveConstant(dst, source.GetConstant());
764 } else {
765 if (destination.IsRegister()) {
766 __ Mov(Register(dst), RegisterFrom(source, type));
767 } else {
Zheng Xuad4450e2015-04-17 18:48:56 +0800768 DCHECK(destination.IsFpuRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000769 __ Fmov(FPRegister(dst), FPRegisterFrom(source, type));
770 }
771 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000772 } else { // The destination is not a register. It must be a stack slot.
773 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
774 if (source.IsRegister() || source.IsFpuRegister()) {
775 if (unspecified_type) {
776 if (source.IsRegister()) {
777 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
778 } else {
779 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
780 }
781 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000782 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
783 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000784 __ Str(CPURegisterFrom(source, type), StackOperandFrom(destination));
785 } else if (source.IsConstant()) {
786 DCHECK(unspecified_type || CoherentConstantAndType(source, type));
787 UseScratchRegisterScope temps(GetVIXLAssembler());
788 HConstant* src_cst = source.GetConstant();
789 CPURegister temp;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000790 if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000791 temp = temps.AcquireW();
792 } else if (src_cst->IsLongConstant()) {
793 temp = temps.AcquireX();
794 } else if (src_cst->IsFloatConstant()) {
795 temp = temps.AcquireS();
796 } else {
797 DCHECK(src_cst->IsDoubleConstant());
798 temp = temps.AcquireD();
799 }
800 MoveConstant(temp, src_cst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000801 __ Str(temp, StackOperandFrom(destination));
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000802 } else {
Alexandre Rames67555f72014-11-18 10:55:16 +0000803 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000804 DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000805 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000806 // There is generally less pressure on FP registers.
807 FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS();
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000808 __ Ldr(temp, StackOperandFrom(source));
809 __ Str(temp, StackOperandFrom(destination));
810 }
811 }
812}
813
814void CodeGeneratorARM64::Load(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000815 CPURegister dst,
816 const MemOperand& src) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000817 switch (type) {
818 case Primitive::kPrimBoolean:
Alexandre Rames67555f72014-11-18 10:55:16 +0000819 __ Ldrb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000820 break;
821 case Primitive::kPrimByte:
Alexandre Rames67555f72014-11-18 10:55:16 +0000822 __ Ldrsb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000823 break;
824 case Primitive::kPrimShort:
Alexandre Rames67555f72014-11-18 10:55:16 +0000825 __ Ldrsh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000826 break;
827 case Primitive::kPrimChar:
Alexandre Rames67555f72014-11-18 10:55:16 +0000828 __ Ldrh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000829 break;
830 case Primitive::kPrimInt:
831 case Primitive::kPrimNot:
832 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000833 case Primitive::kPrimFloat:
834 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000835 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Rames67555f72014-11-18 10:55:16 +0000836 __ Ldr(dst, src);
837 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000838 case Primitive::kPrimVoid:
839 LOG(FATAL) << "Unreachable type " << type;
840 }
841}
842
Calin Juravle77520bc2015-01-12 18:45:46 +0000843void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000844 CPURegister dst,
845 const MemOperand& src) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100846 MacroAssembler* masm = GetVIXLAssembler();
847 BlockPoolsScope block_pools(masm);
848 UseScratchRegisterScope temps(masm);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000849 Register temp_base = temps.AcquireX();
Calin Juravle77520bc2015-01-12 18:45:46 +0000850 Primitive::Type type = instruction->GetType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000851
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000852 DCHECK(!src.IsPreIndex());
853 DCHECK(!src.IsPostIndex());
854
855 // TODO(vixl): Let the MacroAssembler handle MemOperand.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800856 __ Add(temp_base, src.base(), OperandFromMemOperand(src));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000857 MemOperand base = MemOperand(temp_base);
858 switch (type) {
859 case Primitive::kPrimBoolean:
860 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000861 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000862 break;
863 case Primitive::kPrimByte:
864 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000865 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000866 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
867 break;
868 case Primitive::kPrimChar:
869 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000870 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000871 break;
872 case Primitive::kPrimShort:
873 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000874 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000875 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
876 break;
877 case Primitive::kPrimInt:
878 case Primitive::kPrimNot:
879 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000880 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000881 __ Ldar(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000882 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000883 break;
884 case Primitive::kPrimFloat:
885 case Primitive::kPrimDouble: {
886 DCHECK(dst.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000887 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000888
889 Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
890 __ Ldar(temp, base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000891 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000892 __ Fmov(FPRegister(dst), temp);
893 break;
894 }
895 case Primitive::kPrimVoid:
896 LOG(FATAL) << "Unreachable type " << type;
897 }
898}
899
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000900void CodeGeneratorARM64::Store(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000901 CPURegister src,
902 const MemOperand& dst) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000903 switch (type) {
904 case Primitive::kPrimBoolean:
905 case Primitive::kPrimByte:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000906 __ Strb(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000907 break;
908 case Primitive::kPrimChar:
909 case Primitive::kPrimShort:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000910 __ Strh(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000911 break;
912 case Primitive::kPrimInt:
913 case Primitive::kPrimNot:
914 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000915 case Primitive::kPrimFloat:
916 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000917 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000918 __ Str(src, dst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000919 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000920 case Primitive::kPrimVoid:
921 LOG(FATAL) << "Unreachable type " << type;
922 }
923}
924
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000925void CodeGeneratorARM64::StoreRelease(Primitive::Type type,
926 CPURegister src,
927 const MemOperand& dst) {
928 UseScratchRegisterScope temps(GetVIXLAssembler());
929 Register temp_base = temps.AcquireX();
930
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000931 DCHECK(!dst.IsPreIndex());
932 DCHECK(!dst.IsPostIndex());
933
934 // TODO(vixl): Let the MacroAssembler handle this.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800935 Operand op = OperandFromMemOperand(dst);
936 __ Add(temp_base, dst.base(), op);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000937 MemOperand base = MemOperand(temp_base);
938 switch (type) {
939 case Primitive::kPrimBoolean:
940 case Primitive::kPrimByte:
941 __ Stlrb(Register(src), base);
942 break;
943 case Primitive::kPrimChar:
944 case Primitive::kPrimShort:
945 __ Stlrh(Register(src), base);
946 break;
947 case Primitive::kPrimInt:
948 case Primitive::kPrimNot:
949 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000950 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000951 __ Stlr(Register(src), base);
952 break;
953 case Primitive::kPrimFloat:
954 case Primitive::kPrimDouble: {
955 DCHECK(src.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000956 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000957
958 Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
959 __ Fmov(temp, FPRegister(src));
960 __ Stlr(temp, base);
961 break;
962 }
963 case Primitive::kPrimVoid:
964 LOG(FATAL) << "Unreachable type " << type;
965 }
966}
967
Alexandre Rames67555f72014-11-18 10:55:16 +0000968void CodeGeneratorARM64::LoadCurrentMethod(vixl::Register current_method) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000969 DCHECK(RequiresCurrentMethod());
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -0700970 CHECK(current_method.IsX());
Alexandre Rames67555f72014-11-18 10:55:16 +0000971 __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset));
972}
973
974void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset,
975 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000976 uint32_t dex_pc,
977 SlowPathCode* slow_path) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100978 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames67555f72014-11-18 10:55:16 +0000979 __ Ldr(lr, MemOperand(tr, entry_point_offset));
980 __ Blr(lr);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000981 if (instruction != nullptr) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000982 RecordPcInfo(instruction, dex_pc, slow_path);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000983 DCHECK(instruction->IsSuspendCheck()
984 || instruction->IsBoundsCheck()
985 || instruction->IsNullCheck()
986 || instruction->IsDivZeroCheck()
987 || !IsLeafMethod());
988 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000989}
990
991void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path,
992 vixl::Register class_reg) {
993 UseScratchRegisterScope temps(GetVIXLAssembler());
994 Register temp = temps.AcquireW();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000995 size_t status_offset = mirror::Class::StatusOffset().SizeValue();
Serban Constantinescu579885a2015-02-22 20:51:33 +0000996 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000997
Serban Constantinescu02164b32014-11-13 14:05:07 +0000998 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
Serban Constantinescu579885a2015-02-22 20:51:33 +0000999 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001000 // TODO(vixl): Let the MacroAssembler handle MemOperand.
1001 __ Add(temp, class_reg, status_offset);
1002 __ Ldar(temp, HeapOperand(temp));
1003 __ Cmp(temp, mirror::Class::kStatusInitialized);
1004 __ B(lt, slow_path->GetEntryLabel());
1005 } else {
1006 __ Ldr(temp, HeapOperand(class_reg, status_offset));
1007 __ Cmp(temp, mirror::Class::kStatusInitialized);
1008 __ B(lt, slow_path->GetEntryLabel());
1009 __ Dmb(InnerShareable, BarrierReads);
1010 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001011 __ Bind(slow_path->GetExitLabel());
1012}
Alexandre Rames5319def2014-10-23 10:03:10 +01001013
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001014void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) {
1015 BarrierType type = BarrierAll;
1016
1017 switch (kind) {
1018 case MemBarrierKind::kAnyAny:
1019 case MemBarrierKind::kAnyStore: {
1020 type = BarrierAll;
1021 break;
1022 }
1023 case MemBarrierKind::kLoadAny: {
1024 type = BarrierReads;
1025 break;
1026 }
1027 case MemBarrierKind::kStoreStore: {
1028 type = BarrierWrites;
1029 break;
1030 }
1031 default:
1032 LOG(FATAL) << "Unexpected memory barrier " << kind;
1033 }
1034 __ Dmb(InnerShareable, type);
1035}
1036
Serban Constantinescu02164b32014-11-13 14:05:07 +00001037void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction,
1038 HBasicBlock* successor) {
1039 SuspendCheckSlowPathARM64* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01001040 down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath());
1041 if (slow_path == nullptr) {
1042 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor);
1043 instruction->SetSlowPath(slow_path);
1044 codegen_->AddSlowPath(slow_path);
1045 if (successor != nullptr) {
1046 DCHECK(successor->IsLoopHeader());
1047 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
1048 }
1049 } else {
1050 DCHECK_EQ(slow_path->GetSuccessor(), successor);
1051 }
1052
Serban Constantinescu02164b32014-11-13 14:05:07 +00001053 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
1054 Register temp = temps.AcquireW();
1055
1056 __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue()));
1057 if (successor == nullptr) {
1058 __ Cbnz(temp, slow_path->GetEntryLabel());
1059 __ Bind(slow_path->GetReturnLabel());
1060 } else {
1061 __ Cbz(temp, codegen_->GetLabelOf(successor));
1062 __ B(slow_path->GetEntryLabel());
1063 // slow_path will return to GetLabelOf(successor).
1064 }
1065}
1066
Alexandre Rames5319def2014-10-23 10:03:10 +01001067InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
1068 CodeGeneratorARM64* codegen)
1069 : HGraphVisitor(graph),
1070 assembler_(codegen->GetAssembler()),
1071 codegen_(codegen) {}
1072
1073#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Alexandre Rames3e69f162014-12-10 10:36:50 +00001074 /* No unimplemented IR. */
Alexandre Rames5319def2014-10-23 10:03:10 +01001075
1076#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
1077
1078enum UnimplementedInstructionBreakCode {
Alexandre Rames67555f72014-11-18 10:55:16 +00001079 // Using a base helps identify when we hit such breakpoints.
1080 UnimplementedInstructionBreakCodeBaseCode = 0x900,
Alexandre Rames5319def2014-10-23 10:03:10 +01001081#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
1082 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
1083#undef ENUM_UNIMPLEMENTED_INSTRUCTION
1084};
1085
1086#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
1087 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001088 UNUSED(instr); \
Alexandre Rames5319def2014-10-23 10:03:10 +01001089 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
1090 } \
1091 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
1092 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
1093 locations->SetOut(Location::Any()); \
1094 }
1095 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
1096#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
1097
1098#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
Alexandre Rames67555f72014-11-18 10:55:16 +00001099#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
Alexandre Rames5319def2014-10-23 10:03:10 +01001100
Alexandre Rames67555f72014-11-18 10:55:16 +00001101void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001102 DCHECK_EQ(instr->InputCount(), 2U);
1103 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1104 Primitive::Type type = instr->GetResultType();
1105 switch (type) {
1106 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001107 case Primitive::kPrimLong:
Alexandre Rames5319def2014-10-23 10:03:10 +01001108 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001109 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr));
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001110 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001111 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001112
1113 case Primitive::kPrimFloat:
1114 case Primitive::kPrimDouble:
1115 locations->SetInAt(0, Location::RequiresFpuRegister());
1116 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001117 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001118 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001119
Alexandre Rames5319def2014-10-23 10:03:10 +01001120 default:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001121 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001122 }
1123}
1124
Alexandre Rames09a99962015-04-15 11:47:56 +01001125void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) {
1126 LocationSummary* locations =
1127 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1128 locations->SetInAt(0, Location::RequiresRegister());
1129 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1130 locations->SetOut(Location::RequiresFpuRegister());
1131 } else {
1132 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1133 }
1134}
1135
1136void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction,
1137 const FieldInfo& field_info) {
1138 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Alexandre Ramesd921d642015-04-16 15:07:16 +01001139 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001140
1141 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset());
1142 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
1143
1144 if (field_info.IsVolatile()) {
1145 if (use_acquire_release) {
1146 // NB: LoadAcquire will record the pc info if needed.
1147 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
1148 } else {
1149 codegen_->Load(field_info.GetFieldType(), OutputCPURegister(instruction), field);
1150 codegen_->MaybeRecordImplicitNullCheck(instruction);
1151 // For IRIW sequential consistency kLoadAny is not sufficient.
1152 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1153 }
1154 } else {
1155 codegen_->Load(field_info.GetFieldType(), OutputCPURegister(instruction), field);
1156 codegen_->MaybeRecordImplicitNullCheck(instruction);
1157 }
1158}
1159
1160void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) {
1161 LocationSummary* locations =
1162 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1163 locations->SetInAt(0, Location::RequiresRegister());
1164 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
1165 locations->SetInAt(1, Location::RequiresFpuRegister());
1166 } else {
1167 locations->SetInAt(1, Location::RequiresRegister());
1168 }
1169}
1170
1171void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction,
1172 const FieldInfo& field_info) {
1173 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
Alexandre Ramesd921d642015-04-16 15:07:16 +01001174 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001175
1176 Register obj = InputRegisterAt(instruction, 0);
1177 CPURegister value = InputCPURegisterAt(instruction, 1);
1178 Offset offset = field_info.GetFieldOffset();
1179 Primitive::Type field_type = field_info.GetFieldType();
1180 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
1181
1182 if (field_info.IsVolatile()) {
1183 if (use_acquire_release) {
1184 codegen_->StoreRelease(field_type, value, HeapOperand(obj, offset));
1185 codegen_->MaybeRecordImplicitNullCheck(instruction);
1186 } else {
1187 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
1188 codegen_->Store(field_type, value, HeapOperand(obj, offset));
1189 codegen_->MaybeRecordImplicitNullCheck(instruction);
1190 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1191 }
1192 } else {
1193 codegen_->Store(field_type, value, HeapOperand(obj, offset));
1194 codegen_->MaybeRecordImplicitNullCheck(instruction);
1195 }
1196
1197 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
1198 codegen_->MarkGCCard(obj, Register(value));
1199 }
1200}
1201
Alexandre Rames67555f72014-11-18 10:55:16 +00001202void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001203 Primitive::Type type = instr->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001204
1205 switch (type) {
1206 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001207 case Primitive::kPrimLong: {
1208 Register dst = OutputRegister(instr);
1209 Register lhs = InputRegisterAt(instr, 0);
1210 Operand rhs = InputOperandAt(instr, 1);
Alexandre Rames5319def2014-10-23 10:03:10 +01001211 if (instr->IsAdd()) {
1212 __ Add(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001213 } else if (instr->IsAnd()) {
1214 __ And(dst, lhs, rhs);
1215 } else if (instr->IsOr()) {
1216 __ Orr(dst, lhs, rhs);
1217 } else if (instr->IsSub()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001218 __ Sub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001219 } else {
1220 DCHECK(instr->IsXor());
1221 __ Eor(dst, lhs, rhs);
Alexandre Rames5319def2014-10-23 10:03:10 +01001222 }
1223 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001224 }
1225 case Primitive::kPrimFloat:
1226 case Primitive::kPrimDouble: {
1227 FPRegister dst = OutputFPRegister(instr);
1228 FPRegister lhs = InputFPRegisterAt(instr, 0);
1229 FPRegister rhs = InputFPRegisterAt(instr, 1);
1230 if (instr->IsAdd()) {
1231 __ Fadd(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001232 } else if (instr->IsSub()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001233 __ Fsub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001234 } else {
1235 LOG(FATAL) << "Unexpected floating-point binary operation";
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001236 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001237 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001238 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001239 default:
Alexandre Rames67555f72014-11-18 10:55:16 +00001240 LOG(FATAL) << "Unexpected binary operation type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001241 }
1242}
1243
Serban Constantinescu02164b32014-11-13 14:05:07 +00001244void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) {
1245 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1246
1247 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1248 Primitive::Type type = instr->GetResultType();
1249 switch (type) {
1250 case Primitive::kPrimInt:
1251 case Primitive::kPrimLong: {
1252 locations->SetInAt(0, Location::RequiresRegister());
1253 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1254 locations->SetOut(Location::RequiresRegister());
1255 break;
1256 }
1257 default:
1258 LOG(FATAL) << "Unexpected shift type " << type;
1259 }
1260}
1261
1262void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) {
1263 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1264
1265 Primitive::Type type = instr->GetType();
1266 switch (type) {
1267 case Primitive::kPrimInt:
1268 case Primitive::kPrimLong: {
1269 Register dst = OutputRegister(instr);
1270 Register lhs = InputRegisterAt(instr, 0);
1271 Operand rhs = InputOperandAt(instr, 1);
1272 if (rhs.IsImmediate()) {
1273 uint32_t shift_value = (type == Primitive::kPrimInt)
1274 ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue)
1275 : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue);
1276 if (instr->IsShl()) {
1277 __ Lsl(dst, lhs, shift_value);
1278 } else if (instr->IsShr()) {
1279 __ Asr(dst, lhs, shift_value);
1280 } else {
1281 __ Lsr(dst, lhs, shift_value);
1282 }
1283 } else {
1284 Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W();
1285
1286 if (instr->IsShl()) {
1287 __ Lsl(dst, lhs, rhs_reg);
1288 } else if (instr->IsShr()) {
1289 __ Asr(dst, lhs, rhs_reg);
1290 } else {
1291 __ Lsr(dst, lhs, rhs_reg);
1292 }
1293 }
1294 break;
1295 }
1296 default:
1297 LOG(FATAL) << "Unexpected shift operation type " << type;
1298 }
1299}
1300
Alexandre Rames5319def2014-10-23 10:03:10 +01001301void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001302 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001303}
1304
1305void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001306 HandleBinaryOp(instruction);
1307}
1308
1309void LocationsBuilderARM64::VisitAnd(HAnd* instruction) {
1310 HandleBinaryOp(instruction);
1311}
1312
1313void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) {
1314 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001315}
1316
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001317void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) {
1318 LocationSummary* locations =
1319 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1320 locations->SetInAt(0, Location::RequiresRegister());
1321 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01001322 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1323 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1324 } else {
1325 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1326 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001327}
1328
1329void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) {
1330 LocationSummary* locations = instruction->GetLocations();
1331 Primitive::Type type = instruction->GetType();
1332 Register obj = InputRegisterAt(instruction, 0);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001333 Location index = locations->InAt(1);
1334 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001335 MemOperand source = HeapOperand(obj);
Alexandre Ramesd921d642015-04-16 15:07:16 +01001336 MacroAssembler* masm = GetVIXLAssembler();
1337 UseScratchRegisterScope temps(masm);
1338 BlockPoolsScope block_pools(masm);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001339
1340 if (index.IsConstant()) {
1341 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001342 source = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001343 } else {
1344 Register temp = temps.AcquireSameSizeAs(obj);
1345 Register index_reg = RegisterFrom(index, Primitive::kPrimInt);
1346 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001347 source = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001348 }
1349
Alexandre Rames67555f72014-11-18 10:55:16 +00001350 codegen_->Load(type, OutputCPURegister(instruction), source);
Calin Juravle77520bc2015-01-12 18:45:46 +00001351 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001352}
1353
Alexandre Rames5319def2014-10-23 10:03:10 +01001354void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
1355 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1356 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001357 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001358}
1359
1360void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001361 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +01001362 __ Ldr(OutputRegister(instruction),
1363 HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset()));
Calin Juravle77520bc2015-01-12 18:45:46 +00001364 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001365}
1366
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001367void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) {
Alexandre Rames97833a02015-04-16 15:07:12 +01001368 if (instruction->NeedsTypeCheck()) {
1369 LocationSummary* locations =
1370 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001371 InvokeRuntimeCallingConvention calling_convention;
1372 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1373 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1374 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1375 } else {
Alexandre Rames97833a02015-04-16 15:07:12 +01001376 LocationSummary* locations =
1377 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001378 locations->SetInAt(0, Location::RequiresRegister());
1379 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01001380 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1381 locations->SetInAt(2, Location::RequiresFpuRegister());
1382 } else {
1383 locations->SetInAt(2, Location::RequiresRegister());
1384 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001385 }
1386}
1387
1388void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) {
1389 Primitive::Type value_type = instruction->GetComponentType();
Alexandre Rames97833a02015-04-16 15:07:12 +01001390 LocationSummary* locations = instruction->GetLocations();
1391 bool needs_runtime_call = locations->WillCall();
1392
1393 if (needs_runtime_call) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001394 codegen_->InvokeRuntime(
1395 QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001396 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001397 } else {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001398 Register obj = InputRegisterAt(instruction, 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00001399 CPURegister value = InputCPURegisterAt(instruction, 2);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001400 Location index = locations->InAt(1);
1401 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001402 MemOperand destination = HeapOperand(obj);
Alexandre Ramesd921d642015-04-16 15:07:16 +01001403 MacroAssembler* masm = GetVIXLAssembler();
Alexandre Ramesd921d642015-04-16 15:07:16 +01001404 BlockPoolsScope block_pools(masm);
Alexandre Rames97833a02015-04-16 15:07:12 +01001405 {
1406 // We use a block to end the scratch scope before the write barrier, thus
1407 // freeing the temporary registers so they can be used in `MarkGCCard`.
1408 UseScratchRegisterScope temps(masm);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001409
Alexandre Rames97833a02015-04-16 15:07:12 +01001410 if (index.IsConstant()) {
1411 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
1412 destination = HeapOperand(obj, offset);
1413 } else {
1414 Register temp = temps.AcquireSameSizeAs(obj);
1415 Register index_reg = InputRegisterAt(instruction, 1);
1416 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type)));
1417 destination = HeapOperand(temp, offset);
1418 }
1419
1420 codegen_->Store(value_type, value, destination);
1421 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001422 }
Alexandre Rames97833a02015-04-16 15:07:12 +01001423 if (CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue())) {
1424 codegen_->MarkGCCard(obj, value.W());
1425 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001426 }
1427}
1428
Alexandre Rames67555f72014-11-18 10:55:16 +00001429void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1430 LocationSummary* locations =
1431 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1432 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu760d8ef2015-03-28 18:09:56 +00001433 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames67555f72014-11-18 10:55:16 +00001434 if (instruction->HasUses()) {
1435 locations->SetOut(Location::SameAsFirstInput());
1436 }
1437}
1438
1439void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001440 LocationSummary* locations = instruction->GetLocations();
1441 BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(
1442 instruction, locations->InAt(0), locations->InAt(1));
Alexandre Rames67555f72014-11-18 10:55:16 +00001443 codegen_->AddSlowPath(slow_path);
1444
1445 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
1446 __ B(slow_path->GetEntryLabel(), hs);
1447}
1448
1449void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) {
1450 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1451 instruction, LocationSummary::kCallOnSlowPath);
1452 locations->SetInAt(0, Location::RequiresRegister());
1453 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001454 locations->AddTemp(Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001455}
1456
1457void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001458 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames67555f72014-11-18 10:55:16 +00001459 Register obj = InputRegisterAt(instruction, 0);;
1460 Register cls = InputRegisterAt(instruction, 1);;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001461 Register obj_cls = WRegisterFrom(instruction->GetLocations()->GetTemp(0));
Alexandre Rames67555f72014-11-18 10:55:16 +00001462
Alexandre Rames3e69f162014-12-10 10:36:50 +00001463 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1464 instruction, locations->InAt(1), LocationFrom(obj_cls), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001465 codegen_->AddSlowPath(slow_path);
1466
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01001467 // Avoid null check if we know obj is not null.
1468 if (instruction->MustDoNullCheck()) {
1469 __ Cbz(obj, slow_path->GetExitLabel());
1470 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001471 // Compare the class of `obj` with `cls`.
Alexandre Rames3e69f162014-12-10 10:36:50 +00001472 __ Ldr(obj_cls, HeapOperand(obj, mirror::Object::ClassOffset()));
1473 __ Cmp(obj_cls, cls);
Alexandre Rames67555f72014-11-18 10:55:16 +00001474 __ B(ne, slow_path->GetEntryLabel());
1475 __ Bind(slow_path->GetExitLabel());
1476}
1477
1478void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) {
1479 LocationSummary* locations =
1480 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1481 locations->SetInAt(0, Location::RequiresRegister());
1482 if (check->HasUses()) {
1483 locations->SetOut(Location::SameAsFirstInput());
1484 }
1485}
1486
1487void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) {
1488 // We assume the class is not null.
1489 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
1490 check->GetLoadClass(), check, check->GetDexPc(), true);
1491 codegen_->AddSlowPath(slow_path);
1492 GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0));
1493}
1494
Serban Constantinescu02164b32014-11-13 14:05:07 +00001495void LocationsBuilderARM64::VisitCompare(HCompare* compare) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001496 LocationSummary* locations =
Serban Constantinescu02164b32014-11-13 14:05:07 +00001497 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
1498 Primitive::Type in_type = compare->InputAt(0)->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001499 switch (in_type) {
1500 case Primitive::kPrimLong: {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001501 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001502 locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001503 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1504 break;
1505 }
1506 case Primitive::kPrimFloat:
1507 case Primitive::kPrimDouble: {
1508 locations->SetInAt(0, Location::RequiresFpuRegister());
Alexandre Rames93415462015-02-17 15:08:20 +00001509 HInstruction* right = compare->InputAt(1);
1510 if ((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1511 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))) {
1512 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1513 } else {
1514 locations->SetInAt(1, Location::RequiresFpuRegister());
1515 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001516 locations->SetOut(Location::RequiresRegister());
1517 break;
1518 }
1519 default:
1520 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1521 }
1522}
1523
1524void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) {
1525 Primitive::Type in_type = compare->InputAt(0)->GetType();
1526
1527 // 0 if: left == right
1528 // 1 if: left > right
1529 // -1 if: left < right
1530 switch (in_type) {
1531 case Primitive::kPrimLong: {
1532 Register result = OutputRegister(compare);
1533 Register left = InputRegisterAt(compare, 0);
1534 Operand right = InputOperandAt(compare, 1);
1535
1536 __ Cmp(left, right);
1537 __ Cset(result, ne);
1538 __ Cneg(result, result, lt);
1539 break;
1540 }
1541 case Primitive::kPrimFloat:
1542 case Primitive::kPrimDouble: {
1543 Register result = OutputRegister(compare);
1544 FPRegister left = InputFPRegisterAt(compare, 0);
Alexandre Rames93415462015-02-17 15:08:20 +00001545 if (compare->GetLocations()->InAt(1).IsConstant()) {
1546 if (kIsDebugBuild) {
1547 HInstruction* right = compare->GetLocations()->InAt(1).GetConstant();
1548 DCHECK((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1549 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0)));
1550 }
1551 // 0.0 is the only immediate that can be encoded directly in a FCMP instruction.
1552 __ Fcmp(left, 0.0);
1553 } else {
1554 __ Fcmp(left, InputFPRegisterAt(compare, 1));
1555 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001556 if (compare->IsGtBias()) {
1557 __ Cset(result, ne);
1558 } else {
1559 __ Csetm(result, ne);
1560 }
1561 __ Cneg(result, result, compare->IsGtBias() ? mi : gt);
Alexandre Rames5319def2014-10-23 10:03:10 +01001562 break;
1563 }
1564 default:
1565 LOG(FATAL) << "Unimplemented compare type " << in_type;
1566 }
1567}
1568
1569void LocationsBuilderARM64::VisitCondition(HCondition* instruction) {
1570 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1571 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001572 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames5319def2014-10-23 10:03:10 +01001573 if (instruction->NeedsMaterialization()) {
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001574 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001575 }
1576}
1577
1578void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) {
1579 if (!instruction->NeedsMaterialization()) {
1580 return;
1581 }
1582
1583 LocationSummary* locations = instruction->GetLocations();
1584 Register lhs = InputRegisterAt(instruction, 0);
1585 Operand rhs = InputOperandAt(instruction, 1);
1586 Register res = RegisterFrom(locations->Out(), instruction->GetType());
1587 Condition cond = ARM64Condition(instruction->GetCondition());
1588
1589 __ Cmp(lhs, rhs);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001590 __ Cset(res, cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001591}
1592
1593#define FOR_EACH_CONDITION_INSTRUCTION(M) \
1594 M(Equal) \
1595 M(NotEqual) \
1596 M(LessThan) \
1597 M(LessThanOrEqual) \
1598 M(GreaterThan) \
1599 M(GreaterThanOrEqual)
1600#define DEFINE_CONDITION_VISITORS(Name) \
1601void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \
1602void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }
1603FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
Alexandre Rames67555f72014-11-18 10:55:16 +00001604#undef DEFINE_CONDITION_VISITORS
Alexandre Rames5319def2014-10-23 10:03:10 +01001605#undef FOR_EACH_CONDITION_INSTRUCTION
1606
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001607void LocationsBuilderARM64::VisitDiv(HDiv* div) {
1608 LocationSummary* locations =
1609 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1610 switch (div->GetResultType()) {
1611 case Primitive::kPrimInt:
1612 case Primitive::kPrimLong:
1613 locations->SetInAt(0, Location::RequiresRegister());
1614 locations->SetInAt(1, Location::RequiresRegister());
1615 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1616 break;
1617
1618 case Primitive::kPrimFloat:
1619 case Primitive::kPrimDouble:
1620 locations->SetInAt(0, Location::RequiresFpuRegister());
1621 locations->SetInAt(1, Location::RequiresFpuRegister());
1622 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1623 break;
1624
1625 default:
1626 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1627 }
1628}
1629
1630void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) {
1631 Primitive::Type type = div->GetResultType();
1632 switch (type) {
1633 case Primitive::kPrimInt:
1634 case Primitive::kPrimLong:
1635 __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1));
1636 break;
1637
1638 case Primitive::kPrimFloat:
1639 case Primitive::kPrimDouble:
1640 __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1));
1641 break;
1642
1643 default:
1644 LOG(FATAL) << "Unexpected div type " << type;
1645 }
1646}
1647
Alexandre Rames67555f72014-11-18 10:55:16 +00001648void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1649 LocationSummary* locations =
1650 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1651 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1652 if (instruction->HasUses()) {
1653 locations->SetOut(Location::SameAsFirstInput());
1654 }
1655}
1656
1657void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1658 SlowPathCodeARM64* slow_path =
1659 new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction);
1660 codegen_->AddSlowPath(slow_path);
1661 Location value = instruction->GetLocations()->InAt(0);
1662
Alexandre Rames3e69f162014-12-10 10:36:50 +00001663 Primitive::Type type = instruction->GetType();
1664
1665 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1666 LOG(FATAL) << "Unexpected type " << type << "for DivZeroCheck.";
1667 return;
1668 }
1669
Alexandre Rames67555f72014-11-18 10:55:16 +00001670 if (value.IsConstant()) {
1671 int64_t divisor = Int64ConstantFrom(value);
1672 if (divisor == 0) {
1673 __ B(slow_path->GetEntryLabel());
1674 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001675 // A division by a non-null constant is valid. We don't need to perform
1676 // any check, so simply fall through.
Alexandre Rames67555f72014-11-18 10:55:16 +00001677 }
1678 } else {
1679 __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel());
1680 }
1681}
1682
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001683void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1684 LocationSummary* locations =
1685 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1686 locations->SetOut(Location::ConstantLocation(constant));
1687}
1688
1689void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1690 UNUSED(constant);
1691 // Will be generated at use site.
1692}
1693
Alexandre Rames5319def2014-10-23 10:03:10 +01001694void LocationsBuilderARM64::VisitExit(HExit* exit) {
1695 exit->SetLocations(nullptr);
1696}
1697
1698void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001699 UNUSED(exit);
Alexandre Rames5319def2014-10-23 10:03:10 +01001700}
1701
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001702void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) {
1703 LocationSummary* locations =
1704 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1705 locations->SetOut(Location::ConstantLocation(constant));
1706}
1707
1708void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) {
1709 UNUSED(constant);
1710 // Will be generated at use site.
1711}
1712
Alexandre Rames5319def2014-10-23 10:03:10 +01001713void LocationsBuilderARM64::VisitGoto(HGoto* got) {
1714 got->SetLocations(nullptr);
1715}
1716
1717void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
1718 HBasicBlock* successor = got->GetSuccessor();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001719 DCHECK(!successor->IsExitBlock());
1720 HBasicBlock* block = got->GetBlock();
1721 HInstruction* previous = got->GetPrevious();
1722 HLoopInformation* info = block->GetLoopInformation();
1723
David Brazdil46e2a392015-03-16 17:31:52 +00001724 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001725 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1726 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1727 return;
1728 }
1729 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1730 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1731 }
1732 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001733 __ B(codegen_->GetLabelOf(successor));
1734 }
1735}
1736
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001737void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction,
1738 vixl::Label* true_target,
1739 vixl::Label* false_target,
1740 vixl::Label* always_true_target) {
1741 HInstruction* cond = instruction->InputAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001742 HCondition* condition = cond->AsCondition();
Alexandre Rames5319def2014-10-23 10:03:10 +01001743
Serban Constantinescu02164b32014-11-13 14:05:07 +00001744 if (cond->IsIntConstant()) {
1745 int32_t cond_value = cond->AsIntConstant()->GetValue();
1746 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001747 if (always_true_target != nullptr) {
1748 __ B(always_true_target);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001749 }
1750 return;
1751 } else {
1752 DCHECK_EQ(cond_value, 0);
1753 }
1754 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001755 // The condition instruction has been materialized, compare the output to 0.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001756 Location cond_val = instruction->GetLocations()->InAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001757 DCHECK(cond_val.IsRegister());
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001758 __ Cbnz(InputRegisterAt(instruction, 0), true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001759 } else {
1760 // The condition instruction has not been materialized, use its inputs as
1761 // the comparison and its condition as the branch condition.
1762 Register lhs = InputRegisterAt(condition, 0);
1763 Operand rhs = InputOperandAt(condition, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001764 Condition arm64_cond = ARM64Condition(condition->GetCondition());
Alexandre Rames4388dcc2015-02-03 10:28:33 +00001765 if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
1766 switch (arm64_cond) {
1767 case eq:
1768 __ Cbz(lhs, true_target);
1769 break;
1770 case ne:
1771 __ Cbnz(lhs, true_target);
1772 break;
1773 case lt:
1774 // Test the sign bit and branch accordingly.
1775 __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1776 break;
1777 case ge:
1778 // Test the sign bit and branch accordingly.
1779 __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1780 break;
1781 default:
1782 // Without the `static_cast` the compiler throws an error for
1783 // `-Werror=sign-promo`.
1784 LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001785 }
1786 } else {
1787 __ Cmp(lhs, rhs);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001788 __ B(arm64_cond, true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001789 }
1790 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001791 if (false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001792 __ B(false_target);
1793 }
1794}
1795
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001796void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
1797 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1798 HInstruction* cond = if_instr->InputAt(0);
1799 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1800 locations->SetInAt(0, Location::RequiresRegister());
1801 }
1802}
1803
1804void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
1805 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1806 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1807 vixl::Label* always_true_target = true_target;
1808 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1809 if_instr->IfTrueSuccessor())) {
1810 always_true_target = nullptr;
1811 }
1812 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1813 if_instr->IfFalseSuccessor())) {
1814 false_target = nullptr;
1815 }
1816 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1817}
1818
1819void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1820 LocationSummary* locations = new (GetGraph()->GetArena())
1821 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1822 HInstruction* cond = deoptimize->InputAt(0);
1823 DCHECK(cond->IsCondition());
1824 if (cond->AsCondition()->NeedsMaterialization()) {
1825 locations->SetInAt(0, Location::RequiresRegister());
1826 }
1827}
1828
1829void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1830 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
1831 DeoptimizationSlowPathARM64(deoptimize);
1832 codegen_->AddSlowPath(slow_path);
1833 vixl::Label* slow_path_entry = slow_path->GetEntryLabel();
1834 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1835}
1836
Alexandre Rames5319def2014-10-23 10:03:10 +01001837void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001838 HandleFieldGet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001839}
1840
1841void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001842 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01001843}
1844
1845void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001846 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001847}
1848
1849void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001850 HandleFieldSet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01001851}
1852
Alexandre Rames67555f72014-11-18 10:55:16 +00001853void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
1854 LocationSummary::CallKind call_kind =
1855 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
1856 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1857 locations->SetInAt(0, Location::RequiresRegister());
1858 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001859 // The output does overlap inputs.
1860 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexandre Rames67555f72014-11-18 10:55:16 +00001861}
1862
1863void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
1864 LocationSummary* locations = instruction->GetLocations();
1865 Register obj = InputRegisterAt(instruction, 0);;
1866 Register cls = InputRegisterAt(instruction, 1);;
1867 Register out = OutputRegister(instruction);
1868
1869 vixl::Label done;
1870
1871 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01001872 // Avoid null check if we know `obj` is not null.
1873 if (instruction->MustDoNullCheck()) {
1874 __ Mov(out, 0);
1875 __ Cbz(obj, &done);
1876 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001877
1878 // Compare the class of `obj` with `cls`.
Serban Constantinescu02164b32014-11-13 14:05:07 +00001879 __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset()));
Alexandre Rames67555f72014-11-18 10:55:16 +00001880 __ Cmp(out, cls);
1881 if (instruction->IsClassFinal()) {
1882 // Classes must be equal for the instanceof to succeed.
1883 __ Cset(out, eq);
1884 } else {
1885 // If the classes are not equal, we go into a slow path.
1886 DCHECK(locations->OnlyCallsOnSlowPath());
1887 SlowPathCodeARM64* slow_path =
Alexandre Rames3e69f162014-12-10 10:36:50 +00001888 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1889 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001890 codegen_->AddSlowPath(slow_path);
1891 __ B(ne, slow_path->GetEntryLabel());
1892 __ Mov(out, 1);
1893 __ Bind(slow_path->GetExitLabel());
1894 }
1895
1896 __ Bind(&done);
1897}
1898
Alexandre Rames5319def2014-10-23 10:03:10 +01001899void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
1900 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1901 locations->SetOut(Location::ConstantLocation(constant));
1902}
1903
1904void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
1905 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001906 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01001907}
1908
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001909void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
1910 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1911 locations->SetOut(Location::ConstantLocation(constant));
1912}
1913
1914void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) {
1915 // Will be generated at use site.
1916 UNUSED(constant);
1917}
1918
Alexandre Rames5319def2014-10-23 10:03:10 +01001919void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
1920 LocationSummary* locations =
1921 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
1922 locations->AddTemp(LocationFrom(x0));
1923
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001924 InvokeDexCallingConventionVisitorARM64 calling_convention_visitor;
Roland Levillain3e3d7332015-04-28 11:00:54 +01001925 for (size_t i = 0; i < invoke->GetNumberOfArguments(); i++) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001926 HInstruction* input = invoke->InputAt(i);
1927 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1928 }
1929
1930 Primitive::Type return_type = invoke->GetType();
1931 if (return_type != Primitive::kPrimVoid) {
1932 locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type));
1933 }
1934}
1935
Alexandre Rames67555f72014-11-18 10:55:16 +00001936void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1937 HandleInvoke(invoke);
1938}
1939
1940void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1941 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07001942 Register temp = XRegisterFrom(invoke->GetLocations()->GetTemp(0));
1943 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1944 invoke->GetImtIndex() % mirror::Class::kImtSize, kArm64PointerSize).Uint32Value();
Alexandre Rames67555f72014-11-18 10:55:16 +00001945 Location receiver = invoke->GetLocations()->InAt(0);
1946 Offset class_offset = mirror::Object::ClassOffset();
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07001947 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00001948
1949 // The register ip1 is required to be used for the hidden argument in
1950 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
Alexandre Ramesd921d642015-04-16 15:07:16 +01001951 MacroAssembler* masm = GetVIXLAssembler();
1952 UseScratchRegisterScope scratch_scope(masm);
1953 BlockPoolsScope block_pools(masm);
Alexandre Rames67555f72014-11-18 10:55:16 +00001954 scratch_scope.Exclude(ip1);
1955 __ Mov(ip1, invoke->GetDexMethodIndex());
1956
1957 // temp = object->GetClass();
1958 if (receiver.IsStackSlot()) {
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07001959 __ Ldr(temp.W(), StackOperandFrom(receiver));
1960 __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset));
Alexandre Rames67555f72014-11-18 10:55:16 +00001961 } else {
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07001962 __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset));
Alexandre Rames67555f72014-11-18 10:55:16 +00001963 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001964 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames67555f72014-11-18 10:55:16 +00001965 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07001966 __ Ldr(temp, MemOperand(temp, method_offset));
Alexandre Rames67555f72014-11-18 10:55:16 +00001967 // lr = temp->GetEntryPoint();
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07001968 __ Ldr(lr, MemOperand(temp, entry_point.Int32Value()));
Alexandre Rames67555f72014-11-18 10:55:16 +00001969 // lr();
1970 __ Blr(lr);
1971 DCHECK(!codegen_->IsLeafMethod());
1972 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1973}
1974
1975void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001976 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1977 if (intrinsic.TryDispatch(invoke)) {
1978 return;
1979 }
1980
Alexandre Rames67555f72014-11-18 10:55:16 +00001981 HandleInvoke(invoke);
1982}
1983
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001984void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001985 // When we do not run baseline, explicit clinit checks triggered by static
1986 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1987 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001988
Andreas Gampe878d58c2015-01-15 23:24:00 -08001989 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1990 if (intrinsic.TryDispatch(invoke)) {
1991 return;
1992 }
1993
Alexandre Rames67555f72014-11-18 10:55:16 +00001994 HandleInvoke(invoke);
1995}
1996
Andreas Gampe878d58c2015-01-15 23:24:00 -08001997static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
1998 if (invoke->GetLocations()->Intrinsified()) {
1999 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
2000 intrinsic.Dispatch(invoke);
2001 return true;
2002 }
2003 return false;
2004}
2005
2006void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
2007 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
2008 DCHECK(temp.Is(kArtMethodRegister));
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002009 size_t index_in_cache = GetCachePointerOffset(invoke->GetDexMethodIndex());
Alexandre Rames5319def2014-10-23 10:03:10 +01002010
2011 // TODO: Implement all kinds of calls:
2012 // 1) boot -> boot
2013 // 2) app -> boot
2014 // 3) app -> app
2015 //
2016 // Currently we implement the app -> app logic, which looks up in the resolve cache.
2017
Jeff Hao848f70a2014-01-15 13:49:50 -08002018 if (invoke->IsStringInit()) {
2019 // temp = thread->string_init_entrypoint
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002020 __ Ldr(temp.X(), MemOperand(tr, invoke->GetStringInitOffset()));
Jeff Hao848f70a2014-01-15 13:49:50 -08002021 // LR = temp->entry_point_from_quick_compiled_code_;
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002022 __ Ldr(lr, MemOperand(
2023 temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize).Int32Value()));
Jeff Hao848f70a2014-01-15 13:49:50 -08002024 // lr()
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002025 __ Blr(lr);
2026 } else {
Jeff Hao848f70a2014-01-15 13:49:50 -08002027 // temp = method;
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002028 LoadCurrentMethod(temp.X());
Jeff Hao848f70a2014-01-15 13:49:50 -08002029 if (!invoke->IsRecursive()) {
2030 // temp = temp->dex_cache_resolved_methods_;
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002031 __ Ldr(temp.W(), MemOperand(temp.X(),
2032 ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()));
Jeff Hao848f70a2014-01-15 13:49:50 -08002033 // temp = temp[index_in_cache];
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002034 __ Ldr(temp.X(), MemOperand(temp, index_in_cache));
Jeff Hao848f70a2014-01-15 13:49:50 -08002035 // lr = temp->entry_point_from_quick_compiled_code_;
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002036 __ Ldr(lr, MemOperand(temp.X(), ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2037 kArm64WordSize).Int32Value()));
Jeff Hao848f70a2014-01-15 13:49:50 -08002038 // lr();
2039 __ Blr(lr);
2040 } else {
2041 __ Bl(&frame_entry_label_);
2042 }
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002043 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002044
Andreas Gampe878d58c2015-01-15 23:24:00 -08002045 DCHECK(!IsLeafMethod());
2046}
2047
2048void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01002049 // When we do not run baseline, explicit clinit checks triggered by static
2050 // invokes must have been pruned by art::PrepareForRegisterAllocation.
2051 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01002052
Andreas Gampe878d58c2015-01-15 23:24:00 -08002053 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2054 return;
2055 }
2056
Alexandre Ramesd921d642015-04-16 15:07:16 +01002057 BlockPoolsScope block_pools(GetVIXLAssembler());
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002058 Register temp = XRegisterFrom(invoke->GetLocations()->GetTemp(0));
Andreas Gampe878d58c2015-01-15 23:24:00 -08002059 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00002060 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01002061}
2062
2063void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08002064 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2065 return;
2066 }
2067
Alexandre Rames5319def2014-10-23 10:03:10 +01002068 LocationSummary* locations = invoke->GetLocations();
2069 Location receiver = locations->InAt(0);
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002070 Register temp = XRegisterFrom(invoke->GetLocations()->GetTemp(0));
2071 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
2072 invoke->GetVTableIndex(), kArm64PointerSize).SizeValue();
Alexandre Rames5319def2014-10-23 10:03:10 +01002073 Offset class_offset = mirror::Object::ClassOffset();
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002074 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames5319def2014-10-23 10:03:10 +01002075
Alexandre Ramesd921d642015-04-16 15:07:16 +01002076 BlockPoolsScope block_pools(GetVIXLAssembler());
2077
Alexandre Rames5319def2014-10-23 10:03:10 +01002078 // temp = object->GetClass();
2079 if (receiver.IsStackSlot()) {
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002080 __ Ldr(temp.W(), MemOperand(sp, receiver.GetStackIndex()));
2081 __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002082 } else {
2083 DCHECK(receiver.IsRegister());
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002084 __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002085 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002086 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames5319def2014-10-23 10:03:10 +01002087 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002088 __ Ldr(temp, MemOperand(temp, method_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002089 // lr = temp->GetEntryPoint();
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002090 __ Ldr(lr, MemOperand(temp, entry_point.SizeValue()));
Alexandre Rames5319def2014-10-23 10:03:10 +01002091 // lr();
2092 __ Blr(lr);
2093 DCHECK(!codegen_->IsLeafMethod());
2094 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2095}
2096
Alexandre Rames67555f72014-11-18 10:55:16 +00002097void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
2098 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2099 : LocationSummary::kNoCall;
2100 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2101 locations->SetOut(Location::RequiresRegister());
2102}
2103
2104void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
2105 Register out = OutputRegister(cls);
2106 if (cls->IsReferrersClass()) {
2107 DCHECK(!cls->CanCallRuntime());
2108 DCHECK(!cls->MustGenerateClinitCheck());
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002109 codegen_->LoadCurrentMethod(out.X());
2110 __ Ldr(out, MemOperand(out.X(), ArtMethod::DeclaringClassOffset().Int32Value()));
Alexandre Rames67555f72014-11-18 10:55:16 +00002111 } else {
2112 DCHECK(cls->CanCallRuntime());
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002113 codegen_->LoadCurrentMethod(out.X());
2114 __ Ldr(out, MemOperand(out.X(), ArtMethod::DexCacheResolvedTypesOffset().Int32Value()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002115 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002116
2117 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2118 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2119 codegen_->AddSlowPath(slow_path);
2120 __ Cbz(out, slow_path->GetEntryLabel());
2121 if (cls->MustGenerateClinitCheck()) {
2122 GenerateClassInitializationCheck(slow_path, out);
2123 } else {
2124 __ Bind(slow_path->GetExitLabel());
2125 }
2126 }
2127}
2128
2129void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
2130 LocationSummary* locations =
2131 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2132 locations->SetOut(Location::RequiresRegister());
2133}
2134
2135void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
2136 MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value());
2137 __ Ldr(OutputRegister(instruction), exception);
2138 __ Str(wzr, exception);
2139}
2140
Alexandre Rames5319def2014-10-23 10:03:10 +01002141void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
2142 load->SetLocations(nullptr);
2143}
2144
2145void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
2146 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002147 UNUSED(load);
Alexandre Rames5319def2014-10-23 10:03:10 +01002148}
2149
Alexandre Rames67555f72014-11-18 10:55:16 +00002150void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
2151 LocationSummary* locations =
2152 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2153 locations->SetOut(Location::RequiresRegister());
2154}
2155
2156void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
2157 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load);
2158 codegen_->AddSlowPath(slow_path);
2159
2160 Register out = OutputRegister(load);
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002161 codegen_->LoadCurrentMethod(out.X());
2162 __ Ldr(out, MemOperand(out.X(), ArtMethod::DeclaringClassOffset().Int32Value()));
Mathieu Chartiereace4582014-11-24 18:29:54 -08002163 __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002164 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002165 __ Cbz(out, slow_path->GetEntryLabel());
2166 __ Bind(slow_path->GetExitLabel());
2167}
2168
Alexandre Rames5319def2014-10-23 10:03:10 +01002169void LocationsBuilderARM64::VisitLocal(HLocal* local) {
2170 local->SetLocations(nullptr);
2171}
2172
2173void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
2174 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2175}
2176
2177void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
2178 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2179 locations->SetOut(Location::ConstantLocation(constant));
2180}
2181
2182void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
2183 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002184 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002185}
2186
Alexandre Rames67555f72014-11-18 10:55:16 +00002187void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2188 LocationSummary* locations =
2189 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2190 InvokeRuntimeCallingConvention calling_convention;
2191 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2192}
2193
2194void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2195 codegen_->InvokeRuntime(instruction->IsEnter()
2196 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2197 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002198 instruction->GetDexPc(),
2199 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002200 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002201}
2202
Alexandre Rames42d641b2014-10-27 14:00:51 +00002203void LocationsBuilderARM64::VisitMul(HMul* mul) {
2204 LocationSummary* locations =
2205 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2206 switch (mul->GetResultType()) {
2207 case Primitive::kPrimInt:
2208 case Primitive::kPrimLong:
2209 locations->SetInAt(0, Location::RequiresRegister());
2210 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002211 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002212 break;
2213
2214 case Primitive::kPrimFloat:
2215 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002216 locations->SetInAt(0, Location::RequiresFpuRegister());
2217 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002218 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002219 break;
2220
2221 default:
2222 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2223 }
2224}
2225
2226void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
2227 switch (mul->GetResultType()) {
2228 case Primitive::kPrimInt:
2229 case Primitive::kPrimLong:
2230 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
2231 break;
2232
2233 case Primitive::kPrimFloat:
2234 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002235 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00002236 break;
2237
2238 default:
2239 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2240 }
2241}
2242
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002243void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
2244 LocationSummary* locations =
2245 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2246 switch (neg->GetResultType()) {
2247 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00002248 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002249 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00002250 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002251 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002252
2253 case Primitive::kPrimFloat:
2254 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002255 locations->SetInAt(0, Location::RequiresFpuRegister());
2256 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002257 break;
2258
2259 default:
2260 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2261 }
2262}
2263
2264void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
2265 switch (neg->GetResultType()) {
2266 case Primitive::kPrimInt:
2267 case Primitive::kPrimLong:
2268 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
2269 break;
2270
2271 case Primitive::kPrimFloat:
2272 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002273 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002274 break;
2275
2276 default:
2277 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2278 }
2279}
2280
2281void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
2282 LocationSummary* locations =
2283 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2284 InvokeRuntimeCallingConvention calling_convention;
2285 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002286 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002287 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002288 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
2289 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002290 void*, uint32_t, int32_t, ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002291}
2292
2293void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
2294 LocationSummary* locations = instruction->GetLocations();
2295 InvokeRuntimeCallingConvention calling_convention;
2296 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2297 DCHECK(type_index.Is(w0));
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002298 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimLong);
2299 DCHECK(current_method.Is(x2));
2300 codegen_->LoadCurrentMethod(current_method.X());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002301 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002302 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002303 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2304 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002305 instruction->GetDexPc(),
2306 nullptr);
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002307 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002308}
2309
Alexandre Rames5319def2014-10-23 10:03:10 +01002310void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
2311 LocationSummary* locations =
2312 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2313 InvokeRuntimeCallingConvention calling_convention;
2314 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2315 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2316 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002317 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002318}
2319
2320void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
2321 LocationSummary* locations = instruction->GetLocations();
2322 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2323 DCHECK(type_index.Is(w0));
2324 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
2325 DCHECK(current_method.Is(w1));
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002326 codegen_->LoadCurrentMethod(current_method.X());
Alexandre Rames5319def2014-10-23 10:03:10 +01002327 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002328 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002329 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2330 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002331 instruction->GetDexPc(),
2332 nullptr);
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07002333 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002334}
2335
2336void LocationsBuilderARM64::VisitNot(HNot* instruction) {
2337 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00002338 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002339 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002340}
2341
2342void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002343 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002344 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002345 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01002346 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002347 break;
2348
2349 default:
2350 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2351 }
2352}
2353
David Brazdil66d126e2015-04-03 16:02:44 +01002354void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) {
2355 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2356 locations->SetInAt(0, Location::RequiresRegister());
2357 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2358}
2359
2360void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) {
David Brazdil66d126e2015-04-03 16:02:44 +01002361 __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1));
2362}
2363
Alexandre Rames5319def2014-10-23 10:03:10 +01002364void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
2365 LocationSummary* locations =
2366 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2367 locations->SetInAt(0, Location::RequiresRegister());
2368 if (instruction->HasUses()) {
2369 locations->SetOut(Location::SameAsFirstInput());
2370 }
2371}
2372
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002373void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002374 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2375 return;
2376 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002377
Alexandre Ramesd921d642015-04-16 15:07:16 +01002378 BlockPoolsScope block_pools(GetVIXLAssembler());
2379 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002380 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
2381 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2382}
2383
2384void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002385 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
2386 codegen_->AddSlowPath(slow_path);
2387
2388 LocationSummary* locations = instruction->GetLocations();
2389 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002390
2391 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01002392}
2393
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002394void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
2395 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2396 GenerateImplicitNullCheck(instruction);
2397 } else {
2398 GenerateExplicitNullCheck(instruction);
2399 }
2400}
2401
Alexandre Rames67555f72014-11-18 10:55:16 +00002402void LocationsBuilderARM64::VisitOr(HOr* instruction) {
2403 HandleBinaryOp(instruction);
2404}
2405
2406void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
2407 HandleBinaryOp(instruction);
2408}
2409
Alexandre Rames3e69f162014-12-10 10:36:50 +00002410void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2411 LOG(FATAL) << "Unreachable";
2412}
2413
2414void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
2415 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2416}
2417
Alexandre Rames5319def2014-10-23 10:03:10 +01002418void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
2419 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2420 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2421 if (location.IsStackSlot()) {
2422 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2423 } else if (location.IsDoubleStackSlot()) {
2424 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2425 }
2426 locations->SetOut(location);
2427}
2428
2429void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) {
2430 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002431 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002432}
2433
2434void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
2435 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2436 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2437 locations->SetInAt(i, Location::Any());
2438 }
2439 locations->SetOut(Location::Any());
2440}
2441
2442void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002443 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002444 LOG(FATAL) << "Unreachable";
2445}
2446
Serban Constantinescu02164b32014-11-13 14:05:07 +00002447void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002448 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00002449 LocationSummary::CallKind call_kind =
2450 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002451 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2452
2453 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002454 case Primitive::kPrimInt:
2455 case Primitive::kPrimLong:
2456 locations->SetInAt(0, Location::RequiresRegister());
2457 locations->SetInAt(1, Location::RequiresRegister());
2458 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2459 break;
2460
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002461 case Primitive::kPrimFloat:
2462 case Primitive::kPrimDouble: {
2463 InvokeRuntimeCallingConvention calling_convention;
2464 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
2465 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
2466 locations->SetOut(calling_convention.GetReturnLocation(type));
2467
2468 break;
2469 }
2470
Serban Constantinescu02164b32014-11-13 14:05:07 +00002471 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002472 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00002473 }
2474}
2475
2476void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
2477 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002478
Serban Constantinescu02164b32014-11-13 14:05:07 +00002479 switch (type) {
2480 case Primitive::kPrimInt:
2481 case Primitive::kPrimLong: {
2482 UseScratchRegisterScope temps(GetVIXLAssembler());
2483 Register dividend = InputRegisterAt(rem, 0);
2484 Register divisor = InputRegisterAt(rem, 1);
2485 Register output = OutputRegister(rem);
2486 Register temp = temps.AcquireSameSizeAs(output);
2487
2488 __ Sdiv(temp, dividend, divisor);
2489 __ Msub(output, temp, divisor, dividend);
2490 break;
2491 }
2492
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002493 case Primitive::kPrimFloat:
2494 case Primitive::kPrimDouble: {
2495 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2496 : QUICK_ENTRY_POINT(pFmod);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002497 codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002498 break;
2499 }
2500
Serban Constantinescu02164b32014-11-13 14:05:07 +00002501 default:
2502 LOG(FATAL) << "Unexpected rem type " << type;
2503 }
2504}
2505
Calin Juravle27df7582015-04-17 19:12:31 +01002506void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
2507 memory_barrier->SetLocations(nullptr);
2508}
2509
2510void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
2511 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
2512}
2513
Alexandre Rames5319def2014-10-23 10:03:10 +01002514void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
2515 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2516 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002517 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01002518}
2519
2520void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002521 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002522 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002523}
2524
2525void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
2526 instruction->SetLocations(nullptr);
2527}
2528
2529void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002530 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002531 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002532}
2533
Serban Constantinescu02164b32014-11-13 14:05:07 +00002534void LocationsBuilderARM64::VisitShl(HShl* shl) {
2535 HandleShift(shl);
2536}
2537
2538void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
2539 HandleShift(shl);
2540}
2541
2542void LocationsBuilderARM64::VisitShr(HShr* shr) {
2543 HandleShift(shr);
2544}
2545
2546void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
2547 HandleShift(shr);
2548}
2549
Alexandre Rames5319def2014-10-23 10:03:10 +01002550void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
2551 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2552 Primitive::Type field_type = store->InputAt(1)->GetType();
2553 switch (field_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002554 case Primitive::kPrimNot:
Alexandre Rames5319def2014-10-23 10:03:10 +01002555 case Primitive::kPrimBoolean:
2556 case Primitive::kPrimByte:
2557 case Primitive::kPrimChar:
2558 case Primitive::kPrimShort:
2559 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002560 case Primitive::kPrimFloat:
Alexandre Rames5319def2014-10-23 10:03:10 +01002561 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2562 break;
2563
2564 case Primitive::kPrimLong:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002565 case Primitive::kPrimDouble:
Alexandre Rames5319def2014-10-23 10:03:10 +01002566 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2567 break;
2568
2569 default:
2570 LOG(FATAL) << "Unimplemented local type " << field_type;
2571 }
2572}
2573
2574void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002575 UNUSED(store);
Alexandre Rames5319def2014-10-23 10:03:10 +01002576}
2577
2578void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002579 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002580}
2581
2582void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002583 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002584}
2585
Alexandre Rames67555f72014-11-18 10:55:16 +00002586void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002587 HandleFieldGet(instruction);
Alexandre Rames67555f72014-11-18 10:55:16 +00002588}
2589
2590void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002591 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames67555f72014-11-18 10:55:16 +00002592}
2593
2594void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002595 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002596}
2597
Alexandre Rames67555f72014-11-18 10:55:16 +00002598void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002599 HandleFieldSet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01002600}
2601
2602void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
2603 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2604}
2605
2606void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002607 HBasicBlock* block = instruction->GetBlock();
2608 if (block->GetLoopInformation() != nullptr) {
2609 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2610 // The back edge will generate the suspend check.
2611 return;
2612 }
2613 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2614 // The goto will generate the suspend check.
2615 return;
2616 }
2617 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01002618}
2619
2620void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
2621 temp->SetLocations(nullptr);
2622}
2623
2624void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
2625 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002626 UNUSED(temp);
Alexandre Rames5319def2014-10-23 10:03:10 +01002627}
2628
Alexandre Rames67555f72014-11-18 10:55:16 +00002629void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
2630 LocationSummary* locations =
2631 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2632 InvokeRuntimeCallingConvention calling_convention;
2633 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2634}
2635
2636void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
2637 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002638 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002639 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002640}
2641
2642void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
2643 LocationSummary* locations =
2644 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
2645 Primitive::Type input_type = conversion->GetInputType();
2646 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002647 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00002648 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
2649 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
2650 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
2651 }
2652
Alexandre Rames542361f2015-01-29 16:57:31 +00002653 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002654 locations->SetInAt(0, Location::RequiresFpuRegister());
2655 } else {
2656 locations->SetInAt(0, Location::RequiresRegister());
2657 }
2658
Alexandre Rames542361f2015-01-29 16:57:31 +00002659 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002660 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2661 } else {
2662 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2663 }
2664}
2665
2666void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
2667 Primitive::Type result_type = conversion->GetResultType();
2668 Primitive::Type input_type = conversion->GetInputType();
2669
2670 DCHECK_NE(input_type, result_type);
2671
Alexandre Rames542361f2015-01-29 16:57:31 +00002672 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002673 int result_size = Primitive::ComponentSize(result_type);
2674 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002675 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002676 Register output = OutputRegister(conversion);
2677 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002678 if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) {
2679 __ Ubfx(output, source, 0, result_size * kBitsPerByte);
2680 } else if ((result_type == Primitive::kPrimChar) ||
2681 ((input_type == Primitive::kPrimChar) && (result_size > input_size))) {
2682 __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002683 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00002684 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002685 }
Alexandre Rames542361f2015-01-29 16:57:31 +00002686 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002687 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002688 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002689 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
2690 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002691 } else if (Primitive::IsFloatingPointType(result_type) &&
2692 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002693 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
2694 } else {
2695 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
2696 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00002697 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00002698}
Alexandre Rames67555f72014-11-18 10:55:16 +00002699
Serban Constantinescu02164b32014-11-13 14:05:07 +00002700void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
2701 HandleShift(ushr);
2702}
2703
2704void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
2705 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00002706}
2707
2708void LocationsBuilderARM64::VisitXor(HXor* instruction) {
2709 HandleBinaryOp(instruction);
2710}
2711
2712void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
2713 HandleBinaryOp(instruction);
2714}
2715
Calin Juravleb1498f62015-02-16 13:13:29 +00002716void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) {
2717 // Nothing to do, this should be removed during prepare for register allocator.
2718 UNUSED(instruction);
2719 LOG(FATAL) << "Unreachable";
2720}
2721
2722void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) {
2723 // Nothing to do, this should be removed during prepare for register allocator.
2724 UNUSED(instruction);
2725 LOG(FATAL) << "Unreachable";
2726}
2727
Alexandre Rames67555f72014-11-18 10:55:16 +00002728#undef __
2729#undef QUICK_ENTRY_POINT
2730
Alexandre Rames5319def2014-10-23 10:03:10 +01002731} // namespace arm64
2732} // namespace art