blob: f64e8012856413ccda0db2b62259b1bfa040fd4f [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 Chartiere401d142015-04-22 13:56:20 -070020#include "art_method.h"
Zheng Xuc6667102015-05-15 16:08:45 +080021#include "code_generator_utils.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080022#include "common_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010023#include "entrypoints/quick/quick_entrypoints.h"
Andreas Gampe1cc7dba2014-12-17 18:43:01 -080024#include "entrypoints/quick/quick_entrypoints_enum.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010025#include "gc/accounting/card_table.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080026#include "intrinsics.h"
27#include "intrinsics_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010028#include "mirror/array-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070029#include "mirror/class-inl.h"
Calin Juravlecd6dffe2015-01-08 17:35:35 +000030#include "offsets.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010031#include "thread.h"
32#include "utils/arm64/assembler_arm64.h"
33#include "utils/assembler.h"
34#include "utils/stack_checks.h"
35
36
37using namespace vixl; // NOLINT(build/namespaces)
38
39#ifdef __
40#error "ARM64 Codegen VIXL macro-assembler macro already defined."
41#endif
42
Alexandre Rames5319def2014-10-23 10:03:10 +010043namespace art {
44
45namespace arm64 {
46
Andreas Gampe878d58c2015-01-15 23:24:00 -080047using helpers::CPURegisterFrom;
48using helpers::DRegisterFrom;
49using helpers::FPRegisterFrom;
50using helpers::HeapOperand;
51using helpers::HeapOperandFrom;
52using helpers::InputCPURegisterAt;
53using helpers::InputFPRegisterAt;
54using helpers::InputRegisterAt;
55using helpers::InputOperandAt;
56using helpers::Int64ConstantFrom;
Andreas Gampe878d58c2015-01-15 23:24:00 -080057using helpers::LocationFrom;
58using helpers::OperandFromMemOperand;
59using helpers::OutputCPURegister;
60using helpers::OutputFPRegister;
61using helpers::OutputRegister;
62using helpers::RegisterFrom;
63using helpers::StackOperandFrom;
64using helpers::VIXLRegCodeFromART;
65using helpers::WRegisterFrom;
66using helpers::XRegisterFrom;
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +000067using helpers::ARM64EncodableConstantOrRegister;
Zheng Xuda403092015-04-24 17:35:39 +080068using helpers::ArtVixlRegCodeCoherentForRegSet;
Andreas Gampe878d58c2015-01-15 23:24:00 -080069
Alexandre Rames5319def2014-10-23 10:03:10 +010070static constexpr int kCurrentMethodStackOffset = 0;
71
Alexandre Rames5319def2014-10-23 10:03:10 +010072inline Condition ARM64Condition(IfCondition cond) {
73 switch (cond) {
74 case kCondEQ: return eq;
75 case kCondNE: return ne;
76 case kCondLT: return lt;
77 case kCondLE: return le;
78 case kCondGT: return gt;
79 case kCondGE: return ge;
80 default:
81 LOG(FATAL) << "Unknown if condition";
82 }
83 return nv; // Unreachable.
84}
85
Alexandre Ramesa89086e2014-11-07 17:13:25 +000086Location ARM64ReturnLocation(Primitive::Type return_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +000087 // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the
88 // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`,
89 // but we use the exact registers for clarity.
90 if (return_type == Primitive::kPrimFloat) {
91 return LocationFrom(s0);
92 } else if (return_type == Primitive::kPrimDouble) {
93 return LocationFrom(d0);
94 } else if (return_type == Primitive::kPrimLong) {
95 return LocationFrom(x0);
Nicolas Geoffray925e5622015-06-03 12:23:32 +010096 } else if (return_type == Primitive::kPrimVoid) {
97 return Location::NoLocation();
Alexandre Ramesa89086e2014-11-07 17:13:25 +000098 } else {
99 return LocationFrom(w0);
100 }
101}
102
Alexandre Rames5319def2014-10-23 10:03:10 +0100103Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000104 return ARM64ReturnLocation(return_type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100105}
106
Alexandre Rames67555f72014-11-18 10:55:16 +0000107#define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()->
108#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value()
Alexandre Rames5319def2014-10-23 10:03:10 +0100109
Zheng Xuda403092015-04-24 17:35:39 +0800110// Calculate memory accessing operand for save/restore live registers.
111static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen,
112 RegisterSet* register_set,
113 int64_t spill_offset,
114 bool is_save) {
115 DCHECK(ArtVixlRegCodeCoherentForRegSet(register_set->GetCoreRegisters(),
116 codegen->GetNumberOfCoreRegisters(),
117 register_set->GetFloatingPointRegisters(),
118 codegen->GetNumberOfFloatingPointRegisters()));
119
120 CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize,
121 register_set->GetCoreRegisters() & (~callee_saved_core_registers.list()));
122 CPURegList fp_list = CPURegList(CPURegister::kFPRegister, kDRegSize,
123 register_set->GetFloatingPointRegisters() & (~callee_saved_fp_registers.list()));
124
125 MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler();
126 UseScratchRegisterScope temps(masm);
127
128 Register base = masm->StackPointer();
129 int64_t core_spill_size = core_list.TotalSizeInBytes();
130 int64_t fp_spill_size = fp_list.TotalSizeInBytes();
131 int64_t reg_size = kXRegSizeInBytes;
132 int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size;
133 uint32_t ls_access_size = WhichPowerOf2(reg_size);
134 if (((core_list.Count() > 1) || (fp_list.Count() > 1)) &&
135 !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) {
136 // If the offset does not fit in the instruction's immediate field, use an alternate register
137 // to compute the base address(float point registers spill base address).
138 Register new_base = temps.AcquireSameSizeAs(base);
139 __ Add(new_base, base, Operand(spill_offset + core_spill_size));
140 base = new_base;
141 spill_offset = -core_spill_size;
142 int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size;
143 DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size));
144 DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size));
145 }
146
147 if (is_save) {
148 __ StoreCPURegList(core_list, MemOperand(base, spill_offset));
149 __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size));
150 } else {
151 __ LoadCPURegList(core_list, MemOperand(base, spill_offset));
152 __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size));
153 }
154}
155
156void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
157 RegisterSet* register_set = locations->GetLiveRegisters();
158 size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath();
159 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
160 if (!codegen->IsCoreCalleeSaveRegister(i) && register_set->ContainsCoreRegister(i)) {
161 // If the register holds an object, update the stack mask.
162 if (locations->RegisterContainsObject(i)) {
163 locations->SetStackBit(stack_offset / kVRegSize);
164 }
165 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
166 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
167 saved_core_stack_offsets_[i] = stack_offset;
168 stack_offset += kXRegSizeInBytes;
169 }
170 }
171
172 for (size_t i = 0, e = codegen->GetNumberOfFloatingPointRegisters(); i < e; ++i) {
173 if (!codegen->IsFloatingPointCalleeSaveRegister(i) &&
174 register_set->ContainsFloatingPointRegister(i)) {
175 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
176 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
177 saved_fpu_stack_offsets_[i] = stack_offset;
178 stack_offset += kDRegSizeInBytes;
179 }
180 }
181
182 SaveRestoreLiveRegistersHelper(codegen, register_set,
183 codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */);
184}
185
186void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
187 RegisterSet* register_set = locations->GetLiveRegisters();
188 SaveRestoreLiveRegistersHelper(codegen, register_set,
189 codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */);
190}
191
Alexandre Rames5319def2014-10-23 10:03:10 +0100192class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 {
193 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000194 BoundsCheckSlowPathARM64(HBoundsCheck* instruction,
195 Location index_location,
196 Location length_location)
197 : instruction_(instruction),
198 index_location_(index_location),
199 length_location_(length_location) {}
200
Alexandre Rames5319def2014-10-23 10:03:10 +0100201
Alexandre Rames67555f72014-11-18 10:55:16 +0000202 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000203 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100204 __ Bind(GetEntryLabel());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000205 // We're moving two locations to locations that could overlap, so we need a parallel
206 // move resolver.
207 InvokeRuntimeCallingConvention calling_convention;
208 codegen->EmitParallelMoves(
Nicolas Geoffray90218252015-04-15 11:56:51 +0100209 index_location_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt,
210 length_location_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000211 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000212 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800213 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100214 }
215
Alexandre Rames9931f312015-06-19 14:47:01 +0100216 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; }
217
Alexandre Rames5319def2014-10-23 10:03:10 +0100218 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000219 HBoundsCheck* const instruction_;
220 const Location index_location_;
221 const Location length_location_;
222
Alexandre Rames5319def2014-10-23 10:03:10 +0100223 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64);
224};
225
Alexandre Rames67555f72014-11-18 10:55:16 +0000226class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 {
227 public:
228 explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : instruction_(instruction) {}
229
230 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
231 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
232 __ Bind(GetEntryLabel());
233 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000234 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800235 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000236 }
237
Alexandre Rames9931f312015-06-19 14:47:01 +0100238 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; }
239
Alexandre Rames67555f72014-11-18 10:55:16 +0000240 private:
241 HDivZeroCheck* const instruction_;
242 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64);
243};
244
245class LoadClassSlowPathARM64 : public SlowPathCodeARM64 {
246 public:
247 LoadClassSlowPathARM64(HLoadClass* cls,
248 HInstruction* at,
249 uint32_t dex_pc,
250 bool do_clinit)
251 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
252 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
253 }
254
255 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
256 LocationSummary* locations = at_->GetLocations();
257 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
258
259 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000260 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000261
262 InvokeRuntimeCallingConvention calling_convention;
263 __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +0000264 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
265 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000266 arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800267 if (do_clinit_) {
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100268 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800269 } else {
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100270 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800271 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000272
273 // Move the class to the desired location.
274 Location out = locations->Out();
275 if (out.IsValid()) {
276 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
277 Primitive::Type type = at_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000278 arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000279 }
280
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000281 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000282 __ B(GetExitLabel());
283 }
284
Alexandre Rames9931f312015-06-19 14:47:01 +0100285 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; }
286
Alexandre Rames67555f72014-11-18 10:55:16 +0000287 private:
288 // The class this slow path will load.
289 HLoadClass* const cls_;
290
291 // The instruction where this slow path is happening.
292 // (Might be the load class or an initialization check).
293 HInstruction* const at_;
294
295 // The dex PC of `at_`.
296 const uint32_t dex_pc_;
297
298 // Whether to initialize the class.
299 const bool do_clinit_;
300
301 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64);
302};
303
304class LoadStringSlowPathARM64 : public SlowPathCodeARM64 {
305 public:
306 explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {}
307
308 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
309 LocationSummary* locations = instruction_->GetLocations();
310 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
311 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
312
313 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000314 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000315
316 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800317 __ Mov(calling_convention.GetRegisterAt(0).W(), instruction_->GetStringIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +0000318 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000319 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100320 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000321 Primitive::Type type = instruction_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000322 arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000323
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000324 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000325 __ B(GetExitLabel());
326 }
327
Alexandre Rames9931f312015-06-19 14:47:01 +0100328 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; }
329
Alexandre Rames67555f72014-11-18 10:55:16 +0000330 private:
331 HLoadString* const instruction_;
332
333 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64);
334};
335
Alexandre Rames5319def2014-10-23 10:03:10 +0100336class NullCheckSlowPathARM64 : public SlowPathCodeARM64 {
337 public:
338 explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {}
339
Alexandre Rames67555f72014-11-18 10:55:16 +0000340 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
341 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100342 __ Bind(GetEntryLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000343 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000344 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800345 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100346 }
347
Alexandre Rames9931f312015-06-19 14:47:01 +0100348 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; }
349
Alexandre Rames5319def2014-10-23 10:03:10 +0100350 private:
351 HNullCheck* const instruction_;
352
353 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64);
354};
355
356class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 {
357 public:
358 explicit SuspendCheckSlowPathARM64(HSuspendCheck* instruction,
359 HBasicBlock* successor)
360 : instruction_(instruction), successor_(successor) {}
361
Alexandre Rames67555f72014-11-18 10:55:16 +0000362 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
363 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100364 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000365 SaveLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000366 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000367 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800368 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000369 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000370 if (successor_ == nullptr) {
371 __ B(GetReturnLabel());
372 } else {
373 __ B(arm64_codegen->GetLabelOf(successor_));
374 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100375 }
376
377 vixl::Label* GetReturnLabel() {
378 DCHECK(successor_ == nullptr);
379 return &return_label_;
380 }
381
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100382 HBasicBlock* GetSuccessor() const {
383 return successor_;
384 }
385
Alexandre Rames9931f312015-06-19 14:47:01 +0100386 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; }
387
Alexandre Rames5319def2014-10-23 10:03:10 +0100388 private:
389 HSuspendCheck* const instruction_;
390 // If not null, the block to branch to after the suspend check.
391 HBasicBlock* const successor_;
392
393 // If `successor_` is null, the label to branch to after the suspend check.
394 vixl::Label return_label_;
395
396 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64);
397};
398
Alexandre Rames67555f72014-11-18 10:55:16 +0000399class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 {
400 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000401 TypeCheckSlowPathARM64(HInstruction* instruction,
402 Location class_to_check,
403 Location object_class,
404 uint32_t dex_pc)
405 : instruction_(instruction),
406 class_to_check_(class_to_check),
407 object_class_(object_class),
408 dex_pc_(dex_pc) {}
Alexandre Rames67555f72014-11-18 10:55:16 +0000409
410 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000411 LocationSummary* locations = instruction_->GetLocations();
412 DCHECK(instruction_->IsCheckCast()
413 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
414 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
415
Alexandre Rames67555f72014-11-18 10:55:16 +0000416 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000417 SaveLiveRegisters(codegen, locations);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000418
419 // We're moving two locations to locations that could overlap, so we need a parallel
420 // move resolver.
421 InvokeRuntimeCallingConvention calling_convention;
422 codegen->EmitParallelMoves(
Nicolas Geoffray90218252015-04-15 11:56:51 +0100423 class_to_check_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot,
424 object_class_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000425
426 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000427 arm64_codegen->InvokeRuntime(
428 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000429 Primitive::Type ret_type = instruction_->GetType();
430 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
431 arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800432 CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t,
433 const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000434 } else {
435 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000436 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800437 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000438 }
439
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000440 RestoreLiveRegisters(codegen, locations);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000441 __ B(GetExitLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000442 }
443
Alexandre Rames9931f312015-06-19 14:47:01 +0100444 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; }
445
Alexandre Rames67555f72014-11-18 10:55:16 +0000446 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000447 HInstruction* const instruction_;
448 const Location class_to_check_;
449 const Location object_class_;
450 uint32_t dex_pc_;
451
Alexandre Rames67555f72014-11-18 10:55:16 +0000452 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64);
453};
454
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700455class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 {
456 public:
457 explicit DeoptimizationSlowPathARM64(HInstruction* instruction)
458 : instruction_(instruction) {}
459
460 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
461 __ Bind(GetEntryLabel());
462 SaveLiveRegisters(codegen, instruction_->GetLocations());
463 DCHECK(instruction_->IsDeoptimize());
464 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
465 uint32_t dex_pc = deoptimize->GetDexPc();
466 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
467 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
468 }
469
Alexandre Rames9931f312015-06-19 14:47:01 +0100470 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; }
471
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700472 private:
473 HInstruction* const instruction_;
474 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64);
475};
476
Alexandre Rames5319def2014-10-23 10:03:10 +0100477#undef __
478
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100479Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) {
Alexandre Rames5319def2014-10-23 10:03:10 +0100480 Location next_location;
481 if (type == Primitive::kPrimVoid) {
482 LOG(FATAL) << "Unreachable type " << type;
483 }
484
Alexandre Rames542361f2015-01-29 16:57:31 +0000485 if (Primitive::IsFloatingPointType(type) &&
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100486 (float_index_ < calling_convention.GetNumberOfFpuRegisters())) {
487 next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++));
Alexandre Rames542361f2015-01-29 16:57:31 +0000488 } else if (!Primitive::IsFloatingPointType(type) &&
489 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000490 next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++));
491 } else {
492 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Alexandre Rames542361f2015-01-29 16:57:31 +0000493 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
494 : Location::StackSlot(stack_offset);
Alexandre Rames5319def2014-10-23 10:03:10 +0100495 }
496
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000497 // Space on the stack is reserved for all arguments.
Alexandre Rames542361f2015-01-29 16:57:31 +0000498 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
Alexandre Rames5319def2014-10-23 10:03:10 +0100499 return next_location;
500}
501
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100502Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const {
Nicolas Geoffray38207af2015-06-01 15:46:22 +0100503 return LocationFrom(kArtMethodRegister);
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100504}
505
Serban Constantinescu579885a2015-02-22 20:51:33 +0000506CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph,
507 const Arm64InstructionSetFeatures& isa_features,
508 const CompilerOptions& compiler_options)
Alexandre Rames5319def2014-10-23 10:03:10 +0100509 : CodeGenerator(graph,
510 kNumberOfAllocatableRegisters,
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000511 kNumberOfAllocatableFPRegisters,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000512 kNumberOfAllocatableRegisterPairs,
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000513 callee_saved_core_registers.list(),
514 callee_saved_fp_registers.list(),
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000515 compiler_options),
Alexandre Rames5319def2014-10-23 10:03:10 +0100516 block_labels_(nullptr),
517 location_builder_(graph, this),
Alexandre Rames3e69f162014-12-10 10:36:50 +0000518 instruction_visitor_(graph, this),
Serban Constantinescu579885a2015-02-22 20:51:33 +0000519 move_resolver_(graph->GetArena(), this),
520 isa_features_(isa_features) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000521 // Save the link register (containing the return address) to mimic Quick.
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000522 AddAllocatedRegister(LocationFrom(lr));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000523}
Alexandre Rames5319def2014-10-23 10:03:10 +0100524
Alexandre Rames67555f72014-11-18 10:55:16 +0000525#undef __
526#define __ GetVIXLAssembler()->
Alexandre Rames5319def2014-10-23 10:03:10 +0100527
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000528void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) {
529 // Ensure we emit the literal pool.
530 __ FinalizeCode();
531 CodeGenerator::Finalize(allocator);
532}
533
Zheng Xuad4450e2015-04-17 18:48:56 +0800534void ParallelMoveResolverARM64::PrepareForEmitNativeCode() {
535 // Note: There are 6 kinds of moves:
536 // 1. constant -> GPR/FPR (non-cycle)
537 // 2. constant -> stack (non-cycle)
538 // 3. GPR/FPR -> GPR/FPR
539 // 4. GPR/FPR -> stack
540 // 5. stack -> GPR/FPR
541 // 6. stack -> stack (non-cycle)
542 // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5
543 // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting
544 // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the
545 // dependency.
546 vixl_temps_.Open(GetVIXLAssembler());
547}
548
549void ParallelMoveResolverARM64::FinishEmitNativeCode() {
550 vixl_temps_.Close();
551}
552
553Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) {
554 DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister ||
555 kind == Location::kStackSlot || kind == Location::kDoubleStackSlot);
556 kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister;
557 Location scratch = GetScratchLocation(kind);
558 if (!scratch.Equals(Location::NoLocation())) {
559 return scratch;
560 }
561 // Allocate from VIXL temp registers.
562 if (kind == Location::kRegister) {
563 scratch = LocationFrom(vixl_temps_.AcquireX());
564 } else {
565 DCHECK(kind == Location::kFpuRegister);
566 scratch = LocationFrom(vixl_temps_.AcquireD());
567 }
568 AddScratchLocation(scratch);
569 return scratch;
570}
571
572void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) {
573 if (loc.IsRegister()) {
574 vixl_temps_.Release(XRegisterFrom(loc));
575 } else {
576 DCHECK(loc.IsFpuRegister());
577 vixl_temps_.Release(DRegisterFrom(loc));
578 }
579 RemoveScratchLocation(loc);
580}
581
Alexandre Rames3e69f162014-12-10 10:36:50 +0000582void ParallelMoveResolverARM64::EmitMove(size_t index) {
583 MoveOperands* move = moves_.Get(index);
584 codegen_->MoveLocation(move->GetDestination(), move->GetSource());
585}
586
Alexandre Rames5319def2014-10-23 10:03:10 +0100587void CodeGeneratorARM64::GenerateFrameEntry() {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100588 MacroAssembler* masm = GetVIXLAssembler();
589 BlockPoolsScope block_pools(masm);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000590 __ Bind(&frame_entry_label_);
591
Serban Constantinescu02164b32014-11-13 14:05:07 +0000592 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod();
593 if (do_overflow_check) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100594 UseScratchRegisterScope temps(masm);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000595 Register temp = temps.AcquireX();
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000596 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000597 __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64)));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000598 __ Ldr(wzr, MemOperand(temp, 0));
599 RecordPcInfo(nullptr, 0);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000600 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100601
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000602 if (!HasEmptyFrame()) {
603 int frame_size = GetFrameSize();
604 // Stack layout:
605 // sp[frame_size - 8] : lr.
606 // ... : other preserved core registers.
607 // ... : other preserved fp registers.
608 // ... : reserved frame space.
609 // sp[0] : current method.
610 __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100611 GetAssembler()->cfi().AdjustCFAOffset(frame_size);
Zheng Xu69a50302015-04-14 20:04:41 +0800612 GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(),
613 frame_size - GetCoreSpillSize());
614 GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(),
615 frame_size - FrameEntrySpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000616 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100617}
618
619void CodeGeneratorARM64::GenerateFrameExit() {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100620 BlockPoolsScope block_pools(GetVIXLAssembler());
David Srbeckyc34dc932015-04-12 09:27:43 +0100621 GetAssembler()->cfi().RememberState();
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000622 if (!HasEmptyFrame()) {
623 int frame_size = GetFrameSize();
Zheng Xu69a50302015-04-14 20:04:41 +0800624 GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(),
625 frame_size - FrameEntrySpillSize());
626 GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(),
627 frame_size - GetCoreSpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000628 __ Drop(frame_size);
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100629 GetAssembler()->cfi().AdjustCFAOffset(-frame_size);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000630 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100631 __ Ret();
632 GetAssembler()->cfi().RestoreState();
633 GetAssembler()->cfi().DefCFAOffset(GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +0100634}
635
Zheng Xuda403092015-04-24 17:35:39 +0800636vixl::CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const {
637 DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0));
638 return vixl::CPURegList(vixl::CPURegister::kRegister, vixl::kXRegSize,
639 core_spill_mask_);
640}
641
642vixl::CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const {
643 DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_,
644 GetNumberOfFloatingPointRegisters()));
645 return vixl::CPURegList(vixl::CPURegister::kFPRegister, vixl::kDRegSize,
646 fpu_spill_mask_);
647}
648
Alexandre Rames5319def2014-10-23 10:03:10 +0100649void CodeGeneratorARM64::Bind(HBasicBlock* block) {
650 __ Bind(GetLabelOf(block));
651}
652
Alexandre Rames5319def2014-10-23 10:03:10 +0100653void CodeGeneratorARM64::Move(HInstruction* instruction,
654 Location location,
655 HInstruction* move_for) {
656 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames5319def2014-10-23 10:03:10 +0100657 Primitive::Type type = instruction->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000658 DCHECK_NE(type, Primitive::kPrimVoid);
Alexandre Rames5319def2014-10-23 10:03:10 +0100659
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100660 if (instruction->IsCurrentMethod()) {
Mathieu Chartiere3b034a2015-05-31 14:29:23 -0700661 MoveLocation(location, Location::DoubleStackSlot(kCurrentMethodStackOffset));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100662 } else if (locations != nullptr && locations->Out().Equals(location)) {
663 return;
664 } else if (instruction->IsIntConstant()
665 || instruction->IsLongConstant()
666 || instruction->IsNullConstant()) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000667 int64_t value = GetInt64ValueOf(instruction->AsConstant());
Alexandre Rames5319def2014-10-23 10:03:10 +0100668 if (location.IsRegister()) {
669 Register dst = RegisterFrom(location, type);
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000670 DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) ||
Alexandre Rames5319def2014-10-23 10:03:10 +0100671 (instruction->IsLongConstant() && dst.Is64Bits()));
672 __ Mov(dst, value);
673 } else {
674 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000675 UseScratchRegisterScope temps(GetVIXLAssembler());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000676 Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant())
677 ? temps.AcquireW()
678 : temps.AcquireX();
Alexandre Rames5319def2014-10-23 10:03:10 +0100679 __ Mov(temp, value);
680 __ Str(temp, StackOperandFrom(location));
681 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000682 } else if (instruction->IsTemporary()) {
683 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000684 MoveLocation(location, temp_location, type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100685 } else if (instruction->IsLoadLocal()) {
686 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Alexandre Rames542361f2015-01-29 16:57:31 +0000687 if (Primitive::Is64BitType(type)) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000688 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000689 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000690 MoveLocation(location, Location::StackSlot(stack_slot), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100691 }
692
693 } else {
694 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000695 MoveLocation(location, locations->Out(), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100696 }
697}
698
Alexandre Rames5319def2014-10-23 10:03:10 +0100699Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const {
700 Primitive::Type type = load->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000701
Alexandre Rames5319def2014-10-23 10:03:10 +0100702 switch (type) {
703 case Primitive::kPrimNot:
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000704 case Primitive::kPrimInt:
705 case Primitive::kPrimFloat:
706 return Location::StackSlot(GetStackSlot(load->GetLocal()));
707
708 case Primitive::kPrimLong:
709 case Primitive::kPrimDouble:
710 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
711
Alexandre Rames5319def2014-10-23 10:03:10 +0100712 case Primitive::kPrimBoolean:
713 case Primitive::kPrimByte:
714 case Primitive::kPrimChar:
715 case Primitive::kPrimShort:
Alexandre Rames5319def2014-10-23 10:03:10 +0100716 case Primitive::kPrimVoid:
Alexandre Rames5319def2014-10-23 10:03:10 +0100717 LOG(FATAL) << "Unexpected type " << type;
718 }
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000719
Alexandre Rames5319def2014-10-23 10:03:10 +0100720 LOG(FATAL) << "Unreachable";
721 return Location::NoLocation();
722}
723
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100724void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000725 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +0100726 Register card = temps.AcquireX();
Serban Constantinescu02164b32014-11-13 14:05:07 +0000727 Register temp = temps.AcquireW(); // Index within the CardTable - 32bit.
Alexandre Rames5319def2014-10-23 10:03:10 +0100728 vixl::Label done;
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100729 if (value_can_be_null) {
730 __ Cbz(value, &done);
731 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100732 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value()));
733 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000734 __ Strb(card, MemOperand(card, temp.X()));
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100735 if (value_can_be_null) {
736 __ Bind(&done);
737 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100738}
739
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000740void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const {
741 // Blocked core registers:
742 // lr : Runtime reserved.
743 // tr : Runtime reserved.
744 // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it.
745 // ip1 : VIXL core temp.
746 // ip0 : VIXL core temp.
747 //
748 // Blocked fp registers:
749 // d31 : VIXL fp temp.
Alexandre Rames5319def2014-10-23 10:03:10 +0100750 CPURegList reserved_core_registers = vixl_reserved_core_registers;
751 reserved_core_registers.Combine(runtime_reserved_core_registers);
Alexandre Rames5319def2014-10-23 10:03:10 +0100752 while (!reserved_core_registers.IsEmpty()) {
753 blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true;
754 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000755
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000756 CPURegList reserved_fp_registers = vixl_reserved_fp_registers;
Zheng Xua3ec3942015-02-15 18:39:46 +0800757 while (!reserved_fp_registers.IsEmpty()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000758 blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true;
759 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000760
761 if (is_baseline) {
762 CPURegList reserved_core_baseline_registers = callee_saved_core_registers;
763 while (!reserved_core_baseline_registers.IsEmpty()) {
764 blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true;
765 }
766
767 CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers;
768 while (!reserved_fp_baseline_registers.IsEmpty()) {
769 blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true;
770 }
771 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100772}
773
774Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const {
775 if (type == Primitive::kPrimVoid) {
776 LOG(FATAL) << "Unreachable type " << type;
777 }
778
Alexandre Rames542361f2015-01-29 16:57:31 +0000779 if (Primitive::IsFloatingPointType(type)) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000780 ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters);
781 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100782 return Location::FpuRegisterLocation(reg);
783 } else {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000784 ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters);
785 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100786 return Location::RegisterLocation(reg);
787 }
788}
789
Alexandre Rames3e69f162014-12-10 10:36:50 +0000790size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
791 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
792 __ Str(reg, MemOperand(sp, stack_index));
793 return kArm64WordSize;
794}
795
796size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
797 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
798 __ Ldr(reg, MemOperand(sp, stack_index));
799 return kArm64WordSize;
800}
801
802size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
803 FPRegister reg = FPRegister(reg_id, kDRegSize);
804 __ Str(reg, MemOperand(sp, stack_index));
805 return kArm64WordSize;
806}
807
808size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
809 FPRegister reg = FPRegister(reg_id, kDRegSize);
810 __ Ldr(reg, MemOperand(sp, stack_index));
811 return kArm64WordSize;
812}
813
Alexandre Rames5319def2014-10-23 10:03:10 +0100814void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100815 stream << XRegister(reg);
Alexandre Rames5319def2014-10-23 10:03:10 +0100816}
817
818void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100819 stream << DRegister(reg);
Alexandre Rames5319def2014-10-23 10:03:10 +0100820}
821
Alexandre Rames67555f72014-11-18 10:55:16 +0000822void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000823 if (constant->IsIntConstant()) {
824 __ Mov(Register(destination), constant->AsIntConstant()->GetValue());
825 } else if (constant->IsLongConstant()) {
826 __ Mov(Register(destination), constant->AsLongConstant()->GetValue());
827 } else if (constant->IsNullConstant()) {
828 __ Mov(Register(destination), 0);
Alexandre Rames67555f72014-11-18 10:55:16 +0000829 } else if (constant->IsFloatConstant()) {
830 __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue());
831 } else {
832 DCHECK(constant->IsDoubleConstant());
833 __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue());
834 }
835}
836
Alexandre Rames3e69f162014-12-10 10:36:50 +0000837
838static bool CoherentConstantAndType(Location constant, Primitive::Type type) {
839 DCHECK(constant.IsConstant());
840 HConstant* cst = constant.GetConstant();
841 return (cst->IsIntConstant() && type == Primitive::kPrimInt) ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000842 // Null is mapped to a core W register, which we associate with kPrimInt.
843 (cst->IsNullConstant() && type == Primitive::kPrimInt) ||
Alexandre Rames3e69f162014-12-10 10:36:50 +0000844 (cst->IsLongConstant() && type == Primitive::kPrimLong) ||
845 (cst->IsFloatConstant() && type == Primitive::kPrimFloat) ||
846 (cst->IsDoubleConstant() && type == Primitive::kPrimDouble);
847}
848
849void CodeGeneratorARM64::MoveLocation(Location destination, Location source, Primitive::Type type) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000850 if (source.Equals(destination)) {
851 return;
852 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000853
854 // A valid move can always be inferred from the destination and source
855 // locations. When moving from and to a register, the argument type can be
856 // used to generate 32bit instead of 64bit moves. In debug mode we also
857 // checks the coherency of the locations and the type.
858 bool unspecified_type = (type == Primitive::kPrimVoid);
859
860 if (destination.IsRegister() || destination.IsFpuRegister()) {
861 if (unspecified_type) {
862 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
863 if (source.IsStackSlot() ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000864 (src_cst != nullptr && (src_cst->IsIntConstant()
865 || src_cst->IsFloatConstant()
866 || src_cst->IsNullConstant()))) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000867 // For stack slots and 32bit constants, a 64bit type is appropriate.
868 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexandre Rames67555f72014-11-18 10:55:16 +0000869 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000870 // If the source is a double stack slot or a 64bit constant, a 64bit
871 // type is appropriate. Else the source is a register, and since the
872 // type has not been specified, we chose a 64bit type to force a 64bit
873 // move.
874 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexandre Rames67555f72014-11-18 10:55:16 +0000875 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000876 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000877 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
878 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000879 CPURegister dst = CPURegisterFrom(destination, type);
880 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
881 DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot());
882 __ Ldr(dst, StackOperandFrom(source));
883 } else if (source.IsConstant()) {
884 DCHECK(CoherentConstantAndType(source, type));
885 MoveConstant(dst, source.GetConstant());
886 } else {
887 if (destination.IsRegister()) {
888 __ Mov(Register(dst), RegisterFrom(source, type));
889 } else {
Zheng Xuad4450e2015-04-17 18:48:56 +0800890 DCHECK(destination.IsFpuRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000891 __ Fmov(FPRegister(dst), FPRegisterFrom(source, type));
892 }
893 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000894 } else { // The destination is not a register. It must be a stack slot.
895 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
896 if (source.IsRegister() || source.IsFpuRegister()) {
897 if (unspecified_type) {
898 if (source.IsRegister()) {
899 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
900 } else {
901 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
902 }
903 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000904 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
905 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000906 __ Str(CPURegisterFrom(source, type), StackOperandFrom(destination));
907 } else if (source.IsConstant()) {
908 DCHECK(unspecified_type || CoherentConstantAndType(source, type));
909 UseScratchRegisterScope temps(GetVIXLAssembler());
910 HConstant* src_cst = source.GetConstant();
911 CPURegister temp;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000912 if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000913 temp = temps.AcquireW();
914 } else if (src_cst->IsLongConstant()) {
915 temp = temps.AcquireX();
916 } else if (src_cst->IsFloatConstant()) {
917 temp = temps.AcquireS();
918 } else {
919 DCHECK(src_cst->IsDoubleConstant());
920 temp = temps.AcquireD();
921 }
922 MoveConstant(temp, src_cst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000923 __ Str(temp, StackOperandFrom(destination));
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000924 } else {
Alexandre Rames67555f72014-11-18 10:55:16 +0000925 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000926 DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000927 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000928 // There is generally less pressure on FP registers.
929 FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS();
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000930 __ Ldr(temp, StackOperandFrom(source));
931 __ Str(temp, StackOperandFrom(destination));
932 }
933 }
934}
935
936void CodeGeneratorARM64::Load(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000937 CPURegister dst,
938 const MemOperand& src) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000939 switch (type) {
940 case Primitive::kPrimBoolean:
Alexandre Rames67555f72014-11-18 10:55:16 +0000941 __ Ldrb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000942 break;
943 case Primitive::kPrimByte:
Alexandre Rames67555f72014-11-18 10:55:16 +0000944 __ Ldrsb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000945 break;
946 case Primitive::kPrimShort:
Alexandre Rames67555f72014-11-18 10:55:16 +0000947 __ Ldrsh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000948 break;
949 case Primitive::kPrimChar:
Alexandre Rames67555f72014-11-18 10:55:16 +0000950 __ Ldrh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000951 break;
952 case Primitive::kPrimInt:
953 case Primitive::kPrimNot:
954 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000955 case Primitive::kPrimFloat:
956 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000957 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Rames67555f72014-11-18 10:55:16 +0000958 __ Ldr(dst, src);
959 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000960 case Primitive::kPrimVoid:
961 LOG(FATAL) << "Unreachable type " << type;
962 }
963}
964
Calin Juravle77520bc2015-01-12 18:45:46 +0000965void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000966 CPURegister dst,
967 const MemOperand& src) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100968 MacroAssembler* masm = GetVIXLAssembler();
969 BlockPoolsScope block_pools(masm);
970 UseScratchRegisterScope temps(masm);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000971 Register temp_base = temps.AcquireX();
Calin Juravle77520bc2015-01-12 18:45:46 +0000972 Primitive::Type type = instruction->GetType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000973
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000974 DCHECK(!src.IsPreIndex());
975 DCHECK(!src.IsPostIndex());
976
977 // TODO(vixl): Let the MacroAssembler handle MemOperand.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800978 __ Add(temp_base, src.base(), OperandFromMemOperand(src));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000979 MemOperand base = MemOperand(temp_base);
980 switch (type) {
981 case Primitive::kPrimBoolean:
982 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000983 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000984 break;
985 case Primitive::kPrimByte:
986 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000987 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000988 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
989 break;
990 case Primitive::kPrimChar:
991 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000992 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000993 break;
994 case Primitive::kPrimShort:
995 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000996 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000997 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
998 break;
999 case Primitive::kPrimInt:
1000 case Primitive::kPrimNot:
1001 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +00001002 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001003 __ Ldar(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +00001004 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001005 break;
1006 case Primitive::kPrimFloat:
1007 case Primitive::kPrimDouble: {
1008 DCHECK(dst.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +00001009 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001010
1011 Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
1012 __ Ldar(temp, base);
Calin Juravle77520bc2015-01-12 18:45:46 +00001013 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001014 __ Fmov(FPRegister(dst), temp);
1015 break;
1016 }
1017 case Primitive::kPrimVoid:
1018 LOG(FATAL) << "Unreachable type " << type;
1019 }
1020}
1021
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001022void CodeGeneratorARM64::Store(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001023 CPURegister src,
1024 const MemOperand& dst) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001025 switch (type) {
1026 case Primitive::kPrimBoolean:
1027 case Primitive::kPrimByte:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001028 __ Strb(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001029 break;
1030 case Primitive::kPrimChar:
1031 case Primitive::kPrimShort:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001032 __ Strh(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001033 break;
1034 case Primitive::kPrimInt:
1035 case Primitive::kPrimNot:
1036 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001037 case Primitive::kPrimFloat:
1038 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +00001039 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001040 __ Str(src, dst);
Alexandre Rames67555f72014-11-18 10:55:16 +00001041 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001042 case Primitive::kPrimVoid:
1043 LOG(FATAL) << "Unreachable type " << type;
1044 }
1045}
1046
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001047void CodeGeneratorARM64::StoreRelease(Primitive::Type type,
1048 CPURegister src,
1049 const MemOperand& dst) {
1050 UseScratchRegisterScope temps(GetVIXLAssembler());
1051 Register temp_base = temps.AcquireX();
1052
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001053 DCHECK(!dst.IsPreIndex());
1054 DCHECK(!dst.IsPostIndex());
1055
1056 // TODO(vixl): Let the MacroAssembler handle this.
Andreas Gampe878d58c2015-01-15 23:24:00 -08001057 Operand op = OperandFromMemOperand(dst);
1058 __ Add(temp_base, dst.base(), op);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001059 MemOperand base = MemOperand(temp_base);
1060 switch (type) {
1061 case Primitive::kPrimBoolean:
1062 case Primitive::kPrimByte:
1063 __ Stlrb(Register(src), base);
1064 break;
1065 case Primitive::kPrimChar:
1066 case Primitive::kPrimShort:
1067 __ Stlrh(Register(src), base);
1068 break;
1069 case Primitive::kPrimInt:
1070 case Primitive::kPrimNot:
1071 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +00001072 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001073 __ Stlr(Register(src), base);
1074 break;
1075 case Primitive::kPrimFloat:
1076 case Primitive::kPrimDouble: {
1077 DCHECK(src.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +00001078 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001079
1080 Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
1081 __ Fmov(temp, FPRegister(src));
1082 __ Stlr(temp, base);
1083 break;
1084 }
1085 case Primitive::kPrimVoid:
1086 LOG(FATAL) << "Unreachable type " << type;
1087 }
1088}
1089
Alexandre Rames67555f72014-11-18 10:55:16 +00001090void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset,
1091 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001092 uint32_t dex_pc,
1093 SlowPathCode* slow_path) {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001094 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames67555f72014-11-18 10:55:16 +00001095 __ Ldr(lr, MemOperand(tr, entry_point_offset));
1096 __ Blr(lr);
Roland Levillain896e32d2015-05-05 18:07:10 +01001097 RecordPcInfo(instruction, dex_pc, slow_path);
1098 DCHECK(instruction->IsSuspendCheck()
1099 || instruction->IsBoundsCheck()
1100 || instruction->IsNullCheck()
1101 || instruction->IsDivZeroCheck()
1102 || !IsLeafMethod());
Alexandre Rames67555f72014-11-18 10:55:16 +00001103}
1104
1105void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path,
1106 vixl::Register class_reg) {
1107 UseScratchRegisterScope temps(GetVIXLAssembler());
1108 Register temp = temps.AcquireW();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001109 size_t status_offset = mirror::Class::StatusOffset().SizeValue();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001110 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001111
Serban Constantinescu02164b32014-11-13 14:05:07 +00001112 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
Serban Constantinescu579885a2015-02-22 20:51:33 +00001113 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001114 // TODO(vixl): Let the MacroAssembler handle MemOperand.
1115 __ Add(temp, class_reg, status_offset);
1116 __ Ldar(temp, HeapOperand(temp));
1117 __ Cmp(temp, mirror::Class::kStatusInitialized);
1118 __ B(lt, slow_path->GetEntryLabel());
1119 } else {
1120 __ Ldr(temp, HeapOperand(class_reg, status_offset));
1121 __ Cmp(temp, mirror::Class::kStatusInitialized);
1122 __ B(lt, slow_path->GetEntryLabel());
1123 __ Dmb(InnerShareable, BarrierReads);
1124 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001125 __ Bind(slow_path->GetExitLabel());
1126}
Alexandre Rames5319def2014-10-23 10:03:10 +01001127
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001128void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) {
1129 BarrierType type = BarrierAll;
1130
1131 switch (kind) {
1132 case MemBarrierKind::kAnyAny:
1133 case MemBarrierKind::kAnyStore: {
1134 type = BarrierAll;
1135 break;
1136 }
1137 case MemBarrierKind::kLoadAny: {
1138 type = BarrierReads;
1139 break;
1140 }
1141 case MemBarrierKind::kStoreStore: {
1142 type = BarrierWrites;
1143 break;
1144 }
1145 default:
1146 LOG(FATAL) << "Unexpected memory barrier " << kind;
1147 }
1148 __ Dmb(InnerShareable, type);
1149}
1150
Serban Constantinescu02164b32014-11-13 14:05:07 +00001151void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction,
1152 HBasicBlock* successor) {
1153 SuspendCheckSlowPathARM64* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01001154 down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath());
1155 if (slow_path == nullptr) {
1156 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor);
1157 instruction->SetSlowPath(slow_path);
1158 codegen_->AddSlowPath(slow_path);
1159 if (successor != nullptr) {
1160 DCHECK(successor->IsLoopHeader());
1161 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
1162 }
1163 } else {
1164 DCHECK_EQ(slow_path->GetSuccessor(), successor);
1165 }
1166
Serban Constantinescu02164b32014-11-13 14:05:07 +00001167 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
1168 Register temp = temps.AcquireW();
1169
1170 __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue()));
1171 if (successor == nullptr) {
1172 __ Cbnz(temp, slow_path->GetEntryLabel());
1173 __ Bind(slow_path->GetReturnLabel());
1174 } else {
1175 __ Cbz(temp, codegen_->GetLabelOf(successor));
1176 __ B(slow_path->GetEntryLabel());
1177 // slow_path will return to GetLabelOf(successor).
1178 }
1179}
1180
Alexandre Rames5319def2014-10-23 10:03:10 +01001181InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
1182 CodeGeneratorARM64* codegen)
1183 : HGraphVisitor(graph),
1184 assembler_(codegen->GetAssembler()),
1185 codegen_(codegen) {}
1186
1187#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Alexandre Rames3e69f162014-12-10 10:36:50 +00001188 /* No unimplemented IR. */
Alexandre Rames5319def2014-10-23 10:03:10 +01001189
1190#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
1191
1192enum UnimplementedInstructionBreakCode {
Alexandre Rames67555f72014-11-18 10:55:16 +00001193 // Using a base helps identify when we hit such breakpoints.
1194 UnimplementedInstructionBreakCodeBaseCode = 0x900,
Alexandre Rames5319def2014-10-23 10:03:10 +01001195#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
1196 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
1197#undef ENUM_UNIMPLEMENTED_INSTRUCTION
1198};
1199
1200#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
1201 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001202 UNUSED(instr); \
Alexandre Rames5319def2014-10-23 10:03:10 +01001203 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
1204 } \
1205 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
1206 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
1207 locations->SetOut(Location::Any()); \
1208 }
1209 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
1210#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
1211
1212#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
Alexandre Rames67555f72014-11-18 10:55:16 +00001213#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
Alexandre Rames5319def2014-10-23 10:03:10 +01001214
Alexandre Rames67555f72014-11-18 10:55:16 +00001215void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001216 DCHECK_EQ(instr->InputCount(), 2U);
1217 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1218 Primitive::Type type = instr->GetResultType();
1219 switch (type) {
1220 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001221 case Primitive::kPrimLong:
Alexandre Rames5319def2014-10-23 10:03:10 +01001222 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001223 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr));
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001224 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001225 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001226
1227 case Primitive::kPrimFloat:
1228 case Primitive::kPrimDouble:
1229 locations->SetInAt(0, Location::RequiresFpuRegister());
1230 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001231 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001232 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001233
Alexandre Rames5319def2014-10-23 10:03:10 +01001234 default:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001235 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001236 }
1237}
1238
Alexandre Rames09a99962015-04-15 11:47:56 +01001239void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) {
1240 LocationSummary* locations =
1241 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1242 locations->SetInAt(0, Location::RequiresRegister());
1243 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1244 locations->SetOut(Location::RequiresFpuRegister());
1245 } else {
1246 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1247 }
1248}
1249
1250void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction,
1251 const FieldInfo& field_info) {
1252 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Roland Levillain4d027112015-07-01 15:41:14 +01001253 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Ramesd921d642015-04-16 15:07:16 +01001254 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001255
1256 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset());
1257 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
1258
1259 if (field_info.IsVolatile()) {
1260 if (use_acquire_release) {
1261 // NB: LoadAcquire will record the pc info if needed.
1262 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
1263 } else {
Roland Levillain4d027112015-07-01 15:41:14 +01001264 codegen_->Load(field_type, OutputCPURegister(instruction), field);
Alexandre Rames09a99962015-04-15 11:47:56 +01001265 codegen_->MaybeRecordImplicitNullCheck(instruction);
1266 // For IRIW sequential consistency kLoadAny is not sufficient.
1267 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1268 }
1269 } else {
Roland Levillain4d027112015-07-01 15:41:14 +01001270 codegen_->Load(field_type, OutputCPURegister(instruction), field);
Alexandre Rames09a99962015-04-15 11:47:56 +01001271 codegen_->MaybeRecordImplicitNullCheck(instruction);
1272 }
Roland Levillain4d027112015-07-01 15:41:14 +01001273
1274 if (field_type == Primitive::kPrimNot) {
1275 GetAssembler()->MaybeUnpoisonHeapReference(OutputCPURegister(instruction).W());
1276 }
Alexandre Rames09a99962015-04-15 11:47:56 +01001277}
1278
1279void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) {
1280 LocationSummary* locations =
1281 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1282 locations->SetInAt(0, Location::RequiresRegister());
1283 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
1284 locations->SetInAt(1, Location::RequiresFpuRegister());
1285 } else {
1286 locations->SetInAt(1, Location::RequiresRegister());
1287 }
1288}
1289
1290void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01001291 const FieldInfo& field_info,
1292 bool value_can_be_null) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001293 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
Alexandre Ramesd921d642015-04-16 15:07:16 +01001294 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001295
1296 Register obj = InputRegisterAt(instruction, 0);
1297 CPURegister value = InputCPURegisterAt(instruction, 1);
Roland Levillain4d027112015-07-01 15:41:14 +01001298 CPURegister source = value;
Alexandre Rames09a99962015-04-15 11:47:56 +01001299 Offset offset = field_info.GetFieldOffset();
1300 Primitive::Type field_type = field_info.GetFieldType();
1301 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
1302
Roland Levillain4d027112015-07-01 15:41:14 +01001303 {
1304 // We use a block to end the scratch scope before the write barrier, thus
1305 // freeing the temporary registers so they can be used in `MarkGCCard`.
1306 UseScratchRegisterScope temps(GetVIXLAssembler());
1307
1308 if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) {
1309 DCHECK(value.IsW());
1310 Register temp = temps.AcquireW();
1311 __ Mov(temp, value.W());
1312 GetAssembler()->PoisonHeapReference(temp.W());
1313 source = temp;
Alexandre Rames09a99962015-04-15 11:47:56 +01001314 }
Roland Levillain4d027112015-07-01 15:41:14 +01001315
1316 if (field_info.IsVolatile()) {
1317 if (use_acquire_release) {
1318 codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset));
1319 codegen_->MaybeRecordImplicitNullCheck(instruction);
1320 } else {
1321 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
1322 codegen_->Store(field_type, source, HeapOperand(obj, offset));
1323 codegen_->MaybeRecordImplicitNullCheck(instruction);
1324 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1325 }
1326 } else {
1327 codegen_->Store(field_type, source, HeapOperand(obj, offset));
1328 codegen_->MaybeRecordImplicitNullCheck(instruction);
1329 }
Alexandre Rames09a99962015-04-15 11:47:56 +01001330 }
1331
1332 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01001333 codegen_->MarkGCCard(obj, Register(value), value_can_be_null);
Alexandre Rames09a99962015-04-15 11:47:56 +01001334 }
1335}
1336
Alexandre Rames67555f72014-11-18 10:55:16 +00001337void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001338 Primitive::Type type = instr->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001339
1340 switch (type) {
1341 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001342 case Primitive::kPrimLong: {
1343 Register dst = OutputRegister(instr);
1344 Register lhs = InputRegisterAt(instr, 0);
1345 Operand rhs = InputOperandAt(instr, 1);
Alexandre Rames5319def2014-10-23 10:03:10 +01001346 if (instr->IsAdd()) {
1347 __ Add(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001348 } else if (instr->IsAnd()) {
1349 __ And(dst, lhs, rhs);
1350 } else if (instr->IsOr()) {
1351 __ Orr(dst, lhs, rhs);
1352 } else if (instr->IsSub()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001353 __ Sub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001354 } else {
1355 DCHECK(instr->IsXor());
1356 __ Eor(dst, lhs, rhs);
Alexandre Rames5319def2014-10-23 10:03:10 +01001357 }
1358 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001359 }
1360 case Primitive::kPrimFloat:
1361 case Primitive::kPrimDouble: {
1362 FPRegister dst = OutputFPRegister(instr);
1363 FPRegister lhs = InputFPRegisterAt(instr, 0);
1364 FPRegister rhs = InputFPRegisterAt(instr, 1);
1365 if (instr->IsAdd()) {
1366 __ Fadd(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001367 } else if (instr->IsSub()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001368 __ Fsub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001369 } else {
1370 LOG(FATAL) << "Unexpected floating-point binary operation";
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001371 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001372 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001373 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001374 default:
Alexandre Rames67555f72014-11-18 10:55:16 +00001375 LOG(FATAL) << "Unexpected binary operation type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001376 }
1377}
1378
Serban Constantinescu02164b32014-11-13 14:05:07 +00001379void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) {
1380 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1381
1382 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1383 Primitive::Type type = instr->GetResultType();
1384 switch (type) {
1385 case Primitive::kPrimInt:
1386 case Primitive::kPrimLong: {
1387 locations->SetInAt(0, Location::RequiresRegister());
1388 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1389 locations->SetOut(Location::RequiresRegister());
1390 break;
1391 }
1392 default:
1393 LOG(FATAL) << "Unexpected shift type " << type;
1394 }
1395}
1396
1397void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) {
1398 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1399
1400 Primitive::Type type = instr->GetType();
1401 switch (type) {
1402 case Primitive::kPrimInt:
1403 case Primitive::kPrimLong: {
1404 Register dst = OutputRegister(instr);
1405 Register lhs = InputRegisterAt(instr, 0);
1406 Operand rhs = InputOperandAt(instr, 1);
1407 if (rhs.IsImmediate()) {
1408 uint32_t shift_value = (type == Primitive::kPrimInt)
1409 ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue)
1410 : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue);
1411 if (instr->IsShl()) {
1412 __ Lsl(dst, lhs, shift_value);
1413 } else if (instr->IsShr()) {
1414 __ Asr(dst, lhs, shift_value);
1415 } else {
1416 __ Lsr(dst, lhs, shift_value);
1417 }
1418 } else {
1419 Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W();
1420
1421 if (instr->IsShl()) {
1422 __ Lsl(dst, lhs, rhs_reg);
1423 } else if (instr->IsShr()) {
1424 __ Asr(dst, lhs, rhs_reg);
1425 } else {
1426 __ Lsr(dst, lhs, rhs_reg);
1427 }
1428 }
1429 break;
1430 }
1431 default:
1432 LOG(FATAL) << "Unexpected shift operation type " << type;
1433 }
1434}
1435
Alexandre Rames5319def2014-10-23 10:03:10 +01001436void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001437 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001438}
1439
1440void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001441 HandleBinaryOp(instruction);
1442}
1443
1444void LocationsBuilderARM64::VisitAnd(HAnd* instruction) {
1445 HandleBinaryOp(instruction);
1446}
1447
1448void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) {
1449 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001450}
1451
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001452void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) {
1453 LocationSummary* locations =
1454 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1455 locations->SetInAt(0, Location::RequiresRegister());
1456 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01001457 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1458 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1459 } else {
1460 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1461 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001462}
1463
1464void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) {
1465 LocationSummary* locations = instruction->GetLocations();
1466 Primitive::Type type = instruction->GetType();
1467 Register obj = InputRegisterAt(instruction, 0);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001468 Location index = locations->InAt(1);
1469 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001470 MemOperand source = HeapOperand(obj);
Alexandre Ramesd921d642015-04-16 15:07:16 +01001471 MacroAssembler* masm = GetVIXLAssembler();
1472 UseScratchRegisterScope temps(masm);
1473 BlockPoolsScope block_pools(masm);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001474
1475 if (index.IsConstant()) {
1476 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001477 source = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001478 } else {
1479 Register temp = temps.AcquireSameSizeAs(obj);
Alexandre Rames82000b02015-07-07 11:34:16 +01001480 __ Add(temp, obj, offset);
1481 source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001482 }
1483
Alexandre Rames67555f72014-11-18 10:55:16 +00001484 codegen_->Load(type, OutputCPURegister(instruction), source);
Calin Juravle77520bc2015-01-12 18:45:46 +00001485 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01001486
1487 if (type == Primitive::kPrimNot) {
1488 GetAssembler()->MaybeUnpoisonHeapReference(OutputCPURegister(instruction).W());
1489 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001490}
1491
Alexandre Rames5319def2014-10-23 10:03:10 +01001492void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
1493 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1494 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001495 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001496}
1497
1498void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001499 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +01001500 __ Ldr(OutputRegister(instruction),
1501 HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset()));
Calin Juravle77520bc2015-01-12 18:45:46 +00001502 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001503}
1504
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001505void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) {
Alexandre Rames97833a02015-04-16 15:07:12 +01001506 if (instruction->NeedsTypeCheck()) {
1507 LocationSummary* locations =
1508 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001509 InvokeRuntimeCallingConvention calling_convention;
1510 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1511 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1512 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1513 } else {
Alexandre Rames97833a02015-04-16 15:07:12 +01001514 LocationSummary* locations =
1515 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001516 locations->SetInAt(0, Location::RequiresRegister());
1517 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01001518 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1519 locations->SetInAt(2, Location::RequiresFpuRegister());
1520 } else {
1521 locations->SetInAt(2, Location::RequiresRegister());
1522 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001523 }
1524}
1525
1526void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) {
1527 Primitive::Type value_type = instruction->GetComponentType();
Alexandre Rames97833a02015-04-16 15:07:12 +01001528 LocationSummary* locations = instruction->GetLocations();
1529 bool needs_runtime_call = locations->WillCall();
1530
1531 if (needs_runtime_call) {
Roland Levillain4d027112015-07-01 15:41:14 +01001532 // Note: if heap poisoning is enabled, pAputObject takes cares
1533 // of poisoning the reference.
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001534 codegen_->InvokeRuntime(
1535 QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001536 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001537 } else {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001538 Register obj = InputRegisterAt(instruction, 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00001539 CPURegister value = InputCPURegisterAt(instruction, 2);
Roland Levillain4d027112015-07-01 15:41:14 +01001540 CPURegister source = value;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001541 Location index = locations->InAt(1);
1542 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001543 MemOperand destination = HeapOperand(obj);
Alexandre Ramesd921d642015-04-16 15:07:16 +01001544 MacroAssembler* masm = GetVIXLAssembler();
Alexandre Ramesd921d642015-04-16 15:07:16 +01001545 BlockPoolsScope block_pools(masm);
Alexandre Rames97833a02015-04-16 15:07:12 +01001546 {
1547 // We use a block to end the scratch scope before the write barrier, thus
1548 // freeing the temporary registers so they can be used in `MarkGCCard`.
1549 UseScratchRegisterScope temps(masm);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001550
Roland Levillain4d027112015-07-01 15:41:14 +01001551 if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) {
1552 DCHECK(value.IsW());
1553 Register temp = temps.AcquireW();
1554 __ Mov(temp, value.W());
1555 GetAssembler()->PoisonHeapReference(temp.W());
1556 source = temp;
1557 }
1558
Alexandre Rames97833a02015-04-16 15:07:12 +01001559 if (index.IsConstant()) {
1560 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
1561 destination = HeapOperand(obj, offset);
1562 } else {
1563 Register temp = temps.AcquireSameSizeAs(obj);
Alexandre Rames82000b02015-07-07 11:34:16 +01001564 __ Add(temp, obj, offset);
1565 destination = HeapOperand(temp,
1566 XRegisterFrom(index),
1567 LSL,
1568 Primitive::ComponentSizeShift(value_type));
Alexandre Rames97833a02015-04-16 15:07:12 +01001569 }
1570
Roland Levillain4d027112015-07-01 15:41:14 +01001571 codegen_->Store(value_type, source, destination);
Alexandre Rames97833a02015-04-16 15:07:12 +01001572 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001573 }
Alexandre Rames97833a02015-04-16 15:07:12 +01001574 if (CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue())) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01001575 codegen_->MarkGCCard(obj, value.W(), instruction->GetValueCanBeNull());
Alexandre Rames97833a02015-04-16 15:07:12 +01001576 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001577 }
1578}
1579
Alexandre Rames67555f72014-11-18 10:55:16 +00001580void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1581 LocationSummary* locations =
1582 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1583 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu760d8ef2015-03-28 18:09:56 +00001584 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames67555f72014-11-18 10:55:16 +00001585 if (instruction->HasUses()) {
1586 locations->SetOut(Location::SameAsFirstInput());
1587 }
1588}
1589
1590void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001591 LocationSummary* locations = instruction->GetLocations();
1592 BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(
1593 instruction, locations->InAt(0), locations->InAt(1));
Alexandre Rames67555f72014-11-18 10:55:16 +00001594 codegen_->AddSlowPath(slow_path);
1595
1596 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
1597 __ B(slow_path->GetEntryLabel(), hs);
1598}
1599
1600void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) {
1601 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1602 instruction, LocationSummary::kCallOnSlowPath);
1603 locations->SetInAt(0, Location::RequiresRegister());
1604 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001605 locations->AddTemp(Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001606}
1607
1608void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001609 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames67555f72014-11-18 10:55:16 +00001610 Register obj = InputRegisterAt(instruction, 0);;
1611 Register cls = InputRegisterAt(instruction, 1);;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001612 Register obj_cls = WRegisterFrom(instruction->GetLocations()->GetTemp(0));
Alexandre Rames67555f72014-11-18 10:55:16 +00001613
Alexandre Rames3e69f162014-12-10 10:36:50 +00001614 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1615 instruction, locations->InAt(1), LocationFrom(obj_cls), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001616 codegen_->AddSlowPath(slow_path);
1617
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01001618 // Avoid null check if we know obj is not null.
1619 if (instruction->MustDoNullCheck()) {
1620 __ Cbz(obj, slow_path->GetExitLabel());
1621 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001622 // Compare the class of `obj` with `cls`.
Alexandre Rames3e69f162014-12-10 10:36:50 +00001623 __ Ldr(obj_cls, HeapOperand(obj, mirror::Object::ClassOffset()));
Roland Levillain4d027112015-07-01 15:41:14 +01001624 GetAssembler()->MaybeUnpoisonHeapReference(obj_cls.W());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001625 __ Cmp(obj_cls, cls);
Roland Levillain4d027112015-07-01 15:41:14 +01001626 // The checkcast succeeds if the classes are equal (fast path).
1627 // Otherwise, we need to go into the slow path to check the types.
Alexandre Rames67555f72014-11-18 10:55:16 +00001628 __ B(ne, slow_path->GetEntryLabel());
1629 __ Bind(slow_path->GetExitLabel());
1630}
1631
1632void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) {
1633 LocationSummary* locations =
1634 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1635 locations->SetInAt(0, Location::RequiresRegister());
1636 if (check->HasUses()) {
1637 locations->SetOut(Location::SameAsFirstInput());
1638 }
1639}
1640
1641void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) {
1642 // We assume the class is not null.
1643 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
1644 check->GetLoadClass(), check, check->GetDexPc(), true);
1645 codegen_->AddSlowPath(slow_path);
1646 GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0));
1647}
1648
Serban Constantinescu02164b32014-11-13 14:05:07 +00001649void LocationsBuilderARM64::VisitCompare(HCompare* compare) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001650 LocationSummary* locations =
Serban Constantinescu02164b32014-11-13 14:05:07 +00001651 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
1652 Primitive::Type in_type = compare->InputAt(0)->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001653 switch (in_type) {
1654 case Primitive::kPrimLong: {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001655 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001656 locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001657 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1658 break;
1659 }
1660 case Primitive::kPrimFloat:
1661 case Primitive::kPrimDouble: {
1662 locations->SetInAt(0, Location::RequiresFpuRegister());
Alexandre Rames93415462015-02-17 15:08:20 +00001663 HInstruction* right = compare->InputAt(1);
1664 if ((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1665 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))) {
1666 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1667 } else {
1668 locations->SetInAt(1, Location::RequiresFpuRegister());
1669 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001670 locations->SetOut(Location::RequiresRegister());
1671 break;
1672 }
1673 default:
1674 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1675 }
1676}
1677
1678void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) {
1679 Primitive::Type in_type = compare->InputAt(0)->GetType();
1680
1681 // 0 if: left == right
1682 // 1 if: left > right
1683 // -1 if: left < right
1684 switch (in_type) {
1685 case Primitive::kPrimLong: {
1686 Register result = OutputRegister(compare);
1687 Register left = InputRegisterAt(compare, 0);
1688 Operand right = InputOperandAt(compare, 1);
1689
1690 __ Cmp(left, right);
1691 __ Cset(result, ne);
1692 __ Cneg(result, result, lt);
1693 break;
1694 }
1695 case Primitive::kPrimFloat:
1696 case Primitive::kPrimDouble: {
1697 Register result = OutputRegister(compare);
1698 FPRegister left = InputFPRegisterAt(compare, 0);
Alexandre Rames93415462015-02-17 15:08:20 +00001699 if (compare->GetLocations()->InAt(1).IsConstant()) {
1700 if (kIsDebugBuild) {
1701 HInstruction* right = compare->GetLocations()->InAt(1).GetConstant();
1702 DCHECK((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1703 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0)));
1704 }
1705 // 0.0 is the only immediate that can be encoded directly in a FCMP instruction.
1706 __ Fcmp(left, 0.0);
1707 } else {
1708 __ Fcmp(left, InputFPRegisterAt(compare, 1));
1709 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001710 if (compare->IsGtBias()) {
1711 __ Cset(result, ne);
1712 } else {
1713 __ Csetm(result, ne);
1714 }
1715 __ Cneg(result, result, compare->IsGtBias() ? mi : gt);
Alexandre Rames5319def2014-10-23 10:03:10 +01001716 break;
1717 }
1718 default:
1719 LOG(FATAL) << "Unimplemented compare type " << in_type;
1720 }
1721}
1722
1723void LocationsBuilderARM64::VisitCondition(HCondition* instruction) {
1724 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1725 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001726 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames5319def2014-10-23 10:03:10 +01001727 if (instruction->NeedsMaterialization()) {
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001728 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001729 }
1730}
1731
1732void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) {
1733 if (!instruction->NeedsMaterialization()) {
1734 return;
1735 }
1736
1737 LocationSummary* locations = instruction->GetLocations();
1738 Register lhs = InputRegisterAt(instruction, 0);
1739 Operand rhs = InputOperandAt(instruction, 1);
1740 Register res = RegisterFrom(locations->Out(), instruction->GetType());
1741 Condition cond = ARM64Condition(instruction->GetCondition());
1742
1743 __ Cmp(lhs, rhs);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001744 __ Cset(res, cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001745}
1746
1747#define FOR_EACH_CONDITION_INSTRUCTION(M) \
1748 M(Equal) \
1749 M(NotEqual) \
1750 M(LessThan) \
1751 M(LessThanOrEqual) \
1752 M(GreaterThan) \
1753 M(GreaterThanOrEqual)
1754#define DEFINE_CONDITION_VISITORS(Name) \
1755void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \
1756void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }
1757FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
Alexandre Rames67555f72014-11-18 10:55:16 +00001758#undef DEFINE_CONDITION_VISITORS
Alexandre Rames5319def2014-10-23 10:03:10 +01001759#undef FOR_EACH_CONDITION_INSTRUCTION
1760
Zheng Xuc6667102015-05-15 16:08:45 +08001761void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
1762 DCHECK(instruction->IsDiv() || instruction->IsRem());
1763
1764 LocationSummary* locations = instruction->GetLocations();
1765 Location second = locations->InAt(1);
1766 DCHECK(second.IsConstant());
1767
1768 Register out = OutputRegister(instruction);
1769 Register dividend = InputRegisterAt(instruction, 0);
1770 int64_t imm = Int64FromConstant(second.GetConstant());
1771 DCHECK(imm == 1 || imm == -1);
1772
1773 if (instruction->IsRem()) {
1774 __ Mov(out, 0);
1775 } else {
1776 if (imm == 1) {
1777 __ Mov(out, dividend);
1778 } else {
1779 __ Neg(out, dividend);
1780 }
1781 }
1782}
1783
1784void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
1785 DCHECK(instruction->IsDiv() || instruction->IsRem());
1786
1787 LocationSummary* locations = instruction->GetLocations();
1788 Location second = locations->InAt(1);
1789 DCHECK(second.IsConstant());
1790
1791 Register out = OutputRegister(instruction);
1792 Register dividend = InputRegisterAt(instruction, 0);
1793 int64_t imm = Int64FromConstant(second.GetConstant());
Vladimir Marko80afd022015-05-19 18:08:00 +01001794 uint64_t abs_imm = static_cast<uint64_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08001795 DCHECK(IsPowerOfTwo(abs_imm));
1796 int ctz_imm = CTZ(abs_imm);
1797
1798 UseScratchRegisterScope temps(GetVIXLAssembler());
1799 Register temp = temps.AcquireSameSizeAs(out);
1800
1801 if (instruction->IsDiv()) {
1802 __ Add(temp, dividend, abs_imm - 1);
1803 __ Cmp(dividend, 0);
1804 __ Csel(out, temp, dividend, lt);
1805 if (imm > 0) {
1806 __ Asr(out, out, ctz_imm);
1807 } else {
1808 __ Neg(out, Operand(out, ASR, ctz_imm));
1809 }
1810 } else {
1811 int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64;
1812 __ Asr(temp, dividend, bits - 1);
1813 __ Lsr(temp, temp, bits - ctz_imm);
1814 __ Add(out, dividend, temp);
1815 __ And(out, out, abs_imm - 1);
1816 __ Sub(out, out, temp);
1817 }
1818}
1819
1820void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
1821 DCHECK(instruction->IsDiv() || instruction->IsRem());
1822
1823 LocationSummary* locations = instruction->GetLocations();
1824 Location second = locations->InAt(1);
1825 DCHECK(second.IsConstant());
1826
1827 Register out = OutputRegister(instruction);
1828 Register dividend = InputRegisterAt(instruction, 0);
1829 int64_t imm = Int64FromConstant(second.GetConstant());
1830
1831 Primitive::Type type = instruction->GetResultType();
1832 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
1833
1834 int64_t magic;
1835 int shift;
1836 CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift);
1837
1838 UseScratchRegisterScope temps(GetVIXLAssembler());
1839 Register temp = temps.AcquireSameSizeAs(out);
1840
1841 // temp = get_high(dividend * magic)
1842 __ Mov(temp, magic);
1843 if (type == Primitive::kPrimLong) {
1844 __ Smulh(temp, dividend, temp);
1845 } else {
1846 __ Smull(temp.X(), dividend, temp);
1847 __ Lsr(temp.X(), temp.X(), 32);
1848 }
1849
1850 if (imm > 0 && magic < 0) {
1851 __ Add(temp, temp, dividend);
1852 } else if (imm < 0 && magic > 0) {
1853 __ Sub(temp, temp, dividend);
1854 }
1855
1856 if (shift != 0) {
1857 __ Asr(temp, temp, shift);
1858 }
1859
1860 if (instruction->IsDiv()) {
1861 __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31));
1862 } else {
1863 __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31));
1864 // TODO: Strength reduction for msub.
1865 Register temp_imm = temps.AcquireSameSizeAs(out);
1866 __ Mov(temp_imm, imm);
1867 __ Msub(out, temp, temp_imm, dividend);
1868 }
1869}
1870
1871void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) {
1872 DCHECK(instruction->IsDiv() || instruction->IsRem());
1873 Primitive::Type type = instruction->GetResultType();
1874 DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong);
1875
1876 LocationSummary* locations = instruction->GetLocations();
1877 Register out = OutputRegister(instruction);
1878 Location second = locations->InAt(1);
1879
1880 if (second.IsConstant()) {
1881 int64_t imm = Int64FromConstant(second.GetConstant());
1882
1883 if (imm == 0) {
1884 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
1885 } else if (imm == 1 || imm == -1) {
1886 DivRemOneOrMinusOne(instruction);
1887 } else if (IsPowerOfTwo(std::abs(imm))) {
1888 DivRemByPowerOfTwo(instruction);
1889 } else {
1890 DCHECK(imm <= -2 || imm >= 2);
1891 GenerateDivRemWithAnyConstant(instruction);
1892 }
1893 } else {
1894 Register dividend = InputRegisterAt(instruction, 0);
1895 Register divisor = InputRegisterAt(instruction, 1);
1896 if (instruction->IsDiv()) {
1897 __ Sdiv(out, dividend, divisor);
1898 } else {
1899 UseScratchRegisterScope temps(GetVIXLAssembler());
1900 Register temp = temps.AcquireSameSizeAs(out);
1901 __ Sdiv(temp, dividend, divisor);
1902 __ Msub(out, temp, divisor, dividend);
1903 }
1904 }
1905}
1906
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001907void LocationsBuilderARM64::VisitDiv(HDiv* div) {
1908 LocationSummary* locations =
1909 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1910 switch (div->GetResultType()) {
1911 case Primitive::kPrimInt:
1912 case Primitive::kPrimLong:
1913 locations->SetInAt(0, Location::RequiresRegister());
Zheng Xuc6667102015-05-15 16:08:45 +08001914 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001915 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1916 break;
1917
1918 case Primitive::kPrimFloat:
1919 case Primitive::kPrimDouble:
1920 locations->SetInAt(0, Location::RequiresFpuRegister());
1921 locations->SetInAt(1, Location::RequiresFpuRegister());
1922 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1923 break;
1924
1925 default:
1926 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1927 }
1928}
1929
1930void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) {
1931 Primitive::Type type = div->GetResultType();
1932 switch (type) {
1933 case Primitive::kPrimInt:
1934 case Primitive::kPrimLong:
Zheng Xuc6667102015-05-15 16:08:45 +08001935 GenerateDivRemIntegral(div);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001936 break;
1937
1938 case Primitive::kPrimFloat:
1939 case Primitive::kPrimDouble:
1940 __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1));
1941 break;
1942
1943 default:
1944 LOG(FATAL) << "Unexpected div type " << type;
1945 }
1946}
1947
Alexandre Rames67555f72014-11-18 10:55:16 +00001948void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1949 LocationSummary* locations =
1950 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1951 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1952 if (instruction->HasUses()) {
1953 locations->SetOut(Location::SameAsFirstInput());
1954 }
1955}
1956
1957void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1958 SlowPathCodeARM64* slow_path =
1959 new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction);
1960 codegen_->AddSlowPath(slow_path);
1961 Location value = instruction->GetLocations()->InAt(0);
1962
Alexandre Rames3e69f162014-12-10 10:36:50 +00001963 Primitive::Type type = instruction->GetType();
1964
1965 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1966 LOG(FATAL) << "Unexpected type " << type << "for DivZeroCheck.";
1967 return;
1968 }
1969
Alexandre Rames67555f72014-11-18 10:55:16 +00001970 if (value.IsConstant()) {
1971 int64_t divisor = Int64ConstantFrom(value);
1972 if (divisor == 0) {
1973 __ B(slow_path->GetEntryLabel());
1974 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001975 // A division by a non-null constant is valid. We don't need to perform
1976 // any check, so simply fall through.
Alexandre Rames67555f72014-11-18 10:55:16 +00001977 }
1978 } else {
1979 __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel());
1980 }
1981}
1982
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001983void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1984 LocationSummary* locations =
1985 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1986 locations->SetOut(Location::ConstantLocation(constant));
1987}
1988
1989void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1990 UNUSED(constant);
1991 // Will be generated at use site.
1992}
1993
Alexandre Rames5319def2014-10-23 10:03:10 +01001994void LocationsBuilderARM64::VisitExit(HExit* exit) {
1995 exit->SetLocations(nullptr);
1996}
1997
1998void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001999 UNUSED(exit);
Alexandre Rames5319def2014-10-23 10:03:10 +01002000}
2001
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002002void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) {
2003 LocationSummary* locations =
2004 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2005 locations->SetOut(Location::ConstantLocation(constant));
2006}
2007
2008void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) {
2009 UNUSED(constant);
2010 // Will be generated at use site.
2011}
2012
David Brazdilfc6a86a2015-06-26 10:33:45 +00002013void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002014 DCHECK(!successor->IsExitBlock());
2015 HBasicBlock* block = got->GetBlock();
2016 HInstruction* previous = got->GetPrevious();
2017 HLoopInformation* info = block->GetLoopInformation();
2018
David Brazdil46e2a392015-03-16 17:31:52 +00002019 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002020 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2021 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2022 return;
2023 }
2024 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2025 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2026 }
2027 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002028 __ B(codegen_->GetLabelOf(successor));
2029 }
2030}
2031
David Brazdilfc6a86a2015-06-26 10:33:45 +00002032void LocationsBuilderARM64::VisitGoto(HGoto* got) {
2033 got->SetLocations(nullptr);
2034}
2035
2036void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
2037 HandleGoto(got, got->GetSuccessor());
2038}
2039
2040void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) {
2041 try_boundary->SetLocations(nullptr);
2042}
2043
2044void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) {
2045 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2046 if (!successor->IsExitBlock()) {
2047 HandleGoto(try_boundary, successor);
2048 }
2049}
2050
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07002051void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction,
2052 vixl::Label* true_target,
2053 vixl::Label* false_target,
2054 vixl::Label* always_true_target) {
2055 HInstruction* cond = instruction->InputAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01002056 HCondition* condition = cond->AsCondition();
Alexandre Rames5319def2014-10-23 10:03:10 +01002057
Serban Constantinescu02164b32014-11-13 14:05:07 +00002058 if (cond->IsIntConstant()) {
2059 int32_t cond_value = cond->AsIntConstant()->GetValue();
2060 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07002061 if (always_true_target != nullptr) {
2062 __ B(always_true_target);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002063 }
2064 return;
2065 } else {
2066 DCHECK_EQ(cond_value, 0);
2067 }
2068 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002069 // The condition instruction has been materialized, compare the output to 0.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07002070 Location cond_val = instruction->GetLocations()->InAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01002071 DCHECK(cond_val.IsRegister());
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07002072 __ Cbnz(InputRegisterAt(instruction, 0), true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01002073 } else {
2074 // The condition instruction has not been materialized, use its inputs as
2075 // the comparison and its condition as the branch condition.
2076 Register lhs = InputRegisterAt(condition, 0);
2077 Operand rhs = InputOperandAt(condition, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08002078 Condition arm64_cond = ARM64Condition(condition->GetCondition());
Alexandre Rames4388dcc2015-02-03 10:28:33 +00002079 if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
2080 switch (arm64_cond) {
2081 case eq:
2082 __ Cbz(lhs, true_target);
2083 break;
2084 case ne:
2085 __ Cbnz(lhs, true_target);
2086 break;
2087 case lt:
2088 // Test the sign bit and branch accordingly.
2089 __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
2090 break;
2091 case ge:
2092 // Test the sign bit and branch accordingly.
2093 __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
2094 break;
2095 default:
2096 // Without the `static_cast` the compiler throws an error for
2097 // `-Werror=sign-promo`.
2098 LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01002099 }
2100 } else {
2101 __ Cmp(lhs, rhs);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08002102 __ B(arm64_cond, true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01002103 }
2104 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07002105 if (false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002106 __ B(false_target);
2107 }
2108}
2109
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07002110void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
2111 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
2112 HInstruction* cond = if_instr->InputAt(0);
2113 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
2114 locations->SetInAt(0, Location::RequiresRegister());
2115 }
2116}
2117
2118void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
2119 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
2120 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
2121 vixl::Label* always_true_target = true_target;
2122 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
2123 if_instr->IfTrueSuccessor())) {
2124 always_true_target = nullptr;
2125 }
2126 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
2127 if_instr->IfFalseSuccessor())) {
2128 false_target = nullptr;
2129 }
2130 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
2131}
2132
2133void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
2134 LocationSummary* locations = new (GetGraph()->GetArena())
2135 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
2136 HInstruction* cond = deoptimize->InputAt(0);
2137 DCHECK(cond->IsCondition());
2138 if (cond->AsCondition()->NeedsMaterialization()) {
2139 locations->SetInAt(0, Location::RequiresRegister());
2140 }
2141}
2142
2143void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
2144 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
2145 DeoptimizationSlowPathARM64(deoptimize);
2146 codegen_->AddSlowPath(slow_path);
2147 vixl::Label* slow_path_entry = slow_path->GetEntryLabel();
2148 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
2149}
2150
Alexandre Rames5319def2014-10-23 10:03:10 +01002151void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002152 HandleFieldGet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002153}
2154
2155void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002156 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01002157}
2158
2159void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002160 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002161}
2162
2163void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01002164 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexandre Rames5319def2014-10-23 10:03:10 +01002165}
2166
Alexandre Rames67555f72014-11-18 10:55:16 +00002167void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
2168 LocationSummary::CallKind call_kind =
2169 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
2170 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2171 locations->SetInAt(0, Location::RequiresRegister());
2172 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002173 // The output does overlap inputs.
2174 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexandre Rames67555f72014-11-18 10:55:16 +00002175}
2176
2177void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
2178 LocationSummary* locations = instruction->GetLocations();
2179 Register obj = InputRegisterAt(instruction, 0);;
2180 Register cls = InputRegisterAt(instruction, 1);;
2181 Register out = OutputRegister(instruction);
2182
2183 vixl::Label done;
2184
2185 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01002186 // Avoid null check if we know `obj` is not null.
2187 if (instruction->MustDoNullCheck()) {
2188 __ Mov(out, 0);
2189 __ Cbz(obj, &done);
2190 }
Alexandre Rames67555f72014-11-18 10:55:16 +00002191
2192 // Compare the class of `obj` with `cls`.
Serban Constantinescu02164b32014-11-13 14:05:07 +00002193 __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset()));
Roland Levillain4d027112015-07-01 15:41:14 +01002194 GetAssembler()->MaybeUnpoisonHeapReference(out.W());
Alexandre Rames67555f72014-11-18 10:55:16 +00002195 __ Cmp(out, cls);
2196 if (instruction->IsClassFinal()) {
2197 // Classes must be equal for the instanceof to succeed.
2198 __ Cset(out, eq);
2199 } else {
2200 // If the classes are not equal, we go into a slow path.
2201 DCHECK(locations->OnlyCallsOnSlowPath());
2202 SlowPathCodeARM64* slow_path =
Alexandre Rames3e69f162014-12-10 10:36:50 +00002203 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
2204 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00002205 codegen_->AddSlowPath(slow_path);
2206 __ B(ne, slow_path->GetEntryLabel());
2207 __ Mov(out, 1);
2208 __ Bind(slow_path->GetExitLabel());
2209 }
2210
2211 __ Bind(&done);
2212}
2213
Alexandre Rames5319def2014-10-23 10:03:10 +01002214void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
2215 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2216 locations->SetOut(Location::ConstantLocation(constant));
2217}
2218
2219void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
2220 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002221 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002222}
2223
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00002224void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
2225 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2226 locations->SetOut(Location::ConstantLocation(constant));
2227}
2228
2229void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) {
2230 // Will be generated at use site.
2231 UNUSED(constant);
2232}
2233
Alexandre Rames5319def2014-10-23 10:03:10 +01002234void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01002235 InvokeDexCallingConventionVisitorARM64 calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01002236 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Alexandre Rames5319def2014-10-23 10:03:10 +01002237}
2238
Alexandre Rames67555f72014-11-18 10:55:16 +00002239void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
2240 HandleInvoke(invoke);
2241}
2242
2243void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
2244 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Mathieu Chartiere401d142015-04-22 13:56:20 -07002245 Register temp = XRegisterFrom(invoke->GetLocations()->GetTemp(0));
2246 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
2247 invoke->GetImtIndex() % mirror::Class::kImtSize, kArm64PointerSize).Uint32Value();
Alexandre Rames67555f72014-11-18 10:55:16 +00002248 Location receiver = invoke->GetLocations()->InAt(0);
2249 Offset class_offset = mirror::Object::ClassOffset();
Mathieu Chartiere401d142015-04-22 13:56:20 -07002250 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00002251
2252 // The register ip1 is required to be used for the hidden argument in
2253 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
Alexandre Ramesd921d642015-04-16 15:07:16 +01002254 MacroAssembler* masm = GetVIXLAssembler();
2255 UseScratchRegisterScope scratch_scope(masm);
2256 BlockPoolsScope block_pools(masm);
Alexandre Rames67555f72014-11-18 10:55:16 +00002257 scratch_scope.Exclude(ip1);
2258 __ Mov(ip1, invoke->GetDexMethodIndex());
2259
2260 // temp = object->GetClass();
2261 if (receiver.IsStackSlot()) {
Mathieu Chartiere401d142015-04-22 13:56:20 -07002262 __ Ldr(temp.W(), StackOperandFrom(receiver));
2263 __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset));
Alexandre Rames67555f72014-11-18 10:55:16 +00002264 } else {
Mathieu Chartiere401d142015-04-22 13:56:20 -07002265 __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset));
Alexandre Rames67555f72014-11-18 10:55:16 +00002266 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002267 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01002268 GetAssembler()->MaybeUnpoisonHeapReference(temp.W());
Alexandre Rames67555f72014-11-18 10:55:16 +00002269 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07002270 __ Ldr(temp, MemOperand(temp, method_offset));
Alexandre Rames67555f72014-11-18 10:55:16 +00002271 // lr = temp->GetEntryPoint();
Mathieu Chartiere401d142015-04-22 13:56:20 -07002272 __ Ldr(lr, MemOperand(temp, entry_point.Int32Value()));
Alexandre Rames67555f72014-11-18 10:55:16 +00002273 // lr();
2274 __ Blr(lr);
2275 DCHECK(!codegen_->IsLeafMethod());
2276 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2277}
2278
2279void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08002280 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
2281 if (intrinsic.TryDispatch(invoke)) {
2282 return;
2283 }
2284
Alexandre Rames67555f72014-11-18 10:55:16 +00002285 HandleInvoke(invoke);
2286}
2287
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00002288void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01002289 // When we do not run baseline, explicit clinit checks triggered by static
2290 // invokes must have been pruned by art::PrepareForRegisterAllocation.
2291 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01002292
Andreas Gampe878d58c2015-01-15 23:24:00 -08002293 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
2294 if (intrinsic.TryDispatch(invoke)) {
2295 return;
2296 }
2297
Alexandre Rames67555f72014-11-18 10:55:16 +00002298 HandleInvoke(invoke);
2299}
2300
Andreas Gampe878d58c2015-01-15 23:24:00 -08002301static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
2302 if (invoke->GetLocations()->Intrinsified()) {
2303 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
2304 intrinsic.Dispatch(invoke);
2305 return true;
2306 }
2307 return false;
2308}
2309
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002310void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08002311 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
Mathieu Chartiere401d142015-04-22 13:56:20 -07002312 size_t index_in_cache = GetCachePointerOffset(invoke->GetDexMethodIndex());
Alexandre Rames5319def2014-10-23 10:03:10 +01002313
2314 // TODO: Implement all kinds of calls:
2315 // 1) boot -> boot
2316 // 2) app -> boot
2317 // 3) app -> app
2318 //
2319 // Currently we implement the app -> app logic, which looks up in the resolve cache.
2320
Jeff Hao848f70a2014-01-15 13:49:50 -08002321 if (invoke->IsStringInit()) {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002322 Register reg = XRegisterFrom(temp);
Jeff Hao848f70a2014-01-15 13:49:50 -08002323 // temp = thread->string_init_entrypoint
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002324 __ Ldr(reg.X(), MemOperand(tr, invoke->GetStringInitOffset()));
Jeff Hao848f70a2014-01-15 13:49:50 -08002325 // LR = temp->entry_point_from_quick_compiled_code_;
Mathieu Chartiere401d142015-04-22 13:56:20 -07002326 __ Ldr(lr, MemOperand(
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002327 reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize).Int32Value()));
Jeff Hao848f70a2014-01-15 13:49:50 -08002328 // lr()
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002329 __ Blr(lr);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002330 } else if (invoke->IsRecursive()) {
2331 __ Bl(&frame_entry_label_);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002332 } else {
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01002333 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002334 Register reg = XRegisterFrom(temp);
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01002335 Register method_reg;
2336 if (current_method.IsRegister()) {
2337 method_reg = XRegisterFrom(current_method);
2338 } else {
2339 DCHECK(invoke->GetLocations()->Intrinsified());
2340 DCHECK(!current_method.IsValid());
2341 method_reg = reg;
2342 __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset));
2343 }
2344
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002345 // temp = current_method->dex_cache_resolved_methods_;
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01002346 __ Ldr(reg.W(), MemOperand(method_reg.X(),
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002347 ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()));
2348 // temp = temp[index_in_cache];
2349 __ Ldr(reg.X(), MemOperand(reg, index_in_cache));
2350 // lr = temp->entry_point_from_quick_compiled_code_;
2351 __ Ldr(lr, MemOperand(reg.X(), ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2352 kArm64WordSize).Int32Value()));
2353 // lr();
2354 __ Blr(lr);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002355 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002356
Andreas Gampe878d58c2015-01-15 23:24:00 -08002357 DCHECK(!IsLeafMethod());
2358}
2359
2360void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01002361 // When we do not run baseline, explicit clinit checks triggered by static
2362 // invokes must have been pruned by art::PrepareForRegisterAllocation.
2363 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01002364
Andreas Gampe878d58c2015-01-15 23:24:00 -08002365 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2366 return;
2367 }
2368
Alexandre Ramesd921d642015-04-16 15:07:16 +01002369 BlockPoolsScope block_pools(GetVIXLAssembler());
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002370 LocationSummary* locations = invoke->GetLocations();
2371 codegen_->GenerateStaticOrDirectCall(
2372 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00002373 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01002374}
2375
2376void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08002377 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2378 return;
2379 }
2380
Alexandre Rames5319def2014-10-23 10:03:10 +01002381 LocationSummary* locations = invoke->GetLocations();
2382 Location receiver = locations->InAt(0);
Mathieu Chartiere401d142015-04-22 13:56:20 -07002383 Register temp = XRegisterFrom(invoke->GetLocations()->GetTemp(0));
2384 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
2385 invoke->GetVTableIndex(), kArm64PointerSize).SizeValue();
Alexandre Rames5319def2014-10-23 10:03:10 +01002386 Offset class_offset = mirror::Object::ClassOffset();
Mathieu Chartiere401d142015-04-22 13:56:20 -07002387 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames5319def2014-10-23 10:03:10 +01002388
Alexandre Ramesd921d642015-04-16 15:07:16 +01002389 BlockPoolsScope block_pools(GetVIXLAssembler());
2390
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002391 DCHECK(receiver.IsRegister());
2392 __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00002393 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain4d027112015-07-01 15:41:14 +01002394 GetAssembler()->MaybeUnpoisonHeapReference(temp.W());
Alexandre Rames5319def2014-10-23 10:03:10 +01002395 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07002396 __ Ldr(temp, MemOperand(temp, method_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002397 // lr = temp->GetEntryPoint();
Mathieu Chartiere401d142015-04-22 13:56:20 -07002398 __ Ldr(lr, MemOperand(temp, entry_point.SizeValue()));
Alexandre Rames5319def2014-10-23 10:03:10 +01002399 // lr();
2400 __ Blr(lr);
2401 DCHECK(!codegen_->IsLeafMethod());
2402 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2403}
2404
Alexandre Rames67555f72014-11-18 10:55:16 +00002405void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
2406 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2407 : LocationSummary::kNoCall;
2408 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002409 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002410 locations->SetOut(Location::RequiresRegister());
2411}
2412
2413void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
2414 Register out = OutputRegister(cls);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002415 Register current_method = InputRegisterAt(cls, 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00002416 if (cls->IsReferrersClass()) {
2417 DCHECK(!cls->CanCallRuntime());
2418 DCHECK(!cls->MustGenerateClinitCheck());
Mathieu Chartiere401d142015-04-22 13:56:20 -07002419 __ Ldr(out, MemOperand(current_method, ArtMethod::DeclaringClassOffset().Int32Value()));
Alexandre Rames67555f72014-11-18 10:55:16 +00002420 } else {
2421 DCHECK(cls->CanCallRuntime());
Mathieu Chartiere401d142015-04-22 13:56:20 -07002422 __ Ldr(out, MemOperand(current_method, ArtMethod::DexCacheResolvedTypesOffset().Int32Value()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002423 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Roland Levillain4d027112015-07-01 15:41:14 +01002424 GetAssembler()->MaybeUnpoisonHeapReference(out.W());
Alexandre Rames67555f72014-11-18 10:55:16 +00002425
2426 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2427 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2428 codegen_->AddSlowPath(slow_path);
2429 __ Cbz(out, slow_path->GetEntryLabel());
2430 if (cls->MustGenerateClinitCheck()) {
2431 GenerateClassInitializationCheck(slow_path, out);
2432 } else {
2433 __ Bind(slow_path->GetExitLabel());
2434 }
2435 }
2436}
2437
2438void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
2439 LocationSummary* locations =
2440 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2441 locations->SetOut(Location::RequiresRegister());
2442}
2443
2444void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
2445 MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value());
2446 __ Ldr(OutputRegister(instruction), exception);
2447 __ Str(wzr, exception);
2448}
2449
Alexandre Rames5319def2014-10-23 10:03:10 +01002450void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
2451 load->SetLocations(nullptr);
2452}
2453
2454void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
2455 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002456 UNUSED(load);
Alexandre Rames5319def2014-10-23 10:03:10 +01002457}
2458
Alexandre Rames67555f72014-11-18 10:55:16 +00002459void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
2460 LocationSummary* locations =
2461 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01002462 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002463 locations->SetOut(Location::RequiresRegister());
2464}
2465
2466void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
2467 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load);
2468 codegen_->AddSlowPath(slow_path);
2469
2470 Register out = OutputRegister(load);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01002471 Register current_method = InputRegisterAt(load, 0);
Mathieu Chartiere401d142015-04-22 13:56:20 -07002472 __ Ldr(out, MemOperand(current_method, ArtMethod::DeclaringClassOffset().Int32Value()));
Mathieu Chartiereace4582014-11-24 18:29:54 -08002473 __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset()));
Roland Levillain4d027112015-07-01 15:41:14 +01002474 GetAssembler()->MaybeUnpoisonHeapReference(out.W());
Serban Constantinescu02164b32014-11-13 14:05:07 +00002475 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
Roland Levillain4d027112015-07-01 15:41:14 +01002476 GetAssembler()->MaybeUnpoisonHeapReference(out.W());
Alexandre Rames67555f72014-11-18 10:55:16 +00002477 __ Cbz(out, slow_path->GetEntryLabel());
2478 __ Bind(slow_path->GetExitLabel());
2479}
2480
Alexandre Rames5319def2014-10-23 10:03:10 +01002481void LocationsBuilderARM64::VisitLocal(HLocal* local) {
2482 local->SetLocations(nullptr);
2483}
2484
2485void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
2486 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2487}
2488
2489void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
2490 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2491 locations->SetOut(Location::ConstantLocation(constant));
2492}
2493
2494void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
2495 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002496 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002497}
2498
Alexandre Rames67555f72014-11-18 10:55:16 +00002499void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2500 LocationSummary* locations =
2501 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2502 InvokeRuntimeCallingConvention calling_convention;
2503 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2504}
2505
2506void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2507 codegen_->InvokeRuntime(instruction->IsEnter()
2508 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2509 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002510 instruction->GetDexPc(),
2511 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002512 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002513}
2514
Alexandre Rames42d641b2014-10-27 14:00:51 +00002515void LocationsBuilderARM64::VisitMul(HMul* mul) {
2516 LocationSummary* locations =
2517 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2518 switch (mul->GetResultType()) {
2519 case Primitive::kPrimInt:
2520 case Primitive::kPrimLong:
2521 locations->SetInAt(0, Location::RequiresRegister());
2522 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002523 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002524 break;
2525
2526 case Primitive::kPrimFloat:
2527 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002528 locations->SetInAt(0, Location::RequiresFpuRegister());
2529 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002530 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002531 break;
2532
2533 default:
2534 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2535 }
2536}
2537
2538void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
2539 switch (mul->GetResultType()) {
2540 case Primitive::kPrimInt:
2541 case Primitive::kPrimLong:
2542 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
2543 break;
2544
2545 case Primitive::kPrimFloat:
2546 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002547 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00002548 break;
2549
2550 default:
2551 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2552 }
2553}
2554
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002555void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
2556 LocationSummary* locations =
2557 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2558 switch (neg->GetResultType()) {
2559 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00002560 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002561 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00002562 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002563 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002564
2565 case Primitive::kPrimFloat:
2566 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002567 locations->SetInAt(0, Location::RequiresFpuRegister());
2568 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002569 break;
2570
2571 default:
2572 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2573 }
2574}
2575
2576void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
2577 switch (neg->GetResultType()) {
2578 case Primitive::kPrimInt:
2579 case Primitive::kPrimLong:
2580 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
2581 break;
2582
2583 case Primitive::kPrimFloat:
2584 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002585 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002586 break;
2587
2588 default:
2589 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2590 }
2591}
2592
2593void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
2594 LocationSummary* locations =
2595 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2596 InvokeRuntimeCallingConvention calling_convention;
2597 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002598 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002599 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002600 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002601 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
Mathieu Chartiere401d142015-04-22 13:56:20 -07002602 void*, uint32_t, int32_t, ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002603}
2604
2605void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
2606 LocationSummary* locations = instruction->GetLocations();
2607 InvokeRuntimeCallingConvention calling_convention;
2608 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2609 DCHECK(type_index.Is(w0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002610 __ Mov(type_index, instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01002611 // Note: if heap poisoning is enabled, the entry point takes cares
2612 // of poisoning the reference.
Alexandre Rames67555f72014-11-18 10:55:16 +00002613 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002614 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2615 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002616 instruction->GetDexPc(),
2617 nullptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -07002618 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002619}
2620
Alexandre Rames5319def2014-10-23 10:03:10 +01002621void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
2622 LocationSummary* locations =
2623 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2624 InvokeRuntimeCallingConvention calling_convention;
2625 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002626 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
Alexandre Rames5319def2014-10-23 10:03:10 +01002627 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Mathieu Chartiere401d142015-04-22 13:56:20 -07002628 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002629}
2630
2631void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
2632 LocationSummary* locations = instruction->GetLocations();
2633 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2634 DCHECK(type_index.Is(w0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002635 __ Mov(type_index, instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01002636 // Note: if heap poisoning is enabled, the entry point takes cares
2637 // of poisoning the reference.
Alexandre Rames67555f72014-11-18 10:55:16 +00002638 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002639 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2640 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002641 instruction->GetDexPc(),
2642 nullptr);
Mathieu Chartiere401d142015-04-22 13:56:20 -07002643 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002644}
2645
2646void LocationsBuilderARM64::VisitNot(HNot* instruction) {
2647 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00002648 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002649 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002650}
2651
2652void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002653 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002654 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002655 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01002656 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002657 break;
2658
2659 default:
2660 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2661 }
2662}
2663
David Brazdil66d126e2015-04-03 16:02:44 +01002664void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) {
2665 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2666 locations->SetInAt(0, Location::RequiresRegister());
2667 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2668}
2669
2670void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) {
David Brazdil66d126e2015-04-03 16:02:44 +01002671 __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1));
2672}
2673
Alexandre Rames5319def2014-10-23 10:03:10 +01002674void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
2675 LocationSummary* locations =
2676 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2677 locations->SetInAt(0, Location::RequiresRegister());
2678 if (instruction->HasUses()) {
2679 locations->SetOut(Location::SameAsFirstInput());
2680 }
2681}
2682
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002683void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002684 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2685 return;
2686 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002687
Alexandre Ramesd921d642015-04-16 15:07:16 +01002688 BlockPoolsScope block_pools(GetVIXLAssembler());
2689 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002690 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
2691 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2692}
2693
2694void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002695 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
2696 codegen_->AddSlowPath(slow_path);
2697
2698 LocationSummary* locations = instruction->GetLocations();
2699 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002700
2701 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01002702}
2703
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002704void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
2705 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2706 GenerateImplicitNullCheck(instruction);
2707 } else {
2708 GenerateExplicitNullCheck(instruction);
2709 }
2710}
2711
Alexandre Rames67555f72014-11-18 10:55:16 +00002712void LocationsBuilderARM64::VisitOr(HOr* instruction) {
2713 HandleBinaryOp(instruction);
2714}
2715
2716void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
2717 HandleBinaryOp(instruction);
2718}
2719
Alexandre Rames3e69f162014-12-10 10:36:50 +00002720void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2721 LOG(FATAL) << "Unreachable";
2722}
2723
2724void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
2725 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2726}
2727
Alexandre Rames5319def2014-10-23 10:03:10 +01002728void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
2729 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2730 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2731 if (location.IsStackSlot()) {
2732 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2733 } else if (location.IsDoubleStackSlot()) {
2734 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2735 }
2736 locations->SetOut(location);
2737}
2738
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002739void InstructionCodeGeneratorARM64::VisitParameterValue(
2740 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002741 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002742}
2743
2744void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) {
2745 LocationSummary* locations =
2746 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01002747 locations->SetOut(LocationFrom(kArtMethodRegister));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002748}
2749
2750void InstructionCodeGeneratorARM64::VisitCurrentMethod(
2751 HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2752 // Nothing to do, the method is already at its location.
Alexandre Rames5319def2014-10-23 10:03:10 +01002753}
2754
2755void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
2756 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2757 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2758 locations->SetInAt(i, Location::Any());
2759 }
2760 locations->SetOut(Location::Any());
2761}
2762
2763void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002764 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002765 LOG(FATAL) << "Unreachable";
2766}
2767
Serban Constantinescu02164b32014-11-13 14:05:07 +00002768void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002769 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00002770 LocationSummary::CallKind call_kind =
2771 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002772 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2773
2774 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002775 case Primitive::kPrimInt:
2776 case Primitive::kPrimLong:
2777 locations->SetInAt(0, Location::RequiresRegister());
Zheng Xuc6667102015-05-15 16:08:45 +08002778 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002779 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2780 break;
2781
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002782 case Primitive::kPrimFloat:
2783 case Primitive::kPrimDouble: {
2784 InvokeRuntimeCallingConvention calling_convention;
2785 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
2786 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
2787 locations->SetOut(calling_convention.GetReturnLocation(type));
2788
2789 break;
2790 }
2791
Serban Constantinescu02164b32014-11-13 14:05:07 +00002792 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002793 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00002794 }
2795}
2796
2797void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
2798 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002799
Serban Constantinescu02164b32014-11-13 14:05:07 +00002800 switch (type) {
2801 case Primitive::kPrimInt:
2802 case Primitive::kPrimLong: {
Zheng Xuc6667102015-05-15 16:08:45 +08002803 GenerateDivRemIntegral(rem);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002804 break;
2805 }
2806
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002807 case Primitive::kPrimFloat:
2808 case Primitive::kPrimDouble: {
2809 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2810 : QUICK_ENTRY_POINT(pFmod);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002811 codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002812 break;
2813 }
2814
Serban Constantinescu02164b32014-11-13 14:05:07 +00002815 default:
2816 LOG(FATAL) << "Unexpected rem type " << type;
2817 }
2818}
2819
Calin Juravle27df7582015-04-17 19:12:31 +01002820void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
2821 memory_barrier->SetLocations(nullptr);
2822}
2823
2824void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
2825 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
2826}
2827
Alexandre Rames5319def2014-10-23 10:03:10 +01002828void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
2829 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2830 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002831 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01002832}
2833
2834void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002835 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002836 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002837}
2838
2839void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
2840 instruction->SetLocations(nullptr);
2841}
2842
2843void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002844 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002845 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002846}
2847
Serban Constantinescu02164b32014-11-13 14:05:07 +00002848void LocationsBuilderARM64::VisitShl(HShl* shl) {
2849 HandleShift(shl);
2850}
2851
2852void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
2853 HandleShift(shl);
2854}
2855
2856void LocationsBuilderARM64::VisitShr(HShr* shr) {
2857 HandleShift(shr);
2858}
2859
2860void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
2861 HandleShift(shr);
2862}
2863
Alexandre Rames5319def2014-10-23 10:03:10 +01002864void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
2865 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2866 Primitive::Type field_type = store->InputAt(1)->GetType();
2867 switch (field_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002868 case Primitive::kPrimNot:
Alexandre Rames5319def2014-10-23 10:03:10 +01002869 case Primitive::kPrimBoolean:
2870 case Primitive::kPrimByte:
2871 case Primitive::kPrimChar:
2872 case Primitive::kPrimShort:
2873 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002874 case Primitive::kPrimFloat:
Alexandre Rames5319def2014-10-23 10:03:10 +01002875 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2876 break;
2877
2878 case Primitive::kPrimLong:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002879 case Primitive::kPrimDouble:
Alexandre Rames5319def2014-10-23 10:03:10 +01002880 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2881 break;
2882
2883 default:
2884 LOG(FATAL) << "Unimplemented local type " << field_type;
2885 }
2886}
2887
2888void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002889 UNUSED(store);
Alexandre Rames5319def2014-10-23 10:03:10 +01002890}
2891
2892void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002893 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002894}
2895
2896void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002897 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002898}
2899
Alexandre Rames67555f72014-11-18 10:55:16 +00002900void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002901 HandleFieldGet(instruction);
Alexandre Rames67555f72014-11-18 10:55:16 +00002902}
2903
2904void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002905 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames67555f72014-11-18 10:55:16 +00002906}
2907
2908void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002909 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002910}
2911
Alexandre Rames67555f72014-11-18 10:55:16 +00002912void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01002913 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexandre Rames5319def2014-10-23 10:03:10 +01002914}
2915
2916void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
2917 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2918}
2919
2920void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002921 HBasicBlock* block = instruction->GetBlock();
2922 if (block->GetLoopInformation() != nullptr) {
2923 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2924 // The back edge will generate the suspend check.
2925 return;
2926 }
2927 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2928 // The goto will generate the suspend check.
2929 return;
2930 }
2931 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01002932}
2933
2934void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
2935 temp->SetLocations(nullptr);
2936}
2937
2938void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
2939 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002940 UNUSED(temp);
Alexandre Rames5319def2014-10-23 10:03:10 +01002941}
2942
Alexandre Rames67555f72014-11-18 10:55:16 +00002943void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
2944 LocationSummary* locations =
2945 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2946 InvokeRuntimeCallingConvention calling_convention;
2947 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2948}
2949
2950void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
2951 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002952 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002953 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002954}
2955
2956void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
2957 LocationSummary* locations =
2958 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
2959 Primitive::Type input_type = conversion->GetInputType();
2960 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002961 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00002962 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
2963 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
2964 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
2965 }
2966
Alexandre Rames542361f2015-01-29 16:57:31 +00002967 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002968 locations->SetInAt(0, Location::RequiresFpuRegister());
2969 } else {
2970 locations->SetInAt(0, Location::RequiresRegister());
2971 }
2972
Alexandre Rames542361f2015-01-29 16:57:31 +00002973 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002974 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2975 } else {
2976 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2977 }
2978}
2979
2980void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
2981 Primitive::Type result_type = conversion->GetResultType();
2982 Primitive::Type input_type = conversion->GetInputType();
2983
2984 DCHECK_NE(input_type, result_type);
2985
Alexandre Rames542361f2015-01-29 16:57:31 +00002986 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002987 int result_size = Primitive::ComponentSize(result_type);
2988 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002989 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002990 Register output = OutputRegister(conversion);
2991 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002992 if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) {
2993 __ Ubfx(output, source, 0, result_size * kBitsPerByte);
2994 } else if ((result_type == Primitive::kPrimChar) ||
2995 ((input_type == Primitive::kPrimChar) && (result_size > input_size))) {
2996 __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002997 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00002998 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002999 }
Alexandre Rames542361f2015-01-29 16:57:31 +00003000 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00003001 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00003002 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00003003 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
3004 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00003005 } else if (Primitive::IsFloatingPointType(result_type) &&
3006 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00003007 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
3008 } else {
3009 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
3010 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00003011 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00003012}
Alexandre Rames67555f72014-11-18 10:55:16 +00003013
Serban Constantinescu02164b32014-11-13 14:05:07 +00003014void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
3015 HandleShift(ushr);
3016}
3017
3018void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
3019 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00003020}
3021
3022void LocationsBuilderARM64::VisitXor(HXor* instruction) {
3023 HandleBinaryOp(instruction);
3024}
3025
3026void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
3027 HandleBinaryOp(instruction);
3028}
3029
Calin Juravleb1498f62015-02-16 13:13:29 +00003030void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) {
3031 // Nothing to do, this should be removed during prepare for register allocator.
3032 UNUSED(instruction);
3033 LOG(FATAL) << "Unreachable";
3034}
3035
3036void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) {
3037 // Nothing to do, this should be removed during prepare for register allocator.
3038 UNUSED(instruction);
3039 LOG(FATAL) << "Unreachable";
3040}
3041
Alexandre Rames67555f72014-11-18 10:55:16 +00003042#undef __
3043#undef QUICK_ENTRY_POINT
3044
Alexandre Rames5319def2014-10-23 10:03:10 +01003045} // namespace arm64
3046} // namespace art