blob: ef4e511daddfb4f2147e3f46cf1ad8de767fd7b0 [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"
Vladimir Marko58155012015-08-19 12:49:41 +000022#include "compiled_method.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
Scott Wakeling97c72b72016-06-24 16:19:36 +010036using namespace vixl::aarch64; // NOLINT(build/namespaces)
Alexandre Rames5319def2014-10-23 10:03:10 +010037
38#ifdef __
39#error "ARM64 Codegen VIXL macro-assembler macro already defined."
40#endif
41
Alexandre Rames5319def2014-10-23 10:03:10 +010042namespace art {
43
Roland Levillain22ccc3a2015-11-24 13:10:05 +000044template<class MirrorType>
45class GcRoot;
46
Alexandre Rames5319def2014-10-23 10:03:10 +010047namespace arm64 {
48
Alexandre Ramesbe919d92016-08-23 18:33:36 +010049using helpers::ARM64EncodableConstantOrRegister;
50using helpers::ArtVixlRegCodeCoherentForRegSet;
Andreas Gampe878d58c2015-01-15 23:24:00 -080051using helpers::CPURegisterFrom;
52using helpers::DRegisterFrom;
53using helpers::FPRegisterFrom;
54using helpers::HeapOperand;
55using helpers::HeapOperandFrom;
56using helpers::InputCPURegisterAt;
Alexandre Ramesbe919d92016-08-23 18:33:36 +010057using helpers::InputCPURegisterOrZeroRegAt;
Andreas Gampe878d58c2015-01-15 23:24:00 -080058using helpers::InputFPRegisterAt;
Andreas Gampe878d58c2015-01-15 23:24:00 -080059using helpers::InputOperandAt;
Alexandre Ramesbe919d92016-08-23 18:33:36 +010060using helpers::InputRegisterAt;
Andreas Gampe878d58c2015-01-15 23:24:00 -080061using helpers::Int64ConstantFrom;
Alexandre Ramesbe919d92016-08-23 18:33:36 +010062using helpers::IsConstantZeroBitPattern;
Andreas Gampe878d58c2015-01-15 23:24:00 -080063using helpers::LocationFrom;
64using helpers::OperandFromMemOperand;
65using helpers::OutputCPURegister;
66using helpers::OutputFPRegister;
67using helpers::OutputRegister;
68using helpers::RegisterFrom;
69using helpers::StackOperandFrom;
70using helpers::VIXLRegCodeFromART;
71using helpers::WRegisterFrom;
72using helpers::XRegisterFrom;
73
Alexandre Rames5319def2014-10-23 10:03:10 +010074static constexpr int kCurrentMethodStackOffset = 0;
Vladimir Markof3e0ee22015-12-17 15:23:13 +000075// The compare/jump sequence will generate about (1.5 * num_entries + 3) instructions. While jump
Zheng Xu3927c8b2015-11-18 17:46:25 +080076// table version generates 7 instructions and num_entries literals. Compare/jump sequence will
77// generates less code/data with a small num_entries.
Vladimir Markof3e0ee22015-12-17 15:23:13 +000078static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7;
Alexandre Rames5319def2014-10-23 10:03:10 +010079
Alexandre Rames5319def2014-10-23 10:03:10 +010080inline Condition ARM64Condition(IfCondition cond) {
81 switch (cond) {
82 case kCondEQ: return eq;
83 case kCondNE: return ne;
84 case kCondLT: return lt;
85 case kCondLE: return le;
86 case kCondGT: return gt;
87 case kCondGE: return ge;
Aart Bike9f37602015-10-09 11:15:55 -070088 case kCondB: return lo;
89 case kCondBE: return ls;
90 case kCondA: return hi;
91 case kCondAE: return hs;
Alexandre Rames5319def2014-10-23 10:03:10 +010092 }
Roland Levillain7f63c522015-07-13 15:54:55 +000093 LOG(FATAL) << "Unreachable";
94 UNREACHABLE();
Alexandre Rames5319def2014-10-23 10:03:10 +010095}
96
Vladimir Markod6e069b2016-01-18 11:11:01 +000097inline Condition ARM64FPCondition(IfCondition cond, bool gt_bias) {
98 // The ARM64 condition codes can express all the necessary branches, see the
99 // "Meaning (floating-point)" column in the table C1-1 in the ARMv8 reference manual.
100 // There is no dex instruction or HIR that would need the missing conditions
101 // "equal or unordered" or "not equal".
102 switch (cond) {
103 case kCondEQ: return eq;
104 case kCondNE: return ne /* unordered */;
105 case kCondLT: return gt_bias ? cc : lt /* unordered */;
106 case kCondLE: return gt_bias ? ls : le /* unordered */;
107 case kCondGT: return gt_bias ? hi /* unordered */ : gt;
108 case kCondGE: return gt_bias ? cs /* unordered */ : ge;
109 default:
110 LOG(FATAL) << "UNREACHABLE";
111 UNREACHABLE();
112 }
113}
114
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000115Location ARM64ReturnLocation(Primitive::Type return_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000116 // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the
117 // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`,
118 // but we use the exact registers for clarity.
119 if (return_type == Primitive::kPrimFloat) {
120 return LocationFrom(s0);
121 } else if (return_type == Primitive::kPrimDouble) {
122 return LocationFrom(d0);
123 } else if (return_type == Primitive::kPrimLong) {
124 return LocationFrom(x0);
Nicolas Geoffray925e5622015-06-03 12:23:32 +0100125 } else if (return_type == Primitive::kPrimVoid) {
126 return Location::NoLocation();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000127 } else {
128 return LocationFrom(w0);
129 }
130}
131
Alexandre Rames5319def2014-10-23 10:03:10 +0100132Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000133 return ARM64ReturnLocation(return_type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100134}
135
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100136// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
137#define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700138#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, x).Int32Value()
Alexandre Rames5319def2014-10-23 10:03:10 +0100139
Zheng Xuda403092015-04-24 17:35:39 +0800140// Calculate memory accessing operand for save/restore live registers.
141static void SaveRestoreLiveRegistersHelper(CodeGenerator* codegen,
Vladimir Marko804b03f2016-09-14 16:26:36 +0100142 LocationSummary* locations,
Zheng Xuda403092015-04-24 17:35:39 +0800143 int64_t spill_offset,
144 bool is_save) {
Vladimir Marko804b03f2016-09-14 16:26:36 +0100145 const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true);
146 const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false);
147 DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spills,
Zheng Xuda403092015-04-24 17:35:39 +0800148 codegen->GetNumberOfCoreRegisters(),
Vladimir Marko804b03f2016-09-14 16:26:36 +0100149 fp_spills,
Zheng Xuda403092015-04-24 17:35:39 +0800150 codegen->GetNumberOfFloatingPointRegisters()));
151
Vladimir Marko804b03f2016-09-14 16:26:36 +0100152 CPURegList core_list = CPURegList(CPURegister::kRegister, kXRegSize, core_spills);
153 CPURegList fp_list = CPURegList(CPURegister::kFPRegister, kDRegSize, fp_spills);
Zheng Xuda403092015-04-24 17:35:39 +0800154
155 MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler();
156 UseScratchRegisterScope temps(masm);
157
158 Register base = masm->StackPointer();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100159 int64_t core_spill_size = core_list.GetTotalSizeInBytes();
160 int64_t fp_spill_size = fp_list.GetTotalSizeInBytes();
Zheng Xuda403092015-04-24 17:35:39 +0800161 int64_t reg_size = kXRegSizeInBytes;
162 int64_t max_ls_pair_offset = spill_offset + core_spill_size + fp_spill_size - 2 * reg_size;
163 uint32_t ls_access_size = WhichPowerOf2(reg_size);
Scott Wakeling97c72b72016-06-24 16:19:36 +0100164 if (((core_list.GetCount() > 1) || (fp_list.GetCount() > 1)) &&
Zheng Xuda403092015-04-24 17:35:39 +0800165 !masm->IsImmLSPair(max_ls_pair_offset, ls_access_size)) {
166 // If the offset does not fit in the instruction's immediate field, use an alternate register
167 // to compute the base address(float point registers spill base address).
168 Register new_base = temps.AcquireSameSizeAs(base);
169 __ Add(new_base, base, Operand(spill_offset + core_spill_size));
170 base = new_base;
171 spill_offset = -core_spill_size;
172 int64_t new_max_ls_pair_offset = fp_spill_size - 2 * reg_size;
173 DCHECK(masm->IsImmLSPair(spill_offset, ls_access_size));
174 DCHECK(masm->IsImmLSPair(new_max_ls_pair_offset, ls_access_size));
175 }
176
177 if (is_save) {
178 __ StoreCPURegList(core_list, MemOperand(base, spill_offset));
179 __ StoreCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size));
180 } else {
181 __ LoadCPURegList(core_list, MemOperand(base, spill_offset));
182 __ LoadCPURegList(fp_list, MemOperand(base, spill_offset + core_spill_size));
183 }
184}
185
186void SlowPathCodeARM64::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
Zheng Xuda403092015-04-24 17:35:39 +0800187 size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath();
Vladimir Marko804b03f2016-09-14 16:26:36 +0100188 const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ true);
189 for (uint32_t i : LowToHighBits(core_spills)) {
190 // If the register holds an object, update the stack mask.
191 if (locations->RegisterContainsObject(i)) {
192 locations->SetStackBit(stack_offset / kVRegSize);
Zheng Xuda403092015-04-24 17:35:39 +0800193 }
Vladimir Marko804b03f2016-09-14 16:26:36 +0100194 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
195 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
196 saved_core_stack_offsets_[i] = stack_offset;
197 stack_offset += kXRegSizeInBytes;
Zheng Xuda403092015-04-24 17:35:39 +0800198 }
199
Vladimir Marko804b03f2016-09-14 16:26:36 +0100200 const uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers */ false);
201 for (uint32_t i : LowToHighBits(fp_spills)) {
202 DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize());
203 DCHECK_LT(i, kMaximumNumberOfExpectedRegisters);
204 saved_fpu_stack_offsets_[i] = stack_offset;
205 stack_offset += kDRegSizeInBytes;
Zheng Xuda403092015-04-24 17:35:39 +0800206 }
207
Vladimir Marko804b03f2016-09-14 16:26:36 +0100208 SaveRestoreLiveRegistersHelper(codegen,
209 locations,
Zheng Xuda403092015-04-24 17:35:39 +0800210 codegen->GetFirstRegisterSlotInSlowPath(), true /* is_save */);
211}
212
213void SlowPathCodeARM64::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) {
Vladimir Marko804b03f2016-09-14 16:26:36 +0100214 SaveRestoreLiveRegistersHelper(codegen,
215 locations,
Zheng Xuda403092015-04-24 17:35:39 +0800216 codegen->GetFirstRegisterSlotInSlowPath(), false /* is_save */);
217}
218
Alexandre Rames5319def2014-10-23 10:03:10 +0100219class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 {
220 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000221 explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction) : SlowPathCodeARM64(instruction) {}
Alexandre Rames5319def2014-10-23 10:03:10 +0100222
Alexandre Rames67555f72014-11-18 10:55:16 +0000223 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100224 LocationSummary* locations = instruction_->GetLocations();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000225 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100226
Alexandre Rames5319def2014-10-23 10:03:10 +0100227 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000228 if (instruction_->CanThrowIntoCatchBlock()) {
229 // Live registers will be restored in the catch block if caught.
230 SaveLiveRegisters(codegen, instruction_->GetLocations());
231 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000232 // We're moving two locations to locations that could overlap, so we need a parallel
233 // move resolver.
234 InvokeRuntimeCallingConvention calling_convention;
235 codegen->EmitParallelMoves(
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100236 locations->InAt(0), LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt,
237 locations->InAt(1), LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt);
Serban Constantinescu22f81d32016-02-18 16:06:31 +0000238 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
239 ? kQuickThrowStringBounds
240 : kQuickThrowArrayBounds;
241 arm64_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100242 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800243 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100244 }
245
Alexandre Rames8158f282015-08-07 10:26:17 +0100246 bool IsFatal() const OVERRIDE { return true; }
247
Alexandre Rames9931f312015-06-19 14:47:01 +0100248 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathARM64"; }
249
Alexandre Rames5319def2014-10-23 10:03:10 +0100250 private:
Alexandre Rames5319def2014-10-23 10:03:10 +0100251 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64);
252};
253
Alexandre Rames67555f72014-11-18 10:55:16 +0000254class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 {
255 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000256 explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : SlowPathCodeARM64(instruction) {}
Alexandre Rames67555f72014-11-18 10:55:16 +0000257
258 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
259 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
260 __ Bind(GetEntryLabel());
Serban Constantinescu22f81d32016-02-18 16:06:31 +0000261 arm64_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800262 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000263 }
264
Alexandre Rames8158f282015-08-07 10:26:17 +0100265 bool IsFatal() const OVERRIDE { return true; }
266
Alexandre Rames9931f312015-06-19 14:47:01 +0100267 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathARM64"; }
268
Alexandre Rames67555f72014-11-18 10:55:16 +0000269 private:
Alexandre Rames67555f72014-11-18 10:55:16 +0000270 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64);
271};
272
273class LoadClassSlowPathARM64 : public SlowPathCodeARM64 {
274 public:
275 LoadClassSlowPathARM64(HLoadClass* cls,
276 HInstruction* at,
277 uint32_t dex_pc,
278 bool do_clinit)
David Srbecky9cd6d372016-02-09 15:24:47 +0000279 : SlowPathCodeARM64(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000280 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
281 }
282
283 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
284 LocationSummary* locations = at_->GetLocations();
285 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
286
287 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000288 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000289
290 InvokeRuntimeCallingConvention calling_convention;
291 __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex());
Serban Constantinescu22f81d32016-02-18 16:06:31 +0000292 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
293 : kQuickInitializeType;
294 arm64_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800295 if (do_clinit_) {
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100296 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800297 } else {
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100298 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800299 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000300
301 // Move the class to the desired location.
302 Location out = locations->Out();
303 if (out.IsValid()) {
304 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
305 Primitive::Type type = at_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000306 arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000307 }
308
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000309 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000310 __ B(GetExitLabel());
311 }
312
Alexandre Rames9931f312015-06-19 14:47:01 +0100313 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathARM64"; }
314
Alexandre Rames67555f72014-11-18 10:55:16 +0000315 private:
316 // The class this slow path will load.
317 HLoadClass* const cls_;
318
319 // The instruction where this slow path is happening.
320 // (Might be the load class or an initialization check).
321 HInstruction* const at_;
322
323 // The dex PC of `at_`.
324 const uint32_t dex_pc_;
325
326 // Whether to initialize the class.
327 const bool do_clinit_;
328
329 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64);
330};
331
Vladimir Markoaad75c62016-10-03 08:46:48 +0000332class LoadStringSlowPathARM64 : public SlowPathCodeARM64 {
333 public:
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100334 LoadStringSlowPathARM64(HLoadString* instruction, Register temp, vixl::aarch64::Label* adrp_label)
335 : SlowPathCodeARM64(instruction),
336 temp_(temp),
337 adrp_label_(adrp_label) {}
Vladimir Markoaad75c62016-10-03 08:46:48 +0000338
339 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
340 LocationSummary* locations = instruction_->GetLocations();
341 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
342 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
343
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100344 // temp_ is a scratch register. Make sure it's not used for saving/restoring registers.
345 UseScratchRegisterScope temps(arm64_codegen->GetVIXLAssembler());
346 temps.Exclude(temp_);
347
Vladimir Markoaad75c62016-10-03 08:46:48 +0000348 __ Bind(GetEntryLabel());
349 SaveLiveRegisters(codegen, locations);
350
351 InvokeRuntimeCallingConvention calling_convention;
352 const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex();
353 __ Mov(calling_convention.GetRegisterAt(0).W(), string_index);
354 arm64_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this);
355 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
356 Primitive::Type type = instruction_->GetType();
357 arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type);
358
359 RestoreLiveRegisters(codegen, locations);
360
361 // Store the resolved String to the BSS entry.
Vladimir Markoaad75c62016-10-03 08:46:48 +0000362 const DexFile& dex_file = instruction_->AsLoadString()->GetDexFile();
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100363 if (!kUseReadBarrier || kUseBakerReadBarrier) {
364 // The string entry page address was preserved in temp_ thanks to kSaveEverything.
365 } else {
366 // For non-Baker read barrier, we need to re-calculate the address of the string entry page.
367 adrp_label_ = arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index);
368 arm64_codegen->EmitAdrpPlaceholder(adrp_label_, temp_);
369 }
Vladimir Markoaad75c62016-10-03 08:46:48 +0000370 vixl::aarch64::Label* strp_label =
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100371 arm64_codegen->NewPcRelativeStringPatch(dex_file, string_index, adrp_label_);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000372 {
373 SingleEmissionCheckScope guard(arm64_codegen->GetVIXLAssembler());
374 __ Bind(strp_label);
375 __ str(RegisterFrom(locations->Out(), Primitive::kPrimNot),
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100376 MemOperand(temp_, /* offset placeholder */ 0));
Vladimir Markoaad75c62016-10-03 08:46:48 +0000377 }
378
379 __ B(GetExitLabel());
380 }
381
382 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathARM64"; }
383
384 private:
Vladimir Marko94ce9c22016-09-30 14:50:51 +0100385 const Register temp_;
386 vixl::aarch64::Label* adrp_label_;
387
Vladimir Markoaad75c62016-10-03 08:46:48 +0000388 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64);
389};
390
Alexandre Rames5319def2014-10-23 10:03:10 +0100391class NullCheckSlowPathARM64 : public SlowPathCodeARM64 {
392 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000393 explicit NullCheckSlowPathARM64(HNullCheck* instr) : SlowPathCodeARM64(instr) {}
Alexandre Rames5319def2014-10-23 10:03:10 +0100394
Alexandre Rames67555f72014-11-18 10:55:16 +0000395 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
396 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100397 __ Bind(GetEntryLabel());
David Brazdil77a48ae2015-09-15 12:34:04 +0000398 if (instruction_->CanThrowIntoCatchBlock()) {
399 // Live registers will be restored in the catch block if caught.
400 SaveLiveRegisters(codegen, instruction_->GetLocations());
401 }
Serban Constantinescu22f81d32016-02-18 16:06:31 +0000402 arm64_codegen->InvokeRuntime(kQuickThrowNullPointer,
403 instruction_,
404 instruction_->GetDexPc(),
405 this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800406 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100407 }
408
Alexandre Rames8158f282015-08-07 10:26:17 +0100409 bool IsFatal() const OVERRIDE { return true; }
410
Alexandre Rames9931f312015-06-19 14:47:01 +0100411 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathARM64"; }
412
Alexandre Rames5319def2014-10-23 10:03:10 +0100413 private:
Alexandre Rames5319def2014-10-23 10:03:10 +0100414 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64);
415};
416
417class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 {
418 public:
Roland Levillain3887c462015-08-12 18:15:42 +0100419 SuspendCheckSlowPathARM64(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000420 : SlowPathCodeARM64(instruction), successor_(successor) {}
Alexandre Rames5319def2014-10-23 10:03:10 +0100421
Alexandre Rames67555f72014-11-18 10:55:16 +0000422 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
423 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100424 __ Bind(GetEntryLabel());
Serban Constantinescu22f81d32016-02-18 16:06:31 +0000425 arm64_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800426 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000427 if (successor_ == nullptr) {
428 __ B(GetReturnLabel());
429 } else {
430 __ B(arm64_codegen->GetLabelOf(successor_));
431 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100432 }
433
Scott Wakeling97c72b72016-06-24 16:19:36 +0100434 vixl::aarch64::Label* GetReturnLabel() {
Alexandre Rames5319def2014-10-23 10:03:10 +0100435 DCHECK(successor_ == nullptr);
436 return &return_label_;
437 }
438
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100439 HBasicBlock* GetSuccessor() const {
440 return successor_;
441 }
442
Alexandre Rames9931f312015-06-19 14:47:01 +0100443 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathARM64"; }
444
Alexandre Rames5319def2014-10-23 10:03:10 +0100445 private:
Alexandre Rames5319def2014-10-23 10:03:10 +0100446 // If not null, the block to branch to after the suspend check.
447 HBasicBlock* const successor_;
448
449 // If `successor_` is null, the label to branch to after the suspend check.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100450 vixl::aarch64::Label return_label_;
Alexandre Rames5319def2014-10-23 10:03:10 +0100451
452 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64);
453};
454
Alexandre Rames67555f72014-11-18 10:55:16 +0000455class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 {
456 public:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000457 TypeCheckSlowPathARM64(HInstruction* instruction, bool is_fatal)
David Srbecky9cd6d372016-02-09 15:24:47 +0000458 : SlowPathCodeARM64(instruction), is_fatal_(is_fatal) {}
Alexandre Rames67555f72014-11-18 10:55:16 +0000459
460 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000461 LocationSummary* locations = instruction_->GetLocations();
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800462 Location arg0, arg1;
463 if (instruction_->IsInstanceOf()) {
464 arg0 = locations->InAt(1);
465 arg1 = locations->Out();
466 } else {
467 arg0 = locations->InAt(0);
468 arg1 = locations->InAt(1);
469 }
470
Alexandre Rames3e69f162014-12-10 10:36:50 +0000471 DCHECK(instruction_->IsCheckCast()
472 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
473 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Serban Constantinescu5a6cc492015-08-13 15:20:25 +0100474 uint32_t dex_pc = instruction_->GetDexPc();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000475
Alexandre Rames67555f72014-11-18 10:55:16 +0000476 __ Bind(GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000477
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000478 if (!is_fatal_) {
479 SaveLiveRegisters(codegen, locations);
480 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000481
482 // We're moving two locations to locations that could overlap, so we need a parallel
483 // move resolver.
484 InvokeRuntimeCallingConvention calling_convention;
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800485 codegen->EmitParallelMoves(arg0,
486 LocationFrom(calling_convention.GetRegisterAt(0)),
487 Primitive::kPrimNot,
488 arg1,
489 LocationFrom(calling_convention.GetRegisterAt(1)),
490 Primitive::kPrimNot);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000491 if (instruction_->IsInstanceOf()) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +0000492 arm64_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this);
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800493 CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Class*, mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000494 Primitive::Type ret_type = instruction_->GetType();
495 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
496 arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
497 } else {
498 DCHECK(instruction_->IsCheckCast());
Mathieu Chartierb99f4d62016-11-07 16:17:26 -0800499 arm64_codegen->InvokeRuntime(kQuickCheckInstanceOf, instruction_, dex_pc, this);
500 CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000501 }
502
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000503 if (!is_fatal_) {
504 RestoreLiveRegisters(codegen, locations);
505 __ B(GetExitLabel());
506 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000507 }
508
Alexandre Rames9931f312015-06-19 14:47:01 +0100509 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathARM64"; }
Roland Levillainf41f9562016-09-14 19:26:48 +0100510 bool IsFatal() const OVERRIDE { return is_fatal_; }
Alexandre Rames9931f312015-06-19 14:47:01 +0100511
Alexandre Rames67555f72014-11-18 10:55:16 +0000512 private:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +0000513 const bool is_fatal_;
Alexandre Rames3e69f162014-12-10 10:36:50 +0000514
Alexandre Rames67555f72014-11-18 10:55:16 +0000515 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64);
516};
517
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700518class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 {
519 public:
Aart Bik42249c32016-01-07 15:33:50 -0800520 explicit DeoptimizationSlowPathARM64(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000521 : SlowPathCodeARM64(instruction) {}
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700522
523 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800524 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700525 __ Bind(GetEntryLabel());
Serban Constantinescu22f81d32016-02-18 16:06:31 +0000526 arm64_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000527 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700528 }
529
Alexandre Rames9931f312015-06-19 14:47:01 +0100530 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathARM64"; }
531
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700532 private:
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700533 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64);
534};
535
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100536class ArraySetSlowPathARM64 : public SlowPathCodeARM64 {
537 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000538 explicit ArraySetSlowPathARM64(HInstruction* instruction) : SlowPathCodeARM64(instruction) {}
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100539
540 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
541 LocationSummary* locations = instruction_->GetLocations();
542 __ Bind(GetEntryLabel());
543 SaveLiveRegisters(codegen, locations);
544
545 InvokeRuntimeCallingConvention calling_convention;
546 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
547 parallel_move.AddMove(
548 locations->InAt(0),
549 LocationFrom(calling_convention.GetRegisterAt(0)),
550 Primitive::kPrimNot,
551 nullptr);
552 parallel_move.AddMove(
553 locations->InAt(1),
554 LocationFrom(calling_convention.GetRegisterAt(1)),
555 Primitive::kPrimInt,
556 nullptr);
557 parallel_move.AddMove(
558 locations->InAt(2),
559 LocationFrom(calling_convention.GetRegisterAt(2)),
560 Primitive::kPrimNot,
561 nullptr);
562 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
563
564 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Serban Constantinescu22f81d32016-02-18 16:06:31 +0000565 arm64_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100566 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
567 RestoreLiveRegisters(codegen, locations);
568 __ B(GetExitLabel());
569 }
570
571 const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathARM64"; }
572
573 private:
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +0100574 DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARM64);
575};
576
Zheng Xu3927c8b2015-11-18 17:46:25 +0800577void JumpTableARM64::EmitTable(CodeGeneratorARM64* codegen) {
578 uint32_t num_entries = switch_instr_->GetNumEntries();
Vladimir Markof3e0ee22015-12-17 15:23:13 +0000579 DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold);
Zheng Xu3927c8b2015-11-18 17:46:25 +0800580
581 // We are about to use the assembler to place literals directly. Make sure we have enough
582 // underlying code buffer and we have generated the jump table with right size.
583 CodeBufferCheckScope scope(codegen->GetVIXLAssembler(), num_entries * sizeof(int32_t),
584 CodeBufferCheckScope::kCheck, CodeBufferCheckScope::kExactSize);
585
586 __ Bind(&table_start_);
587 const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors();
588 for (uint32_t i = 0; i < num_entries; i++) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100589 vixl::aarch64::Label* target_label = codegen->GetLabelOf(successors[i]);
Zheng Xu3927c8b2015-11-18 17:46:25 +0800590 DCHECK(target_label->IsBound());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100591 ptrdiff_t jump_offset = target_label->GetLocation() - table_start_.GetLocation();
Zheng Xu3927c8b2015-11-18 17:46:25 +0800592 DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min());
593 DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max());
594 Literal<int32_t> literal(jump_offset);
595 __ place(&literal);
596 }
597}
598
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100599// Slow path marking an object reference `ref` during a read
600// barrier. The field `obj.field` in the object `obj` holding this
601// reference does not get updated by this slow path after marking (see
602// ReadBarrierMarkAndUpdateFieldSlowPathARM64 below for that).
603//
604// This means that after the execution of this slow path, `ref` will
605// always be up-to-date, but `obj.field` may not; i.e., after the
606// flip, `ref` will be a to-space reference, but `obj.field` will
607// probably still be a from-space reference (unless it gets updated by
608// another thread, or if another thread installed another object
609// reference (different from `ref`) in `obj.field`).
Roland Levillain44015862016-01-22 11:47:17 +0000610class ReadBarrierMarkSlowPathARM64 : public SlowPathCodeARM64 {
611 public:
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100612 ReadBarrierMarkSlowPathARM64(HInstruction* instruction, Location ref)
613 : SlowPathCodeARM64(instruction), ref_(ref) {
Roland Levillain44015862016-01-22 11:47:17 +0000614 DCHECK(kEmitCompilerReadBarrier);
615 }
616
617 const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathARM64"; }
618
619 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
620 LocationSummary* locations = instruction_->GetLocations();
Roland Levillain44015862016-01-22 11:47:17 +0000621 DCHECK(locations->CanCall());
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100622 DCHECK(ref_.IsRegister()) << ref_;
623 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg();
Roland Levillain44015862016-01-22 11:47:17 +0000624 DCHECK(instruction_->IsInstanceFieldGet() ||
625 instruction_->IsStaticFieldGet() ||
626 instruction_->IsArrayGet() ||
Roland Levillain16d9f942016-08-25 17:27:56 +0100627 instruction_->IsArraySet() ||
Roland Levillain44015862016-01-22 11:47:17 +0000628 instruction_->IsLoadClass() ||
629 instruction_->IsLoadString() ||
630 instruction_->IsInstanceOf() ||
Roland Levillain3d312422016-06-23 13:53:42 +0100631 instruction_->IsCheckCast() ||
Roland Levillain0b671c02016-08-19 12:02:34 +0100632 (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) ||
633 (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified()))
Roland Levillain44015862016-01-22 11:47:17 +0000634 << "Unexpected instruction in read barrier marking slow path: "
635 << instruction_->DebugName();
Roland Levillain19c54192016-11-04 13:44:09 +0000636 // The read barrier instrumentation of object ArrayGet
637 // instructions does not support the HIntermediateAddress
638 // instruction.
639 DCHECK(!(instruction_->IsArrayGet() &&
640 instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress()));
Roland Levillain44015862016-01-22 11:47:17 +0000641
642 __ Bind(GetEntryLabel());
Roland Levillain4359e612016-07-20 11:32:19 +0100643 // No need to save live registers; it's taken care of by the
644 // entrypoint. Also, there is no need to update the stack mask,
645 // as this runtime call will not trigger a garbage collection.
Roland Levillain44015862016-01-22 11:47:17 +0000646 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100647 DCHECK_NE(ref_.reg(), LR);
648 DCHECK_NE(ref_.reg(), WSP);
649 DCHECK_NE(ref_.reg(), WZR);
Roland Levillain0b671c02016-08-19 12:02:34 +0100650 // IP0 is used internally by the ReadBarrierMarkRegX entry point
651 // as a temporary, it cannot be the entry point's input/output.
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100652 DCHECK_NE(ref_.reg(), IP0);
653 DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg();
Roland Levillain02b75802016-07-13 11:54:35 +0100654 // "Compact" slow path, saving two moves.
655 //
656 // Instead of using the standard runtime calling convention (input
657 // and output in W0):
658 //
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100659 // W0 <- ref
Roland Levillain02b75802016-07-13 11:54:35 +0100660 // W0 <- ReadBarrierMark(W0)
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100661 // ref <- W0
Roland Levillain02b75802016-07-13 11:54:35 +0100662 //
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100663 // we just use rX (the register containing `ref`) as input and output
Roland Levillain02b75802016-07-13 11:54:35 +0100664 // of a dedicated entrypoint:
665 //
666 // rX <- ReadBarrierMarkRegX(rX)
667 //
668 int32_t entry_point_offset =
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100669 CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg());
Roland Levillaindec8f632016-07-22 17:10:06 +0100670 // This runtime call does not require a stack map.
671 arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
Roland Levillain44015862016-01-22 11:47:17 +0000672 __ B(GetExitLabel());
673 }
674
675 private:
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100676 // The location (register) of the marked object reference.
677 const Location ref_;
Roland Levillain44015862016-01-22 11:47:17 +0000678
679 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathARM64);
680};
681
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100682// Slow path marking an object reference `ref` during a read barrier,
683// and if needed, atomically updating the field `obj.field` in the
684// object `obj` holding this reference after marking (contrary to
685// ReadBarrierMarkSlowPathARM64 above, which never tries to update
686// `obj.field`).
687//
688// This means that after the execution of this slow path, both `ref`
689// and `obj.field` will be up-to-date; i.e., after the flip, both will
690// hold the same to-space reference (unless another thread installed
691// another object reference (different from `ref`) in `obj.field`).
692class ReadBarrierMarkAndUpdateFieldSlowPathARM64 : public SlowPathCodeARM64 {
693 public:
694 ReadBarrierMarkAndUpdateFieldSlowPathARM64(HInstruction* instruction,
695 Location ref,
696 Register obj,
697 Location field_offset,
698 Register temp)
699 : SlowPathCodeARM64(instruction),
700 ref_(ref),
701 obj_(obj),
702 field_offset_(field_offset),
703 temp_(temp) {
704 DCHECK(kEmitCompilerReadBarrier);
705 }
706
707 const char* GetDescription() const OVERRIDE {
708 return "ReadBarrierMarkAndUpdateFieldSlowPathARM64";
709 }
710
711 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
712 LocationSummary* locations = instruction_->GetLocations();
713 Register ref_reg = WRegisterFrom(ref_);
714 DCHECK(locations->CanCall());
715 DCHECK(ref_.IsRegister()) << ref_;
716 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_.reg())) << ref_.reg();
717 // This slow path is only used by the UnsafeCASObject intrinsic.
718 DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()))
719 << "Unexpected instruction in read barrier marking and field updating slow path: "
720 << instruction_->DebugName();
721 DCHECK(instruction_->GetLocations()->Intrinsified());
722 DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject);
723 DCHECK(field_offset_.IsRegister()) << field_offset_;
724
725 __ Bind(GetEntryLabel());
726
727 // Save the old reference.
728 // Note that we cannot use IP to save the old reference, as IP is
729 // used internally by the ReadBarrierMarkRegX entry point, and we
730 // need the old reference after the call to that entry point.
731 DCHECK_NE(LocationFrom(temp_).reg(), IP0);
732 __ Mov(temp_.W(), ref_reg);
733
734 // No need to save live registers; it's taken care of by the
735 // entrypoint. Also, there is no need to update the stack mask,
736 // as this runtime call will not trigger a garbage collection.
737 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
738 DCHECK_NE(ref_.reg(), LR);
739 DCHECK_NE(ref_.reg(), WSP);
740 DCHECK_NE(ref_.reg(), WZR);
741 // IP0 is used internally by the ReadBarrierMarkRegX entry point
742 // as a temporary, it cannot be the entry point's input/output.
743 DCHECK_NE(ref_.reg(), IP0);
744 DCHECK(0 <= ref_.reg() && ref_.reg() < kNumberOfWRegisters) << ref_.reg();
745 // "Compact" slow path, saving two moves.
746 //
747 // Instead of using the standard runtime calling convention (input
748 // and output in W0):
749 //
750 // W0 <- ref
751 // W0 <- ReadBarrierMark(W0)
752 // ref <- W0
753 //
754 // we just use rX (the register containing `ref`) as input and output
755 // of a dedicated entrypoint:
756 //
757 // rX <- ReadBarrierMarkRegX(rX)
758 //
759 int32_t entry_point_offset =
760 CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(ref_.reg());
761 // This runtime call does not require a stack map.
762 arm64_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
763
764 // If the new reference is different from the old reference,
765 // update the field in the holder (`*(obj_ + field_offset_)`).
766 //
767 // Note that this field could also hold a different object, if
768 // another thread had concurrently changed it. In that case, the
769 // LDXR/CMP/BNE sequence of instructions in the compare-and-set
770 // (CAS) operation below would abort the CAS, leaving the field
771 // as-is.
772 vixl::aarch64::Label done;
773 __ Cmp(temp_.W(), ref_reg);
774 __ B(eq, &done);
775
776 // Update the the holder's field atomically. This may fail if
777 // mutator updates before us, but it's OK. This is achieved
778 // using a strong compare-and-set (CAS) operation with relaxed
779 // memory synchronization ordering, where the expected value is
780 // the old reference and the desired value is the new reference.
781
782 MacroAssembler* masm = arm64_codegen->GetVIXLAssembler();
783 UseScratchRegisterScope temps(masm);
784
785 // Convenience aliases.
786 Register base = obj_.W();
787 Register offset = XRegisterFrom(field_offset_);
788 Register expected = temp_.W();
789 Register value = ref_reg;
790 Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory.
791 Register tmp_value = temps.AcquireW(); // Value in memory.
792
793 __ Add(tmp_ptr, base.X(), Operand(offset));
794
795 if (kPoisonHeapReferences) {
796 arm64_codegen->GetAssembler()->PoisonHeapReference(expected);
797 if (value.Is(expected)) {
798 // Do not poison `value`, as it is the same register as
799 // `expected`, which has just been poisoned.
800 } else {
801 arm64_codegen->GetAssembler()->PoisonHeapReference(value);
802 }
803 }
804
805 // do {
806 // tmp_value = [tmp_ptr] - expected;
807 // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value));
808
Roland Levillain24a4d112016-10-26 13:10:46 +0100809 vixl::aarch64::Label loop_head, comparison_failed, exit_loop;
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100810 __ Bind(&loop_head);
811 __ Ldxr(tmp_value, MemOperand(tmp_ptr));
812 __ Cmp(tmp_value, expected);
Roland Levillain24a4d112016-10-26 13:10:46 +0100813 __ B(&comparison_failed, ne);
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100814 __ Stxr(tmp_value, value, MemOperand(tmp_ptr));
815 __ Cbnz(tmp_value, &loop_head);
Roland Levillain24a4d112016-10-26 13:10:46 +0100816 __ B(&exit_loop);
817 __ Bind(&comparison_failed);
818 __ Clrex();
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100819 __ Bind(&exit_loop);
820
821 if (kPoisonHeapReferences) {
822 arm64_codegen->GetAssembler()->UnpoisonHeapReference(expected);
823 if (value.Is(expected)) {
824 // Do not unpoison `value`, as it is the same register as
825 // `expected`, which has just been unpoisoned.
826 } else {
827 arm64_codegen->GetAssembler()->UnpoisonHeapReference(value);
828 }
829 }
830
831 __ Bind(&done);
832 __ B(GetExitLabel());
833 }
834
835 private:
836 // The location (register) of the marked object reference.
837 const Location ref_;
838 // The register containing the object holding the marked object reference field.
839 const Register obj_;
840 // The location of the offset of the marked reference field within `obj_`.
841 Location field_offset_;
842
843 const Register temp_;
844
845 DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathARM64);
846};
847
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000848// Slow path generating a read barrier for a heap reference.
849class ReadBarrierForHeapReferenceSlowPathARM64 : public SlowPathCodeARM64 {
850 public:
851 ReadBarrierForHeapReferenceSlowPathARM64(HInstruction* instruction,
852 Location out,
853 Location ref,
854 Location obj,
855 uint32_t offset,
856 Location index)
David Srbecky9cd6d372016-02-09 15:24:47 +0000857 : SlowPathCodeARM64(instruction),
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000858 out_(out),
859 ref_(ref),
860 obj_(obj),
861 offset_(offset),
862 index_(index) {
863 DCHECK(kEmitCompilerReadBarrier);
864 // If `obj` is equal to `out` or `ref`, it means the initial object
865 // has been overwritten by (or after) the heap object reference load
866 // to be instrumented, e.g.:
867 //
868 // __ Ldr(out, HeapOperand(out, class_offset);
Roland Levillain44015862016-01-22 11:47:17 +0000869 // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset);
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000870 //
871 // In that case, we have lost the information about the original
872 // object, and the emitted read barrier cannot work properly.
873 DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out;
874 DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref;
875 }
876
877 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
878 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
879 LocationSummary* locations = instruction_->GetLocations();
880 Primitive::Type type = Primitive::kPrimNot;
881 DCHECK(locations->CanCall());
882 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg()));
Roland Levillain3d312422016-06-23 13:53:42 +0100883 DCHECK(instruction_->IsInstanceFieldGet() ||
884 instruction_->IsStaticFieldGet() ||
885 instruction_->IsArrayGet() ||
886 instruction_->IsInstanceOf() ||
887 instruction_->IsCheckCast() ||
Roland Levillaindec8f632016-07-22 17:10:06 +0100888 (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified())
Roland Levillain44015862016-01-22 11:47:17 +0000889 << "Unexpected instruction in read barrier for heap reference slow path: "
890 << instruction_->DebugName();
Roland Levillain19c54192016-11-04 13:44:09 +0000891 // The read barrier instrumentation of object ArrayGet
892 // instructions does not support the HIntermediateAddress
893 // instruction.
Roland Levillaincd3d0fb2016-01-15 19:26:48 +0000894 DCHECK(!(instruction_->IsArrayGet() &&
Artem Serov328429f2016-07-06 16:23:04 +0100895 instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress()));
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000896
897 __ Bind(GetEntryLabel());
898
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000899 SaveLiveRegisters(codegen, locations);
900
901 // We may have to change the index's value, but as `index_` is a
902 // constant member (like other "inputs" of this slow path),
903 // introduce a copy of it, `index`.
904 Location index = index_;
905 if (index_.IsValid()) {
Roland Levillain3d312422016-06-23 13:53:42 +0100906 // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics.
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000907 if (instruction_->IsArrayGet()) {
908 // Compute the actual memory offset and store it in `index`.
909 Register index_reg = RegisterFrom(index_, Primitive::kPrimInt);
910 DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_.reg()));
911 if (codegen->IsCoreCalleeSaveRegister(index_.reg())) {
912 // We are about to change the value of `index_reg` (see the
913 // calls to vixl::MacroAssembler::Lsl and
914 // vixl::MacroAssembler::Mov below), but it has
915 // not been saved by the previous call to
916 // art::SlowPathCode::SaveLiveRegisters, as it is a
917 // callee-save register --
918 // art::SlowPathCode::SaveLiveRegisters does not consider
919 // callee-save registers, as it has been designed with the
920 // assumption that callee-save registers are supposed to be
921 // handled by the called function. So, as a callee-save
922 // register, `index_reg` _would_ eventually be saved onto
923 // the stack, but it would be too late: we would have
924 // changed its value earlier. Therefore, we manually save
925 // it here into another freely available register,
926 // `free_reg`, chosen of course among the caller-save
927 // registers (as a callee-save `free_reg` register would
928 // exhibit the same problem).
929 //
930 // Note we could have requested a temporary register from
931 // the register allocator instead; but we prefer not to, as
932 // this is a slow path, and we know we can find a
933 // caller-save register that is available.
934 Register free_reg = FindAvailableCallerSaveRegister(codegen);
935 __ Mov(free_reg.W(), index_reg);
936 index_reg = free_reg;
937 index = LocationFrom(index_reg);
938 } else {
939 // The initial register stored in `index_` has already been
940 // saved in the call to art::SlowPathCode::SaveLiveRegisters
941 // (as it is not a callee-save register), so we can freely
942 // use it.
943 }
944 // Shifting the index value contained in `index_reg` by the scale
945 // factor (2) cannot overflow in practice, as the runtime is
946 // unable to allocate object arrays with a size larger than
947 // 2^26 - 1 (that is, 2^28 - 4 bytes).
948 __ Lsl(index_reg, index_reg, Primitive::ComponentSizeShift(type));
949 static_assert(
950 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
951 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
952 __ Add(index_reg, index_reg, Operand(offset_));
953 } else {
Roland Levillain3d312422016-06-23 13:53:42 +0100954 // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile
955 // intrinsics, `index_` is not shifted by a scale factor of 2
956 // (as in the case of ArrayGet), as it is actually an offset
957 // to an object field within an object.
958 DCHECK(instruction_->IsInvoke()) << instruction_->DebugName();
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000959 DCHECK(instruction_->GetLocations()->Intrinsified());
960 DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) ||
961 (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile))
962 << instruction_->AsInvoke()->GetIntrinsic();
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100963 DCHECK_EQ(offset_, 0u);
Roland Levillaina7426c62016-08-03 15:02:10 +0100964 DCHECK(index_.IsRegister());
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000965 }
966 }
967
968 // We're moving two or three locations to locations that could
969 // overlap, so we need a parallel move resolver.
970 InvokeRuntimeCallingConvention calling_convention;
971 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
972 parallel_move.AddMove(ref_,
973 LocationFrom(calling_convention.GetRegisterAt(0)),
974 type,
975 nullptr);
976 parallel_move.AddMove(obj_,
977 LocationFrom(calling_convention.GetRegisterAt(1)),
978 type,
979 nullptr);
980 if (index.IsValid()) {
981 parallel_move.AddMove(index,
982 LocationFrom(calling_convention.GetRegisterAt(2)),
983 Primitive::kPrimInt,
984 nullptr);
985 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
986 } else {
987 codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
988 arm64_codegen->MoveConstant(LocationFrom(calling_convention.GetRegisterAt(2)), offset_);
989 }
Serban Constantinescu22f81d32016-02-18 16:06:31 +0000990 arm64_codegen->InvokeRuntime(kQuickReadBarrierSlow,
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000991 instruction_,
992 instruction_->GetDexPc(),
993 this);
994 CheckEntrypointTypes<
995 kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>();
996 arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type);
997
998 RestoreLiveRegisters(codegen, locations);
999
Roland Levillain22ccc3a2015-11-24 13:10:05 +00001000 __ B(GetExitLabel());
1001 }
1002
1003 const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathARM64"; }
1004
1005 private:
1006 Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01001007 size_t ref = static_cast<int>(XRegisterFrom(ref_).GetCode());
1008 size_t obj = static_cast<int>(XRegisterFrom(obj_).GetCode());
Roland Levillain22ccc3a2015-11-24 13:10:05 +00001009 for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) {
1010 if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) {
1011 return Register(VIXLRegCodeFromART(i), kXRegSize);
1012 }
1013 }
1014 // We shall never fail to find a free caller-save register, as
1015 // there are more than two core caller-save registers on ARM64
1016 // (meaning it is possible to find one which is different from
1017 // `ref` and `obj`).
1018 DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u);
1019 LOG(FATAL) << "Could not find a free register";
1020 UNREACHABLE();
1021 }
1022
Roland Levillain22ccc3a2015-11-24 13:10:05 +00001023 const Location out_;
1024 const Location ref_;
1025 const Location obj_;
1026 const uint32_t offset_;
1027 // An additional location containing an index to an array.
1028 // Only used for HArrayGet and the UnsafeGetObject &
1029 // UnsafeGetObjectVolatile intrinsics.
1030 const Location index_;
1031
1032 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARM64);
1033};
1034
1035// Slow path generating a read barrier for a GC root.
1036class ReadBarrierForRootSlowPathARM64 : public SlowPathCodeARM64 {
1037 public:
1038 ReadBarrierForRootSlowPathARM64(HInstruction* instruction, Location out, Location root)
David Srbecky9cd6d372016-02-09 15:24:47 +00001039 : SlowPathCodeARM64(instruction), out_(out), root_(root) {
Roland Levillain44015862016-01-22 11:47:17 +00001040 DCHECK(kEmitCompilerReadBarrier);
1041 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00001042
1043 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
1044 LocationSummary* locations = instruction_->GetLocations();
1045 Primitive::Type type = Primitive::kPrimNot;
1046 DCHECK(locations->CanCall());
1047 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(out_.reg()));
Roland Levillain44015862016-01-22 11:47:17 +00001048 DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString())
1049 << "Unexpected instruction in read barrier for GC root slow path: "
1050 << instruction_->DebugName();
Roland Levillain22ccc3a2015-11-24 13:10:05 +00001051
1052 __ Bind(GetEntryLabel());
1053 SaveLiveRegisters(codegen, locations);
1054
1055 InvokeRuntimeCallingConvention calling_convention;
1056 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
1057 // The argument of the ReadBarrierForRootSlow is not a managed
1058 // reference (`mirror::Object*`), but a `GcRoot<mirror::Object>*`;
1059 // thus we need a 64-bit move here, and we cannot use
1060 //
1061 // arm64_codegen->MoveLocation(
1062 // LocationFrom(calling_convention.GetRegisterAt(0)),
1063 // root_,
1064 // type);
1065 //
1066 // which would emit a 32-bit move, as `type` is a (32-bit wide)
1067 // reference type (`Primitive::kPrimNot`).
1068 __ Mov(calling_convention.GetRegisterAt(0), XRegisterFrom(out_));
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001069 arm64_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow,
Roland Levillain22ccc3a2015-11-24 13:10:05 +00001070 instruction_,
1071 instruction_->GetDexPc(),
1072 this);
1073 CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>();
1074 arm64_codegen->MoveLocation(out_, calling_convention.GetReturnLocation(type), type);
1075
1076 RestoreLiveRegisters(codegen, locations);
1077 __ B(GetExitLabel());
1078 }
1079
1080 const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathARM64"; }
1081
1082 private:
Roland Levillain22ccc3a2015-11-24 13:10:05 +00001083 const Location out_;
1084 const Location root_;
1085
1086 DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARM64);
1087};
1088
Alexandre Rames5319def2014-10-23 10:03:10 +01001089#undef __
1090
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001091Location InvokeDexCallingConventionVisitorARM64::GetNextLocation(Primitive::Type type) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001092 Location next_location;
1093 if (type == Primitive::kPrimVoid) {
1094 LOG(FATAL) << "Unreachable type " << type;
1095 }
1096
Alexandre Rames542361f2015-01-29 16:57:31 +00001097 if (Primitive::IsFloatingPointType(type) &&
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001098 (float_index_ < calling_convention.GetNumberOfFpuRegisters())) {
1099 next_location = LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++));
Alexandre Rames542361f2015-01-29 16:57:31 +00001100 } else if (!Primitive::IsFloatingPointType(type) &&
1101 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001102 next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++));
1103 } else {
1104 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Alexandre Rames542361f2015-01-29 16:57:31 +00001105 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
1106 : Location::StackSlot(stack_offset);
Alexandre Rames5319def2014-10-23 10:03:10 +01001107 }
1108
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001109 // Space on the stack is reserved for all arguments.
Alexandre Rames542361f2015-01-29 16:57:31 +00001110 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
Alexandre Rames5319def2014-10-23 10:03:10 +01001111 return next_location;
1112}
1113
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001114Location InvokeDexCallingConventionVisitorARM64::GetMethodLocation() const {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001115 return LocationFrom(kArtMethodRegister);
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001116}
1117
Serban Constantinescu579885a2015-02-22 20:51:33 +00001118CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph,
1119 const Arm64InstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +01001120 const CompilerOptions& compiler_options,
1121 OptimizingCompilerStats* stats)
Alexandre Rames5319def2014-10-23 10:03:10 +01001122 : CodeGenerator(graph,
1123 kNumberOfAllocatableRegisters,
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001124 kNumberOfAllocatableFPRegisters,
Calin Juravlecd6dffe2015-01-08 17:35:35 +00001125 kNumberOfAllocatableRegisterPairs,
Scott Wakeling97c72b72016-06-24 16:19:36 +01001126 callee_saved_core_registers.GetList(),
1127 callee_saved_fp_registers.GetList(),
Serban Constantinescuecc43662015-08-13 13:33:12 +01001128 compiler_options,
1129 stats),
Alexandre Ramesc01a6642016-04-15 11:54:06 +01001130 block_labels_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Zheng Xu3927c8b2015-11-18 17:46:25 +08001131 jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexandre Rames5319def2014-10-23 10:03:10 +01001132 location_builder_(graph, this),
Alexandre Rames3e69f162014-12-10 10:36:50 +00001133 instruction_visitor_(graph, this),
Serban Constantinescu579885a2015-02-22 20:51:33 +00001134 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +01001135 assembler_(graph->GetArena()),
Vladimir Marko58155012015-08-19 12:49:41 +00001136 isa_features_(isa_features),
Vladimir Markocac5a7e2016-02-22 10:39:50 +00001137 uint32_literals_(std::less<uint32_t>(),
1138 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Marko5233f932015-09-29 19:01:15 +01001139 uint64_literals_(std::less<uint64_t>(),
1140 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
1141 method_patches_(MethodReferenceComparator(),
1142 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
1143 call_patches_(MethodReferenceComparator(),
1144 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
1145 relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +00001146 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
1147 boot_image_string_patches_(StringReferenceValueComparator(),
1148 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
1149 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01001150 boot_image_type_patches_(TypeReferenceValueComparator(),
1151 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
1152 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Vladimir Markocac5a7e2016-02-22 10:39:50 +00001153 boot_image_address_patches_(std::less<uint32_t>(),
Nicolas Geoffray07c919f2016-11-09 17:29:03 +00001154 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +00001155 // Save the link register (containing the return address) to mimic Quick.
Serban Constantinescu3d087de2015-01-28 11:57:05 +00001156 AddAllocatedRegister(LocationFrom(lr));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +00001157}
Alexandre Rames5319def2014-10-23 10:03:10 +01001158
Alexandre Rames67555f72014-11-18 10:55:16 +00001159#define __ GetVIXLAssembler()->
Alexandre Rames5319def2014-10-23 10:03:10 +01001160
Zheng Xu3927c8b2015-11-18 17:46:25 +08001161void CodeGeneratorARM64::EmitJumpTables() {
Alexandre Ramesc01a6642016-04-15 11:54:06 +01001162 for (auto&& jump_table : jump_tables_) {
Zheng Xu3927c8b2015-11-18 17:46:25 +08001163 jump_table->EmitTable(this);
1164 }
1165}
1166
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +00001167void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) {
Zheng Xu3927c8b2015-11-18 17:46:25 +08001168 EmitJumpTables();
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +00001169 // Ensure we emit the literal pool.
1170 __ FinalizeCode();
Vladimir Marko58155012015-08-19 12:49:41 +00001171
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +00001172 CodeGenerator::Finalize(allocator);
1173}
1174
Zheng Xuad4450e2015-04-17 18:48:56 +08001175void ParallelMoveResolverARM64::PrepareForEmitNativeCode() {
1176 // Note: There are 6 kinds of moves:
1177 // 1. constant -> GPR/FPR (non-cycle)
1178 // 2. constant -> stack (non-cycle)
1179 // 3. GPR/FPR -> GPR/FPR
1180 // 4. GPR/FPR -> stack
1181 // 5. stack -> GPR/FPR
1182 // 6. stack -> stack (non-cycle)
1183 // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5
1184 // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting
1185 // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the
1186 // dependency.
1187 vixl_temps_.Open(GetVIXLAssembler());
1188}
1189
1190void ParallelMoveResolverARM64::FinishEmitNativeCode() {
1191 vixl_temps_.Close();
1192}
1193
1194Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) {
1195 DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister ||
1196 kind == Location::kStackSlot || kind == Location::kDoubleStackSlot);
1197 kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister;
1198 Location scratch = GetScratchLocation(kind);
1199 if (!scratch.Equals(Location::NoLocation())) {
1200 return scratch;
1201 }
1202 // Allocate from VIXL temp registers.
1203 if (kind == Location::kRegister) {
1204 scratch = LocationFrom(vixl_temps_.AcquireX());
1205 } else {
1206 DCHECK(kind == Location::kFpuRegister);
1207 scratch = LocationFrom(vixl_temps_.AcquireD());
1208 }
1209 AddScratchLocation(scratch);
1210 return scratch;
1211}
1212
1213void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) {
1214 if (loc.IsRegister()) {
1215 vixl_temps_.Release(XRegisterFrom(loc));
1216 } else {
1217 DCHECK(loc.IsFpuRegister());
1218 vixl_temps_.Release(DRegisterFrom(loc));
1219 }
1220 RemoveScratchLocation(loc);
1221}
1222
Alexandre Rames3e69f162014-12-10 10:36:50 +00001223void ParallelMoveResolverARM64::EmitMove(size_t index) {
Vladimir Marko225b6462015-09-28 12:17:40 +01001224 MoveOperands* move = moves_[index];
Calin Juravlee460d1d2015-09-29 04:52:17 +01001225 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), Primitive::kPrimVoid);
Alexandre Rames3e69f162014-12-10 10:36:50 +00001226}
1227
Alexandre Rames5319def2014-10-23 10:03:10 +01001228void CodeGeneratorARM64::GenerateFrameEntry() {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001229 MacroAssembler* masm = GetVIXLAssembler();
1230 BlockPoolsScope block_pools(masm);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001231 __ Bind(&frame_entry_label_);
1232
Serban Constantinescu02164b32014-11-13 14:05:07 +00001233 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod();
1234 if (do_overflow_check) {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001235 UseScratchRegisterScope temps(masm);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001236 Register temp = temps.AcquireX();
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +00001237 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Serban Constantinescu3d087de2015-01-28 11:57:05 +00001238 __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64)));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +00001239 __ Ldr(wzr, MemOperand(temp, 0));
1240 RecordPcInfo(nullptr, 0);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001241 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001242
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001243 if (!HasEmptyFrame()) {
1244 int frame_size = GetFrameSize();
1245 // Stack layout:
1246 // sp[frame_size - 8] : lr.
1247 // ... : other preserved core registers.
1248 // ... : other preserved fp registers.
1249 // ... : reserved frame space.
1250 // sp[0] : current method.
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +01001251
1252 // Save the current method if we need it. Note that we do not
1253 // do this in HCurrentMethod, as the instruction might have been removed
1254 // in the SSA graph.
1255 if (RequiresCurrentMethod()) {
1256 __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex));
Nicolas Geoffray9989b162016-10-13 13:42:30 +01001257 } else {
1258 __ Claim(frame_size);
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +01001259 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +01001260 GetAssembler()->cfi().AdjustCFAOffset(frame_size);
Zheng Xu69a50302015-04-14 20:04:41 +08001261 GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(),
1262 frame_size - GetCoreSpillSize());
1263 GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(),
1264 frame_size - FrameEntrySpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001265 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001266}
1267
1268void CodeGeneratorARM64::GenerateFrameExit() {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001269 BlockPoolsScope block_pools(GetVIXLAssembler());
David Srbeckyc34dc932015-04-12 09:27:43 +01001270 GetAssembler()->cfi().RememberState();
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001271 if (!HasEmptyFrame()) {
1272 int frame_size = GetFrameSize();
Zheng Xu69a50302015-04-14 20:04:41 +08001273 GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(),
1274 frame_size - FrameEntrySpillSize());
1275 GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(),
1276 frame_size - GetCoreSpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001277 __ Drop(frame_size);
David Srbeckyc6b4dd82015-04-07 20:32:43 +01001278 GetAssembler()->cfi().AdjustCFAOffset(-frame_size);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001279 }
David Srbeckyc34dc932015-04-12 09:27:43 +01001280 __ Ret();
1281 GetAssembler()->cfi().RestoreState();
1282 GetAssembler()->cfi().DefCFAOffset(GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +01001283}
1284
Scott Wakeling97c72b72016-06-24 16:19:36 +01001285CPURegList CodeGeneratorARM64::GetFramePreservedCoreRegisters() const {
Zheng Xuda403092015-04-24 17:35:39 +08001286 DCHECK(ArtVixlRegCodeCoherentForRegSet(core_spill_mask_, GetNumberOfCoreRegisters(), 0, 0));
Scott Wakeling97c72b72016-06-24 16:19:36 +01001287 return CPURegList(CPURegister::kRegister, kXRegSize,
1288 core_spill_mask_);
Zheng Xuda403092015-04-24 17:35:39 +08001289}
1290
Scott Wakeling97c72b72016-06-24 16:19:36 +01001291CPURegList CodeGeneratorARM64::GetFramePreservedFPRegisters() const {
Zheng Xuda403092015-04-24 17:35:39 +08001292 DCHECK(ArtVixlRegCodeCoherentForRegSet(0, 0, fpu_spill_mask_,
1293 GetNumberOfFloatingPointRegisters()));
Scott Wakeling97c72b72016-06-24 16:19:36 +01001294 return CPURegList(CPURegister::kFPRegister, kDRegSize,
1295 fpu_spill_mask_);
Zheng Xuda403092015-04-24 17:35:39 +08001296}
1297
Alexandre Rames5319def2014-10-23 10:03:10 +01001298void CodeGeneratorARM64::Bind(HBasicBlock* block) {
1299 __ Bind(GetLabelOf(block));
1300}
1301
Calin Juravle175dc732015-08-25 15:42:32 +01001302void CodeGeneratorARM64::MoveConstant(Location location, int32_t value) {
1303 DCHECK(location.IsRegister());
1304 __ Mov(RegisterFrom(location, Primitive::kPrimInt), value);
1305}
1306
Calin Juravlee460d1d2015-09-29 04:52:17 +01001307void CodeGeneratorARM64::AddLocationAsTemp(Location location, LocationSummary* locations) {
1308 if (location.IsRegister()) {
1309 locations->AddTemp(location);
1310 } else {
1311 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
1312 }
1313}
1314
Nicolas Geoffray07276db2015-05-18 14:22:09 +01001315void CodeGeneratorARM64::MarkGCCard(Register object, Register value, bool value_can_be_null) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001316 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +01001317 Register card = temps.AcquireX();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001318 Register temp = temps.AcquireW(); // Index within the CardTable - 32bit.
Scott Wakeling97c72b72016-06-24 16:19:36 +01001319 vixl::aarch64::Label done;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01001320 if (value_can_be_null) {
1321 __ Cbz(value, &done);
1322 }
Andreas Gampe542451c2016-07-26 09:02:02 -07001323 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64PointerSize>().Int32Value()));
Alexandre Rames5319def2014-10-23 10:03:10 +01001324 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001325 __ Strb(card, MemOperand(card, temp.X()));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01001326 if (value_can_be_null) {
1327 __ Bind(&done);
1328 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001329}
1330
David Brazdil58282f42016-01-14 12:45:10 +00001331void CodeGeneratorARM64::SetupBlockedRegisters() const {
Serban Constantinescu3d087de2015-01-28 11:57:05 +00001332 // Blocked core registers:
1333 // lr : Runtime reserved.
1334 // tr : Runtime reserved.
1335 // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it.
1336 // ip1 : VIXL core temp.
1337 // ip0 : VIXL core temp.
1338 //
1339 // Blocked fp registers:
1340 // d31 : VIXL fp temp.
Alexandre Rames5319def2014-10-23 10:03:10 +01001341 CPURegList reserved_core_registers = vixl_reserved_core_registers;
1342 reserved_core_registers.Combine(runtime_reserved_core_registers);
Alexandre Rames5319def2014-10-23 10:03:10 +01001343 while (!reserved_core_registers.IsEmpty()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01001344 blocked_core_registers_[reserved_core_registers.PopLowestIndex().GetCode()] = true;
Alexandre Rames5319def2014-10-23 10:03:10 +01001345 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +00001346
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001347 CPURegList reserved_fp_registers = vixl_reserved_fp_registers;
Zheng Xua3ec3942015-02-15 18:39:46 +08001348 while (!reserved_fp_registers.IsEmpty()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01001349 blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().GetCode()] = true;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001350 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +00001351
David Brazdil58282f42016-01-14 12:45:10 +00001352 if (GetGraph()->IsDebuggable()) {
Nicolas Geoffrayecf680d2015-10-05 11:15:37 +01001353 // Stubs do not save callee-save floating point registers. If the graph
1354 // is debuggable, we need to deal with these registers differently. For
1355 // now, just block them.
David Brazdil58282f42016-01-14 12:45:10 +00001356 CPURegList reserved_fp_registers_debuggable = callee_saved_fp_registers;
1357 while (!reserved_fp_registers_debuggable.IsEmpty()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01001358 blocked_fpu_registers_[reserved_fp_registers_debuggable.PopLowestIndex().GetCode()] = true;
Serban Constantinescu3d087de2015-01-28 11:57:05 +00001359 }
1360 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001361}
1362
Alexandre Rames3e69f162014-12-10 10:36:50 +00001363size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1364 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
1365 __ Str(reg, MemOperand(sp, stack_index));
1366 return kArm64WordSize;
1367}
1368
1369size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1370 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
1371 __ Ldr(reg, MemOperand(sp, stack_index));
1372 return kArm64WordSize;
1373}
1374
1375size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1376 FPRegister reg = FPRegister(reg_id, kDRegSize);
1377 __ Str(reg, MemOperand(sp, stack_index));
1378 return kArm64WordSize;
1379}
1380
1381size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1382 FPRegister reg = FPRegister(reg_id, kDRegSize);
1383 __ Ldr(reg, MemOperand(sp, stack_index));
1384 return kArm64WordSize;
1385}
1386
Alexandre Rames5319def2014-10-23 10:03:10 +01001387void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +01001388 stream << XRegister(reg);
Alexandre Rames5319def2014-10-23 10:03:10 +01001389}
1390
1391void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +01001392 stream << DRegister(reg);
Alexandre Rames5319def2014-10-23 10:03:10 +01001393}
1394
Alexandre Rames67555f72014-11-18 10:55:16 +00001395void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001396 if (constant->IsIntConstant()) {
1397 __ Mov(Register(destination), constant->AsIntConstant()->GetValue());
1398 } else if (constant->IsLongConstant()) {
1399 __ Mov(Register(destination), constant->AsLongConstant()->GetValue());
1400 } else if (constant->IsNullConstant()) {
1401 __ Mov(Register(destination), 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00001402 } else if (constant->IsFloatConstant()) {
1403 __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue());
1404 } else {
1405 DCHECK(constant->IsDoubleConstant());
1406 __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue());
1407 }
1408}
1409
Alexandre Rames3e69f162014-12-10 10:36:50 +00001410
1411static bool CoherentConstantAndType(Location constant, Primitive::Type type) {
1412 DCHECK(constant.IsConstant());
1413 HConstant* cst = constant.GetConstant();
1414 return (cst->IsIntConstant() && type == Primitive::kPrimInt) ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001415 // Null is mapped to a core W register, which we associate with kPrimInt.
1416 (cst->IsNullConstant() && type == Primitive::kPrimInt) ||
Alexandre Rames3e69f162014-12-10 10:36:50 +00001417 (cst->IsLongConstant() && type == Primitive::kPrimLong) ||
1418 (cst->IsFloatConstant() && type == Primitive::kPrimFloat) ||
1419 (cst->IsDoubleConstant() && type == Primitive::kPrimDouble);
1420}
1421
Calin Juravlee460d1d2015-09-29 04:52:17 +01001422void CodeGeneratorARM64::MoveLocation(Location destination,
1423 Location source,
1424 Primitive::Type dst_type) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001425 if (source.Equals(destination)) {
1426 return;
1427 }
Alexandre Rames3e69f162014-12-10 10:36:50 +00001428
1429 // A valid move can always be inferred from the destination and source
1430 // locations. When moving from and to a register, the argument type can be
1431 // used to generate 32bit instead of 64bit moves. In debug mode we also
1432 // checks the coherency of the locations and the type.
Calin Juravlee460d1d2015-09-29 04:52:17 +01001433 bool unspecified_type = (dst_type == Primitive::kPrimVoid);
Alexandre Rames3e69f162014-12-10 10:36:50 +00001434
1435 if (destination.IsRegister() || destination.IsFpuRegister()) {
1436 if (unspecified_type) {
1437 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
1438 if (source.IsStackSlot() ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001439 (src_cst != nullptr && (src_cst->IsIntConstant()
1440 || src_cst->IsFloatConstant()
1441 || src_cst->IsNullConstant()))) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001442 // For stack slots and 32bit constants, a 64bit type is appropriate.
Calin Juravlee460d1d2015-09-29 04:52:17 +01001443 dst_type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexandre Rames67555f72014-11-18 10:55:16 +00001444 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001445 // If the source is a double stack slot or a 64bit constant, a 64bit
1446 // type is appropriate. Else the source is a register, and since the
1447 // type has not been specified, we chose a 64bit type to force a 64bit
1448 // move.
Calin Juravlee460d1d2015-09-29 04:52:17 +01001449 dst_type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexandre Rames67555f72014-11-18 10:55:16 +00001450 }
Alexandre Rames3e69f162014-12-10 10:36:50 +00001451 }
Calin Juravlee460d1d2015-09-29 04:52:17 +01001452 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(dst_type)) ||
1453 (destination.IsRegister() && !Primitive::IsFloatingPointType(dst_type)));
1454 CPURegister dst = CPURegisterFrom(destination, dst_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00001455 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
1456 DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot());
1457 __ Ldr(dst, StackOperandFrom(source));
1458 } else if (source.IsConstant()) {
Calin Juravlee460d1d2015-09-29 04:52:17 +01001459 DCHECK(CoherentConstantAndType(source, dst_type));
Alexandre Rames3e69f162014-12-10 10:36:50 +00001460 MoveConstant(dst, source.GetConstant());
Calin Juravlee460d1d2015-09-29 04:52:17 +01001461 } else if (source.IsRegister()) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001462 if (destination.IsRegister()) {
Calin Juravlee460d1d2015-09-29 04:52:17 +01001463 __ Mov(Register(dst), RegisterFrom(source, dst_type));
Alexandre Rames3e69f162014-12-10 10:36:50 +00001464 } else {
Zheng Xuad4450e2015-04-17 18:48:56 +08001465 DCHECK(destination.IsFpuRegister());
Calin Juravlee460d1d2015-09-29 04:52:17 +01001466 Primitive::Type source_type = Primitive::Is64BitType(dst_type)
1467 ? Primitive::kPrimLong
1468 : Primitive::kPrimInt;
1469 __ Fmov(FPRegisterFrom(destination, dst_type), RegisterFrom(source, source_type));
1470 }
1471 } else {
1472 DCHECK(source.IsFpuRegister());
1473 if (destination.IsRegister()) {
1474 Primitive::Type source_type = Primitive::Is64BitType(dst_type)
1475 ? Primitive::kPrimDouble
1476 : Primitive::kPrimFloat;
1477 __ Fmov(RegisterFrom(destination, dst_type), FPRegisterFrom(source, source_type));
1478 } else {
1479 DCHECK(destination.IsFpuRegister());
1480 __ Fmov(FPRegister(dst), FPRegisterFrom(source, dst_type));
Alexandre Rames3e69f162014-12-10 10:36:50 +00001481 }
1482 }
Alexandre Rames3e69f162014-12-10 10:36:50 +00001483 } else { // The destination is not a register. It must be a stack slot.
1484 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
1485 if (source.IsRegister() || source.IsFpuRegister()) {
1486 if (unspecified_type) {
1487 if (source.IsRegister()) {
Calin Juravlee460d1d2015-09-29 04:52:17 +01001488 dst_type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001489 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +01001490 dst_type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001491 }
1492 }
Calin Juravlee460d1d2015-09-29 04:52:17 +01001493 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(dst_type)) &&
1494 (source.IsFpuRegister() == Primitive::IsFloatingPointType(dst_type)));
1495 __ Str(CPURegisterFrom(source, dst_type), StackOperandFrom(destination));
Alexandre Rames3e69f162014-12-10 10:36:50 +00001496 } else if (source.IsConstant()) {
Calin Juravlee460d1d2015-09-29 04:52:17 +01001497 DCHECK(unspecified_type || CoherentConstantAndType(source, dst_type))
1498 << source << " " << dst_type;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001499 UseScratchRegisterScope temps(GetVIXLAssembler());
1500 HConstant* src_cst = source.GetConstant();
1501 CPURegister temp;
Alexandre Ramesb2b753c2016-08-02 13:45:28 +01001502 if (src_cst->IsZeroBitPattern()) {
1503 temp = (src_cst->IsLongConstant() || src_cst->IsDoubleConstant()) ? xzr : wzr;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001504 } else {
Alexandre Ramesb2b753c2016-08-02 13:45:28 +01001505 if (src_cst->IsIntConstant()) {
1506 temp = temps.AcquireW();
1507 } else if (src_cst->IsLongConstant()) {
1508 temp = temps.AcquireX();
1509 } else if (src_cst->IsFloatConstant()) {
1510 temp = temps.AcquireS();
1511 } else {
1512 DCHECK(src_cst->IsDoubleConstant());
1513 temp = temps.AcquireD();
1514 }
1515 MoveConstant(temp, src_cst);
Alexandre Rames3e69f162014-12-10 10:36:50 +00001516 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001517 __ Str(temp, StackOperandFrom(destination));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001518 } else {
Alexandre Rames67555f72014-11-18 10:55:16 +00001519 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001520 DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +00001521 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001522 // There is generally less pressure on FP registers.
1523 FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001524 __ Ldr(temp, StackOperandFrom(source));
1525 __ Str(temp, StackOperandFrom(destination));
1526 }
1527 }
1528}
1529
1530void CodeGeneratorARM64::Load(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001531 CPURegister dst,
1532 const MemOperand& src) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001533 switch (type) {
1534 case Primitive::kPrimBoolean:
Alexandre Rames67555f72014-11-18 10:55:16 +00001535 __ Ldrb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001536 break;
1537 case Primitive::kPrimByte:
Alexandre Rames67555f72014-11-18 10:55:16 +00001538 __ Ldrsb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001539 break;
1540 case Primitive::kPrimShort:
Alexandre Rames67555f72014-11-18 10:55:16 +00001541 __ Ldrsh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001542 break;
1543 case Primitive::kPrimChar:
Alexandre Rames67555f72014-11-18 10:55:16 +00001544 __ Ldrh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001545 break;
1546 case Primitive::kPrimInt:
1547 case Primitive::kPrimNot:
1548 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001549 case Primitive::kPrimFloat:
1550 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +00001551 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Rames67555f72014-11-18 10:55:16 +00001552 __ Ldr(dst, src);
1553 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001554 case Primitive::kPrimVoid:
1555 LOG(FATAL) << "Unreachable type " << type;
1556 }
1557}
1558
Calin Juravle77520bc2015-01-12 18:45:46 +00001559void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001560 CPURegister dst,
Roland Levillain44015862016-01-22 11:47:17 +00001561 const MemOperand& src,
1562 bool needs_null_check) {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001563 MacroAssembler* masm = GetVIXLAssembler();
1564 BlockPoolsScope block_pools(masm);
1565 UseScratchRegisterScope temps(masm);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001566 Register temp_base = temps.AcquireX();
Calin Juravle77520bc2015-01-12 18:45:46 +00001567 Primitive::Type type = instruction->GetType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001568
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001569 DCHECK(!src.IsPreIndex());
1570 DCHECK(!src.IsPostIndex());
1571
1572 // TODO(vixl): Let the MacroAssembler handle MemOperand.
Scott Wakeling97c72b72016-06-24 16:19:36 +01001573 __ Add(temp_base, src.GetBaseRegister(), OperandFromMemOperand(src));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001574 MemOperand base = MemOperand(temp_base);
1575 switch (type) {
1576 case Primitive::kPrimBoolean:
1577 __ Ldarb(Register(dst), base);
Roland Levillain44015862016-01-22 11:47:17 +00001578 if (needs_null_check) {
1579 MaybeRecordImplicitNullCheck(instruction);
1580 }
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001581 break;
1582 case Primitive::kPrimByte:
1583 __ Ldarb(Register(dst), base);
Roland Levillain44015862016-01-22 11:47:17 +00001584 if (needs_null_check) {
1585 MaybeRecordImplicitNullCheck(instruction);
1586 }
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001587 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
1588 break;
1589 case Primitive::kPrimChar:
1590 __ Ldarh(Register(dst), base);
Roland Levillain44015862016-01-22 11:47:17 +00001591 if (needs_null_check) {
1592 MaybeRecordImplicitNullCheck(instruction);
1593 }
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001594 break;
1595 case Primitive::kPrimShort:
1596 __ Ldarh(Register(dst), base);
Roland Levillain44015862016-01-22 11:47:17 +00001597 if (needs_null_check) {
1598 MaybeRecordImplicitNullCheck(instruction);
1599 }
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001600 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
1601 break;
1602 case Primitive::kPrimInt:
1603 case Primitive::kPrimNot:
1604 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +00001605 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001606 __ Ldar(Register(dst), base);
Roland Levillain44015862016-01-22 11:47:17 +00001607 if (needs_null_check) {
1608 MaybeRecordImplicitNullCheck(instruction);
1609 }
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001610 break;
1611 case Primitive::kPrimFloat:
1612 case Primitive::kPrimDouble: {
1613 DCHECK(dst.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +00001614 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001615
1616 Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
1617 __ Ldar(temp, base);
Roland Levillain44015862016-01-22 11:47:17 +00001618 if (needs_null_check) {
1619 MaybeRecordImplicitNullCheck(instruction);
1620 }
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001621 __ Fmov(FPRegister(dst), temp);
1622 break;
1623 }
1624 case Primitive::kPrimVoid:
1625 LOG(FATAL) << "Unreachable type " << type;
1626 }
1627}
1628
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001629void CodeGeneratorARM64::Store(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001630 CPURegister src,
1631 const MemOperand& dst) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001632 switch (type) {
1633 case Primitive::kPrimBoolean:
1634 case Primitive::kPrimByte:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001635 __ Strb(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001636 break;
1637 case Primitive::kPrimChar:
1638 case Primitive::kPrimShort:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001639 __ Strh(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001640 break;
1641 case Primitive::kPrimInt:
1642 case Primitive::kPrimNot:
1643 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001644 case Primitive::kPrimFloat:
1645 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +00001646 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001647 __ Str(src, dst);
Alexandre Rames67555f72014-11-18 10:55:16 +00001648 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001649 case Primitive::kPrimVoid:
1650 LOG(FATAL) << "Unreachable type " << type;
1651 }
1652}
1653
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001654void CodeGeneratorARM64::StoreRelease(Primitive::Type type,
1655 CPURegister src,
1656 const MemOperand& dst) {
1657 UseScratchRegisterScope temps(GetVIXLAssembler());
1658 Register temp_base = temps.AcquireX();
1659
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001660 DCHECK(!dst.IsPreIndex());
1661 DCHECK(!dst.IsPostIndex());
1662
1663 // TODO(vixl): Let the MacroAssembler handle this.
Andreas Gampe878d58c2015-01-15 23:24:00 -08001664 Operand op = OperandFromMemOperand(dst);
Scott Wakeling97c72b72016-06-24 16:19:36 +01001665 __ Add(temp_base, dst.GetBaseRegister(), op);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001666 MemOperand base = MemOperand(temp_base);
1667 switch (type) {
1668 case Primitive::kPrimBoolean:
1669 case Primitive::kPrimByte:
1670 __ Stlrb(Register(src), base);
1671 break;
1672 case Primitive::kPrimChar:
1673 case Primitive::kPrimShort:
1674 __ Stlrh(Register(src), base);
1675 break;
1676 case Primitive::kPrimInt:
1677 case Primitive::kPrimNot:
1678 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +00001679 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001680 __ Stlr(Register(src), base);
1681 break;
1682 case Primitive::kPrimFloat:
1683 case Primitive::kPrimDouble: {
Alexandre Rames542361f2015-01-29 16:57:31 +00001684 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Ramesbe919d92016-08-23 18:33:36 +01001685 Register temp_src;
1686 if (src.IsZero()) {
1687 // The zero register is used to avoid synthesizing zero constants.
1688 temp_src = Register(src);
1689 } else {
1690 DCHECK(src.IsFPRegister());
1691 temp_src = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
1692 __ Fmov(temp_src, FPRegister(src));
1693 }
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001694
Alexandre Ramesbe919d92016-08-23 18:33:36 +01001695 __ Stlr(temp_src, base);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001696 break;
1697 }
1698 case Primitive::kPrimVoid:
1699 LOG(FATAL) << "Unreachable type " << type;
1700 }
1701}
1702
Calin Juravle175dc732015-08-25 15:42:32 +01001703void CodeGeneratorARM64::InvokeRuntime(QuickEntrypointEnum entrypoint,
1704 HInstruction* instruction,
1705 uint32_t dex_pc,
1706 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001707 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001708 GenerateInvokeRuntime(GetThreadOffset<kArm64PointerSize>(entrypoint).Int32Value());
Serban Constantinescuda8ffec2016-03-09 12:02:11 +00001709 if (EntrypointRequiresStackMap(entrypoint)) {
1710 RecordPcInfo(instruction, dex_pc, slow_path);
1711 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001712}
1713
Roland Levillaindec8f632016-07-22 17:10:06 +01001714void CodeGeneratorARM64::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
1715 HInstruction* instruction,
1716 SlowPathCode* slow_path) {
1717 ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path);
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001718 GenerateInvokeRuntime(entry_point_offset);
1719}
1720
1721void CodeGeneratorARM64::GenerateInvokeRuntime(int32_t entry_point_offset) {
Roland Levillaindec8f632016-07-22 17:10:06 +01001722 BlockPoolsScope block_pools(GetVIXLAssembler());
1723 __ Ldr(lr, MemOperand(tr, entry_point_offset));
1724 __ Blr(lr);
1725}
1726
Alexandre Rames67555f72014-11-18 10:55:16 +00001727void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path,
Scott Wakeling97c72b72016-06-24 16:19:36 +01001728 Register class_reg) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001729 UseScratchRegisterScope temps(GetVIXLAssembler());
1730 Register temp = temps.AcquireW();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001731 size_t status_offset = mirror::Class::StatusOffset().SizeValue();
1732
Serban Constantinescu02164b32014-11-13 14:05:07 +00001733 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
Serban Constantinescu4a6a67c2016-01-27 09:19:56 +00001734 // TODO(vixl): Let the MacroAssembler handle MemOperand.
1735 __ Add(temp, class_reg, status_offset);
1736 __ Ldar(temp, HeapOperand(temp));
1737 __ Cmp(temp, mirror::Class::kStatusInitialized);
1738 __ B(lt, slow_path->GetEntryLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +00001739 __ Bind(slow_path->GetExitLabel());
1740}
Alexandre Rames5319def2014-10-23 10:03:10 +01001741
Roland Levillain44015862016-01-22 11:47:17 +00001742void CodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001743 BarrierType type = BarrierAll;
1744
1745 switch (kind) {
1746 case MemBarrierKind::kAnyAny:
1747 case MemBarrierKind::kAnyStore: {
1748 type = BarrierAll;
1749 break;
1750 }
1751 case MemBarrierKind::kLoadAny: {
1752 type = BarrierReads;
1753 break;
1754 }
1755 case MemBarrierKind::kStoreStore: {
1756 type = BarrierWrites;
1757 break;
1758 }
1759 default:
1760 LOG(FATAL) << "Unexpected memory barrier " << kind;
1761 }
1762 __ Dmb(InnerShareable, type);
1763}
1764
Serban Constantinescu02164b32014-11-13 14:05:07 +00001765void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction,
1766 HBasicBlock* successor) {
1767 SuspendCheckSlowPathARM64* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01001768 down_cast<SuspendCheckSlowPathARM64*>(instruction->GetSlowPath());
1769 if (slow_path == nullptr) {
1770 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor);
1771 instruction->SetSlowPath(slow_path);
1772 codegen_->AddSlowPath(slow_path);
1773 if (successor != nullptr) {
1774 DCHECK(successor->IsLoopHeader());
1775 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
1776 }
1777 } else {
1778 DCHECK_EQ(slow_path->GetSuccessor(), successor);
1779 }
1780
Serban Constantinescu02164b32014-11-13 14:05:07 +00001781 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
1782 Register temp = temps.AcquireW();
1783
Andreas Gampe542451c2016-07-26 09:02:02 -07001784 __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64PointerSize>().SizeValue()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001785 if (successor == nullptr) {
1786 __ Cbnz(temp, slow_path->GetEntryLabel());
1787 __ Bind(slow_path->GetReturnLabel());
1788 } else {
1789 __ Cbz(temp, codegen_->GetLabelOf(successor));
1790 __ B(slow_path->GetEntryLabel());
1791 // slow_path will return to GetLabelOf(successor).
1792 }
1793}
1794
Alexandre Rames5319def2014-10-23 10:03:10 +01001795InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
1796 CodeGeneratorARM64* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001797 : InstructionCodeGenerator(graph, codegen),
Alexandre Rames5319def2014-10-23 10:03:10 +01001798 assembler_(codegen->GetAssembler()),
1799 codegen_(codegen) {}
1800
1801#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Alexandre Rames3e69f162014-12-10 10:36:50 +00001802 /* No unimplemented IR. */
Alexandre Rames5319def2014-10-23 10:03:10 +01001803
1804#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
1805
1806enum UnimplementedInstructionBreakCode {
Alexandre Rames67555f72014-11-18 10:55:16 +00001807 // Using a base helps identify when we hit such breakpoints.
1808 UnimplementedInstructionBreakCodeBaseCode = 0x900,
Alexandre Rames5319def2014-10-23 10:03:10 +01001809#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
1810 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
1811#undef ENUM_UNIMPLEMENTED_INSTRUCTION
1812};
1813
1814#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001815 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr ATTRIBUTE_UNUSED) { \
Alexandre Rames5319def2014-10-23 10:03:10 +01001816 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
1817 } \
1818 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
1819 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
1820 locations->SetOut(Location::Any()); \
1821 }
1822 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
1823#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
1824
1825#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
Alexandre Rames67555f72014-11-18 10:55:16 +00001826#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
Alexandre Rames5319def2014-10-23 10:03:10 +01001827
Alexandre Rames67555f72014-11-18 10:55:16 +00001828void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001829 DCHECK_EQ(instr->InputCount(), 2U);
1830 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1831 Primitive::Type type = instr->GetResultType();
1832 switch (type) {
1833 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001834 case Primitive::kPrimLong:
Alexandre Rames5319def2014-10-23 10:03:10 +01001835 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001836 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr));
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001837 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001838 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001839
1840 case Primitive::kPrimFloat:
1841 case Primitive::kPrimDouble:
1842 locations->SetInAt(0, Location::RequiresFpuRegister());
1843 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001844 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001845 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001846
Alexandre Rames5319def2014-10-23 10:03:10 +01001847 default:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001848 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001849 }
1850}
1851
Alexandre Rames09a99962015-04-15 11:47:56 +01001852void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) {
Roland Levillain22ccc3a2015-11-24 13:10:05 +00001853 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
1854
1855 bool object_field_get_with_read_barrier =
1856 kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot);
Alexandre Rames09a99962015-04-15 11:47:56 +01001857 LocationSummary* locations =
Roland Levillain22ccc3a2015-11-24 13:10:05 +00001858 new (GetGraph()->GetArena()) LocationSummary(instruction,
1859 object_field_get_with_read_barrier ?
1860 LocationSummary::kCallOnSlowPath :
1861 LocationSummary::kNoCall);
Vladimir Marko70e97462016-08-09 11:04:26 +01001862 if (object_field_get_with_read_barrier && kUseBakerReadBarrier) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01001863 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Vladimir Marko70e97462016-08-09 11:04:26 +01001864 }
Alexandre Rames09a99962015-04-15 11:47:56 +01001865 locations->SetInAt(0, Location::RequiresRegister());
1866 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1867 locations->SetOut(Location::RequiresFpuRegister());
1868 } else {
Roland Levillain22ccc3a2015-11-24 13:10:05 +00001869 // The output overlaps for an object field get when read barriers
1870 // are enabled: we do not want the load to overwrite the object's
1871 // location, as we need it to emit the read barrier.
1872 locations->SetOut(
1873 Location::RequiresRegister(),
1874 object_field_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Alexandre Rames09a99962015-04-15 11:47:56 +01001875 }
1876}
1877
1878void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction,
1879 const FieldInfo& field_info) {
1880 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Roland Levillain44015862016-01-22 11:47:17 +00001881 LocationSummary* locations = instruction->GetLocations();
1882 Location base_loc = locations->InAt(0);
1883 Location out = locations->Out();
1884 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Roland Levillain4d027112015-07-01 15:41:14 +01001885 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Ramesd921d642015-04-16 15:07:16 +01001886 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001887 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset());
Alexandre Rames09a99962015-04-15 11:47:56 +01001888
Roland Levillain44015862016-01-22 11:47:17 +00001889 if (field_type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1890 // Object FieldGet with Baker's read barrier case.
1891 MacroAssembler* masm = GetVIXLAssembler();
1892 UseScratchRegisterScope temps(masm);
1893 // /* HeapReference<Object> */ out = *(base + offset)
1894 Register base = RegisterFrom(base_loc, Primitive::kPrimNot);
1895 Register temp = temps.AcquireW();
1896 // Note that potential implicit null checks are handled in this
1897 // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier call.
1898 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1899 instruction,
1900 out,
1901 base,
1902 offset,
1903 temp,
1904 /* needs_null_check */ true,
Serban Constantinescu4a6a67c2016-01-27 09:19:56 +00001905 field_info.IsVolatile());
Roland Levillain44015862016-01-22 11:47:17 +00001906 } else {
1907 // General case.
1908 if (field_info.IsVolatile()) {
Serban Constantinescu4a6a67c2016-01-27 09:19:56 +00001909 // Note that a potential implicit null check is handled in this
1910 // CodeGeneratorARM64::LoadAcquire call.
1911 // NB: LoadAcquire will record the pc info if needed.
1912 codegen_->LoadAcquire(
1913 instruction, OutputCPURegister(instruction), field, /* needs_null_check */ true);
Alexandre Rames09a99962015-04-15 11:47:56 +01001914 } else {
Roland Levillain4d027112015-07-01 15:41:14 +01001915 codegen_->Load(field_type, OutputCPURegister(instruction), field);
Alexandre Rames09a99962015-04-15 11:47:56 +01001916 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Rames09a99962015-04-15 11:47:56 +01001917 }
Roland Levillain44015862016-01-22 11:47:17 +00001918 if (field_type == Primitive::kPrimNot) {
1919 // If read barriers are enabled, emit read barriers other than
1920 // Baker's using a slow path (and also unpoison the loaded
1921 // reference, if heap poisoning is enabled).
1922 codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset);
1923 }
Roland Levillain4d027112015-07-01 15:41:14 +01001924 }
Alexandre Rames09a99962015-04-15 11:47:56 +01001925}
1926
1927void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) {
1928 LocationSummary* locations =
1929 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1930 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesbe919d92016-08-23 18:33:36 +01001931 if (IsConstantZeroBitPattern(instruction->InputAt(1))) {
1932 locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant()));
1933 } else if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001934 locations->SetInAt(1, Location::RequiresFpuRegister());
1935 } else {
1936 locations->SetInAt(1, Location::RequiresRegister());
1937 }
1938}
1939
1940void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01001941 const FieldInfo& field_info,
1942 bool value_can_be_null) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001943 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
Alexandre Ramesd921d642015-04-16 15:07:16 +01001944 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001945
1946 Register obj = InputRegisterAt(instruction, 0);
Alexandre Ramesbe919d92016-08-23 18:33:36 +01001947 CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 1);
Roland Levillain4d027112015-07-01 15:41:14 +01001948 CPURegister source = value;
Alexandre Rames09a99962015-04-15 11:47:56 +01001949 Offset offset = field_info.GetFieldOffset();
1950 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames09a99962015-04-15 11:47:56 +01001951
Roland Levillain4d027112015-07-01 15:41:14 +01001952 {
1953 // We use a block to end the scratch scope before the write barrier, thus
1954 // freeing the temporary registers so they can be used in `MarkGCCard`.
1955 UseScratchRegisterScope temps(GetVIXLAssembler());
1956
1957 if (kPoisonHeapReferences && field_type == Primitive::kPrimNot) {
1958 DCHECK(value.IsW());
1959 Register temp = temps.AcquireW();
1960 __ Mov(temp, value.W());
1961 GetAssembler()->PoisonHeapReference(temp.W());
1962 source = temp;
Alexandre Rames09a99962015-04-15 11:47:56 +01001963 }
Roland Levillain4d027112015-07-01 15:41:14 +01001964
1965 if (field_info.IsVolatile()) {
Serban Constantinescu4a6a67c2016-01-27 09:19:56 +00001966 codegen_->StoreRelease(field_type, source, HeapOperand(obj, offset));
1967 codegen_->MaybeRecordImplicitNullCheck(instruction);
Roland Levillain4d027112015-07-01 15:41:14 +01001968 } else {
1969 codegen_->Store(field_type, source, HeapOperand(obj, offset));
1970 codegen_->MaybeRecordImplicitNullCheck(instruction);
1971 }
Alexandre Rames09a99962015-04-15 11:47:56 +01001972 }
1973
1974 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01001975 codegen_->MarkGCCard(obj, Register(value), value_can_be_null);
Alexandre Rames09a99962015-04-15 11:47:56 +01001976 }
1977}
1978
Alexandre Rames67555f72014-11-18 10:55:16 +00001979void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001980 Primitive::Type type = instr->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001981
1982 switch (type) {
1983 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001984 case Primitive::kPrimLong: {
1985 Register dst = OutputRegister(instr);
1986 Register lhs = InputRegisterAt(instr, 0);
1987 Operand rhs = InputOperandAt(instr, 1);
Alexandre Rames5319def2014-10-23 10:03:10 +01001988 if (instr->IsAdd()) {
1989 __ Add(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001990 } else if (instr->IsAnd()) {
1991 __ And(dst, lhs, rhs);
1992 } else if (instr->IsOr()) {
1993 __ Orr(dst, lhs, rhs);
1994 } else if (instr->IsSub()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001995 __ Sub(dst, lhs, rhs);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00001996 } else if (instr->IsRor()) {
1997 if (rhs.IsImmediate()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01001998 uint32_t shift = rhs.GetImmediate() & (lhs.GetSizeInBits() - 1);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00001999 __ Ror(dst, lhs, shift);
2000 } else {
2001 // Ensure shift distance is in the same size register as the result. If
2002 // we are rotating a long and the shift comes in a w register originally,
2003 // we don't need to sxtw for use as an x since the shift distances are
2004 // all & reg_bits - 1.
2005 __ Ror(dst, lhs, RegisterFrom(instr->GetLocations()->InAt(1), type));
2006 }
Alexandre Rames67555f72014-11-18 10:55:16 +00002007 } else {
2008 DCHECK(instr->IsXor());
2009 __ Eor(dst, lhs, rhs);
Alexandre Rames5319def2014-10-23 10:03:10 +01002010 }
2011 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002012 }
2013 case Primitive::kPrimFloat:
2014 case Primitive::kPrimDouble: {
2015 FPRegister dst = OutputFPRegister(instr);
2016 FPRegister lhs = InputFPRegisterAt(instr, 0);
2017 FPRegister rhs = InputFPRegisterAt(instr, 1);
2018 if (instr->IsAdd()) {
2019 __ Fadd(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00002020 } else if (instr->IsSub()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002021 __ Fsub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00002022 } else {
2023 LOG(FATAL) << "Unexpected floating-point binary operation";
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002024 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002025 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002026 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002027 default:
Alexandre Rames67555f72014-11-18 10:55:16 +00002028 LOG(FATAL) << "Unexpected binary operation type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01002029 }
2030}
2031
Serban Constantinescu02164b32014-11-13 14:05:07 +00002032void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) {
2033 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
2034
2035 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
2036 Primitive::Type type = instr->GetResultType();
2037 switch (type) {
2038 case Primitive::kPrimInt:
2039 case Primitive::kPrimLong: {
2040 locations->SetInAt(0, Location::RequiresRegister());
2041 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
2042 locations->SetOut(Location::RequiresRegister());
2043 break;
2044 }
2045 default:
2046 LOG(FATAL) << "Unexpected shift type " << type;
2047 }
2048}
2049
2050void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) {
2051 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
2052
2053 Primitive::Type type = instr->GetType();
2054 switch (type) {
2055 case Primitive::kPrimInt:
2056 case Primitive::kPrimLong: {
2057 Register dst = OutputRegister(instr);
2058 Register lhs = InputRegisterAt(instr, 0);
2059 Operand rhs = InputOperandAt(instr, 1);
2060 if (rhs.IsImmediate()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01002061 uint32_t shift_value = rhs.GetImmediate() &
Roland Levillain5b5b9312016-03-22 14:57:31 +00002062 (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002063 if (instr->IsShl()) {
2064 __ Lsl(dst, lhs, shift_value);
2065 } else if (instr->IsShr()) {
2066 __ Asr(dst, lhs, shift_value);
2067 } else {
2068 __ Lsr(dst, lhs, shift_value);
2069 }
2070 } else {
Scott Wakeling97c72b72016-06-24 16:19:36 +01002071 Register rhs_reg = dst.IsX() ? rhs.GetRegister().X() : rhs.GetRegister().W();
Serban Constantinescu02164b32014-11-13 14:05:07 +00002072
2073 if (instr->IsShl()) {
2074 __ Lsl(dst, lhs, rhs_reg);
2075 } else if (instr->IsShr()) {
2076 __ Asr(dst, lhs, rhs_reg);
2077 } else {
2078 __ Lsr(dst, lhs, rhs_reg);
2079 }
2080 }
2081 break;
2082 }
2083 default:
2084 LOG(FATAL) << "Unexpected shift operation type " << type;
2085 }
2086}
2087
Alexandre Rames5319def2014-10-23 10:03:10 +01002088void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002089 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002090}
2091
2092void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002093 HandleBinaryOp(instruction);
2094}
2095
2096void LocationsBuilderARM64::VisitAnd(HAnd* instruction) {
2097 HandleBinaryOp(instruction);
2098}
2099
2100void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) {
2101 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002102}
2103
Artem Serov7fc63502016-02-09 17:15:29 +00002104void LocationsBuilderARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) {
Kevin Brodsky9ff0d202016-01-11 13:43:31 +00002105 DCHECK(Primitive::IsIntegralType(instr->GetType())) << instr->GetType();
2106 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
2107 locations->SetInAt(0, Location::RequiresRegister());
2108 // There is no immediate variant of negated bitwise instructions in AArch64.
2109 locations->SetInAt(1, Location::RequiresRegister());
2110 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2111}
2112
Artem Serov7fc63502016-02-09 17:15:29 +00002113void InstructionCodeGeneratorARM64::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instr) {
Kevin Brodsky9ff0d202016-01-11 13:43:31 +00002114 Register dst = OutputRegister(instr);
2115 Register lhs = InputRegisterAt(instr, 0);
2116 Register rhs = InputRegisterAt(instr, 1);
2117
2118 switch (instr->GetOpKind()) {
2119 case HInstruction::kAnd:
2120 __ Bic(dst, lhs, rhs);
2121 break;
2122 case HInstruction::kOr:
2123 __ Orn(dst, lhs, rhs);
2124 break;
2125 case HInstruction::kXor:
2126 __ Eon(dst, lhs, rhs);
2127 break;
2128 default:
2129 LOG(FATAL) << "Unreachable";
2130 }
2131}
2132
Alexandre Rames8626b742015-11-25 16:28:08 +00002133void LocationsBuilderARM64::VisitArm64DataProcWithShifterOp(
2134 HArm64DataProcWithShifterOp* instruction) {
2135 DCHECK(instruction->GetType() == Primitive::kPrimInt ||
2136 instruction->GetType() == Primitive::kPrimLong);
2137 LocationSummary* locations =
2138 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2139 if (instruction->GetInstrKind() == HInstruction::kNeg) {
2140 locations->SetInAt(0, Location::ConstantLocation(instruction->InputAt(0)->AsConstant()));
2141 } else {
2142 locations->SetInAt(0, Location::RequiresRegister());
2143 }
2144 locations->SetInAt(1, Location::RequiresRegister());
2145 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2146}
2147
2148void InstructionCodeGeneratorARM64::VisitArm64DataProcWithShifterOp(
2149 HArm64DataProcWithShifterOp* instruction) {
2150 Primitive::Type type = instruction->GetType();
2151 HInstruction::InstructionKind kind = instruction->GetInstrKind();
2152 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
2153 Register out = OutputRegister(instruction);
2154 Register left;
2155 if (kind != HInstruction::kNeg) {
2156 left = InputRegisterAt(instruction, 0);
2157 }
2158 // If this `HArm64DataProcWithShifterOp` was created by merging a type conversion as the
2159 // shifter operand operation, the IR generating `right_reg` (input to the type
2160 // conversion) can have a different type from the current instruction's type,
2161 // so we manually indicate the type.
2162 Register right_reg = RegisterFrom(instruction->GetLocations()->InAt(1), type);
Roland Levillain5b5b9312016-03-22 14:57:31 +00002163 int64_t shift_amount = instruction->GetShiftAmount() &
2164 (type == Primitive::kPrimInt ? kMaxIntShiftDistance : kMaxLongShiftDistance);
Alexandre Rames8626b742015-11-25 16:28:08 +00002165
2166 Operand right_operand(0);
2167
2168 HArm64DataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind();
2169 if (HArm64DataProcWithShifterOp::IsExtensionOp(op_kind)) {
2170 right_operand = Operand(right_reg, helpers::ExtendFromOpKind(op_kind));
2171 } else {
2172 right_operand = Operand(right_reg, helpers::ShiftFromOpKind(op_kind), shift_amount);
2173 }
2174
2175 // Logical binary operations do not support extension operations in the
2176 // operand. Note that VIXL would still manage if it was passed by generating
2177 // the extension as a separate instruction.
2178 // `HNeg` also does not support extension. See comments in `ShifterOperandSupportsExtension()`.
2179 DCHECK(!right_operand.IsExtendedRegister() ||
2180 (kind != HInstruction::kAnd && kind != HInstruction::kOr && kind != HInstruction::kXor &&
2181 kind != HInstruction::kNeg));
2182 switch (kind) {
2183 case HInstruction::kAdd:
2184 __ Add(out, left, right_operand);
2185 break;
2186 case HInstruction::kAnd:
2187 __ And(out, left, right_operand);
2188 break;
2189 case HInstruction::kNeg:
Roland Levillain1a653882016-03-18 18:05:57 +00002190 DCHECK(instruction->InputAt(0)->AsConstant()->IsArithmeticZero());
Alexandre Rames8626b742015-11-25 16:28:08 +00002191 __ Neg(out, right_operand);
2192 break;
2193 case HInstruction::kOr:
2194 __ Orr(out, left, right_operand);
2195 break;
2196 case HInstruction::kSub:
2197 __ Sub(out, left, right_operand);
2198 break;
2199 case HInstruction::kXor:
2200 __ Eor(out, left, right_operand);
2201 break;
2202 default:
2203 LOG(FATAL) << "Unexpected operation kind: " << kind;
2204 UNREACHABLE();
2205 }
2206}
2207
Artem Serov328429f2016-07-06 16:23:04 +01002208void LocationsBuilderARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) {
Alexandre Ramese6dbf482015-10-19 10:10:41 +01002209 LocationSummary* locations =
2210 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2211 locations->SetInAt(0, Location::RequiresRegister());
2212 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->GetOffset(), instruction));
2213 locations->SetOut(Location::RequiresRegister());
2214}
2215
Roland Levillain19c54192016-11-04 13:44:09 +00002216void InstructionCodeGeneratorARM64::VisitIntermediateAddress(HIntermediateAddress* instruction) {
Alexandre Ramese6dbf482015-10-19 10:10:41 +01002217 __ Add(OutputRegister(instruction),
2218 InputRegisterAt(instruction, 0),
2219 Operand(InputOperandAt(instruction, 1)));
2220}
2221
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03002222void LocationsBuilderARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
Alexandre Rames418318f2015-11-20 15:55:47 +00002223 LocationSummary* locations =
2224 new (GetGraph()->GetArena()) LocationSummary(instr, LocationSummary::kNoCall);
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03002225 HInstruction* accumulator = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex);
2226 if (instr->GetOpKind() == HInstruction::kSub &&
2227 accumulator->IsConstant() &&
Roland Levillain1a653882016-03-18 18:05:57 +00002228 accumulator->AsConstant()->IsArithmeticZero()) {
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03002229 // Don't allocate register for Mneg instruction.
2230 } else {
2231 locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex,
2232 Location::RequiresRegister());
2233 }
2234 locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister());
2235 locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister());
Alexandre Rames418318f2015-11-20 15:55:47 +00002236 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2237}
2238
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03002239void InstructionCodeGeneratorARM64::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) {
Alexandre Rames418318f2015-11-20 15:55:47 +00002240 Register res = OutputRegister(instr);
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03002241 Register mul_left = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex);
2242 Register mul_right = InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex);
Alexandre Rames418318f2015-11-20 15:55:47 +00002243
2244 // Avoid emitting code that could trigger Cortex A53's erratum 835769.
2245 // This fixup should be carried out for all multiply-accumulate instructions:
2246 // madd, msub, smaddl, smsubl, umaddl and umsubl.
2247 if (instr->GetType() == Primitive::kPrimLong &&
2248 codegen_->GetInstructionSetFeatures().NeedFixCortexA53_835769()) {
2249 MacroAssembler* masm = down_cast<CodeGeneratorARM64*>(codegen_)->GetVIXLAssembler();
Scott Wakeling97c72b72016-06-24 16:19:36 +01002250 vixl::aarch64::Instruction* prev =
2251 masm->GetCursorAddress<vixl::aarch64::Instruction*>() - kInstructionSize;
Alexandre Rames418318f2015-11-20 15:55:47 +00002252 if (prev->IsLoadOrStore()) {
2253 // Make sure we emit only exactly one nop.
Scott Wakeling97c72b72016-06-24 16:19:36 +01002254 vixl::aarch64::CodeBufferCheckScope scope(masm,
2255 kInstructionSize,
2256 vixl::aarch64::CodeBufferCheckScope::kCheck,
2257 vixl::aarch64::CodeBufferCheckScope::kExactSize);
Alexandre Rames418318f2015-11-20 15:55:47 +00002258 __ nop();
2259 }
2260 }
2261
2262 if (instr->GetOpKind() == HInstruction::kAdd) {
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03002263 Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex);
Alexandre Rames418318f2015-11-20 15:55:47 +00002264 __ Madd(res, mul_left, mul_right, accumulator);
2265 } else {
2266 DCHECK(instr->GetOpKind() == HInstruction::kSub);
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03002267 HInstruction* accum_instr = instr->InputAt(HMultiplyAccumulate::kInputAccumulatorIndex);
Roland Levillain1a653882016-03-18 18:05:57 +00002268 if (accum_instr->IsConstant() && accum_instr->AsConstant()->IsArithmeticZero()) {
Artem Udovichenko4a0dad62016-01-26 12:28:31 +03002269 __ Mneg(res, mul_left, mul_right);
2270 } else {
2271 Register accumulator = InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex);
2272 __ Msub(res, mul_left, mul_right, accumulator);
2273 }
Alexandre Rames418318f2015-11-20 15:55:47 +00002274 }
2275}
2276
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002277void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) {
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002278 bool object_array_get_with_read_barrier =
2279 kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002280 LocationSummary* locations =
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002281 new (GetGraph()->GetArena()) LocationSummary(instruction,
2282 object_array_get_with_read_barrier ?
2283 LocationSummary::kCallOnSlowPath :
2284 LocationSummary::kNoCall);
Vladimir Marko70e97462016-08-09 11:04:26 +01002285 if (object_array_get_with_read_barrier && kUseBakerReadBarrier) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002286 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Vladimir Marko70e97462016-08-09 11:04:26 +01002287 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002288 locations->SetInAt(0, Location::RequiresRegister());
2289 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01002290 if (Primitive::IsFloatingPointType(instruction->GetType())) {
2291 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2292 } else {
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002293 // The output overlaps in the case of an object array get with
2294 // read barriers enabled: we do not want the move to overwrite the
2295 // array's location, as we need it to emit the read barrier.
2296 locations->SetOut(
2297 Location::RequiresRegister(),
2298 object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Alexandre Rames88c13cd2015-04-14 17:35:39 +01002299 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002300}
2301
2302void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002303 Primitive::Type type = instruction->GetType();
2304 Register obj = InputRegisterAt(instruction, 0);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002305 LocationSummary* locations = instruction->GetLocations();
2306 Location index = locations->InAt(1);
Roland Levillain44015862016-01-22 11:47:17 +00002307 Location out = locations->Out();
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01002308 uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction);
jessicahandojo05765752016-09-09 19:01:32 -07002309 const bool maybe_compressed_char_at = mirror::kUseStringCompression &&
2310 instruction->IsStringCharAt();
Alexandre Ramesd921d642015-04-16 15:07:16 +01002311 MacroAssembler* masm = GetVIXLAssembler();
2312 UseScratchRegisterScope temps(masm);
Alexandre Ramese6dbf482015-10-19 10:10:41 +01002313 // Block pools between `Load` and `MaybeRecordImplicitNullCheck`.
Alexandre Ramesd921d642015-04-16 15:07:16 +01002314 BlockPoolsScope block_pools(masm);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002315
Roland Levillain19c54192016-11-04 13:44:09 +00002316 // The read barrier instrumentation of object ArrayGet instructions
2317 // does not support the HIntermediateAddress instruction.
2318 DCHECK(!((type == Primitive::kPrimNot) &&
2319 instruction->GetArray()->IsIntermediateAddress() &&
2320 kEmitCompilerReadBarrier));
2321
Roland Levillain44015862016-01-22 11:47:17 +00002322 if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
2323 // Object ArrayGet with Baker's read barrier case.
2324 Register temp = temps.AcquireW();
Roland Levillain44015862016-01-22 11:47:17 +00002325 // Note that a potential implicit null check is handled in the
2326 // CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier call.
2327 codegen_->GenerateArrayLoadWithBakerReadBarrier(
2328 instruction, out, obj.W(), offset, index, temp, /* needs_null_check */ true);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002329 } else {
Roland Levillain44015862016-01-22 11:47:17 +00002330 // General case.
2331 MemOperand source = HeapOperand(obj);
jessicahandojo05765752016-09-09 19:01:32 -07002332 Register length;
2333 if (maybe_compressed_char_at) {
2334 uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
2335 length = temps.AcquireW();
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002336 if (instruction->GetArray()->IsIntermediateAddress()) {
2337 DCHECK_LT(count_offset, offset);
2338 int64_t adjusted_offset = static_cast<int64_t>(count_offset) - static_cast<int64_t>(offset);
2339 // Note that `adjusted_offset` is negative, so this will be a LDUR.
2340 __ Ldr(length, MemOperand(obj.X(), adjusted_offset));
2341 } else {
2342 __ Ldr(length, HeapOperand(obj, count_offset));
2343 }
jessicahandojo05765752016-09-09 19:01:32 -07002344 codegen_->MaybeRecordImplicitNullCheck(instruction);
2345 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002346 if (index.IsConstant()) {
jessicahandojo05765752016-09-09 19:01:32 -07002347 if (maybe_compressed_char_at) {
2348 vixl::aarch64::Label uncompressed_load, done;
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002349 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
2350 "Expecting 0=compressed, 1=uncompressed");
2351 __ Tbnz(length.W(), 0, &uncompressed_load);
jessicahandojo05765752016-09-09 19:01:32 -07002352 __ Ldrb(Register(OutputCPURegister(instruction)),
2353 HeapOperand(obj, offset + Int64ConstantFrom(index)));
2354 __ B(&done);
2355 __ Bind(&uncompressed_load);
2356 __ Ldrh(Register(OutputCPURegister(instruction)),
2357 HeapOperand(obj, offset + (Int64ConstantFrom(index) << 1)));
2358 __ Bind(&done);
2359 } else {
2360 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type);
2361 source = HeapOperand(obj, offset);
2362 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002363 } else {
Roland Levillain44015862016-01-22 11:47:17 +00002364 Register temp = temps.AcquireSameSizeAs(obj);
Artem Serov328429f2016-07-06 16:23:04 +01002365 if (instruction->GetArray()->IsIntermediateAddress()) {
Roland Levillain44015862016-01-22 11:47:17 +00002366 // We do not need to compute the intermediate address from the array: the
2367 // input instruction has done it already. See the comment in
Artem Serov328429f2016-07-06 16:23:04 +01002368 // `TryExtractArrayAccessAddress()`.
Roland Levillain44015862016-01-22 11:47:17 +00002369 if (kIsDebugBuild) {
Artem Serov328429f2016-07-06 16:23:04 +01002370 HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress();
Roland Levillain44015862016-01-22 11:47:17 +00002371 DCHECK_EQ(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64(), offset);
2372 }
2373 temp = obj;
2374 } else {
2375 __ Add(temp, obj, offset);
2376 }
jessicahandojo05765752016-09-09 19:01:32 -07002377 if (maybe_compressed_char_at) {
2378 vixl::aarch64::Label uncompressed_load, done;
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002379 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
2380 "Expecting 0=compressed, 1=uncompressed");
2381 __ Tbnz(length.W(), 0, &uncompressed_load);
jessicahandojo05765752016-09-09 19:01:32 -07002382 __ Ldrb(Register(OutputCPURegister(instruction)),
2383 HeapOperand(temp, XRegisterFrom(index), LSL, 0));
2384 __ B(&done);
2385 __ Bind(&uncompressed_load);
2386 __ Ldrh(Register(OutputCPURegister(instruction)),
2387 HeapOperand(temp, XRegisterFrom(index), LSL, 1));
2388 __ Bind(&done);
2389 } else {
2390 source = HeapOperand(temp, XRegisterFrom(index), LSL, Primitive::ComponentSizeShift(type));
2391 }
Roland Levillain44015862016-01-22 11:47:17 +00002392 }
jessicahandojo05765752016-09-09 19:01:32 -07002393 if (!maybe_compressed_char_at) {
2394 codegen_->Load(type, OutputCPURegister(instruction), source);
2395 codegen_->MaybeRecordImplicitNullCheck(instruction);
2396 }
Roland Levillain44015862016-01-22 11:47:17 +00002397
2398 if (type == Primitive::kPrimNot) {
2399 static_assert(
2400 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
2401 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
2402 Location obj_loc = locations->InAt(0);
2403 if (index.IsConstant()) {
2404 codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset);
2405 } else {
2406 codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, obj_loc, offset, index);
2407 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002408 }
Roland Levillain4d027112015-07-01 15:41:14 +01002409 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002410}
2411
Alexandre Rames5319def2014-10-23 10:03:10 +01002412void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
2413 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2414 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002415 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002416}
2417
2418void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
Vladimir Markodce016e2016-04-28 13:10:02 +01002419 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
jessicahandojo05765752016-09-09 19:01:32 -07002420 vixl::aarch64::Register out = OutputRegister(instruction);
Alexandre Ramesd921d642015-04-16 15:07:16 +01002421 BlockPoolsScope block_pools(GetVIXLAssembler());
jessicahandojo05765752016-09-09 19:01:32 -07002422 __ Ldr(out, HeapOperand(InputRegisterAt(instruction, 0), offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00002423 codegen_->MaybeRecordImplicitNullCheck(instruction);
jessicahandojo05765752016-09-09 19:01:32 -07002424 // Mask out compression flag from String's array length.
2425 if (mirror::kUseStringCompression && instruction->IsStringLength()) {
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002426 __ Lsr(out.W(), out.W(), 1u);
jessicahandojo05765752016-09-09 19:01:32 -07002427 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002428}
2429
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002430void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) {
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002431 Primitive::Type value_type = instruction->GetComponentType();
2432
2433 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002434 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2435 instruction,
Vladimir Marko8d49fd72016-08-25 15:20:47 +01002436 may_need_runtime_call_for_type_check ?
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002437 LocationSummary::kCallOnSlowPath :
2438 LocationSummary::kNoCall);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002439 locations->SetInAt(0, Location::RequiresRegister());
2440 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Ramesbe919d92016-08-23 18:33:36 +01002441 if (IsConstantZeroBitPattern(instruction->InputAt(2))) {
2442 locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant()));
2443 } else if (Primitive::IsFloatingPointType(value_type)) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002444 locations->SetInAt(2, Location::RequiresFpuRegister());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002445 } else {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002446 locations->SetInAt(2, Location::RequiresRegister());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002447 }
2448}
2449
2450void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) {
2451 Primitive::Type value_type = instruction->GetComponentType();
Alexandre Rames97833a02015-04-16 15:07:12 +01002452 LocationSummary* locations = instruction->GetLocations();
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002453 bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck();
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002454 bool needs_write_barrier =
2455 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Alexandre Rames97833a02015-04-16 15:07:12 +01002456
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002457 Register array = InputRegisterAt(instruction, 0);
Alexandre Ramesbe919d92016-08-23 18:33:36 +01002458 CPURegister value = InputCPURegisterOrZeroRegAt(instruction, 2);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002459 CPURegister source = value;
2460 Location index = locations->InAt(1);
2461 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
2462 MemOperand destination = HeapOperand(array);
2463 MacroAssembler* masm = GetVIXLAssembler();
2464 BlockPoolsScope block_pools(masm);
2465
2466 if (!needs_write_barrier) {
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002467 DCHECK(!may_need_runtime_call_for_type_check);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002468 if (index.IsConstant()) {
2469 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
2470 destination = HeapOperand(array, offset);
2471 } else {
2472 UseScratchRegisterScope temps(masm);
2473 Register temp = temps.AcquireSameSizeAs(array);
Artem Serov328429f2016-07-06 16:23:04 +01002474 if (instruction->GetArray()->IsIntermediateAddress()) {
Alexandre Ramese6dbf482015-10-19 10:10:41 +01002475 // We do not need to compute the intermediate address from the array: the
2476 // input instruction has done it already. See the comment in
Artem Serov328429f2016-07-06 16:23:04 +01002477 // `TryExtractArrayAccessAddress()`.
Alexandre Ramese6dbf482015-10-19 10:10:41 +01002478 if (kIsDebugBuild) {
Artem Serov328429f2016-07-06 16:23:04 +01002479 HIntermediateAddress* tmp = instruction->GetArray()->AsIntermediateAddress();
Alexandre Ramese6dbf482015-10-19 10:10:41 +01002480 DCHECK(tmp->GetOffset()->AsIntConstant()->GetValueAsUint64() == offset);
2481 }
2482 temp = array;
2483 } else {
2484 __ Add(temp, array, offset);
2485 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002486 destination = HeapOperand(temp,
2487 XRegisterFrom(index),
2488 LSL,
2489 Primitive::ComponentSizeShift(value_type));
2490 }
2491 codegen_->Store(value_type, value, destination);
2492 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002493 } else {
Artem Serov328429f2016-07-06 16:23:04 +01002494 DCHECK(!instruction->GetArray()->IsIntermediateAddress());
Scott Wakeling97c72b72016-06-24 16:19:36 +01002495 vixl::aarch64::Label done;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002496 SlowPathCodeARM64* slow_path = nullptr;
Alexandre Rames97833a02015-04-16 15:07:12 +01002497 {
2498 // We use a block to end the scratch scope before the write barrier, thus
2499 // freeing the temporary registers so they can be used in `MarkGCCard`.
2500 UseScratchRegisterScope temps(masm);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002501 Register temp = temps.AcquireSameSizeAs(array);
Alexandre Rames97833a02015-04-16 15:07:12 +01002502 if (index.IsConstant()) {
2503 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002504 destination = HeapOperand(array, offset);
Alexandre Rames97833a02015-04-16 15:07:12 +01002505 } else {
Alexandre Rames82000b02015-07-07 11:34:16 +01002506 destination = HeapOperand(temp,
2507 XRegisterFrom(index),
2508 LSL,
2509 Primitive::ComponentSizeShift(value_type));
Alexandre Rames97833a02015-04-16 15:07:12 +01002510 }
2511
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002512 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2513 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
2514 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
2515
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002516 if (may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002517 slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathARM64(instruction);
2518 codegen_->AddSlowPath(slow_path);
2519 if (instruction->GetValueCanBeNull()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01002520 vixl::aarch64::Label non_zero;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002521 __ Cbnz(Register(value), &non_zero);
2522 if (!index.IsConstant()) {
2523 __ Add(temp, array, offset);
2524 }
2525 __ Str(wzr, destination);
2526 codegen_->MaybeRecordImplicitNullCheck(instruction);
2527 __ B(&done);
2528 __ Bind(&non_zero);
2529 }
2530
Roland Levillain9d6e1f82016-09-05 15:57:33 +01002531 // Note that when Baker read barriers are enabled, the type
2532 // checks are performed without read barriers. This is fine,
2533 // even in the case where a class object is in the from-space
2534 // after the flip, as a comparison involving such a type would
2535 // not produce a false positive; it may of course produce a
2536 // false negative, in which case we would take the ArraySet
2537 // slow path.
Roland Levillain16d9f942016-08-25 17:27:56 +01002538
Roland Levillain9d6e1f82016-09-05 15:57:33 +01002539 Register temp2 = temps.AcquireSameSizeAs(array);
2540 // /* HeapReference<Class> */ temp = array->klass_
2541 __ Ldr(temp, HeapOperand(array, class_offset));
2542 codegen_->MaybeRecordImplicitNullCheck(instruction);
2543 GetAssembler()->MaybeUnpoisonHeapReference(temp);
Roland Levillain16d9f942016-08-25 17:27:56 +01002544
Roland Levillain9d6e1f82016-09-05 15:57:33 +01002545 // /* HeapReference<Class> */ temp = temp->component_type_
2546 __ Ldr(temp, HeapOperand(temp, component_offset));
2547 // /* HeapReference<Class> */ temp2 = value->klass_
2548 __ Ldr(temp2, HeapOperand(Register(value), class_offset));
2549 // If heap poisoning is enabled, no need to unpoison `temp`
2550 // nor `temp2`, as we are comparing two poisoned references.
2551 __ Cmp(temp, temp2);
2552 temps.Release(temp2);
Roland Levillain16d9f942016-08-25 17:27:56 +01002553
Roland Levillain9d6e1f82016-09-05 15:57:33 +01002554 if (instruction->StaticTypeOfArrayIsObjectArray()) {
2555 vixl::aarch64::Label do_put;
2556 __ B(eq, &do_put);
2557 // If heap poisoning is enabled, the `temp` reference has
2558 // not been unpoisoned yet; unpoison it now.
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002559 GetAssembler()->MaybeUnpoisonHeapReference(temp);
2560
Roland Levillain9d6e1f82016-09-05 15:57:33 +01002561 // /* HeapReference<Class> */ temp = temp->super_class_
2562 __ Ldr(temp, HeapOperand(temp, super_offset));
2563 // If heap poisoning is enabled, no need to unpoison
2564 // `temp`, as we are comparing against null below.
2565 __ Cbnz(temp, slow_path->GetEntryLabel());
2566 __ Bind(&do_put);
2567 } else {
2568 __ B(ne, slow_path->GetEntryLabel());
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002569 }
2570 }
2571
2572 if (kPoisonHeapReferences) {
Nicolas Geoffraya8a0fe22015-10-01 15:50:27 +01002573 Register temp2 = temps.AcquireSameSizeAs(array);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002574 DCHECK(value.IsW());
Nicolas Geoffraya8a0fe22015-10-01 15:50:27 +01002575 __ Mov(temp2, value.W());
2576 GetAssembler()->PoisonHeapReference(temp2);
2577 source = temp2;
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002578 }
2579
2580 if (!index.IsConstant()) {
2581 __ Add(temp, array, offset);
2582 }
Nicolas Geoffray61b1dbe2015-10-01 10:27:52 +01002583 __ Str(source, destination);
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002584
Roland Levillain22ccc3a2015-11-24 13:10:05 +00002585 if (!may_need_runtime_call_for_type_check) {
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002586 codegen_->MaybeRecordImplicitNullCheck(instruction);
2587 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002588 }
Nicolas Geoffraye0395dd2015-09-25 11:04:45 +01002589
2590 codegen_->MarkGCCard(array, value.W(), instruction->GetValueCanBeNull());
2591
2592 if (done.IsLinked()) {
2593 __ Bind(&done);
2594 }
2595
2596 if (slow_path != nullptr) {
2597 __ Bind(slow_path->GetExitLabel());
Alexandre Rames97833a02015-04-16 15:07:12 +01002598 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002599 }
2600}
2601
Alexandre Rames67555f72014-11-18 10:55:16 +00002602void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002603 RegisterSet caller_saves = RegisterSet::Empty();
2604 InvokeRuntimeCallingConvention calling_convention;
2605 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode()));
2606 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1).GetCode()));
2607 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Alexandre Rames67555f72014-11-18 10:55:16 +00002608 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu760d8ef2015-03-28 18:09:56 +00002609 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames67555f72014-11-18 10:55:16 +00002610}
2611
2612void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Serban Constantinescu5a6cc492015-08-13 15:20:25 +01002613 BoundsCheckSlowPathARM64* slow_path =
2614 new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(instruction);
Alexandre Rames67555f72014-11-18 10:55:16 +00002615 codegen_->AddSlowPath(slow_path);
Alexandre Rames67555f72014-11-18 10:55:16 +00002616 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
2617 __ B(slow_path->GetEntryLabel(), hs);
2618}
2619
Alexandre Rames67555f72014-11-18 10:55:16 +00002620void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) {
2621 LocationSummary* locations =
2622 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2623 locations->SetInAt(0, Location::RequiresRegister());
2624 if (check->HasUses()) {
2625 locations->SetOut(Location::SameAsFirstInput());
2626 }
2627}
2628
2629void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) {
2630 // We assume the class is not null.
2631 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2632 check->GetLoadClass(), check, check->GetDexPc(), true);
2633 codegen_->AddSlowPath(slow_path);
2634 GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0));
2635}
2636
Roland Levillain1a653882016-03-18 18:05:57 +00002637static bool IsFloatingPointZeroConstant(HInstruction* inst) {
2638 return (inst->IsFloatConstant() && (inst->AsFloatConstant()->IsArithmeticZero()))
2639 || (inst->IsDoubleConstant() && (inst->AsDoubleConstant()->IsArithmeticZero()));
2640}
2641
2642void InstructionCodeGeneratorARM64::GenerateFcmp(HInstruction* instruction) {
2643 FPRegister lhs_reg = InputFPRegisterAt(instruction, 0);
2644 Location rhs_loc = instruction->GetLocations()->InAt(1);
2645 if (rhs_loc.IsConstant()) {
2646 // 0.0 is the only immediate that can be encoded directly in
2647 // an FCMP instruction.
2648 //
2649 // Both the JLS (section 15.20.1) and the JVMS (section 6.5)
2650 // specify that in a floating-point comparison, positive zero
2651 // and negative zero are considered equal, so we can use the
2652 // literal 0.0 for both cases here.
2653 //
2654 // Note however that some methods (Float.equal, Float.compare,
2655 // Float.compareTo, Double.equal, Double.compare,
2656 // Double.compareTo, Math.max, Math.min, StrictMath.max,
2657 // StrictMath.min) consider 0.0 to be (strictly) greater than
2658 // -0.0. So if we ever translate calls to these methods into a
2659 // HCompare instruction, we must handle the -0.0 case with
2660 // care here.
2661 DCHECK(IsFloatingPointZeroConstant(rhs_loc.GetConstant()));
2662 __ Fcmp(lhs_reg, 0.0);
2663 } else {
2664 __ Fcmp(lhs_reg, InputFPRegisterAt(instruction, 1));
2665 }
Roland Levillain7f63c522015-07-13 15:54:55 +00002666}
2667
Serban Constantinescu02164b32014-11-13 14:05:07 +00002668void LocationsBuilderARM64::VisitCompare(HCompare* compare) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002669 LocationSummary* locations =
Serban Constantinescu02164b32014-11-13 14:05:07 +00002670 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
2671 Primitive::Type in_type = compare->InputAt(0)->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01002672 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002673 case Primitive::kPrimBoolean:
2674 case Primitive::kPrimByte:
2675 case Primitive::kPrimShort:
2676 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002677 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002678 case Primitive::kPrimLong: {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002679 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002680 locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002681 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2682 break;
2683 }
2684 case Primitive::kPrimFloat:
2685 case Primitive::kPrimDouble: {
2686 locations->SetInAt(0, Location::RequiresFpuRegister());
Roland Levillain7f63c522015-07-13 15:54:55 +00002687 locations->SetInAt(1,
2688 IsFloatingPointZeroConstant(compare->InputAt(1))
2689 ? Location::ConstantLocation(compare->InputAt(1)->AsConstant())
2690 : Location::RequiresFpuRegister());
Serban Constantinescu02164b32014-11-13 14:05:07 +00002691 locations->SetOut(Location::RequiresRegister());
2692 break;
2693 }
2694 default:
2695 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
2696 }
2697}
2698
2699void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) {
2700 Primitive::Type in_type = compare->InputAt(0)->GetType();
2701
2702 // 0 if: left == right
2703 // 1 if: left > right
2704 // -1 if: left < right
2705 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002706 case Primitive::kPrimBoolean:
2707 case Primitive::kPrimByte:
2708 case Primitive::kPrimShort:
2709 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002710 case Primitive::kPrimInt:
Serban Constantinescu02164b32014-11-13 14:05:07 +00002711 case Primitive::kPrimLong: {
2712 Register result = OutputRegister(compare);
2713 Register left = InputRegisterAt(compare, 0);
2714 Operand right = InputOperandAt(compare, 1);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002715 __ Cmp(left, right);
Aart Bika19616e2016-02-01 18:57:58 -08002716 __ Cset(result, ne); // result == +1 if NE or 0 otherwise
2717 __ Cneg(result, result, lt); // result == -1 if LT or unchanged otherwise
Serban Constantinescu02164b32014-11-13 14:05:07 +00002718 break;
2719 }
2720 case Primitive::kPrimFloat:
2721 case Primitive::kPrimDouble: {
2722 Register result = OutputRegister(compare);
Roland Levillain1a653882016-03-18 18:05:57 +00002723 GenerateFcmp(compare);
Vladimir Markod6e069b2016-01-18 11:11:01 +00002724 __ Cset(result, ne);
2725 __ Cneg(result, result, ARM64FPCondition(kCondLT, compare->IsGtBias()));
Alexandre Rames5319def2014-10-23 10:03:10 +01002726 break;
2727 }
2728 default:
2729 LOG(FATAL) << "Unimplemented compare type " << in_type;
2730 }
2731}
2732
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002733void LocationsBuilderARM64::HandleCondition(HCondition* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002734 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Roland Levillain7f63c522015-07-13 15:54:55 +00002735
2736 if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) {
2737 locations->SetInAt(0, Location::RequiresFpuRegister());
2738 locations->SetInAt(1,
2739 IsFloatingPointZeroConstant(instruction->InputAt(1))
2740 ? Location::ConstantLocation(instruction->InputAt(1)->AsConstant())
2741 : Location::RequiresFpuRegister());
2742 } else {
2743 // Integer cases.
2744 locations->SetInAt(0, Location::RequiresRegister());
2745 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
2746 }
2747
David Brazdilb3e773e2016-01-26 11:28:37 +00002748 if (!instruction->IsEmittedAtUseSite()) {
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002749 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002750 }
2751}
2752
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002753void InstructionCodeGeneratorARM64::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00002754 if (instruction->IsEmittedAtUseSite()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002755 return;
2756 }
2757
2758 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames5319def2014-10-23 10:03:10 +01002759 Register res = RegisterFrom(locations->Out(), instruction->GetType());
Roland Levillain7f63c522015-07-13 15:54:55 +00002760 IfCondition if_cond = instruction->GetCondition();
Alexandre Rames5319def2014-10-23 10:03:10 +01002761
Roland Levillain7f63c522015-07-13 15:54:55 +00002762 if (Primitive::IsFloatingPointType(instruction->InputAt(0)->GetType())) {
Roland Levillain1a653882016-03-18 18:05:57 +00002763 GenerateFcmp(instruction);
Vladimir Markod6e069b2016-01-18 11:11:01 +00002764 __ Cset(res, ARM64FPCondition(if_cond, instruction->IsGtBias()));
Roland Levillain7f63c522015-07-13 15:54:55 +00002765 } else {
2766 // Integer cases.
2767 Register lhs = InputRegisterAt(instruction, 0);
2768 Operand rhs = InputOperandAt(instruction, 1);
2769 __ Cmp(lhs, rhs);
Vladimir Markod6e069b2016-01-18 11:11:01 +00002770 __ Cset(res, ARM64Condition(if_cond));
Roland Levillain7f63c522015-07-13 15:54:55 +00002771 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002772}
2773
2774#define FOR_EACH_CONDITION_INSTRUCTION(M) \
2775 M(Equal) \
2776 M(NotEqual) \
2777 M(LessThan) \
2778 M(LessThanOrEqual) \
2779 M(GreaterThan) \
Aart Bike9f37602015-10-09 11:15:55 -07002780 M(GreaterThanOrEqual) \
2781 M(Below) \
2782 M(BelowOrEqual) \
2783 M(Above) \
2784 M(AboveOrEqual)
Alexandre Rames5319def2014-10-23 10:03:10 +01002785#define DEFINE_CONDITION_VISITORS(Name) \
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002786void LocationsBuilderARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); } \
2787void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { HandleCondition(comp); }
Alexandre Rames5319def2014-10-23 10:03:10 +01002788FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
Alexandre Rames67555f72014-11-18 10:55:16 +00002789#undef DEFINE_CONDITION_VISITORS
Alexandre Rames5319def2014-10-23 10:03:10 +01002790#undef FOR_EACH_CONDITION_INSTRUCTION
2791
Zheng Xuc6667102015-05-15 16:08:45 +08002792void InstructionCodeGeneratorARM64::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2793 DCHECK(instruction->IsDiv() || instruction->IsRem());
2794
2795 LocationSummary* locations = instruction->GetLocations();
2796 Location second = locations->InAt(1);
2797 DCHECK(second.IsConstant());
2798
2799 Register out = OutputRegister(instruction);
2800 Register dividend = InputRegisterAt(instruction, 0);
2801 int64_t imm = Int64FromConstant(second.GetConstant());
2802 DCHECK(imm == 1 || imm == -1);
2803
2804 if (instruction->IsRem()) {
2805 __ Mov(out, 0);
2806 } else {
2807 if (imm == 1) {
2808 __ Mov(out, dividend);
2809 } else {
2810 __ Neg(out, dividend);
2811 }
2812 }
2813}
2814
2815void InstructionCodeGeneratorARM64::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2816 DCHECK(instruction->IsDiv() || instruction->IsRem());
2817
2818 LocationSummary* locations = instruction->GetLocations();
2819 Location second = locations->InAt(1);
2820 DCHECK(second.IsConstant());
2821
2822 Register out = OutputRegister(instruction);
2823 Register dividend = InputRegisterAt(instruction, 0);
2824 int64_t imm = Int64FromConstant(second.GetConstant());
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002825 uint64_t abs_imm = static_cast<uint64_t>(AbsOrMin(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002826 int ctz_imm = CTZ(abs_imm);
2827
2828 UseScratchRegisterScope temps(GetVIXLAssembler());
2829 Register temp = temps.AcquireSameSizeAs(out);
2830
2831 if (instruction->IsDiv()) {
2832 __ Add(temp, dividend, abs_imm - 1);
2833 __ Cmp(dividend, 0);
2834 __ Csel(out, temp, dividend, lt);
2835 if (imm > 0) {
2836 __ Asr(out, out, ctz_imm);
2837 } else {
2838 __ Neg(out, Operand(out, ASR, ctz_imm));
2839 }
2840 } else {
2841 int bits = instruction->GetResultType() == Primitive::kPrimInt ? 32 : 64;
2842 __ Asr(temp, dividend, bits - 1);
2843 __ Lsr(temp, temp, bits - ctz_imm);
2844 __ Add(out, dividend, temp);
2845 __ And(out, out, abs_imm - 1);
2846 __ Sub(out, out, temp);
2847 }
2848}
2849
2850void InstructionCodeGeneratorARM64::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2851 DCHECK(instruction->IsDiv() || instruction->IsRem());
2852
2853 LocationSummary* locations = instruction->GetLocations();
2854 Location second = locations->InAt(1);
2855 DCHECK(second.IsConstant());
2856
2857 Register out = OutputRegister(instruction);
2858 Register dividend = InputRegisterAt(instruction, 0);
2859 int64_t imm = Int64FromConstant(second.GetConstant());
2860
2861 Primitive::Type type = instruction->GetResultType();
2862 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
2863
2864 int64_t magic;
2865 int shift;
2866 CalculateMagicAndShiftForDivRem(imm, type == Primitive::kPrimLong /* is_long */, &magic, &shift);
2867
2868 UseScratchRegisterScope temps(GetVIXLAssembler());
2869 Register temp = temps.AcquireSameSizeAs(out);
2870
2871 // temp = get_high(dividend * magic)
2872 __ Mov(temp, magic);
2873 if (type == Primitive::kPrimLong) {
2874 __ Smulh(temp, dividend, temp);
2875 } else {
2876 __ Smull(temp.X(), dividend, temp);
2877 __ Lsr(temp.X(), temp.X(), 32);
2878 }
2879
2880 if (imm > 0 && magic < 0) {
2881 __ Add(temp, temp, dividend);
2882 } else if (imm < 0 && magic > 0) {
2883 __ Sub(temp, temp, dividend);
2884 }
2885
2886 if (shift != 0) {
2887 __ Asr(temp, temp, shift);
2888 }
2889
2890 if (instruction->IsDiv()) {
2891 __ Sub(out, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31));
2892 } else {
2893 __ Sub(temp, temp, Operand(temp, ASR, type == Primitive::kPrimLong ? 63 : 31));
2894 // TODO: Strength reduction for msub.
2895 Register temp_imm = temps.AcquireSameSizeAs(out);
2896 __ Mov(temp_imm, imm);
2897 __ Msub(out, temp, temp_imm, dividend);
2898 }
2899}
2900
2901void InstructionCodeGeneratorARM64::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2902 DCHECK(instruction->IsDiv() || instruction->IsRem());
2903 Primitive::Type type = instruction->GetResultType();
2904 DCHECK(type == Primitive::kPrimInt || Primitive::kPrimLong);
2905
2906 LocationSummary* locations = instruction->GetLocations();
2907 Register out = OutputRegister(instruction);
2908 Location second = locations->InAt(1);
2909
2910 if (second.IsConstant()) {
2911 int64_t imm = Int64FromConstant(second.GetConstant());
2912
2913 if (imm == 0) {
2914 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2915 } else if (imm == 1 || imm == -1) {
2916 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002917 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Zheng Xuc6667102015-05-15 16:08:45 +08002918 DivRemByPowerOfTwo(instruction);
2919 } else {
2920 DCHECK(imm <= -2 || imm >= 2);
2921 GenerateDivRemWithAnyConstant(instruction);
2922 }
2923 } else {
2924 Register dividend = InputRegisterAt(instruction, 0);
2925 Register divisor = InputRegisterAt(instruction, 1);
2926 if (instruction->IsDiv()) {
2927 __ Sdiv(out, dividend, divisor);
2928 } else {
2929 UseScratchRegisterScope temps(GetVIXLAssembler());
2930 Register temp = temps.AcquireSameSizeAs(out);
2931 __ Sdiv(temp, dividend, divisor);
2932 __ Msub(out, temp, divisor, dividend);
2933 }
2934 }
2935}
2936
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002937void LocationsBuilderARM64::VisitDiv(HDiv* div) {
2938 LocationSummary* locations =
2939 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
2940 switch (div->GetResultType()) {
2941 case Primitive::kPrimInt:
2942 case Primitive::kPrimLong:
2943 locations->SetInAt(0, Location::RequiresRegister());
Zheng Xuc6667102015-05-15 16:08:45 +08002944 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002945 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2946 break;
2947
2948 case Primitive::kPrimFloat:
2949 case Primitive::kPrimDouble:
2950 locations->SetInAt(0, Location::RequiresFpuRegister());
2951 locations->SetInAt(1, Location::RequiresFpuRegister());
2952 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2953 break;
2954
2955 default:
2956 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2957 }
2958}
2959
2960void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) {
2961 Primitive::Type type = div->GetResultType();
2962 switch (type) {
2963 case Primitive::kPrimInt:
2964 case Primitive::kPrimLong:
Zheng Xuc6667102015-05-15 16:08:45 +08002965 GenerateDivRemIntegral(div);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002966 break;
2967
2968 case Primitive::kPrimFloat:
2969 case Primitive::kPrimDouble:
2970 __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1));
2971 break;
2972
2973 default:
2974 LOG(FATAL) << "Unexpected div type " << type;
2975 }
2976}
2977
Alexandre Rames67555f72014-11-18 10:55:16 +00002978void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002979 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Alexandre Rames67555f72014-11-18 10:55:16 +00002980 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Alexandre Rames67555f72014-11-18 10:55:16 +00002981}
2982
2983void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2984 SlowPathCodeARM64* slow_path =
2985 new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction);
2986 codegen_->AddSlowPath(slow_path);
2987 Location value = instruction->GetLocations()->InAt(0);
2988
Alexandre Rames3e69f162014-12-10 10:36:50 +00002989 Primitive::Type type = instruction->GetType();
2990
Nicolas Geoffraye5671612016-03-16 11:03:54 +00002991 if (!Primitive::IsIntegralType(type)) {
2992 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
Alexandre Rames3e69f162014-12-10 10:36:50 +00002993 return;
2994 }
2995
Alexandre Rames67555f72014-11-18 10:55:16 +00002996 if (value.IsConstant()) {
2997 int64_t divisor = Int64ConstantFrom(value);
2998 if (divisor == 0) {
2999 __ B(slow_path->GetEntryLabel());
3000 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00003001 // A division by a non-null constant is valid. We don't need to perform
3002 // any check, so simply fall through.
Alexandre Rames67555f72014-11-18 10:55:16 +00003003 }
3004 } else {
3005 __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel());
3006 }
3007}
3008
Alexandre Ramesa89086e2014-11-07 17:13:25 +00003009void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) {
3010 LocationSummary* locations =
3011 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
3012 locations->SetOut(Location::ConstantLocation(constant));
3013}
3014
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003015void InstructionCodeGeneratorARM64::VisitDoubleConstant(
3016 HDoubleConstant* constant ATTRIBUTE_UNUSED) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00003017 // Will be generated at use site.
3018}
3019
Alexandre Rames5319def2014-10-23 10:03:10 +01003020void LocationsBuilderARM64::VisitExit(HExit* exit) {
3021 exit->SetLocations(nullptr);
3022}
3023
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003024void InstructionCodeGeneratorARM64::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
Alexandre Rames5319def2014-10-23 10:03:10 +01003025}
3026
Alexandre Ramesa89086e2014-11-07 17:13:25 +00003027void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) {
3028 LocationSummary* locations =
3029 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
3030 locations->SetOut(Location::ConstantLocation(constant));
3031}
3032
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003033void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00003034 // Will be generated at use site.
3035}
3036
David Brazdilfc6a86a2015-06-26 10:33:45 +00003037void InstructionCodeGeneratorARM64::HandleGoto(HInstruction* got, HBasicBlock* successor) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00003038 DCHECK(!successor->IsExitBlock());
3039 HBasicBlock* block = got->GetBlock();
3040 HInstruction* previous = got->GetPrevious();
3041 HLoopInformation* info = block->GetLoopInformation();
3042
David Brazdil46e2a392015-03-16 17:31:52 +00003043 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00003044 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
3045 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
3046 return;
3047 }
3048 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
3049 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
3050 }
3051 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01003052 __ B(codegen_->GetLabelOf(successor));
3053 }
3054}
3055
David Brazdilfc6a86a2015-06-26 10:33:45 +00003056void LocationsBuilderARM64::VisitGoto(HGoto* got) {
3057 got->SetLocations(nullptr);
3058}
3059
3060void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
3061 HandleGoto(got, got->GetSuccessor());
3062}
3063
3064void LocationsBuilderARM64::VisitTryBoundary(HTryBoundary* try_boundary) {
3065 try_boundary->SetLocations(nullptr);
3066}
3067
3068void InstructionCodeGeneratorARM64::VisitTryBoundary(HTryBoundary* try_boundary) {
3069 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
3070 if (!successor->IsExitBlock()) {
3071 HandleGoto(try_boundary, successor);
3072 }
3073}
3074
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07003075void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00003076 size_t condition_input_index,
Scott Wakeling97c72b72016-06-24 16:19:36 +01003077 vixl::aarch64::Label* true_target,
3078 vixl::aarch64::Label* false_target) {
David Brazdil0debae72015-11-12 18:37:00 +00003079 // FP branching requires both targets to be explicit. If either of the targets
3080 // is nullptr (fallthrough) use and bind `fallthrough_target` instead.
Scott Wakeling97c72b72016-06-24 16:19:36 +01003081 vixl::aarch64::Label fallthrough_target;
David Brazdil0debae72015-11-12 18:37:00 +00003082 HInstruction* cond = instruction->InputAt(condition_input_index);
Alexandre Rames5319def2014-10-23 10:03:10 +01003083
David Brazdil0debae72015-11-12 18:37:00 +00003084 if (true_target == nullptr && false_target == nullptr) {
3085 // Nothing to do. The code always falls through.
3086 return;
3087 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00003088 // Constant condition, statically compared against "true" (integer value 1).
3089 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00003090 if (true_target != nullptr) {
3091 __ B(true_target);
Serban Constantinescu02164b32014-11-13 14:05:07 +00003092 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00003093 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00003094 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00003095 if (false_target != nullptr) {
3096 __ B(false_target);
3097 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00003098 }
David Brazdil0debae72015-11-12 18:37:00 +00003099 return;
3100 }
3101
3102 // The following code generates these patterns:
3103 // (1) true_target == nullptr && false_target != nullptr
3104 // - opposite condition true => branch to false_target
3105 // (2) true_target != nullptr && false_target == nullptr
3106 // - condition true => branch to true_target
3107 // (3) true_target != nullptr && false_target != nullptr
3108 // - condition true => branch to true_target
3109 // - branch to false_target
3110 if (IsBooleanValueOrMaterializedCondition(cond)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01003111 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00003112 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Alexandre Rames5319def2014-10-23 10:03:10 +01003113 DCHECK(cond_val.IsRegister());
David Brazdil0debae72015-11-12 18:37:00 +00003114 if (true_target == nullptr) {
3115 __ Cbz(InputRegisterAt(instruction, condition_input_index), false_target);
3116 } else {
3117 __ Cbnz(InputRegisterAt(instruction, condition_input_index), true_target);
3118 }
Alexandre Rames5319def2014-10-23 10:03:10 +01003119 } else {
3120 // The condition instruction has not been materialized, use its inputs as
3121 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00003122 HCondition* condition = cond->AsCondition();
Roland Levillain7f63c522015-07-13 15:54:55 +00003123
David Brazdil0debae72015-11-12 18:37:00 +00003124 Primitive::Type type = condition->InputAt(0)->GetType();
Roland Levillain7f63c522015-07-13 15:54:55 +00003125 if (Primitive::IsFloatingPointType(type)) {
Roland Levillain1a653882016-03-18 18:05:57 +00003126 GenerateFcmp(condition);
David Brazdil0debae72015-11-12 18:37:00 +00003127 if (true_target == nullptr) {
Vladimir Markod6e069b2016-01-18 11:11:01 +00003128 IfCondition opposite_condition = condition->GetOppositeCondition();
3129 __ B(ARM64FPCondition(opposite_condition, condition->IsGtBias()), false_target);
David Brazdil0debae72015-11-12 18:37:00 +00003130 } else {
Vladimir Markod6e069b2016-01-18 11:11:01 +00003131 __ B(ARM64FPCondition(condition->GetCondition(), condition->IsGtBias()), true_target);
David Brazdil0debae72015-11-12 18:37:00 +00003132 }
Alexandre Rames5319def2014-10-23 10:03:10 +01003133 } else {
Roland Levillain7f63c522015-07-13 15:54:55 +00003134 // Integer cases.
3135 Register lhs = InputRegisterAt(condition, 0);
3136 Operand rhs = InputOperandAt(condition, 1);
David Brazdil0debae72015-11-12 18:37:00 +00003137
3138 Condition arm64_cond;
Scott Wakeling97c72b72016-06-24 16:19:36 +01003139 vixl::aarch64::Label* non_fallthrough_target;
David Brazdil0debae72015-11-12 18:37:00 +00003140 if (true_target == nullptr) {
3141 arm64_cond = ARM64Condition(condition->GetOppositeCondition());
3142 non_fallthrough_target = false_target;
3143 } else {
3144 arm64_cond = ARM64Condition(condition->GetCondition());
3145 non_fallthrough_target = true_target;
3146 }
3147
Aart Bik086d27e2016-01-20 17:02:00 -08003148 if ((arm64_cond == eq || arm64_cond == ne || arm64_cond == lt || arm64_cond == ge) &&
Scott Wakeling97c72b72016-06-24 16:19:36 +01003149 rhs.IsImmediate() && (rhs.GetImmediate() == 0)) {
Roland Levillain7f63c522015-07-13 15:54:55 +00003150 switch (arm64_cond) {
3151 case eq:
David Brazdil0debae72015-11-12 18:37:00 +00003152 __ Cbz(lhs, non_fallthrough_target);
Roland Levillain7f63c522015-07-13 15:54:55 +00003153 break;
3154 case ne:
David Brazdil0debae72015-11-12 18:37:00 +00003155 __ Cbnz(lhs, non_fallthrough_target);
Roland Levillain7f63c522015-07-13 15:54:55 +00003156 break;
3157 case lt:
3158 // Test the sign bit and branch accordingly.
David Brazdil0debae72015-11-12 18:37:00 +00003159 __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target);
Roland Levillain7f63c522015-07-13 15:54:55 +00003160 break;
3161 case ge:
3162 // Test the sign bit and branch accordingly.
David Brazdil0debae72015-11-12 18:37:00 +00003163 __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, non_fallthrough_target);
Roland Levillain7f63c522015-07-13 15:54:55 +00003164 break;
3165 default:
3166 // Without the `static_cast` the compiler throws an error for
3167 // `-Werror=sign-promo`.
3168 LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond);
3169 }
3170 } else {
3171 __ Cmp(lhs, rhs);
David Brazdil0debae72015-11-12 18:37:00 +00003172 __ B(arm64_cond, non_fallthrough_target);
Roland Levillain7f63c522015-07-13 15:54:55 +00003173 }
Alexandre Rames5319def2014-10-23 10:03:10 +01003174 }
3175 }
David Brazdil0debae72015-11-12 18:37:00 +00003176
3177 // If neither branch falls through (case 3), the conditional branch to `true_target`
3178 // was already emitted (case 2) and we need to emit a jump to `false_target`.
3179 if (true_target != nullptr && false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01003180 __ B(false_target);
3181 }
David Brazdil0debae72015-11-12 18:37:00 +00003182
3183 if (fallthrough_target.IsLinked()) {
3184 __ Bind(&fallthrough_target);
3185 }
Alexandre Rames5319def2014-10-23 10:03:10 +01003186}
3187
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07003188void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
3189 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00003190 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07003191 locations->SetInAt(0, Location::RequiresRegister());
3192 }
3193}
3194
3195void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00003196 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
3197 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
Scott Wakeling97c72b72016-06-24 16:19:36 +01003198 vixl::aarch64::Label* true_target = codegen_->GetLabelOf(true_successor);
3199 if (codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor)) {
3200 true_target = nullptr;
3201 }
3202 vixl::aarch64::Label* false_target = codegen_->GetLabelOf(false_successor);
3203 if (codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor)) {
3204 false_target = nullptr;
3205 }
David Brazdil0debae72015-11-12 18:37:00 +00003206 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07003207}
3208
3209void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
3210 LocationSummary* locations = new (GetGraph()->GetArena())
3211 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01003212 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
David Brazdil0debae72015-11-12 18:37:00 +00003213 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07003214 locations->SetInAt(0, Location::RequiresRegister());
3215 }
3216}
3217
3218void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08003219 SlowPathCodeARM64* slow_path =
3220 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARM64>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00003221 GenerateTestAndBranch(deoptimize,
3222 /* condition_input_index */ 0,
3223 slow_path->GetEntryLabel(),
3224 /* false_target */ nullptr);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07003225}
3226
David Brazdilc0b601b2016-02-08 14:20:45 +00003227static inline bool IsConditionOnFloatingPointValues(HInstruction* condition) {
3228 return condition->IsCondition() &&
3229 Primitive::IsFloatingPointType(condition->InputAt(0)->GetType());
3230}
3231
Alexandre Rames880f1192016-06-13 16:04:50 +01003232static inline Condition GetConditionForSelect(HCondition* condition) {
3233 IfCondition cond = condition->AsCondition()->GetCondition();
David Brazdilc0b601b2016-02-08 14:20:45 +00003234 return IsConditionOnFloatingPointValues(condition) ? ARM64FPCondition(cond, condition->IsGtBias())
3235 : ARM64Condition(cond);
3236}
3237
David Brazdil74eb1b22015-12-14 11:44:01 +00003238void LocationsBuilderARM64::VisitSelect(HSelect* select) {
3239 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
Alexandre Rames880f1192016-06-13 16:04:50 +01003240 if (Primitive::IsFloatingPointType(select->GetType())) {
3241 locations->SetInAt(0, Location::RequiresFpuRegister());
3242 locations->SetInAt(1, Location::RequiresFpuRegister());
3243 locations->SetOut(Location::RequiresFpuRegister());
3244 } else {
3245 HConstant* cst_true_value = select->GetTrueValue()->AsConstant();
3246 HConstant* cst_false_value = select->GetFalseValue()->AsConstant();
3247 bool is_true_value_constant = cst_true_value != nullptr;
3248 bool is_false_value_constant = cst_false_value != nullptr;
3249 // Ask VIXL whether we should synthesize constants in registers.
3250 // We give an arbitrary register to VIXL when dealing with non-constant inputs.
3251 Operand true_op = is_true_value_constant ?
3252 Operand(Int64FromConstant(cst_true_value)) : Operand(x1);
3253 Operand false_op = is_false_value_constant ?
3254 Operand(Int64FromConstant(cst_false_value)) : Operand(x2);
3255 bool true_value_in_register = false;
3256 bool false_value_in_register = false;
3257 MacroAssembler::GetCselSynthesisInformation(
3258 x0, true_op, false_op, &true_value_in_register, &false_value_in_register);
3259 true_value_in_register |= !is_true_value_constant;
3260 false_value_in_register |= !is_false_value_constant;
3261
3262 locations->SetInAt(1, true_value_in_register ? Location::RequiresRegister()
3263 : Location::ConstantLocation(cst_true_value));
3264 locations->SetInAt(0, false_value_in_register ? Location::RequiresRegister()
3265 : Location::ConstantLocation(cst_false_value));
3266 locations->SetOut(Location::RequiresRegister());
David Brazdil74eb1b22015-12-14 11:44:01 +00003267 }
Alexandre Rames880f1192016-06-13 16:04:50 +01003268
David Brazdil74eb1b22015-12-14 11:44:01 +00003269 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
3270 locations->SetInAt(2, Location::RequiresRegister());
3271 }
David Brazdil74eb1b22015-12-14 11:44:01 +00003272}
3273
3274void InstructionCodeGeneratorARM64::VisitSelect(HSelect* select) {
David Brazdilc0b601b2016-02-08 14:20:45 +00003275 HInstruction* cond = select->GetCondition();
David Brazdilc0b601b2016-02-08 14:20:45 +00003276 Condition csel_cond;
3277
3278 if (IsBooleanValueOrMaterializedCondition(cond)) {
3279 if (cond->IsCondition() && cond->GetNext() == select) {
Alexandre Rames880f1192016-06-13 16:04:50 +01003280 // Use the condition flags set by the previous instruction.
3281 csel_cond = GetConditionForSelect(cond->AsCondition());
David Brazdilc0b601b2016-02-08 14:20:45 +00003282 } else {
3283 __ Cmp(InputRegisterAt(select, 2), 0);
Alexandre Rames880f1192016-06-13 16:04:50 +01003284 csel_cond = ne;
David Brazdilc0b601b2016-02-08 14:20:45 +00003285 }
3286 } else if (IsConditionOnFloatingPointValues(cond)) {
Roland Levillain1a653882016-03-18 18:05:57 +00003287 GenerateFcmp(cond);
Alexandre Rames880f1192016-06-13 16:04:50 +01003288 csel_cond = GetConditionForSelect(cond->AsCondition());
David Brazdilc0b601b2016-02-08 14:20:45 +00003289 } else {
3290 __ Cmp(InputRegisterAt(cond, 0), InputOperandAt(cond, 1));
Alexandre Rames880f1192016-06-13 16:04:50 +01003291 csel_cond = GetConditionForSelect(cond->AsCondition());
David Brazdilc0b601b2016-02-08 14:20:45 +00003292 }
3293
Alexandre Rames880f1192016-06-13 16:04:50 +01003294 if (Primitive::IsFloatingPointType(select->GetType())) {
3295 __ Fcsel(OutputFPRegister(select),
3296 InputFPRegisterAt(select, 1),
3297 InputFPRegisterAt(select, 0),
3298 csel_cond);
3299 } else {
3300 __ Csel(OutputRegister(select),
3301 InputOperandAt(select, 1),
3302 InputOperandAt(select, 0),
3303 csel_cond);
David Brazdilc0b601b2016-02-08 14:20:45 +00003304 }
David Brazdil74eb1b22015-12-14 11:44:01 +00003305}
3306
David Srbecky0cf44932015-12-09 14:09:59 +00003307void LocationsBuilderARM64::VisitNativeDebugInfo(HNativeDebugInfo* info) {
3308 new (GetGraph()->GetArena()) LocationSummary(info);
3309}
3310
David Srbeckyd28f4a02016-03-14 17:14:24 +00003311void InstructionCodeGeneratorARM64::VisitNativeDebugInfo(HNativeDebugInfo*) {
3312 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00003313}
3314
3315void CodeGeneratorARM64::GenerateNop() {
3316 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00003317}
3318
Alexandre Rames5319def2014-10-23 10:03:10 +01003319void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01003320 HandleFieldGet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01003321}
3322
3323void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01003324 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01003325}
3326
3327void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01003328 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01003329}
3330
3331void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003332 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexandre Rames5319def2014-10-23 10:03:10 +01003333}
3334
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003335// Temp is used for read barrier.
3336static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) {
3337 if (kEmitCompilerReadBarrier &&
Roland Levillain44015862016-01-22 11:47:17 +00003338 (kUseBakerReadBarrier ||
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003339 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
3340 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
3341 type_check_kind == TypeCheckKind::kArrayObjectCheck)) {
3342 return 1;
3343 }
3344 return 0;
3345}
3346
Mathieu Chartieraa474eb2016-11-09 15:18:27 -08003347// Interface case has 3 temps, one for holding the number of interfaces, one for the current
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003348// interface pointer, one for loading the current interface.
3349// The other checks have one temp for loading the object's class.
3350static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) {
3351 if (type_check_kind == TypeCheckKind::kInterfaceCheck) {
3352 return 3;
3353 }
3354 return 1 + NumberOfInstanceOfTemps(type_check_kind);
Roland Levillain44015862016-01-22 11:47:17 +00003355}
3356
Alexandre Rames67555f72014-11-18 10:55:16 +00003357void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003358 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003359 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Vladimir Marko70e97462016-08-09 11:04:26 +01003360 bool baker_read_barrier_slow_path = false;
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003361 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003362 case TypeCheckKind::kExactCheck:
3363 case TypeCheckKind::kAbstractClassCheck:
3364 case TypeCheckKind::kClassHierarchyCheck:
3365 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003366 call_kind =
3367 kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall;
Vladimir Marko70e97462016-08-09 11:04:26 +01003368 baker_read_barrier_slow_path = kUseBakerReadBarrier;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003369 break;
3370 case TypeCheckKind::kArrayCheck:
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003371 case TypeCheckKind::kUnresolvedCheck:
3372 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003373 call_kind = LocationSummary::kCallOnSlowPath;
3374 break;
3375 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003376
Alexandre Rames67555f72014-11-18 10:55:16 +00003377 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
Vladimir Marko70e97462016-08-09 11:04:26 +01003378 if (baker_read_barrier_slow_path) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01003379 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Vladimir Marko70e97462016-08-09 11:04:26 +01003380 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003381 locations->SetInAt(0, Location::RequiresRegister());
3382 locations->SetInAt(1, Location::RequiresRegister());
3383 // The "out" register is used as a temporary, so it overlaps with the inputs.
3384 // Note that TypeCheckSlowPathARM64 uses this register too.
3385 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003386 // Add temps if necessary for read barriers.
3387 locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind));
Alexandre Rames67555f72014-11-18 10:55:16 +00003388}
3389
3390void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
Roland Levillain44015862016-01-22 11:47:17 +00003391 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Alexandre Rames67555f72014-11-18 10:55:16 +00003392 LocationSummary* locations = instruction->GetLocations();
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003393 Location obj_loc = locations->InAt(0);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003394 Register obj = InputRegisterAt(instruction, 0);
3395 Register cls = InputRegisterAt(instruction, 1);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003396 Location out_loc = locations->Out();
Alexandre Rames67555f72014-11-18 10:55:16 +00003397 Register out = OutputRegister(instruction);
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003398 const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind);
3399 DCHECK_LE(num_temps, 1u);
3400 Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003401 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3402 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
3403 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
3404 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Alexandre Rames67555f72014-11-18 10:55:16 +00003405
Scott Wakeling97c72b72016-06-24 16:19:36 +01003406 vixl::aarch64::Label done, zero;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003407 SlowPathCodeARM64* slow_path = nullptr;
Alexandre Rames67555f72014-11-18 10:55:16 +00003408
3409 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01003410 // Avoid null check if we know `obj` is not null.
3411 if (instruction->MustDoNullCheck()) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003412 __ Cbz(obj, &zero);
3413 }
3414
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003415 // /* HeapReference<Class> */ out = obj->klass_
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003416 GenerateReferenceLoadTwoRegisters(instruction,
3417 out_loc,
3418 obj_loc,
3419 class_offset,
3420 maybe_temp_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003421 kCompilerReadBarrierOption);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003422
Roland Levillain44015862016-01-22 11:47:17 +00003423 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003424 case TypeCheckKind::kExactCheck: {
3425 __ Cmp(out, cls);
3426 __ Cset(out, eq);
3427 if (zero.IsLinked()) {
3428 __ B(&done);
3429 }
3430 break;
3431 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003432
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003433 case TypeCheckKind::kAbstractClassCheck: {
3434 // If the class is abstract, we eagerly fetch the super class of the
3435 // object to avoid doing a comparison we know will fail.
Scott Wakeling97c72b72016-06-24 16:19:36 +01003436 vixl::aarch64::Label loop, success;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003437 __ Bind(&loop);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003438 // /* HeapReference<Class> */ out = out->super_class_
Mathieu Chartieraa474eb2016-11-09 15:18:27 -08003439 GenerateReferenceLoadOneRegister(instruction,
3440 out_loc,
3441 super_offset,
3442 maybe_temp_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003443 kCompilerReadBarrierOption);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003444 // If `out` is null, we use it for the result, and jump to `done`.
3445 __ Cbz(out, &done);
3446 __ Cmp(out, cls);
3447 __ B(ne, &loop);
3448 __ Mov(out, 1);
3449 if (zero.IsLinked()) {
3450 __ B(&done);
3451 }
3452 break;
3453 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003454
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003455 case TypeCheckKind::kClassHierarchyCheck: {
3456 // Walk over the class hierarchy to find a match.
Scott Wakeling97c72b72016-06-24 16:19:36 +01003457 vixl::aarch64::Label loop, success;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003458 __ Bind(&loop);
3459 __ Cmp(out, cls);
3460 __ B(eq, &success);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003461 // /* HeapReference<Class> */ out = out->super_class_
Mathieu Chartieraa474eb2016-11-09 15:18:27 -08003462 GenerateReferenceLoadOneRegister(instruction,
3463 out_loc,
3464 super_offset,
3465 maybe_temp_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003466 kCompilerReadBarrierOption);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003467 __ Cbnz(out, &loop);
3468 // If `out` is null, we use it for the result, and jump to `done`.
3469 __ B(&done);
3470 __ Bind(&success);
3471 __ Mov(out, 1);
3472 if (zero.IsLinked()) {
3473 __ B(&done);
3474 }
3475 break;
3476 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003477
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003478 case TypeCheckKind::kArrayObjectCheck: {
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01003479 // Do an exact check.
Scott Wakeling97c72b72016-06-24 16:19:36 +01003480 vixl::aarch64::Label exact_check;
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01003481 __ Cmp(out, cls);
3482 __ B(eq, &exact_check);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003483 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003484 // /* HeapReference<Class> */ out = out->component_type_
Mathieu Chartieraa474eb2016-11-09 15:18:27 -08003485 GenerateReferenceLoadOneRegister(instruction,
3486 out_loc,
3487 component_offset,
3488 maybe_temp_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003489 kCompilerReadBarrierOption);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003490 // If `out` is null, we use it for the result, and jump to `done`.
3491 __ Cbz(out, &done);
3492 __ Ldrh(out, HeapOperand(out, primitive_offset));
3493 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
3494 __ Cbnz(out, &zero);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01003495 __ Bind(&exact_check);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003496 __ Mov(out, 1);
3497 __ B(&done);
3498 break;
3499 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003500
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003501 case TypeCheckKind::kArrayCheck: {
3502 __ Cmp(out, cls);
3503 DCHECK(locations->OnlyCallsOnSlowPath());
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003504 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction,
3505 /* is_fatal */ false);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003506 codegen_->AddSlowPath(slow_path);
3507 __ B(ne, slow_path->GetEntryLabel());
3508 __ Mov(out, 1);
3509 if (zero.IsLinked()) {
3510 __ B(&done);
3511 }
3512 break;
3513 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003514
Calin Juravle98893e12015-10-02 21:05:03 +01003515 case TypeCheckKind::kUnresolvedCheck:
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003516 case TypeCheckKind::kInterfaceCheck: {
3517 // Note that we indeed only call on slow path, but we always go
3518 // into the slow path for the unresolved and interface check
3519 // cases.
3520 //
3521 // We cannot directly call the InstanceofNonTrivial runtime
3522 // entry point without resorting to a type checking slow path
3523 // here (i.e. by calling InvokeRuntime directly), as it would
3524 // require to assign fixed registers for the inputs of this
3525 // HInstanceOf instruction (following the runtime calling
3526 // convention), which might be cluttered by the potential first
3527 // read barrier emission at the beginning of this method.
Roland Levillain44015862016-01-22 11:47:17 +00003528 //
3529 // TODO: Introduce a new runtime entry point taking the object
3530 // to test (instead of its class) as argument, and let it deal
3531 // with the read barrier issues. This will let us refactor this
3532 // case of the `switch` code as it was previously (with a direct
3533 // call to the runtime not using a type checking slow path).
3534 // This should also be beneficial for the other cases above.
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003535 DCHECK(locations->OnlyCallsOnSlowPath());
3536 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction,
3537 /* is_fatal */ false);
3538 codegen_->AddSlowPath(slow_path);
3539 __ B(slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003540 if (zero.IsLinked()) {
3541 __ B(&done);
3542 }
3543 break;
3544 }
3545 }
3546
3547 if (zero.IsLinked()) {
3548 __ Bind(&zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01003549 __ Mov(out, 0);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003550 }
3551
3552 if (done.IsLinked()) {
3553 __ Bind(&done);
3554 }
3555
3556 if (slow_path != nullptr) {
3557 __ Bind(slow_path->GetExitLabel());
3558 }
3559}
3560
3561void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) {
3562 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
3563 bool throws_into_catch = instruction->CanThrowIntoCatchBlock();
3564
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003565 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
3566 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003567 case TypeCheckKind::kExactCheck:
3568 case TypeCheckKind::kAbstractClassCheck:
3569 case TypeCheckKind::kClassHierarchyCheck:
3570 case TypeCheckKind::kArrayObjectCheck:
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003571 call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ?
3572 LocationSummary::kCallOnSlowPath :
3573 LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003574 break;
3575 case TypeCheckKind::kArrayCheck:
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003576 case TypeCheckKind::kUnresolvedCheck:
3577 case TypeCheckKind::kInterfaceCheck:
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003578 call_kind = LocationSummary::kCallOnSlowPath;
3579 break;
3580 }
3581
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003582 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3583 locations->SetInAt(0, Location::RequiresRegister());
3584 locations->SetInAt(1, Location::RequiresRegister());
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003585 // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathARM64.
3586 locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind));
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003587}
3588
3589void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) {
Roland Levillain44015862016-01-22 11:47:17 +00003590 TypeCheckKind type_check_kind = instruction->GetTypeCheckKind();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003591 LocationSummary* locations = instruction->GetLocations();
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003592 Location obj_loc = locations->InAt(0);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003593 Register obj = InputRegisterAt(instruction, 0);
3594 Register cls = InputRegisterAt(instruction, 1);
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003595 const size_t num_temps = NumberOfCheckCastTemps(type_check_kind);
3596 DCHECK_GE(num_temps, 1u);
3597 DCHECK_LE(num_temps, 3u);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003598 Location temp_loc = locations->GetTemp(0);
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003599 Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation();
3600 Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation();
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003601 Register temp = WRegisterFrom(temp_loc);
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003602 const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3603 const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
3604 const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
3605 const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
3606 const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value();
3607 const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value();
3608 const uint32_t object_array_data_offset =
3609 mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value();
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003610
Mathieu Chartieraa474eb2016-11-09 15:18:27 -08003611 bool is_type_check_slow_path_fatal = false;
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003612 // Always false for read barriers since we may need to go to the entrypoint for non-fatal cases
3613 // from false negatives. The false negatives may come from avoiding read barriers below. Avoiding
3614 // read barriers is done for performance and code size reasons.
Mathieu Chartieraa474eb2016-11-09 15:18:27 -08003615 if (!kEmitCompilerReadBarrier) {
3616 is_type_check_slow_path_fatal =
3617 (type_check_kind == TypeCheckKind::kExactCheck ||
3618 type_check_kind == TypeCheckKind::kAbstractClassCheck ||
3619 type_check_kind == TypeCheckKind::kClassHierarchyCheck ||
3620 type_check_kind == TypeCheckKind::kArrayObjectCheck) &&
3621 !instruction->CanThrowIntoCatchBlock();
3622 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003623 SlowPathCodeARM64* type_check_slow_path =
3624 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(instruction,
3625 is_type_check_slow_path_fatal);
3626 codegen_->AddSlowPath(type_check_slow_path);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003627
Scott Wakeling97c72b72016-06-24 16:19:36 +01003628 vixl::aarch64::Label done;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003629 // Avoid null check if we know obj is not null.
3630 if (instruction->MustDoNullCheck()) {
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01003631 __ Cbz(obj, &done);
3632 }
Alexandre Rames67555f72014-11-18 10:55:16 +00003633
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003634 switch (type_check_kind) {
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003635 case TypeCheckKind::kExactCheck:
3636 case TypeCheckKind::kArrayCheck: {
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003637 // /* HeapReference<Class> */ temp = obj->klass_
3638 GenerateReferenceLoadTwoRegisters(instruction,
3639 temp_loc,
3640 obj_loc,
3641 class_offset,
3642 maybe_temp2_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003643 kWithoutReadBarrier);
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003644
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003645 __ Cmp(temp, cls);
3646 // Jump to slow path for throwing the exception or doing a
3647 // more involved array check.
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003648 __ B(ne, type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003649 break;
3650 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003651
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003652 case TypeCheckKind::kAbstractClassCheck: {
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003653 // /* HeapReference<Class> */ temp = obj->klass_
3654 GenerateReferenceLoadTwoRegisters(instruction,
3655 temp_loc,
3656 obj_loc,
3657 class_offset,
3658 maybe_temp2_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003659 kWithoutReadBarrier);
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003660
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003661 // If the class is abstract, we eagerly fetch the super class of the
3662 // object to avoid doing a comparison we know will fail.
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08003663 vixl::aarch64::Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003664 __ Bind(&loop);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003665 // /* HeapReference<Class> */ temp = temp->super_class_
Mathieu Chartieraa474eb2016-11-09 15:18:27 -08003666 GenerateReferenceLoadOneRegister(instruction,
3667 temp_loc,
3668 super_offset,
3669 maybe_temp2_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003670 kWithoutReadBarrier);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003671
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08003672 // If the class reference currently in `temp` is null, jump to the slow path to throw the
3673 // exception.
3674 __ Cbz(temp, type_check_slow_path->GetEntryLabel());
3675 // Otherwise, compare classes.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003676 __ Cmp(temp, cls);
3677 __ B(ne, &loop);
3678 break;
3679 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003680
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003681 case TypeCheckKind::kClassHierarchyCheck: {
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003682 // /* HeapReference<Class> */ temp = obj->klass_
3683 GenerateReferenceLoadTwoRegisters(instruction,
3684 temp_loc,
3685 obj_loc,
3686 class_offset,
3687 maybe_temp2_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003688 kWithoutReadBarrier);
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003689
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003690 // Walk over the class hierarchy to find a match.
Scott Wakeling97c72b72016-06-24 16:19:36 +01003691 vixl::aarch64::Label loop;
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003692 __ Bind(&loop);
3693 __ Cmp(temp, cls);
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01003694 __ B(eq, &done);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003695
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003696 // /* HeapReference<Class> */ temp = temp->super_class_
Mathieu Chartieraa474eb2016-11-09 15:18:27 -08003697 GenerateReferenceLoadOneRegister(instruction,
3698 temp_loc,
3699 super_offset,
3700 maybe_temp2_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003701 kWithoutReadBarrier);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003702
3703 // If the class reference currently in `temp` is not null, jump
3704 // back at the beginning of the loop.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003705 __ Cbnz(temp, &loop);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003706 // Otherwise, jump to the slow path to throw the exception.
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003707 __ B(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003708 break;
3709 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003710
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003711 case TypeCheckKind::kArrayObjectCheck: {
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003712 // /* HeapReference<Class> */ temp = obj->klass_
3713 GenerateReferenceLoadTwoRegisters(instruction,
3714 temp_loc,
3715 obj_loc,
3716 class_offset,
3717 maybe_temp2_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003718 kWithoutReadBarrier);
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003719
Nicolas Geoffrayabfcf182015-09-21 18:41:21 +01003720 // Do an exact check.
3721 __ Cmp(temp, cls);
3722 __ B(eq, &done);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003723
3724 // Otherwise, we need to check that the object's class is a non-primitive array.
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003725 // /* HeapReference<Class> */ temp = temp->component_type_
Mathieu Chartieraa474eb2016-11-09 15:18:27 -08003726 GenerateReferenceLoadOneRegister(instruction,
3727 temp_loc,
3728 component_offset,
3729 maybe_temp2_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003730 kWithoutReadBarrier);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003731
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08003732 // If the component type is null, jump to the slow path to throw the exception.
3733 __ Cbz(temp, type_check_slow_path->GetEntryLabel());
3734 // Otherwise, the object is indeed an array. Further check that this component type is not a
3735 // primitive type.
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003736 __ Ldrh(temp, HeapOperand(temp, primitive_offset));
3737 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
Mathieu Chartierb99f4d62016-11-07 16:17:26 -08003738 __ Cbnz(temp, type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003739 break;
3740 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003741
Calin Juravle98893e12015-10-02 21:05:03 +01003742 case TypeCheckKind::kUnresolvedCheck:
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003743 // We always go into the type check slow path for the unresolved check cases.
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003744 //
3745 // We cannot directly call the CheckCast runtime entry point
3746 // without resorting to a type checking slow path here (i.e. by
3747 // calling InvokeRuntime directly), as it would require to
3748 // assign fixed registers for the inputs of this HInstanceOf
3749 // instruction (following the runtime calling convention), which
3750 // might be cluttered by the potential first read barrier
3751 // emission at the beginning of this method.
3752 __ B(type_check_slow_path->GetEntryLabel());
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003753 break;
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003754 case TypeCheckKind::kInterfaceCheck: {
3755 // /* HeapReference<Class> */ temp = obj->klass_
3756 GenerateReferenceLoadTwoRegisters(instruction,
3757 temp_loc,
3758 obj_loc,
3759 class_offset,
3760 maybe_temp2_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003761 kWithoutReadBarrier);
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003762
3763 // /* HeapReference<Class> */ temp = temp->iftable_
3764 GenerateReferenceLoadTwoRegisters(instruction,
3765 temp_loc,
3766 temp_loc,
3767 iftable_offset,
3768 maybe_temp2_loc,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08003769 kWithoutReadBarrier);
Mathieu Chartier5c44c1b2016-11-04 18:13:04 -07003770 vixl::aarch64::Label is_null;
3771 // Null iftable means it is empty and will always fail the check.
3772 __ Cbz(temp, &is_null);
3773
3774 // Loop through the iftable and check if any class matches.
3775 __ Ldr(WRegisterFrom(maybe_temp2_loc), HeapOperand(temp.W(), array_length_offset));
3776
3777 vixl::aarch64::Label start_loop;
3778 __ Bind(&start_loop);
3779 __ Ldr(WRegisterFrom(maybe_temp3_loc), HeapOperand(temp.W(), object_array_data_offset));
3780 GetAssembler()->MaybeUnpoisonHeapReference(WRegisterFrom(maybe_temp3_loc));
3781 __ Cmp(cls, WRegisterFrom(maybe_temp3_loc));
3782 __ B(eq, &done); // Return if same class.
3783 // Go to next interface.
3784 __ Add(temp, temp, 2 * kHeapReferenceSize);
3785 __ Sub(WRegisterFrom(maybe_temp2_loc), WRegisterFrom(maybe_temp2_loc), 2);
3786 __ Cbnz(WRegisterFrom(maybe_temp2_loc), &start_loop);
3787 __ Bind(&is_null);
3788
3789 __ B(type_check_slow_path->GetEntryLabel());
3790 break;
3791 }
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003792 }
Nicolas Geoffray75374372015-09-17 17:12:19 +00003793 __ Bind(&done);
Nicolas Geoffray85c7bab2015-09-18 13:40:46 +00003794
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003795 __ Bind(type_check_slow_path->GetExitLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +00003796}
3797
Alexandre Rames5319def2014-10-23 10:03:10 +01003798void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
3799 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3800 locations->SetOut(Location::ConstantLocation(constant));
3801}
3802
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003803void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
Alexandre Rames5319def2014-10-23 10:03:10 +01003804 // Will be generated at use site.
3805}
3806
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003807void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
3808 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
3809 locations->SetOut(Location::ConstantLocation(constant));
3810}
3811
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01003812void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003813 // Will be generated at use site.
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003814}
3815
Calin Juravle175dc732015-08-25 15:42:32 +01003816void LocationsBuilderARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
3817 // The trampoline uses the same calling convention as dex calling conventions,
3818 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
3819 // the method_idx.
3820 HandleInvoke(invoke);
3821}
3822
3823void InstructionCodeGeneratorARM64::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
3824 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
3825}
3826
Alexandre Rames5319def2014-10-23 10:03:10 +01003827void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01003828 InvokeDexCallingConventionVisitorARM64 calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01003829 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Alexandre Rames5319def2014-10-23 10:03:10 +01003830}
3831
Alexandre Rames67555f72014-11-18 10:55:16 +00003832void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
3833 HandleInvoke(invoke);
3834}
3835
3836void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
3837 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003838 LocationSummary* locations = invoke->GetLocations();
3839 Register temp = XRegisterFrom(locations->GetTemp(0));
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003840 Location receiver = locations->InAt(0);
Alexandre Rames67555f72014-11-18 10:55:16 +00003841 Offset class_offset = mirror::Object::ClassOffset();
Andreas Gampe542451c2016-07-26 09:02:02 -07003842 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00003843
3844 // The register ip1 is required to be used for the hidden argument in
3845 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
Alexandre Ramesd921d642015-04-16 15:07:16 +01003846 MacroAssembler* masm = GetVIXLAssembler();
3847 UseScratchRegisterScope scratch_scope(masm);
3848 BlockPoolsScope block_pools(masm);
Alexandre Rames67555f72014-11-18 10:55:16 +00003849 scratch_scope.Exclude(ip1);
3850 __ Mov(ip1, invoke->GetDexMethodIndex());
3851
Alexandre Rames67555f72014-11-18 10:55:16 +00003852 if (receiver.IsStackSlot()) {
Mathieu Chartiere401d142015-04-22 13:56:20 -07003853 __ Ldr(temp.W(), StackOperandFrom(receiver));
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003854 // /* HeapReference<Class> */ temp = temp->klass_
Mathieu Chartiere401d142015-04-22 13:56:20 -07003855 __ Ldr(temp.W(), HeapOperand(temp.W(), class_offset));
Alexandre Rames67555f72014-11-18 10:55:16 +00003856 } else {
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003857 // /* HeapReference<Class> */ temp = receiver->klass_
Mathieu Chartiere401d142015-04-22 13:56:20 -07003858 __ Ldr(temp.W(), HeapOperandFrom(receiver, class_offset));
Alexandre Rames67555f72014-11-18 10:55:16 +00003859 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003860 codegen_->MaybeRecordImplicitNullCheck(invoke);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003861 // Instead of simply (possibly) unpoisoning `temp` here, we should
3862 // emit a read barrier for the previous class reference load.
3863 // However this is not required in practice, as this is an
3864 // intermediate/temporary reference and because the current
3865 // concurrent copying collector keeps the from-space memory
3866 // intact/accessible until the end of the marking phase (the
3867 // concurrent copying collector may not in the future).
Roland Levillain4d027112015-07-01 15:41:14 +01003868 GetAssembler()->MaybeUnpoisonHeapReference(temp.W());
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00003869 __ Ldr(temp,
3870 MemOperand(temp, mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value()));
3871 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00003872 invoke->GetImtIndex(), kArm64PointerSize));
Alexandre Rames67555f72014-11-18 10:55:16 +00003873 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07003874 __ Ldr(temp, MemOperand(temp, method_offset));
Alexandre Rames67555f72014-11-18 10:55:16 +00003875 // lr = temp->GetEntryPoint();
Mathieu Chartiere401d142015-04-22 13:56:20 -07003876 __ Ldr(lr, MemOperand(temp, entry_point.Int32Value()));
Alexandre Rames67555f72014-11-18 10:55:16 +00003877 // lr();
3878 __ Blr(lr);
3879 DCHECK(!codegen_->IsLeafMethod());
3880 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
3881}
3882
3883void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08003884 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
3885 if (intrinsic.TryDispatch(invoke)) {
3886 return;
3887 }
3888
Alexandre Rames67555f72014-11-18 10:55:16 +00003889 HandleInvoke(invoke);
3890}
3891
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00003892void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00003893 // Explicit clinit checks triggered by static invokes must have been pruned by
3894 // art::PrepareForRegisterAllocation.
3895 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01003896
Andreas Gampe878d58c2015-01-15 23:24:00 -08003897 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
3898 if (intrinsic.TryDispatch(invoke)) {
3899 return;
3900 }
3901
Alexandre Rames67555f72014-11-18 10:55:16 +00003902 HandleInvoke(invoke);
3903}
3904
Andreas Gampe878d58c2015-01-15 23:24:00 -08003905static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
3906 if (invoke->GetLocations()->Intrinsified()) {
3907 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
3908 intrinsic.Dispatch(invoke);
3909 return true;
3910 }
3911 return false;
3912}
3913
Vladimir Markodc151b22015-10-15 18:02:30 +01003914HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARM64::GetSupportedInvokeStaticOrDirectDispatch(
3915 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01003916 HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) {
Roland Levillain44015862016-01-22 11:47:17 +00003917 // On ARM64 we support all dispatch types.
Vladimir Markodc151b22015-10-15 18:02:30 +01003918 return desired_dispatch_info;
3919}
3920
Nicolas Geoffray38207af2015-06-01 15:46:22 +01003921void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Vladimir Marko58155012015-08-19 12:49:41 +00003922 // For better instruction scheduling we load the direct code pointer before the method pointer.
3923 bool direct_code_loaded = false;
3924 switch (invoke->GetCodePtrLocation()) {
3925 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
3926 // LR = code address from literal pool with link-time patch.
3927 __ Ldr(lr, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
3928 direct_code_loaded = true;
3929 break;
3930 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
3931 // LR = invoke->GetDirectCodePtr();
3932 __ Ldr(lr, DeduplicateUint64Literal(invoke->GetDirectCodePtr()));
3933 direct_code_loaded = true;
3934 break;
3935 default:
3936 break;
3937 }
3938
Andreas Gampe878d58c2015-01-15 23:24:00 -08003939 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
Vladimir Marko58155012015-08-19 12:49:41 +00003940 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
3941 switch (invoke->GetMethodLoadKind()) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01003942 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
3943 uint32_t offset =
3944 GetThreadOffset<kArm64PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Vladimir Marko58155012015-08-19 12:49:41 +00003945 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01003946 __ Ldr(XRegisterFrom(temp), MemOperand(tr, offset));
Vladimir Marko58155012015-08-19 12:49:41 +00003947 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01003948 }
Vladimir Marko58155012015-08-19 12:49:41 +00003949 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00003950 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00003951 break;
3952 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
3953 // Load method address from literal pool.
Alexandre Rames6dc01742015-11-12 14:44:19 +00003954 __ Ldr(XRegisterFrom(temp), DeduplicateUint64Literal(invoke->GetMethodAddress()));
Vladimir Marko58155012015-08-19 12:49:41 +00003955 break;
3956 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
3957 // Load method address from literal pool with a link-time patch.
Alexandre Rames6dc01742015-11-12 14:44:19 +00003958 __ Ldr(XRegisterFrom(temp),
Vladimir Marko58155012015-08-19 12:49:41 +00003959 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
3960 break;
3961 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
3962 // Add ADRP with its PC-relative DexCache access patch.
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01003963 const DexFile& dex_file = invoke->GetDexFile();
Vladimir Markocac5a7e2016-02-22 10:39:50 +00003964 uint32_t element_offset = invoke->GetDexCacheArrayOffset();
Scott Wakeling97c72b72016-06-24 16:19:36 +01003965 vixl::aarch64::Label* adrp_label = NewPcRelativeDexCacheArrayPatch(dex_file, element_offset);
Vladimir Markoaad75c62016-10-03 08:46:48 +00003966 EmitAdrpPlaceholder(adrp_label, XRegisterFrom(temp));
Vladimir Marko58155012015-08-19 12:49:41 +00003967 // Add LDR with its PC-relative DexCache access patch.
Scott Wakeling97c72b72016-06-24 16:19:36 +01003968 vixl::aarch64::Label* ldr_label =
Vladimir Markocac5a7e2016-02-22 10:39:50 +00003969 NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00003970 EmitLdrOffsetPlaceholder(ldr_label, XRegisterFrom(temp), XRegisterFrom(temp));
Vladimir Marko58155012015-08-19 12:49:41 +00003971 break;
Vladimir Marko9b688a02015-05-06 14:12:42 +01003972 }
Vladimir Marko58155012015-08-19 12:49:41 +00003973 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00003974 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Vladimir Marko58155012015-08-19 12:49:41 +00003975 Register reg = XRegisterFrom(temp);
3976 Register method_reg;
3977 if (current_method.IsRegister()) {
3978 method_reg = XRegisterFrom(current_method);
3979 } else {
3980 DCHECK(invoke->GetLocations()->Intrinsified());
3981 DCHECK(!current_method.IsValid());
3982 method_reg = reg;
3983 __ Ldr(reg.X(), MemOperand(sp, kCurrentMethodStackOffset));
3984 }
Vladimir Markob2c431e2015-08-19 12:45:42 +00003985
Roland Levillain22ccc3a2015-11-24 13:10:05 +00003986 // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_;
Vladimir Marko05792b92015-08-03 11:56:49 +01003987 __ Ldr(reg.X(),
3988 MemOperand(method_reg.X(),
Andreas Gampe542451c2016-07-26 09:02:02 -07003989 ArtMethod::DexCacheResolvedMethodsOffset(kArm64PointerSize).Int32Value()));
Vladimir Marko58155012015-08-19 12:49:41 +00003990 // temp = temp[index_in_cache];
Vladimir Marko40ecb122016-04-06 17:33:41 +01003991 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
3992 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Vladimir Marko58155012015-08-19 12:49:41 +00003993 __ Ldr(reg.X(), MemOperand(reg.X(), GetCachePointerOffset(index_in_cache)));
3994 break;
3995 }
3996 }
3997
3998 switch (invoke->GetCodePtrLocation()) {
3999 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
4000 __ Bl(&frame_entry_label_);
4001 break;
4002 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: {
Vladimir Markoaad75c62016-10-03 08:46:48 +00004003 relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file,
4004 invoke->GetTargetMethod().dex_method_index);
Scott Wakeling97c72b72016-06-24 16:19:36 +01004005 vixl::aarch64::Label* label = &relative_call_patches_.back().label;
4006 SingleEmissionCheckScope guard(GetVIXLAssembler());
Alexandre Rames6dc01742015-11-12 14:44:19 +00004007 __ Bind(label);
4008 __ bl(0); // Branch and link to itself. This will be overriden at link time.
Vladimir Marko58155012015-08-19 12:49:41 +00004009 break;
4010 }
4011 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4012 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4013 // LR prepared above for better instruction scheduling.
4014 DCHECK(direct_code_loaded);
4015 // lr()
4016 __ Blr(lr);
4017 break;
4018 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
4019 // LR = callee_method->entry_point_from_quick_compiled_code_;
4020 __ Ldr(lr, MemOperand(
Alexandre Rames6dc01742015-11-12 14:44:19 +00004021 XRegisterFrom(callee_method),
Andreas Gampe542451c2016-07-26 09:02:02 -07004022 ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize).Int32Value()));
Vladimir Marko58155012015-08-19 12:49:41 +00004023 // lr()
4024 __ Blr(lr);
4025 break;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00004026 }
Alexandre Rames5319def2014-10-23 10:03:10 +01004027
Andreas Gampe878d58c2015-01-15 23:24:00 -08004028 DCHECK(!IsLeafMethod());
4029}
4030
Andreas Gampebfb5ba92015-09-01 15:45:02 +00004031void CodeGeneratorARM64::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) {
Nicolas Geoffraye5234232015-12-02 09:06:11 +00004032 // Use the calling convention instead of the location of the receiver, as
4033 // intrinsics may have put the receiver in a different register. In the intrinsics
4034 // slow path, the arguments have been moved to the right place, so here we are
4035 // guaranteed that the receiver is the first register of the calling convention.
4036 InvokeDexCallingConvention calling_convention;
4037 Register receiver = calling_convention.GetRegisterAt(0);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00004038 Register temp = XRegisterFrom(temp_in);
4039 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
4040 invoke->GetVTableIndex(), kArm64PointerSize).SizeValue();
4041 Offset class_offset = mirror::Object::ClassOffset();
Andreas Gampe542451c2016-07-26 09:02:02 -07004042 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize);
Andreas Gampebfb5ba92015-09-01 15:45:02 +00004043
4044 BlockPoolsScope block_pools(GetVIXLAssembler());
4045
4046 DCHECK(receiver.IsRegister());
Roland Levillain22ccc3a2015-11-24 13:10:05 +00004047 // /* HeapReference<Class> */ temp = receiver->klass_
Nicolas Geoffraye5234232015-12-02 09:06:11 +00004048 __ Ldr(temp.W(), HeapOperandFrom(LocationFrom(receiver), class_offset));
Andreas Gampebfb5ba92015-09-01 15:45:02 +00004049 MaybeRecordImplicitNullCheck(invoke);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00004050 // Instead of simply (possibly) unpoisoning `temp` here, we should
4051 // emit a read barrier for the previous class reference load.
Roland Levillain22ccc3a2015-11-24 13:10:05 +00004052 // intermediate/temporary reference and because the current
4053 // concurrent copying collector keeps the from-space memory
4054 // intact/accessible until the end of the marking phase (the
4055 // concurrent copying collector may not in the future).
Andreas Gampebfb5ba92015-09-01 15:45:02 +00004056 GetAssembler()->MaybeUnpoisonHeapReference(temp.W());
4057 // temp = temp->GetMethodAt(method_offset);
4058 __ Ldr(temp, MemOperand(temp, method_offset));
4059 // lr = temp->GetEntryPoint();
4060 __ Ldr(lr, MemOperand(temp, entry_point.SizeValue()));
4061 // lr();
4062 __ Blr(lr);
4063}
4064
Scott Wakeling97c72b72016-06-24 16:19:36 +01004065vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeStringPatch(
4066 const DexFile& dex_file,
4067 uint32_t string_index,
4068 vixl::aarch64::Label* adrp_label) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004069 return NewPcRelativePatch(dex_file, string_index, adrp_label, &pc_relative_string_patches_);
4070}
4071
Scott Wakeling97c72b72016-06-24 16:19:36 +01004072vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeTypePatch(
4073 const DexFile& dex_file,
4074 uint32_t type_index,
4075 vixl::aarch64::Label* adrp_label) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004076 return NewPcRelativePatch(dex_file, type_index, adrp_label, &pc_relative_type_patches_);
4077}
4078
Scott Wakeling97c72b72016-06-24 16:19:36 +01004079vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativeDexCacheArrayPatch(
4080 const DexFile& dex_file,
4081 uint32_t element_offset,
4082 vixl::aarch64::Label* adrp_label) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004083 return NewPcRelativePatch(dex_file, element_offset, adrp_label, &pc_relative_dex_cache_patches_);
4084}
4085
Scott Wakeling97c72b72016-06-24 16:19:36 +01004086vixl::aarch64::Label* CodeGeneratorARM64::NewPcRelativePatch(
4087 const DexFile& dex_file,
4088 uint32_t offset_or_index,
4089 vixl::aarch64::Label* adrp_label,
4090 ArenaDeque<PcRelativePatchInfo>* patches) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004091 // Add a patch entry and return the label.
4092 patches->emplace_back(dex_file, offset_or_index);
4093 PcRelativePatchInfo* info = &patches->back();
Scott Wakeling97c72b72016-06-24 16:19:36 +01004094 vixl::aarch64::Label* label = &info->label;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004095 // If adrp_label is null, this is the ADRP patch and needs to point to its own label.
4096 info->pc_insn_label = (adrp_label != nullptr) ? adrp_label : label;
4097 return label;
4098}
4099
Scott Wakeling97c72b72016-06-24 16:19:36 +01004100vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageStringLiteral(
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004101 const DexFile& dex_file, uint32_t string_index) {
4102 return boot_image_string_patches_.GetOrCreate(
4103 StringReference(&dex_file, string_index),
4104 [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); });
4105}
4106
Scott Wakeling97c72b72016-06-24 16:19:36 +01004107vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageTypeLiteral(
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004108 const DexFile& dex_file, uint32_t type_index) {
4109 return boot_image_type_patches_.GetOrCreate(
4110 TypeReference(&dex_file, type_index),
4111 [this]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(/* placeholder */ 0u); });
4112}
4113
Scott Wakeling97c72b72016-06-24 16:19:36 +01004114vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateBootImageAddressLiteral(
4115 uint64_t address) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004116 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
4117 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
4118 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
4119}
4120
Scott Wakeling97c72b72016-06-24 16:19:36 +01004121vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateDexCacheAddressLiteral(
4122 uint64_t address) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004123 return DeduplicateUint64Literal(address);
4124}
4125
Vladimir Markoaad75c62016-10-03 08:46:48 +00004126void CodeGeneratorARM64::EmitAdrpPlaceholder(vixl::aarch64::Label* fixup_label,
4127 vixl::aarch64::Register reg) {
4128 DCHECK(reg.IsX());
4129 SingleEmissionCheckScope guard(GetVIXLAssembler());
4130 __ Bind(fixup_label);
4131 __ adrp(reg, /* offset placeholder */ 0);
4132}
4133
4134void CodeGeneratorARM64::EmitAddPlaceholder(vixl::aarch64::Label* fixup_label,
4135 vixl::aarch64::Register out,
4136 vixl::aarch64::Register base) {
4137 DCHECK(out.IsX());
4138 DCHECK(base.IsX());
4139 SingleEmissionCheckScope guard(GetVIXLAssembler());
4140 __ Bind(fixup_label);
4141 __ add(out, base, Operand(/* offset placeholder */ 0));
4142}
4143
4144void CodeGeneratorARM64::EmitLdrOffsetPlaceholder(vixl::aarch64::Label* fixup_label,
4145 vixl::aarch64::Register out,
4146 vixl::aarch64::Register base) {
4147 DCHECK(base.IsX());
4148 SingleEmissionCheckScope guard(GetVIXLAssembler());
4149 __ Bind(fixup_label);
4150 __ ldr(out, MemOperand(base, /* offset placeholder */ 0));
4151}
4152
4153template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
4154inline void CodeGeneratorARM64::EmitPcRelativeLinkerPatches(
4155 const ArenaDeque<PcRelativePatchInfo>& infos,
4156 ArenaVector<LinkerPatch>* linker_patches) {
4157 for (const PcRelativePatchInfo& info : infos) {
4158 linker_patches->push_back(Factory(info.label.GetLocation(),
4159 &info.target_dex_file,
4160 info.pc_insn_label->GetLocation(),
4161 info.offset_or_index));
4162 }
4163}
4164
Vladimir Marko58155012015-08-19 12:49:41 +00004165void CodeGeneratorARM64::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
4166 DCHECK(linker_patches->empty());
4167 size_t size =
4168 method_patches_.size() +
4169 call_patches_.size() +
4170 relative_call_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004171 pc_relative_dex_cache_patches_.size() +
4172 boot_image_string_patches_.size() +
4173 pc_relative_string_patches_.size() +
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004174 boot_image_type_patches_.size() +
4175 pc_relative_type_patches_.size() +
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004176 boot_image_address_patches_.size();
Vladimir Marko58155012015-08-19 12:49:41 +00004177 linker_patches->reserve(size);
4178 for (const auto& entry : method_patches_) {
4179 const MethodReference& target_method = entry.first;
Scott Wakeling97c72b72016-06-24 16:19:36 +01004180 vixl::aarch64::Literal<uint64_t>* literal = entry.second;
4181 linker_patches->push_back(LinkerPatch::MethodPatch(literal->GetOffset(),
Vladimir Marko58155012015-08-19 12:49:41 +00004182 target_method.dex_file,
4183 target_method.dex_method_index));
4184 }
4185 for (const auto& entry : call_patches_) {
4186 const MethodReference& target_method = entry.first;
Scott Wakeling97c72b72016-06-24 16:19:36 +01004187 vixl::aarch64::Literal<uint64_t>* literal = entry.second;
4188 linker_patches->push_back(LinkerPatch::CodePatch(literal->GetOffset(),
Vladimir Marko58155012015-08-19 12:49:41 +00004189 target_method.dex_file,
4190 target_method.dex_method_index));
4191 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00004192 for (const PatchInfo<vixl::aarch64::Label>& info : relative_call_patches_) {
4193 linker_patches->push_back(
4194 LinkerPatch::RelativeCodePatch(info.label.GetLocation(), &info.dex_file, info.index));
Vladimir Marko58155012015-08-19 12:49:41 +00004195 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004196 for (const PcRelativePatchInfo& info : pc_relative_dex_cache_patches_) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01004197 linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(info.label.GetLocation(),
Vladimir Marko58155012015-08-19 12:49:41 +00004198 &info.target_dex_file,
Scott Wakeling97c72b72016-06-24 16:19:36 +01004199 info.pc_insn_label->GetLocation(),
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004200 info.offset_or_index));
4201 }
4202 for (const auto& entry : boot_image_string_patches_) {
4203 const StringReference& target_string = entry.first;
Scott Wakeling97c72b72016-06-24 16:19:36 +01004204 vixl::aarch64::Literal<uint32_t>* literal = entry.second;
4205 linker_patches->push_back(LinkerPatch::StringPatch(literal->GetOffset(),
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004206 target_string.dex_file,
4207 target_string.string_index));
4208 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00004209 if (!GetCompilerOptions().IsBootImage()) {
4210 EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_,
4211 linker_patches);
4212 } else {
4213 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_,
4214 linker_patches);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004215 }
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004216 for (const auto& entry : boot_image_type_patches_) {
4217 const TypeReference& target_type = entry.first;
Scott Wakeling97c72b72016-06-24 16:19:36 +01004218 vixl::aarch64::Literal<uint32_t>* literal = entry.second;
4219 linker_patches->push_back(LinkerPatch::TypePatch(literal->GetOffset(),
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004220 target_type.dex_file,
4221 target_type.type_index));
4222 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00004223 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_,
4224 linker_patches);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004225 for (const auto& entry : boot_image_address_patches_) {
4226 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
Scott Wakeling97c72b72016-06-24 16:19:36 +01004227 vixl::aarch64::Literal<uint32_t>* literal = entry.second;
4228 linker_patches->push_back(LinkerPatch::RecordPosition(literal->GetOffset()));
Vladimir Marko58155012015-08-19 12:49:41 +00004229 }
4230}
4231
Scott Wakeling97c72b72016-06-24 16:19:36 +01004232vixl::aarch64::Literal<uint32_t>* CodeGeneratorARM64::DeduplicateUint32Literal(uint32_t value,
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004233 Uint32ToLiteralMap* map) {
4234 return map->GetOrCreate(
4235 value,
4236 [this, value]() { return __ CreateLiteralDestroyedWithPool<uint32_t>(value); });
4237}
4238
Scott Wakeling97c72b72016-06-24 16:19:36 +01004239vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateUint64Literal(uint64_t value) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004240 return uint64_literals_.GetOrCreate(
4241 value,
4242 [this, value]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(value); });
Vladimir Marko58155012015-08-19 12:49:41 +00004243}
4244
Scott Wakeling97c72b72016-06-24 16:19:36 +01004245vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodLiteral(
Vladimir Marko58155012015-08-19 12:49:41 +00004246 MethodReference target_method,
4247 MethodToLiteralMap* map) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004248 return map->GetOrCreate(
4249 target_method,
4250 [this]() { return __ CreateLiteralDestroyedWithPool<uint64_t>(/* placeholder */ 0u); });
Vladimir Marko58155012015-08-19 12:49:41 +00004251}
4252
Scott Wakeling97c72b72016-06-24 16:19:36 +01004253vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodAddressLiteral(
Vladimir Marko58155012015-08-19 12:49:41 +00004254 MethodReference target_method) {
4255 return DeduplicateMethodLiteral(target_method, &method_patches_);
4256}
4257
Scott Wakeling97c72b72016-06-24 16:19:36 +01004258vixl::aarch64::Literal<uint64_t>* CodeGeneratorARM64::DeduplicateMethodCodeLiteral(
Vladimir Marko58155012015-08-19 12:49:41 +00004259 MethodReference target_method) {
4260 return DeduplicateMethodLiteral(target_method, &call_patches_);
4261}
4262
4263
Andreas Gampe878d58c2015-01-15 23:24:00 -08004264void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00004265 // Explicit clinit checks triggered by static invokes must have been pruned by
4266 // art::PrepareForRegisterAllocation.
4267 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01004268
Andreas Gampe878d58c2015-01-15 23:24:00 -08004269 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
4270 return;
4271 }
4272
Alexandre Ramesd921d642015-04-16 15:07:16 +01004273 BlockPoolsScope block_pools(GetVIXLAssembler());
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004274 LocationSummary* locations = invoke->GetLocations();
4275 codegen_->GenerateStaticOrDirectCall(
4276 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00004277 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01004278}
4279
4280void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08004281 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
4282 return;
4283 }
4284
Andreas Gampebfb5ba92015-09-01 15:45:02 +00004285 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Alexandre Rames5319def2014-10-23 10:03:10 +01004286 DCHECK(!codegen_->IsLeafMethod());
4287 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
4288}
4289
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004290HLoadClass::LoadKind CodeGeneratorARM64::GetSupportedLoadClassKind(
4291 HLoadClass::LoadKind desired_class_load_kind) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004292 switch (desired_class_load_kind) {
4293 case HLoadClass::LoadKind::kReferrersClass:
4294 break;
4295 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4296 DCHECK(!GetCompilerOptions().GetCompilePic());
4297 break;
4298 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4299 DCHECK(GetCompilerOptions().GetCompilePic());
4300 break;
4301 case HLoadClass::LoadKind::kBootImageAddress:
4302 break;
4303 case HLoadClass::LoadKind::kDexCacheAddress:
4304 DCHECK(Runtime::Current()->UseJitCompilation());
4305 break;
4306 case HLoadClass::LoadKind::kDexCachePcRelative:
4307 DCHECK(!Runtime::Current()->UseJitCompilation());
4308 break;
4309 case HLoadClass::LoadKind::kDexCacheViaMethod:
4310 break;
4311 }
4312 return desired_class_load_kind;
4313}
4314
Alexandre Rames67555f72014-11-18 10:55:16 +00004315void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004316 if (cls->NeedsAccessCheck()) {
4317 InvokeRuntimeCallingConvention calling_convention;
4318 CodeGenerator::CreateLoadClassLocationSummary(
4319 cls,
4320 LocationFrom(calling_convention.GetRegisterAt(0)),
Scott Wakeling97c72b72016-06-24 16:19:36 +01004321 LocationFrom(vixl::aarch64::x0),
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004322 /* code_generator_supports_read_barrier */ true);
4323 return;
4324 }
4325
Mathieu Chartier31b12e32016-09-02 17:11:57 -07004326 const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage();
4327 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier)
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004328 ? LocationSummary::kCallOnSlowPath
4329 : LocationSummary::kNoCall;
4330 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Mathieu Chartier31b12e32016-09-02 17:11:57 -07004331 if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01004332 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Vladimir Marko70e97462016-08-09 11:04:26 +01004333 }
4334
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004335 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
4336 if (load_kind == HLoadClass::LoadKind::kReferrersClass ||
4337 load_kind == HLoadClass::LoadKind::kDexCacheViaMethod) {
4338 locations->SetInAt(0, Location::RequiresRegister());
4339 }
4340 locations->SetOut(Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00004341}
4342
4343void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
Calin Juravle98893e12015-10-02 21:05:03 +01004344 if (cls->NeedsAccessCheck()) {
4345 codegen_->MoveConstant(cls->GetLocations()->GetTemp(0), cls->GetTypeIndex());
Serban Constantinescu22f81d32016-02-18 16:06:31 +00004346 codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00004347 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Calin Juravle580b6092015-10-06 17:35:58 +01004348 return;
4349 }
4350
Roland Levillain22ccc3a2015-11-24 13:10:05 +00004351 Location out_loc = cls->GetLocations()->Out();
Calin Juravle580b6092015-10-06 17:35:58 +01004352 Register out = OutputRegister(cls);
Alexandre Rames67555f72014-11-18 10:55:16 +00004353
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08004354 const ReadBarrierOption read_barrier_option = cls->IsInBootImage()
4355 ? kWithoutReadBarrier
4356 : kCompilerReadBarrierOption;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004357 bool generate_null_check = false;
4358 switch (cls->GetLoadKind()) {
4359 case HLoadClass::LoadKind::kReferrersClass: {
4360 DCHECK(!cls->CanCallRuntime());
4361 DCHECK(!cls->MustGenerateClinitCheck());
4362 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
4363 Register current_method = InputRegisterAt(cls, 0);
Mathieu Chartier31b12e32016-09-02 17:11:57 -07004364 GenerateGcRootFieldLoad(cls,
4365 out_loc,
4366 current_method,
4367 ArtMethod::DeclaringClassOffset().Int32Value(),
Roland Levillain00468f32016-10-27 18:02:48 +01004368 /* fixup_label */ nullptr,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08004369 read_barrier_option);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004370 break;
4371 }
4372 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08004373 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004374 __ Ldr(out, codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
4375 cls->GetTypeIndex()));
4376 break;
4377 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08004378 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004379 // Add ADRP with its PC-relative type patch.
4380 const DexFile& dex_file = cls->GetDexFile();
4381 uint32_t type_index = cls->GetTypeIndex();
Scott Wakeling97c72b72016-06-24 16:19:36 +01004382 vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeTypePatch(dex_file, type_index);
Vladimir Markoaad75c62016-10-03 08:46:48 +00004383 codegen_->EmitAdrpPlaceholder(adrp_label, out.X());
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004384 // Add ADD with its PC-relative type patch.
Scott Wakeling97c72b72016-06-24 16:19:36 +01004385 vixl::aarch64::Label* add_label =
4386 codegen_->NewPcRelativeTypePatch(dex_file, type_index, adrp_label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00004387 codegen_->EmitAddPlaceholder(add_label, out.X(), out.X());
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004388 break;
4389 }
4390 case HLoadClass::LoadKind::kBootImageAddress: {
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08004391 DCHECK_EQ(read_barrier_option, kWithoutReadBarrier);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004392 DCHECK(cls->GetAddress() != 0u && IsUint<32>(cls->GetAddress()));
4393 __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(cls->GetAddress()));
4394 break;
4395 }
4396 case HLoadClass::LoadKind::kDexCacheAddress: {
4397 DCHECK_NE(cls->GetAddress(), 0u);
4398 // LDR immediate has a 12-bit offset multiplied by the size and for 32-bit loads
4399 // that gives a 16KiB range. To try and reduce the number of literals if we load
4400 // multiple types, simply split the dex cache address to a 16KiB aligned base
4401 // loaded from a literal and the remaining offset embedded in the load.
4402 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
4403 DCHECK_ALIGNED(cls->GetAddress(), 4u);
4404 constexpr size_t offset_bits = /* encoded bits */ 12 + /* scale */ 2;
4405 uint64_t base_address = cls->GetAddress() & ~MaxInt<uint64_t>(offset_bits);
4406 uint32_t offset = cls->GetAddress() & MaxInt<uint64_t>(offset_bits);
4407 __ Ldr(out.X(), codegen_->DeduplicateDexCacheAddressLiteral(base_address));
4408 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
Mathieu Chartier31b12e32016-09-02 17:11:57 -07004409 GenerateGcRootFieldLoad(cls,
4410 out_loc,
4411 out.X(),
4412 offset,
Roland Levillain00468f32016-10-27 18:02:48 +01004413 /* fixup_label */ nullptr,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08004414 read_barrier_option);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004415 generate_null_check = !cls->IsInDexCache();
4416 break;
4417 }
4418 case HLoadClass::LoadKind::kDexCachePcRelative: {
4419 // Add ADRP with its PC-relative DexCache access patch.
4420 const DexFile& dex_file = cls->GetDexFile();
4421 uint32_t element_offset = cls->GetDexCacheElementOffset();
Scott Wakeling97c72b72016-06-24 16:19:36 +01004422 vixl::aarch64::Label* adrp_label =
4423 codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset);
Vladimir Markoaad75c62016-10-03 08:46:48 +00004424 codegen_->EmitAdrpPlaceholder(adrp_label, out.X());
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004425 // Add LDR with its PC-relative DexCache access patch.
Scott Wakeling97c72b72016-06-24 16:19:36 +01004426 vixl::aarch64::Label* ldr_label =
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004427 codegen_->NewPcRelativeDexCacheArrayPatch(dex_file, element_offset, adrp_label);
4428 // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */
Mathieu Chartier31b12e32016-09-02 17:11:57 -07004429 GenerateGcRootFieldLoad(cls,
4430 out_loc,
4431 out.X(),
4432 /* offset placeholder */ 0,
4433 ldr_label,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08004434 read_barrier_option);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004435 generate_null_check = !cls->IsInDexCache();
4436 break;
4437 }
4438 case HLoadClass::LoadKind::kDexCacheViaMethod: {
4439 MemberOffset resolved_types_offset =
4440 ArtMethod::DexCacheResolvedTypesOffset(kArm64PointerSize);
4441 // /* GcRoot<mirror::Class>[] */ out =
4442 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
4443 Register current_method = InputRegisterAt(cls, 0);
4444 __ Ldr(out.X(), MemOperand(current_method, resolved_types_offset.Int32Value()));
4445 // /* GcRoot<mirror::Class> */ out = out[type_index]
Mathieu Chartier31b12e32016-09-02 17:11:57 -07004446 GenerateGcRootFieldLoad(cls,
4447 out_loc,
4448 out.X(),
4449 CodeGenerator::GetCacheOffset(cls->GetTypeIndex()),
Roland Levillain00468f32016-10-27 18:02:48 +01004450 /* fixup_label */ nullptr,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08004451 read_barrier_option);
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004452 generate_null_check = !cls->IsInDexCache();
4453 break;
4454 }
4455 }
4456
4457 if (generate_null_check || cls->MustGenerateClinitCheck()) {
4458 DCHECK(cls->CanCallRuntime());
4459 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
4460 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4461 codegen_->AddSlowPath(slow_path);
4462 if (generate_null_check) {
4463 __ Cbz(out, slow_path->GetEntryLabel());
4464 }
4465 if (cls->MustGenerateClinitCheck()) {
4466 GenerateClassInitializationCheck(slow_path, out);
4467 } else {
4468 __ Bind(slow_path->GetExitLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +00004469 }
4470 }
4471}
4472
David Brazdilcb1c0552015-08-04 16:22:25 +01004473static MemOperand GetExceptionTlsAddress() {
Andreas Gampe542451c2016-07-26 09:02:02 -07004474 return MemOperand(tr, Thread::ExceptionOffset<kArm64PointerSize>().Int32Value());
David Brazdilcb1c0552015-08-04 16:22:25 +01004475}
4476
Alexandre Rames67555f72014-11-18 10:55:16 +00004477void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
4478 LocationSummary* locations =
4479 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4480 locations->SetOut(Location::RequiresRegister());
4481}
4482
4483void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
David Brazdilcb1c0552015-08-04 16:22:25 +01004484 __ Ldr(OutputRegister(instruction), GetExceptionTlsAddress());
4485}
4486
4487void LocationsBuilderARM64::VisitClearException(HClearException* clear) {
4488 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4489}
4490
4491void InstructionCodeGeneratorARM64::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
4492 __ Str(wzr, GetExceptionTlsAddress());
Alexandre Rames67555f72014-11-18 10:55:16 +00004493}
4494
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004495HLoadString::LoadKind CodeGeneratorARM64::GetSupportedLoadStringKind(
4496 HLoadString::LoadKind desired_string_load_kind) {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004497 switch (desired_string_load_kind) {
4498 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4499 DCHECK(!GetCompilerOptions().GetCompilePic());
4500 break;
4501 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
4502 DCHECK(GetCompilerOptions().GetCompilePic());
4503 break;
4504 case HLoadString::LoadKind::kBootImageAddress:
4505 break;
Vladimir Markoaad75c62016-10-03 08:46:48 +00004506 case HLoadString::LoadKind::kBssEntry:
Calin Juravleffc87072016-04-20 14:22:09 +01004507 DCHECK(!Runtime::Current()->UseJitCompilation());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004508 break;
4509 case HLoadString::LoadKind::kDexCacheViaMethod:
4510 break;
4511 }
4512 return desired_string_load_kind;
4513}
4514
Alexandre Rames67555f72014-11-18 10:55:16 +00004515void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
Christina Wadsworth1fe89ea2016-08-31 16:14:38 -07004516 LocationSummary::CallKind call_kind = load->NeedsEnvironment()
Vladimir Markoaad75c62016-10-03 08:46:48 +00004517 ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod)
4518 ? LocationSummary::kCallOnMainOnly
4519 : LocationSummary::kCallOnSlowPath)
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004520 : LocationSummary::kNoCall;
4521 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004522 if (load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) {
Christina Wadsworth1fe89ea2016-08-31 16:14:38 -07004523 InvokeRuntimeCallingConvention calling_convention;
4524 locations->SetOut(calling_convention.GetReturnLocation(load->GetType()));
4525 } else {
4526 locations->SetOut(Location::RequiresRegister());
Vladimir Marko94ce9c22016-09-30 14:50:51 +01004527 if (load->GetLoadKind() == HLoadString::LoadKind::kBssEntry) {
4528 if (!kUseReadBarrier || kUseBakerReadBarrier) {
4529 // Rely on the pResolveString and/or marking to save everything, including temps.
4530 RegisterSet caller_saves = RegisterSet::Empty();
4531 InvokeRuntimeCallingConvention calling_convention;
4532 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode()));
4533 DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(),
4534 RegisterFrom(calling_convention.GetReturnLocation(Primitive::kPrimNot),
4535 Primitive::kPrimNot).GetCode());
4536 locations->SetCustomSlowPathCallerSaves(caller_saves);
4537 } else {
4538 // For non-Baker read barrier we have a temp-clobbering call.
4539 }
4540 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004541 }
Alexandre Rames67555f72014-11-18 10:55:16 +00004542}
4543
4544void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
Alexandre Rames67555f72014-11-18 10:55:16 +00004545 Register out = OutputRegister(load);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00004546
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004547 switch (load->GetLoadKind()) {
4548 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004549 __ Ldr(out, codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
4550 load->GetStringIndex()));
4551 return; // No dex cache slow path.
4552 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004553 // Add ADRP with its PC-relative String patch.
4554 const DexFile& dex_file = load->GetDexFile();
4555 uint32_t string_index = load->GetStringIndex();
Vladimir Markoaad75c62016-10-03 08:46:48 +00004556 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Scott Wakeling97c72b72016-06-24 16:19:36 +01004557 vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index);
Vladimir Markoaad75c62016-10-03 08:46:48 +00004558 codegen_->EmitAdrpPlaceholder(adrp_label, out.X());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004559 // Add ADD with its PC-relative String patch.
Scott Wakeling97c72b72016-06-24 16:19:36 +01004560 vixl::aarch64::Label* add_label =
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004561 codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00004562 codegen_->EmitAddPlaceholder(add_label, out.X(), out.X());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004563 return; // No dex cache slow path.
4564 }
4565 case HLoadString::LoadKind::kBootImageAddress: {
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004566 DCHECK(load->GetAddress() != 0u && IsUint<32>(load->GetAddress()));
4567 __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(load->GetAddress()));
4568 return; // No dex cache slow path.
4569 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00004570 case HLoadString::LoadKind::kBssEntry: {
4571 // Add ADRP with its PC-relative String .bss entry patch.
4572 const DexFile& dex_file = load->GetDexFile();
4573 uint32_t string_index = load->GetStringIndex();
4574 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
Vladimir Marko94ce9c22016-09-30 14:50:51 +01004575 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
4576 Register temp = temps.AcquireX();
Vladimir Markoaad75c62016-10-03 08:46:48 +00004577 vixl::aarch64::Label* adrp_label = codegen_->NewPcRelativeStringPatch(dex_file, string_index);
Vladimir Marko94ce9c22016-09-30 14:50:51 +01004578 codegen_->EmitAdrpPlaceholder(adrp_label, temp);
Vladimir Markoaad75c62016-10-03 08:46:48 +00004579 // Add LDR with its PC-relative String patch.
4580 vixl::aarch64::Label* ldr_label =
4581 codegen_->NewPcRelativeStringPatch(dex_file, string_index, adrp_label);
Nicolas Geoffray07c919f2016-11-09 17:29:03 +00004582 // /* GcRoot<mirror::Class> */ out = *(base_address + offset) /* PC-relative */
Vladimir Markoaad75c62016-10-03 08:46:48 +00004583 GenerateGcRootFieldLoad(load,
Nicolas Geoffray07c919f2016-11-09 17:29:03 +00004584 load->GetLocations()->Out(),
Vladimir Marko94ce9c22016-09-30 14:50:51 +01004585 temp,
Roland Levillain00468f32016-10-27 18:02:48 +01004586 /* offset placeholder */ 0u,
4587 ldr_label,
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08004588 kCompilerReadBarrierOption);
Vladimir Marko94ce9c22016-09-30 14:50:51 +01004589 SlowPathCodeARM64* slow_path =
4590 new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load, temp, adrp_label);
Vladimir Markoaad75c62016-10-03 08:46:48 +00004591 codegen_->AddSlowPath(slow_path);
4592 __ Cbz(out.X(), slow_path->GetEntryLabel());
4593 __ Bind(slow_path->GetExitLabel());
4594 return;
4595 }
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004596 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07004597 break;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004598 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +00004599
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07004600 // TODO: Re-add the compiler code to do string dex cache lookup again.
Christina Wadsworth1fe89ea2016-08-31 16:14:38 -07004601 InvokeRuntimeCallingConvention calling_convention;
Vladimir Marko94ce9c22016-09-30 14:50:51 +01004602 DCHECK_EQ(calling_convention.GetRegisterAt(0).GetCode(), out.GetCode());
Christina Wadsworth1fe89ea2016-08-31 16:14:38 -07004603 __ Mov(calling_convention.GetRegisterAt(0).W(), load->GetStringIndex());
4604 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
4605 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexandre Rames67555f72014-11-18 10:55:16 +00004606}
4607
Alexandre Rames5319def2014-10-23 10:03:10 +01004608void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
4609 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
4610 locations->SetOut(Location::ConstantLocation(constant));
4611}
4612
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01004613void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
Alexandre Rames5319def2014-10-23 10:03:10 +01004614 // Will be generated at use site.
4615}
4616
Alexandre Rames67555f72014-11-18 10:55:16 +00004617void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
4618 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004619 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexandre Rames67555f72014-11-18 10:55:16 +00004620 InvokeRuntimeCallingConvention calling_convention;
4621 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
4622}
4623
4624void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00004625 codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject: kQuickUnlockObject,
4626 instruction,
4627 instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00004628 if (instruction->IsEnter()) {
4629 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
4630 } else {
4631 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
4632 }
Alexandre Rames67555f72014-11-18 10:55:16 +00004633}
4634
Alexandre Rames42d641b2014-10-27 14:00:51 +00004635void LocationsBuilderARM64::VisitMul(HMul* mul) {
4636 LocationSummary* locations =
4637 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
4638 switch (mul->GetResultType()) {
4639 case Primitive::kPrimInt:
4640 case Primitive::kPrimLong:
4641 locations->SetInAt(0, Location::RequiresRegister());
4642 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00004643 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00004644 break;
4645
4646 case Primitive::kPrimFloat:
4647 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00004648 locations->SetInAt(0, Location::RequiresFpuRegister());
4649 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00004650 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00004651 break;
4652
4653 default:
4654 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
4655 }
4656}
4657
4658void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
4659 switch (mul->GetResultType()) {
4660 case Primitive::kPrimInt:
4661 case Primitive::kPrimLong:
4662 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
4663 break;
4664
4665 case Primitive::kPrimFloat:
4666 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00004667 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00004668 break;
4669
4670 default:
4671 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
4672 }
4673}
4674
Alexandre Ramesfc19de82014-11-07 17:13:31 +00004675void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
4676 LocationSummary* locations =
4677 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
4678 switch (neg->GetResultType()) {
4679 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00004680 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00004681 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00004682 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00004683 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00004684
4685 case Primitive::kPrimFloat:
4686 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00004687 locations->SetInAt(0, Location::RequiresFpuRegister());
4688 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00004689 break;
4690
4691 default:
4692 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
4693 }
4694}
4695
4696void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
4697 switch (neg->GetResultType()) {
4698 case Primitive::kPrimInt:
4699 case Primitive::kPrimLong:
4700 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
4701 break;
4702
4703 case Primitive::kPrimFloat:
4704 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00004705 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00004706 break;
4707
4708 default:
4709 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
4710 }
4711}
4712
4713void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
4714 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004715 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00004716 InvokeRuntimeCallingConvention calling_convention;
4717 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00004718 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08004719 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01004720 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(2)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00004721}
4722
4723void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
4724 LocationSummary* locations = instruction->GetLocations();
4725 InvokeRuntimeCallingConvention calling_convention;
4726 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
4727 DCHECK(type_index.Is(w0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00004728 __ Mov(type_index, instruction->GetTypeIndex());
Roland Levillain4d027112015-07-01 15:41:14 +01004729 // Note: if heap poisoning is enabled, the entry point takes cares
4730 // of poisoning the reference.
Serban Constantinescu22f81d32016-02-18 16:06:31 +00004731 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Mathieu Chartiere401d142015-04-22 13:56:20 -07004732 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00004733}
4734
Alexandre Rames5319def2014-10-23 10:03:10 +01004735void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
4736 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004737 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexandre Rames5319def2014-10-23 10:03:10 +01004738 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00004739 if (instruction->IsStringAlloc()) {
4740 locations->AddTemp(LocationFrom(kArtMethodRegister));
4741 } else {
4742 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
4743 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
4744 }
Alexandre Rames5319def2014-10-23 10:03:10 +01004745 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
4746}
4747
4748void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
Roland Levillain4d027112015-07-01 15:41:14 +01004749 // Note: if heap poisoning is enabled, the entry point takes cares
4750 // of poisoning the reference.
David Brazdil6de19382016-01-08 17:37:10 +00004751 if (instruction->IsStringAlloc()) {
4752 // String is allocated through StringFactory. Call NewEmptyString entry point.
4753 Location temp = instruction->GetLocations()->GetTemp(0);
Andreas Gampe542451c2016-07-26 09:02:02 -07004754 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64PointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00004755 __ Ldr(XRegisterFrom(temp), MemOperand(tr, QUICK_ENTRY_POINT(pNewEmptyString)));
4756 __ Ldr(lr, MemOperand(XRegisterFrom(temp), code_offset.Int32Value()));
4757 __ Blr(lr);
4758 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
4759 } else {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00004760 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
David Brazdil6de19382016-01-08 17:37:10 +00004761 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
4762 }
Alexandre Rames5319def2014-10-23 10:03:10 +01004763}
4764
4765void LocationsBuilderARM64::VisitNot(HNot* instruction) {
4766 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00004767 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00004768 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01004769}
4770
4771void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00004772 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01004773 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01004774 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01004775 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01004776 break;
4777
4778 default:
4779 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
4780 }
4781}
4782
David Brazdil66d126e2015-04-03 16:02:44 +01004783void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) {
4784 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4785 locations->SetInAt(0, Location::RequiresRegister());
4786 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4787}
4788
4789void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01004790 __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::aarch64::Operand(1));
David Brazdil66d126e2015-04-03 16:02:44 +01004791}
4792
Alexandre Rames5319def2014-10-23 10:03:10 +01004793void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01004794 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
4795 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Rames5319def2014-10-23 10:03:10 +01004796}
4797
Calin Juravle2ae48182016-03-16 14:05:09 +00004798void CodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
4799 if (CanMoveNullCheckToUser(instruction)) {
Calin Juravle77520bc2015-01-12 18:45:46 +00004800 return;
4801 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004802
Alexandre Ramesd921d642015-04-16 15:07:16 +01004803 BlockPoolsScope block_pools(GetVIXLAssembler());
4804 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004805 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
Calin Juravle2ae48182016-03-16 14:05:09 +00004806 RecordPcInfo(instruction, instruction->GetDexPc());
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004807}
4808
Calin Juravle2ae48182016-03-16 14:05:09 +00004809void CodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01004810 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00004811 AddSlowPath(slow_path);
Alexandre Rames5319def2014-10-23 10:03:10 +01004812
4813 LocationSummary* locations = instruction->GetLocations();
4814 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00004815
4816 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01004817}
4818
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004819void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00004820 codegen_->GenerateNullCheck(instruction);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00004821}
4822
Alexandre Rames67555f72014-11-18 10:55:16 +00004823void LocationsBuilderARM64::VisitOr(HOr* instruction) {
4824 HandleBinaryOp(instruction);
4825}
4826
4827void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
4828 HandleBinaryOp(instruction);
4829}
4830
Alexandre Rames3e69f162014-12-10 10:36:50 +00004831void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
4832 LOG(FATAL) << "Unreachable";
4833}
4834
4835void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
4836 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
4837}
4838
Alexandre Rames5319def2014-10-23 10:03:10 +01004839void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
4840 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4841 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
4842 if (location.IsStackSlot()) {
4843 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4844 } else if (location.IsDoubleStackSlot()) {
4845 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
4846 }
4847 locations->SetOut(location);
4848}
4849
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004850void InstructionCodeGeneratorARM64::VisitParameterValue(
4851 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Alexandre Rames5319def2014-10-23 10:03:10 +01004852 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004853}
4854
4855void LocationsBuilderARM64::VisitCurrentMethod(HCurrentMethod* instruction) {
4856 LocationSummary* locations =
4857 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004858 locations->SetOut(LocationFrom(kArtMethodRegister));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01004859}
4860
4861void InstructionCodeGeneratorARM64::VisitCurrentMethod(
4862 HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
4863 // Nothing to do, the method is already at its location.
Alexandre Rames5319def2014-10-23 10:03:10 +01004864}
4865
4866void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
4867 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01004868 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Alexandre Rames5319def2014-10-23 10:03:10 +01004869 locations->SetInAt(i, Location::Any());
4870 }
4871 locations->SetOut(Location::Any());
4872}
4873
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01004874void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
Alexandre Rames5319def2014-10-23 10:03:10 +01004875 LOG(FATAL) << "Unreachable";
4876}
4877
Serban Constantinescu02164b32014-11-13 14:05:07 +00004878void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00004879 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00004880 LocationSummary::CallKind call_kind =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004881 Primitive::IsFloatingPointType(type) ? LocationSummary::kCallOnMainOnly
4882 : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00004883 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
4884
4885 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00004886 case Primitive::kPrimInt:
4887 case Primitive::kPrimLong:
4888 locations->SetInAt(0, Location::RequiresRegister());
Zheng Xuc6667102015-05-15 16:08:45 +08004889 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00004890 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4891 break;
4892
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00004893 case Primitive::kPrimFloat:
4894 case Primitive::kPrimDouble: {
4895 InvokeRuntimeCallingConvention calling_convention;
4896 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
4897 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
4898 locations->SetOut(calling_convention.GetReturnLocation(type));
4899
4900 break;
4901 }
4902
Serban Constantinescu02164b32014-11-13 14:05:07 +00004903 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00004904 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00004905 }
4906}
4907
4908void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
4909 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00004910
Serban Constantinescu02164b32014-11-13 14:05:07 +00004911 switch (type) {
4912 case Primitive::kPrimInt:
4913 case Primitive::kPrimLong: {
Zheng Xuc6667102015-05-15 16:08:45 +08004914 GenerateDivRemIntegral(rem);
Serban Constantinescu02164b32014-11-13 14:05:07 +00004915 break;
4916 }
4917
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00004918 case Primitive::kPrimFloat:
4919 case Primitive::kPrimDouble: {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00004920 QuickEntrypointEnum entrypoint = (type == Primitive::kPrimFloat) ? kQuickFmodf : kQuickFmod;
4921 codegen_->InvokeRuntime(entrypoint, rem, rem->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00004922 if (type == Primitive::kPrimFloat) {
4923 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
4924 } else {
4925 CheckEntrypointTypes<kQuickFmod, double, double, double>();
4926 }
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00004927 break;
4928 }
4929
Serban Constantinescu02164b32014-11-13 14:05:07 +00004930 default:
4931 LOG(FATAL) << "Unexpected rem type " << type;
Vladimir Marko351dddf2015-12-11 16:34:46 +00004932 UNREACHABLE();
Serban Constantinescu02164b32014-11-13 14:05:07 +00004933 }
4934}
4935
Calin Juravle27df7582015-04-17 19:12:31 +01004936void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
4937 memory_barrier->SetLocations(nullptr);
4938}
4939
4940void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
Roland Levillain44015862016-01-22 11:47:17 +00004941 codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
Calin Juravle27df7582015-04-17 19:12:31 +01004942}
4943
Alexandre Rames5319def2014-10-23 10:03:10 +01004944void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
4945 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
4946 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00004947 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01004948}
4949
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01004950void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction ATTRIBUTE_UNUSED) {
Alexandre Rames5319def2014-10-23 10:03:10 +01004951 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01004952}
4953
4954void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
4955 instruction->SetLocations(nullptr);
4956}
4957
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01004958void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction ATTRIBUTE_UNUSED) {
Alexandre Rames5319def2014-10-23 10:03:10 +01004959 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01004960}
4961
Scott Wakeling40a04bf2015-12-11 09:50:36 +00004962void LocationsBuilderARM64::VisitRor(HRor* ror) {
4963 HandleBinaryOp(ror);
4964}
4965
4966void InstructionCodeGeneratorARM64::VisitRor(HRor* ror) {
4967 HandleBinaryOp(ror);
4968}
4969
Serban Constantinescu02164b32014-11-13 14:05:07 +00004970void LocationsBuilderARM64::VisitShl(HShl* shl) {
4971 HandleShift(shl);
4972}
4973
4974void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
4975 HandleShift(shl);
4976}
4977
4978void LocationsBuilderARM64::VisitShr(HShr* shr) {
4979 HandleShift(shr);
4980}
4981
4982void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
4983 HandleShift(shr);
4984}
4985
Alexandre Rames5319def2014-10-23 10:03:10 +01004986void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00004987 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01004988}
4989
4990void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00004991 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01004992}
4993
Alexandre Rames67555f72014-11-18 10:55:16 +00004994void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01004995 HandleFieldGet(instruction);
Alexandre Rames67555f72014-11-18 10:55:16 +00004996}
4997
4998void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01004999 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames67555f72014-11-18 10:55:16 +00005000}
5001
5002void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01005003 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01005004}
5005
Alexandre Rames67555f72014-11-18 10:55:16 +00005006void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01005007 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Alexandre Rames5319def2014-10-23 10:03:10 +01005008}
5009
Calin Juravlee460d1d2015-09-29 04:52:17 +01005010void LocationsBuilderARM64::VisitUnresolvedInstanceFieldGet(
5011 HUnresolvedInstanceFieldGet* instruction) {
5012 FieldAccessCallingConventionARM64 calling_convention;
5013 codegen_->CreateUnresolvedFieldLocationSummary(
5014 instruction, instruction->GetFieldType(), calling_convention);
5015}
5016
5017void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldGet(
5018 HUnresolvedInstanceFieldGet* instruction) {
5019 FieldAccessCallingConventionARM64 calling_convention;
5020 codegen_->GenerateUnresolvedFieldAccess(instruction,
5021 instruction->GetFieldType(),
5022 instruction->GetFieldIndex(),
5023 instruction->GetDexPc(),
5024 calling_convention);
5025}
5026
5027void LocationsBuilderARM64::VisitUnresolvedInstanceFieldSet(
5028 HUnresolvedInstanceFieldSet* instruction) {
5029 FieldAccessCallingConventionARM64 calling_convention;
5030 codegen_->CreateUnresolvedFieldLocationSummary(
5031 instruction, instruction->GetFieldType(), calling_convention);
5032}
5033
5034void InstructionCodeGeneratorARM64::VisitUnresolvedInstanceFieldSet(
5035 HUnresolvedInstanceFieldSet* instruction) {
5036 FieldAccessCallingConventionARM64 calling_convention;
5037 codegen_->GenerateUnresolvedFieldAccess(instruction,
5038 instruction->GetFieldType(),
5039 instruction->GetFieldIndex(),
5040 instruction->GetDexPc(),
5041 calling_convention);
5042}
5043
5044void LocationsBuilderARM64::VisitUnresolvedStaticFieldGet(
5045 HUnresolvedStaticFieldGet* instruction) {
5046 FieldAccessCallingConventionARM64 calling_convention;
5047 codegen_->CreateUnresolvedFieldLocationSummary(
5048 instruction, instruction->GetFieldType(), calling_convention);
5049}
5050
5051void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldGet(
5052 HUnresolvedStaticFieldGet* instruction) {
5053 FieldAccessCallingConventionARM64 calling_convention;
5054 codegen_->GenerateUnresolvedFieldAccess(instruction,
5055 instruction->GetFieldType(),
5056 instruction->GetFieldIndex(),
5057 instruction->GetDexPc(),
5058 calling_convention);
5059}
5060
5061void LocationsBuilderARM64::VisitUnresolvedStaticFieldSet(
5062 HUnresolvedStaticFieldSet* instruction) {
5063 FieldAccessCallingConventionARM64 calling_convention;
5064 codegen_->CreateUnresolvedFieldLocationSummary(
5065 instruction, instruction->GetFieldType(), calling_convention);
5066}
5067
5068void InstructionCodeGeneratorARM64::VisitUnresolvedStaticFieldSet(
5069 HUnresolvedStaticFieldSet* instruction) {
5070 FieldAccessCallingConventionARM64 calling_convention;
5071 codegen_->GenerateUnresolvedFieldAccess(instruction,
5072 instruction->GetFieldType(),
5073 instruction->GetFieldIndex(),
5074 instruction->GetDexPc(),
5075 calling_convention);
5076}
5077
Alexandre Rames5319def2014-10-23 10:03:10 +01005078void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Marko70e97462016-08-09 11:04:26 +01005079 LocationSummary* locations =
5080 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01005081 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Alexandre Rames5319def2014-10-23 10:03:10 +01005082}
5083
5084void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00005085 HBasicBlock* block = instruction->GetBlock();
5086 if (block->GetLoopInformation() != nullptr) {
5087 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5088 // The back edge will generate the suspend check.
5089 return;
5090 }
5091 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5092 // The goto will generate the suspend check.
5093 return;
5094 }
5095 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01005096}
5097
Alexandre Rames67555f72014-11-18 10:55:16 +00005098void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
5099 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005100 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Alexandre Rames67555f72014-11-18 10:55:16 +00005101 InvokeRuntimeCallingConvention calling_convention;
5102 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
5103}
5104
5105void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00005106 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08005107 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00005108}
5109
5110void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
5111 LocationSummary* locations =
5112 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
5113 Primitive::Type input_type = conversion->GetInputType();
5114 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00005115 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00005116 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
5117 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
5118 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
5119 }
5120
Alexandre Rames542361f2015-01-29 16:57:31 +00005121 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00005122 locations->SetInAt(0, Location::RequiresFpuRegister());
5123 } else {
5124 locations->SetInAt(0, Location::RequiresRegister());
5125 }
5126
Alexandre Rames542361f2015-01-29 16:57:31 +00005127 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00005128 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
5129 } else {
5130 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5131 }
5132}
5133
5134void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
5135 Primitive::Type result_type = conversion->GetResultType();
5136 Primitive::Type input_type = conversion->GetInputType();
5137
5138 DCHECK_NE(input_type, result_type);
5139
Alexandre Rames542361f2015-01-29 16:57:31 +00005140 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00005141 int result_size = Primitive::ComponentSize(result_type);
5142 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00005143 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00005144 Register output = OutputRegister(conversion);
5145 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames8626b742015-11-25 16:28:08 +00005146 if (result_type == Primitive::kPrimInt && input_type == Primitive::kPrimLong) {
Alexandre Rames4dff2fd2015-08-20 13:36:35 +01005147 // 'int' values are used directly as W registers, discarding the top
5148 // bits, so we don't need to sign-extend and can just perform a move.
5149 // We do not pass the `kDiscardForSameWReg` argument to force clearing the
5150 // top 32 bits of the target register. We theoretically could leave those
5151 // bits unchanged, but we would have to make sure that no code uses a
5152 // 32bit input value as a 64bit value assuming that the top 32 bits are
5153 // zero.
5154 __ Mov(output.W(), source.W());
Alexandre Rames8626b742015-11-25 16:28:08 +00005155 } else if (result_type == Primitive::kPrimChar ||
5156 (input_type == Primitive::kPrimChar && input_size < result_size)) {
5157 __ Ubfx(output,
5158 output.IsX() ? source.X() : source.W(),
5159 0, Primitive::ComponentSize(Primitive::kPrimChar) * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00005160 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00005161 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00005162 }
Alexandre Rames542361f2015-01-29 16:57:31 +00005163 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00005164 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00005165 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00005166 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
5167 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00005168 } else if (Primitive::IsFloatingPointType(result_type) &&
5169 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00005170 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
5171 } else {
5172 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
5173 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00005174 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00005175}
Alexandre Rames67555f72014-11-18 10:55:16 +00005176
Serban Constantinescu02164b32014-11-13 14:05:07 +00005177void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
5178 HandleShift(ushr);
5179}
5180
5181void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
5182 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00005183}
5184
5185void LocationsBuilderARM64::VisitXor(HXor* instruction) {
5186 HandleBinaryOp(instruction);
5187}
5188
5189void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
5190 HandleBinaryOp(instruction);
5191}
5192
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005193void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00005194 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00005195 LOG(FATAL) << "Unreachable";
5196}
5197
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01005198void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
Calin Juravleb1498f62015-02-16 13:13:29 +00005199 // Nothing to do, this should be removed during prepare for register allocator.
Calin Juravleb1498f62015-02-16 13:13:29 +00005200 LOG(FATAL) << "Unreachable";
5201}
5202
Mark Mendellfe57faa2015-09-18 09:26:15 -04005203// Simple implementation of packed switch - generate cascaded compare/jumps.
5204void LocationsBuilderARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5205 LocationSummary* locations =
5206 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
5207 locations->SetInAt(0, Location::RequiresRegister());
5208}
5209
5210void InstructionCodeGeneratorARM64::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5211 int32_t lower_bound = switch_instr->GetStartValue();
Zheng Xu3927c8b2015-11-18 17:46:25 +08005212 uint32_t num_entries = switch_instr->GetNumEntries();
Mark Mendellfe57faa2015-09-18 09:26:15 -04005213 Register value_reg = InputRegisterAt(switch_instr, 0);
5214 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
5215
Zheng Xu3927c8b2015-11-18 17:46:25 +08005216 // Roughly set 16 as max average assemblies generated per HIR in a graph.
Scott Wakeling97c72b72016-06-24 16:19:36 +01005217 static constexpr int32_t kMaxExpectedSizePerHInstruction = 16 * kInstructionSize;
Zheng Xu3927c8b2015-11-18 17:46:25 +08005218 // ADR has a limited range(+/-1MB), so we set a threshold for the number of HIRs in the graph to
5219 // make sure we don't emit it if the target may run out of range.
5220 // TODO: Instead of emitting all jump tables at the end of the code, we could keep track of ADR
5221 // ranges and emit the tables only as required.
5222 static constexpr int32_t kJumpTableInstructionThreshold = 1* MB / kMaxExpectedSizePerHInstruction;
Mark Mendellfe57faa2015-09-18 09:26:15 -04005223
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005224 if (num_entries <= kPackedSwitchCompareJumpThreshold ||
Zheng Xu3927c8b2015-11-18 17:46:25 +08005225 // Current instruction id is an upper bound of the number of HIRs in the graph.
5226 GetGraph()->GetCurrentInstructionId() > kJumpTableInstructionThreshold) {
5227 // Create a series of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005228 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
5229 Register temp = temps.AcquireW();
5230 __ Subs(temp, value_reg, Operand(lower_bound));
5231
Zheng Xu3927c8b2015-11-18 17:46:25 +08005232 const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005233 // Jump to successors[0] if value == lower_bound.
5234 __ B(eq, codegen_->GetLabelOf(successors[0]));
5235 int32_t last_index = 0;
5236 for (; num_entries - last_index > 2; last_index += 2) {
5237 __ Subs(temp, temp, Operand(2));
5238 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
5239 __ B(lo, codegen_->GetLabelOf(successors[last_index + 1]));
5240 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
5241 __ B(eq, codegen_->GetLabelOf(successors[last_index + 2]));
5242 }
5243 if (num_entries - last_index == 2) {
5244 // The last missing case_value.
5245 __ Cmp(temp, Operand(1));
5246 __ B(eq, codegen_->GetLabelOf(successors[last_index + 1]));
Zheng Xu3927c8b2015-11-18 17:46:25 +08005247 }
5248
5249 // And the default for any other value.
5250 if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) {
5251 __ B(codegen_->GetLabelOf(default_block));
5252 }
5253 } else {
Alexandre Ramesc01a6642016-04-15 11:54:06 +01005254 JumpTableARM64* jump_table = codegen_->CreateJumpTable(switch_instr);
Zheng Xu3927c8b2015-11-18 17:46:25 +08005255
5256 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
5257
5258 // Below instructions should use at most one blocked register. Since there are two blocked
5259 // registers, we are free to block one.
5260 Register temp_w = temps.AcquireW();
5261 Register index;
5262 // Remove the bias.
5263 if (lower_bound != 0) {
5264 index = temp_w;
5265 __ Sub(index, value_reg, Operand(lower_bound));
5266 } else {
5267 index = value_reg;
5268 }
5269
5270 // Jump to default block if index is out of the range.
5271 __ Cmp(index, Operand(num_entries));
5272 __ B(hs, codegen_->GetLabelOf(default_block));
5273
5274 // In current VIXL implementation, it won't require any blocked registers to encode the
5275 // immediate value for Adr. So we are free to use both VIXL blocked registers to reduce the
5276 // register pressure.
5277 Register table_base = temps.AcquireX();
5278 // Load jump offset from the table.
5279 __ Adr(table_base, jump_table->GetTableStartLabel());
5280 Register jump_offset = temp_w;
5281 __ Ldr(jump_offset, MemOperand(table_base, index, UXTW, 2));
5282
5283 // Jump to target block by branching to table_base(pc related) + offset.
5284 Register target_address = table_base;
5285 __ Add(target_address, table_base, Operand(jump_offset, SXTW));
5286 __ Br(target_address);
Mark Mendellfe57faa2015-09-18 09:26:15 -04005287 }
5288}
5289
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08005290void InstructionCodeGeneratorARM64::GenerateReferenceLoadOneRegister(
5291 HInstruction* instruction,
5292 Location out,
5293 uint32_t offset,
5294 Location maybe_temp,
5295 ReadBarrierOption read_barrier_option) {
Roland Levillain44015862016-01-22 11:47:17 +00005296 Primitive::Type type = Primitive::kPrimNot;
5297 Register out_reg = RegisterFrom(out, type);
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08005298 if (read_barrier_option == kWithReadBarrier) {
Mathieu Chartieraa474eb2016-11-09 15:18:27 -08005299 CHECK(kEmitCompilerReadBarrier);
Roland Levillain44015862016-01-22 11:47:17 +00005300 Register temp_reg = RegisterFrom(maybe_temp, type);
5301 if (kUseBakerReadBarrier) {
5302 // Load with fast path based Baker's read barrier.
5303 // /* HeapReference<Object> */ out = *(out + offset)
5304 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
5305 out,
5306 out_reg,
5307 offset,
5308 temp_reg,
5309 /* needs_null_check */ false,
5310 /* use_load_acquire */ false);
5311 } else {
5312 // Load with slow path based read barrier.
5313 // Save the value of `out` into `maybe_temp` before overwriting it
5314 // in the following move operation, as we will need it for the
5315 // read barrier below.
5316 __ Mov(temp_reg, out_reg);
5317 // /* HeapReference<Object> */ out = *(out + offset)
5318 __ Ldr(out_reg, HeapOperand(out_reg, offset));
5319 codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset);
5320 }
5321 } else {
5322 // Plain load with no read barrier.
5323 // /* HeapReference<Object> */ out = *(out + offset)
5324 __ Ldr(out_reg, HeapOperand(out_reg, offset));
5325 GetAssembler()->MaybeUnpoisonHeapReference(out_reg);
5326 }
5327}
5328
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08005329void InstructionCodeGeneratorARM64::GenerateReferenceLoadTwoRegisters(
5330 HInstruction* instruction,
5331 Location out,
5332 Location obj,
5333 uint32_t offset,
5334 Location maybe_temp,
5335 ReadBarrierOption read_barrier_option) {
Roland Levillain44015862016-01-22 11:47:17 +00005336 Primitive::Type type = Primitive::kPrimNot;
5337 Register out_reg = RegisterFrom(out, type);
5338 Register obj_reg = RegisterFrom(obj, type);
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08005339 if (read_barrier_option == kWithReadBarrier) {
Mathieu Chartieraa474eb2016-11-09 15:18:27 -08005340 CHECK(kEmitCompilerReadBarrier);
Roland Levillain44015862016-01-22 11:47:17 +00005341 if (kUseBakerReadBarrier) {
5342 // Load with fast path based Baker's read barrier.
5343 Register temp_reg = RegisterFrom(maybe_temp, type);
5344 // /* HeapReference<Object> */ out = *(obj + offset)
5345 codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction,
5346 out,
5347 obj_reg,
5348 offset,
5349 temp_reg,
5350 /* needs_null_check */ false,
5351 /* use_load_acquire */ false);
5352 } else {
5353 // Load with slow path based read barrier.
5354 // /* HeapReference<Object> */ out = *(obj + offset)
5355 __ Ldr(out_reg, HeapOperand(obj_reg, offset));
5356 codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset);
5357 }
5358 } else {
5359 // Plain load with no read barrier.
5360 // /* HeapReference<Object> */ out = *(obj + offset)
5361 __ Ldr(out_reg, HeapOperand(obj_reg, offset));
5362 GetAssembler()->MaybeUnpoisonHeapReference(out_reg);
5363 }
5364}
5365
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08005366void InstructionCodeGeneratorARM64::GenerateGcRootFieldLoad(
5367 HInstruction* instruction,
5368 Location root,
5369 Register obj,
5370 uint32_t offset,
5371 vixl::aarch64::Label* fixup_label,
5372 ReadBarrierOption read_barrier_option) {
Vladimir Markoaad75c62016-10-03 08:46:48 +00005373 DCHECK(fixup_label == nullptr || offset == 0u);
Roland Levillain44015862016-01-22 11:47:17 +00005374 Register root_reg = RegisterFrom(root, Primitive::kPrimNot);
Mathieu Chartier3af00dc2016-11-10 11:25:57 -08005375 if (read_barrier_option == kWithReadBarrier) {
Mathieu Chartier31b12e32016-09-02 17:11:57 -07005376 DCHECK(kEmitCompilerReadBarrier);
Roland Levillain44015862016-01-22 11:47:17 +00005377 if (kUseBakerReadBarrier) {
5378 // Fast path implementation of art::ReadBarrier::BarrierForRoot when
5379 // Baker's read barrier are used:
5380 //
5381 // root = obj.field;
5382 // if (Thread::Current()->GetIsGcMarking()) {
5383 // root = ReadBarrier::Mark(root)
5384 // }
5385
5386 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005387 if (fixup_label == nullptr) {
5388 __ Ldr(root_reg, MemOperand(obj, offset));
5389 } else {
Vladimir Markoaad75c62016-10-03 08:46:48 +00005390 codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj);
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005391 }
Roland Levillain44015862016-01-22 11:47:17 +00005392 static_assert(
5393 sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>),
5394 "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> "
5395 "have different sizes.");
5396 static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t),
5397 "art::mirror::CompressedReference<mirror::Object> and int32_t "
5398 "have different sizes.");
5399
Vladimir Marko953437b2016-08-24 08:30:46 +00005400 // Slow path marking the GC root `root`.
Roland Levillain44015862016-01-22 11:47:17 +00005401 SlowPathCodeARM64* slow_path =
Roland Levillain02b75802016-07-13 11:54:35 +01005402 new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, root);
Roland Levillain44015862016-01-22 11:47:17 +00005403 codegen_->AddSlowPath(slow_path);
5404
5405 MacroAssembler* masm = GetVIXLAssembler();
5406 UseScratchRegisterScope temps(masm);
5407 Register temp = temps.AcquireW();
5408 // temp = Thread::Current()->GetIsGcMarking()
Andreas Gampe542451c2016-07-26 09:02:02 -07005409 __ Ldr(temp, MemOperand(tr, Thread::IsGcMarkingOffset<kArm64PointerSize>().Int32Value()));
Roland Levillain44015862016-01-22 11:47:17 +00005410 __ Cbnz(temp, slow_path->GetEntryLabel());
5411 __ Bind(slow_path->GetExitLabel());
5412 } else {
5413 // GC root loaded through a slow path for read barriers other
5414 // than Baker's.
5415 // /* GcRoot<mirror::Object>* */ root = obj + offset
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005416 if (fixup_label == nullptr) {
5417 __ Add(root_reg.X(), obj.X(), offset);
5418 } else {
Vladimir Markoaad75c62016-10-03 08:46:48 +00005419 codegen_->EmitAddPlaceholder(fixup_label, root_reg.X(), obj.X());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005420 }
Roland Levillain44015862016-01-22 11:47:17 +00005421 // /* mirror::Object* */ root = root->Read()
5422 codegen_->GenerateReadBarrierForRootSlow(instruction, root, root);
5423 }
5424 } else {
5425 // Plain GC root load with no read barrier.
5426 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005427 if (fixup_label == nullptr) {
5428 __ Ldr(root_reg, MemOperand(obj, offset));
5429 } else {
Vladimir Markoaad75c62016-10-03 08:46:48 +00005430 codegen_->EmitLdrOffsetPlaceholder(fixup_label, root_reg, obj.X());
Vladimir Markocac5a7e2016-02-22 10:39:50 +00005431 }
Roland Levillain44015862016-01-22 11:47:17 +00005432 // Note that GC roots are not affected by heap poisoning, thus we
5433 // do not have to unpoison `root_reg` here.
5434 }
5435}
5436
5437void CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
5438 Location ref,
Scott Wakeling97c72b72016-06-24 16:19:36 +01005439 Register obj,
Roland Levillain44015862016-01-22 11:47:17 +00005440 uint32_t offset,
5441 Register temp,
5442 bool needs_null_check,
5443 bool use_load_acquire) {
5444 DCHECK(kEmitCompilerReadBarrier);
5445 DCHECK(kUseBakerReadBarrier);
5446
5447 // /* HeapReference<Object> */ ref = *(obj + offset)
5448 Location no_index = Location::NoLocation();
Roland Levillaina1aa3b12016-10-26 13:03:38 +01005449 size_t no_scale_factor = 0u;
Roland Levillainbfea3352016-06-23 13:48:47 +01005450 GenerateReferenceLoadWithBakerReadBarrier(instruction,
5451 ref,
5452 obj,
5453 offset,
5454 no_index,
5455 no_scale_factor,
5456 temp,
5457 needs_null_check,
5458 use_load_acquire);
Roland Levillain44015862016-01-22 11:47:17 +00005459}
5460
5461void CodeGeneratorARM64::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
5462 Location ref,
Scott Wakeling97c72b72016-06-24 16:19:36 +01005463 Register obj,
Roland Levillain44015862016-01-22 11:47:17 +00005464 uint32_t data_offset,
5465 Location index,
5466 Register temp,
5467 bool needs_null_check) {
5468 DCHECK(kEmitCompilerReadBarrier);
5469 DCHECK(kUseBakerReadBarrier);
5470
5471 // Array cells are never volatile variables, therefore array loads
5472 // never use Load-Acquire instructions on ARM64.
5473 const bool use_load_acquire = false;
5474
Roland Levillainbfea3352016-06-23 13:48:47 +01005475 static_assert(
5476 sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
5477 "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes.");
Roland Levillain44015862016-01-22 11:47:17 +00005478 // /* HeapReference<Object> */ ref =
5479 // *(obj + data_offset + index * sizeof(HeapReference<Object>))
Roland Levillainbfea3352016-06-23 13:48:47 +01005480 size_t scale_factor = Primitive::ComponentSizeShift(Primitive::kPrimNot);
5481 GenerateReferenceLoadWithBakerReadBarrier(instruction,
5482 ref,
5483 obj,
5484 data_offset,
5485 index,
5486 scale_factor,
5487 temp,
5488 needs_null_check,
5489 use_load_acquire);
Roland Levillain44015862016-01-22 11:47:17 +00005490}
5491
5492void CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
5493 Location ref,
Scott Wakeling97c72b72016-06-24 16:19:36 +01005494 Register obj,
Roland Levillain44015862016-01-22 11:47:17 +00005495 uint32_t offset,
5496 Location index,
Roland Levillainbfea3352016-06-23 13:48:47 +01005497 size_t scale_factor,
Roland Levillain44015862016-01-22 11:47:17 +00005498 Register temp,
5499 bool needs_null_check,
Roland Levillaina1aa3b12016-10-26 13:03:38 +01005500 bool use_load_acquire,
5501 bool always_update_field) {
Roland Levillain44015862016-01-22 11:47:17 +00005502 DCHECK(kEmitCompilerReadBarrier);
5503 DCHECK(kUseBakerReadBarrier);
Roland Levillainbfea3352016-06-23 13:48:47 +01005504 // If we are emitting an array load, we should not be using a
5505 // Load Acquire instruction. In other words:
5506 // `instruction->IsArrayGet()` => `!use_load_acquire`.
5507 DCHECK(!instruction->IsArrayGet() || !use_load_acquire);
Roland Levillain44015862016-01-22 11:47:17 +00005508
5509 MacroAssembler* masm = GetVIXLAssembler();
5510 UseScratchRegisterScope temps(masm);
5511
5512 // In slow path based read barriers, the read barrier call is
5513 // inserted after the original load. However, in fast path based
5514 // Baker's read barriers, we need to perform the load of
5515 // mirror::Object::monitor_ *before* the original reference load.
5516 // This load-load ordering is required by the read barrier.
5517 // The fast path/slow path (for Baker's algorithm) should look like:
5518 //
5519 // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState();
5520 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
5521 // HeapReference<Object> ref = *src; // Original reference load.
Hiroshi Yamauchi12b58b22016-11-01 11:55:29 -07005522 // bool is_gray = (rb_state == ReadBarrier::GrayState());
Roland Levillain44015862016-01-22 11:47:17 +00005523 // if (is_gray) {
5524 // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path.
5525 // }
5526 //
5527 // Note: the original implementation in ReadBarrier::Barrier is
5528 // slightly more complex as it performs additional checks that we do
5529 // not do here for performance reasons.
5530
5531 Primitive::Type type = Primitive::kPrimNot;
5532 Register ref_reg = RegisterFrom(ref, type);
5533 DCHECK(obj.IsW());
5534 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
5535
5536 // /* int32_t */ monitor = obj->monitor_
5537 __ Ldr(temp, HeapOperand(obj, monitor_offset));
5538 if (needs_null_check) {
5539 MaybeRecordImplicitNullCheck(instruction);
5540 }
5541 // /* LockWord */ lock_word = LockWord(monitor)
5542 static_assert(sizeof(LockWord) == sizeof(int32_t),
5543 "art::LockWord and int32_t have different sizes.");
Roland Levillain44015862016-01-22 11:47:17 +00005544
Vladimir Marko877a0332016-07-11 19:30:56 +01005545 // Introduce a dependency on the lock_word including rb_state,
5546 // to prevent load-load reordering, and without using
Roland Levillain44015862016-01-22 11:47:17 +00005547 // a memory barrier (which would be more expensive).
Roland Levillain0b671c02016-08-19 12:02:34 +01005548 // `obj` is unchanged by this operation, but its value now depends
5549 // on `temp`.
Vladimir Marko877a0332016-07-11 19:30:56 +01005550 __ Add(obj.X(), obj.X(), Operand(temp.X(), LSR, 32));
Roland Levillain44015862016-01-22 11:47:17 +00005551
5552 // The actual reference load.
5553 if (index.IsValid()) {
Roland Levillaina1aa3b12016-10-26 13:03:38 +01005554 // Load types involving an "index": ArrayGet,
5555 // UnsafeGetObject/UnsafeGetObjectVolatile and UnsafeCASObject
5556 // intrinsics.
Roland Levillainbfea3352016-06-23 13:48:47 +01005557 if (use_load_acquire) {
5558 // UnsafeGetObjectVolatile intrinsic case.
5559 // Register `index` is not an index in an object array, but an
5560 // offset to an object reference field within object `obj`.
5561 DCHECK(instruction->IsInvoke()) << instruction->DebugName();
5562 DCHECK(instruction->GetLocations()->Intrinsified());
5563 DCHECK(instruction->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)
5564 << instruction->AsInvoke()->GetIntrinsic();
Roland Levillaina1aa3b12016-10-26 13:03:38 +01005565 DCHECK_EQ(offset, 0u);
5566 DCHECK_EQ(scale_factor, 0u);
5567 DCHECK_EQ(needs_null_check, 0u);
Roland Levillainbfea3352016-06-23 13:48:47 +01005568 // /* HeapReference<Object> */ ref = *(obj + index)
5569 MemOperand field = HeapOperand(obj, XRegisterFrom(index));
5570 LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false);
Roland Levillain44015862016-01-22 11:47:17 +00005571 } else {
Roland Levillainbfea3352016-06-23 13:48:47 +01005572 // ArrayGet and UnsafeGetObject intrinsics cases.
5573 // /* HeapReference<Object> */ ref = *(obj + offset + (index << scale_factor))
5574 if (index.IsConstant()) {
5575 uint32_t computed_offset = offset + (Int64ConstantFrom(index) << scale_factor);
5576 Load(type, ref_reg, HeapOperand(obj, computed_offset));
5577 } else {
Roland Levillaina1aa3b12016-10-26 13:03:38 +01005578 Register temp3 = temps.AcquireW();
5579 __ Add(temp3, obj, offset);
5580 Load(type, ref_reg, HeapOperand(temp3, XRegisterFrom(index), LSL, scale_factor));
5581 temps.Release(temp3);
Roland Levillainbfea3352016-06-23 13:48:47 +01005582 }
Roland Levillain44015862016-01-22 11:47:17 +00005583 }
Roland Levillain44015862016-01-22 11:47:17 +00005584 } else {
5585 // /* HeapReference<Object> */ ref = *(obj + offset)
5586 MemOperand field = HeapOperand(obj, offset);
5587 if (use_load_acquire) {
5588 LoadAcquire(instruction, ref_reg, field, /* needs_null_check */ false);
5589 } else {
5590 Load(type, ref_reg, field);
5591 }
5592 }
5593
5594 // Object* ref = ref_addr->AsMirrorPtr()
5595 GetAssembler()->MaybeUnpoisonHeapReference(ref_reg);
5596
Vladimir Marko953437b2016-08-24 08:30:46 +00005597 // Slow path marking the object `ref` when it is gray.
Roland Levillaina1aa3b12016-10-26 13:03:38 +01005598 SlowPathCodeARM64* slow_path;
5599 if (always_update_field) {
5600 // ReadBarrierMarkAndUpdateFieldSlowPathARM64 only supports
5601 // address of the form `obj + field_offset`, where `obj` is a
5602 // register and `field_offset` is a register. Thus `offset` and
5603 // `scale_factor` above are expected to be null in this code path.
5604 DCHECK_EQ(offset, 0u);
5605 DCHECK_EQ(scale_factor, 0u); /* "times 1" */
5606 slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkAndUpdateFieldSlowPathARM64(
5607 instruction, ref, obj, /* field_offset */ index, temp);
5608 } else {
5609 slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathARM64(instruction, ref);
5610 }
Roland Levillain44015862016-01-22 11:47:17 +00005611 AddSlowPath(slow_path);
5612
Hiroshi Yamauchi12b58b22016-11-01 11:55:29 -07005613 // if (rb_state == ReadBarrier::GrayState())
Roland Levillain44015862016-01-22 11:47:17 +00005614 // ref = ReadBarrier::Mark(ref);
Vladimir Marko877a0332016-07-11 19:30:56 +01005615 // Given the numeric representation, it's enough to check the low bit of the rb_state.
Hiroshi Yamauchi12b58b22016-11-01 11:55:29 -07005616 static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0");
5617 static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1");
Vladimir Marko877a0332016-07-11 19:30:56 +01005618 __ Tbnz(temp, LockWord::kReadBarrierStateShift, slow_path->GetEntryLabel());
Roland Levillain44015862016-01-22 11:47:17 +00005619 __ Bind(slow_path->GetExitLabel());
5620}
5621
5622void CodeGeneratorARM64::GenerateReadBarrierSlow(HInstruction* instruction,
5623 Location out,
5624 Location ref,
5625 Location obj,
5626 uint32_t offset,
5627 Location index) {
Roland Levillain22ccc3a2015-11-24 13:10:05 +00005628 DCHECK(kEmitCompilerReadBarrier);
5629
Roland Levillain44015862016-01-22 11:47:17 +00005630 // Insert a slow path based read barrier *after* the reference load.
5631 //
Roland Levillain22ccc3a2015-11-24 13:10:05 +00005632 // If heap poisoning is enabled, the unpoisoning of the loaded
5633 // reference will be carried out by the runtime within the slow
5634 // path.
5635 //
5636 // Note that `ref` currently does not get unpoisoned (when heap
5637 // poisoning is enabled), which is alright as the `ref` argument is
5638 // not used by the artReadBarrierSlow entry point.
5639 //
5640 // TODO: Unpoison `ref` when it is used by artReadBarrierSlow.
5641 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
5642 ReadBarrierForHeapReferenceSlowPathARM64(instruction, out, ref, obj, offset, index);
5643 AddSlowPath(slow_path);
5644
Roland Levillain22ccc3a2015-11-24 13:10:05 +00005645 __ B(slow_path->GetEntryLabel());
5646 __ Bind(slow_path->GetExitLabel());
5647}
5648
Roland Levillain44015862016-01-22 11:47:17 +00005649void CodeGeneratorARM64::MaybeGenerateReadBarrierSlow(HInstruction* instruction,
5650 Location out,
5651 Location ref,
5652 Location obj,
5653 uint32_t offset,
5654 Location index) {
Roland Levillain22ccc3a2015-11-24 13:10:05 +00005655 if (kEmitCompilerReadBarrier) {
Roland Levillain44015862016-01-22 11:47:17 +00005656 // Baker's read barriers shall be handled by the fast path
5657 // (CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier).
5658 DCHECK(!kUseBakerReadBarrier);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00005659 // If heap poisoning is enabled, unpoisoning will be taken care of
5660 // by the runtime within the slow path.
Roland Levillain44015862016-01-22 11:47:17 +00005661 GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index);
Roland Levillain22ccc3a2015-11-24 13:10:05 +00005662 } else if (kPoisonHeapReferences) {
5663 GetAssembler()->UnpoisonHeapReference(WRegisterFrom(out));
5664 }
5665}
5666
Roland Levillain44015862016-01-22 11:47:17 +00005667void CodeGeneratorARM64::GenerateReadBarrierForRootSlow(HInstruction* instruction,
5668 Location out,
5669 Location root) {
Roland Levillain22ccc3a2015-11-24 13:10:05 +00005670 DCHECK(kEmitCompilerReadBarrier);
5671
Roland Levillain44015862016-01-22 11:47:17 +00005672 // Insert a slow path based read barrier *after* the GC root load.
5673 //
Roland Levillain22ccc3a2015-11-24 13:10:05 +00005674 // Note that GC roots are not affected by heap poisoning, so we do
5675 // not need to do anything special for this here.
5676 SlowPathCodeARM64* slow_path =
5677 new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathARM64(instruction, out, root);
5678 AddSlowPath(slow_path);
5679
Roland Levillain22ccc3a2015-11-24 13:10:05 +00005680 __ B(slow_path->GetEntryLabel());
5681 __ Bind(slow_path->GetExitLabel());
5682}
5683
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005684void LocationsBuilderARM64::VisitClassTableGet(HClassTableGet* instruction) {
5685 LocationSummary* locations =
5686 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5687 locations->SetInAt(0, Location::RequiresRegister());
5688 locations->SetOut(Location::RequiresRegister());
5689}
5690
5691void InstructionCodeGeneratorARM64::VisitClassTableGet(HClassTableGet* instruction) {
5692 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00005693 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005694 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005695 instruction->GetIndex(), kArm64PointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005696 __ Ldr(XRegisterFrom(locations->Out()),
5697 MemOperand(XRegisterFrom(locations->InAt(0)), method_offset));
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005698 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005699 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00005700 instruction->GetIndex(), kArm64PointerSize));
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00005701 __ Ldr(XRegisterFrom(locations->Out()), MemOperand(XRegisterFrom(locations->InAt(0)),
5702 mirror::Class::ImtPtrOffset(kArm64PointerSize).Uint32Value()));
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01005703 __ Ldr(XRegisterFrom(locations->Out()),
5704 MemOperand(XRegisterFrom(locations->Out()), method_offset));
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005705 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005706}
5707
Nicolas Geoffray07c919f2016-11-09 17:29:03 +00005708
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00005709
Alexandre Rames67555f72014-11-18 10:55:16 +00005710#undef __
5711#undef QUICK_ENTRY_POINT
5712
Alexandre Rames5319def2014-10-23 10:03:10 +01005713} // namespace arm64
5714} // namespace art