blob: 38c756fb0fcbe977ff33a7bacd93e622a3fc1b9c [file] [log] [blame]
Scott Wakelingfe885462016-09-22 10:24:38 +01001/*
2 * Copyright (C) 2016 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#ifndef ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM_VIXL_H_
18#define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM_VIXL_H_
19
20#include "code_generator_arm.h"
Artem Serovcfbe9132016-10-14 15:58:56 +010021#include "common_arm.h"
Scott Wakelingfe885462016-09-22 10:24:38 +010022#include "utils/arm/assembler_arm_vixl.h"
23
24// TODO(VIXL): make vixl clean wrt -Wshadow.
25#pragma GCC diagnostic push
26#pragma GCC diagnostic ignored "-Wshadow"
27#include "aarch32/constants-aarch32.h"
28#include "aarch32/instructions-aarch32.h"
29#include "aarch32/macro-assembler-aarch32.h"
30#pragma GCC diagnostic pop
31
32// True if VIXL32 should be used for codegen on ARM.
Scott Wakelinga7812ae2016-10-17 10:03:36 +010033#ifdef ART_USE_VIXL_ARM_BACKEND
Scott Wakelingfe885462016-09-22 10:24:38 +010034static constexpr bool kArmUseVIXL32 = true;
35#else
36static constexpr bool kArmUseVIXL32 = false;
37#endif
38
39namespace art {
40namespace arm {
41
Scott Wakelinga7812ae2016-10-17 10:03:36 +010042static const vixl::aarch32::Register kParameterCoreRegistersVIXL[] = {
43 vixl::aarch32::r1,
44 vixl::aarch32::r2,
45 vixl::aarch32::r3
46};
47static const size_t kParameterCoreRegistersLengthVIXL = arraysize(kParameterCoreRegisters);
48static const vixl::aarch32::SRegister kParameterFpuRegistersVIXL[] = {
49 vixl::aarch32::s0,
50 vixl::aarch32::s1,
51 vixl::aarch32::s2,
52 vixl::aarch32::s3,
53 vixl::aarch32::s4,
54 vixl::aarch32::s5,
55 vixl::aarch32::s6,
56 vixl::aarch32::s7,
57 vixl::aarch32::s8,
58 vixl::aarch32::s9,
59 vixl::aarch32::s10,
60 vixl::aarch32::s11,
61 vixl::aarch32::s12,
62 vixl::aarch32::s13,
63 vixl::aarch32::s14,
64 vixl::aarch32::s15
65};
66static const size_t kParameterFpuRegistersLengthVIXL = arraysize(kParameterFpuRegisters);
67
Scott Wakelingfe885462016-09-22 10:24:38 +010068static const vixl::aarch32::Register kMethodRegister = vixl::aarch32::r0;
Scott Wakelinga7812ae2016-10-17 10:03:36 +010069
Scott Wakelingfe885462016-09-22 10:24:38 +010070static const vixl::aarch32::Register kCoreAlwaysSpillRegister = vixl::aarch32::r5;
Scott Wakelinga7812ae2016-10-17 10:03:36 +010071
72// Callee saves core registers r5, r6, r7, r8, r10, r11, and lr.
73static const vixl::aarch32::RegisterList kCoreCalleeSaves = vixl::aarch32::RegisterList::Union(
74 vixl::aarch32::RegisterList(vixl::aarch32::r5,
75 vixl::aarch32::r6,
76 vixl::aarch32::r7,
77 vixl::aarch32::r8),
78 vixl::aarch32::RegisterList(vixl::aarch32::r10,
79 vixl::aarch32::r11,
80 vixl::aarch32::lr));
81
82// Callee saves FP registers s16 to s31 inclusive.
Scott Wakelingfe885462016-09-22 10:24:38 +010083static const vixl::aarch32::SRegisterList kFpuCalleeSaves =
84 vixl::aarch32::SRegisterList(vixl::aarch32::s16, 16);
85
Scott Wakelinga7812ae2016-10-17 10:03:36 +010086static const vixl::aarch32::Register kRuntimeParameterCoreRegistersVIXL[] = {
87 vixl::aarch32::r0,
88 vixl::aarch32::r1,
89 vixl::aarch32::r2,
90 vixl::aarch32::r3
91};
92static const size_t kRuntimeParameterCoreRegistersLengthVIXL =
93 arraysize(kRuntimeParameterCoreRegisters);
94static const vixl::aarch32::SRegister kRuntimeParameterFpuRegistersVIXL[] = {
95 vixl::aarch32::s0,
96 vixl::aarch32::s1,
97 vixl::aarch32::s2,
98 vixl::aarch32::s3
99};
100static const size_t kRuntimeParameterFpuRegistersLengthVIXL =
101 arraysize(kRuntimeParameterFpuRegisters);
102
103class LoadClassSlowPathARMVIXL;
104
Scott Wakelingfe885462016-09-22 10:24:38 +0100105#define FOR_EACH_IMPLEMENTED_INSTRUCTION(M) \
106 M(Above) \
107 M(AboveOrEqual) \
108 M(Add) \
Artem Serov02109dd2016-09-23 17:17:54 +0100109 M(And) \
Scott Wakelingc34dba72016-10-03 10:14:44 +0100110 M(ArrayGet) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100111 M(ArrayLength) \
Scott Wakelingc34dba72016-10-03 10:14:44 +0100112 M(ArraySet) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100113 M(Below) \
114 M(BelowOrEqual) \
Artem Serov2bbc9532016-10-21 11:51:50 +0100115 M(BitwiseNegatedRight) \
Scott Wakelingc34dba72016-10-03 10:14:44 +0100116 M(BooleanNot) \
117 M(BoundsCheck) \
Artem Serov551b28f2016-10-18 19:11:30 +0100118 M(BoundType) \
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100119 M(CheckCast) \
Artem Serov551b28f2016-10-18 19:11:30 +0100120 M(ClassTableGet) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100121 M(ClearException) \
122 M(ClinitCheck) \
Alexandre Rames9c19bd62016-10-24 11:50:32 +0100123 M(Compare) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100124 M(CurrentMethod) \
Scott Wakelingc34dba72016-10-03 10:14:44 +0100125 M(Deoptimize) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100126 M(Div) \
127 M(DivZeroCheck) \
Alexandre Ramesb45fbaa52016-10-17 14:57:13 +0100128 M(DoubleConstant) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100129 M(Equal) \
130 M(Exit) \
Alexandre Ramesb45fbaa52016-10-17 14:57:13 +0100131 M(FloatConstant) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100132 M(Goto) \
133 M(GreaterThan) \
134 M(GreaterThanOrEqual) \
135 M(If) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100136 M(InstanceFieldGet) \
137 M(InstanceFieldSet) \
Artem Serovcfbe9132016-10-14 15:58:56 +0100138 M(InstanceOf) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100139 M(IntConstant) \
Artem Serov2bbc9532016-10-21 11:51:50 +0100140 M(IntermediateAddress) \
Artem Serovcfbe9132016-10-14 15:58:56 +0100141 M(InvokeInterface) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100142 M(InvokeStaticOrDirect) \
Artem Serovcfbe9132016-10-14 15:58:56 +0100143 M(InvokeUnresolved) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100144 M(InvokeVirtual) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100145 M(LessThan) \
146 M(LessThanOrEqual) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100147 M(LoadClass) \
148 M(LoadException) \
149 M(LoadString) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100150 M(LongConstant) \
151 M(MemoryBarrier) \
Artem Serov551b28f2016-10-18 19:11:30 +0100152 M(MonitorOperation) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100153 M(Mul) \
Artem Serov2bbc9532016-10-21 11:51:50 +0100154 M(MultiplyAccumulate) \
Artem Serov551b28f2016-10-18 19:11:30 +0100155 M(NativeDebugInfo) \
Artem Serov02109dd2016-09-23 17:17:54 +0100156 M(Neg) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100157 M(NewArray) \
158 M(NewInstance) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100159 M(Not) \
160 M(NotEqual) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100161 M(NullCheck) \
162 M(NullConstant) \
Artem Serov02109dd2016-09-23 17:17:54 +0100163 M(Or) \
Artem Serov551b28f2016-10-18 19:11:30 +0100164 M(PackedSwitch) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100165 M(ParallelMove) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100166 M(ParameterValue) \
167 M(Phi) \
Artem Serov551b28f2016-10-18 19:11:30 +0100168 M(Rem) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100169 M(Return) \
170 M(ReturnVoid) \
Artem Serov02109dd2016-09-23 17:17:54 +0100171 M(Ror) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100172 M(Select) \
Artem Serov02109dd2016-09-23 17:17:54 +0100173 M(Shl) \
174 M(Shr) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100175 M(StaticFieldGet) \
Scott Wakelingc34dba72016-10-03 10:14:44 +0100176 M(StaticFieldSet) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100177 M(Sub) \
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100178 M(SuspendCheck) \
179 M(Throw) \
180 M(TryBoundary) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100181 M(TypeConversion) \
Artem Serovcfbe9132016-10-14 15:58:56 +0100182 M(UnresolvedInstanceFieldGet) \
183 M(UnresolvedInstanceFieldSet) \
184 M(UnresolvedStaticFieldGet) \
185 M(UnresolvedStaticFieldSet) \
Artem Serov02109dd2016-09-23 17:17:54 +0100186 M(UShr) \
187 M(Xor) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100188
189// TODO: Remove once the VIXL32 backend is implemented completely.
190#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Artem Serovcfbe9132016-10-14 15:58:56 +0100191 M(ArmDexCacheArraysBase) \
Scott Wakelingfe885462016-09-22 10:24:38 +0100192
193class CodeGeneratorARMVIXL;
194
Artem Serov551b28f2016-10-18 19:11:30 +0100195class JumpTableARMVIXL : public DeletableArenaObject<kArenaAllocSwitchTable> {
196 public:
Artem Serov09a940d2016-11-11 16:15:11 +0000197 typedef vixl::aarch32::Literal<int32_t> IntLiteral;
198
Artem Serov551b28f2016-10-18 19:11:30 +0100199 explicit JumpTableARMVIXL(HPackedSwitch* switch_instr)
Artem Serov09a940d2016-11-11 16:15:11 +0000200 : switch_instr_(switch_instr),
201 table_start_(),
202 bb_addresses_(switch_instr->GetArena()->Adapter(kArenaAllocCodeGenerator)) {
203 uint32_t num_entries = switch_instr_->GetNumEntries();
204 for (uint32_t i = 0; i < num_entries; i++) {
205 IntLiteral *lit = new IntLiteral(0);
206 bb_addresses_.emplace_back(lit);
207 }
208 }
Artem Serov551b28f2016-10-18 19:11:30 +0100209
210 vixl::aarch32::Label* GetTableStartLabel() { return &table_start_; }
211
212 void EmitTable(CodeGeneratorARMVIXL* codegen);
Artem Serov09a940d2016-11-11 16:15:11 +0000213 void FixTable(CodeGeneratorARMVIXL* codegen);
Artem Serov551b28f2016-10-18 19:11:30 +0100214
215 private:
216 HPackedSwitch* const switch_instr_;
217 vixl::aarch32::Label table_start_;
Artem Serov09a940d2016-11-11 16:15:11 +0000218 ArenaVector<std::unique_ptr<IntLiteral>> bb_addresses_;
Artem Serov551b28f2016-10-18 19:11:30 +0100219
220 DISALLOW_COPY_AND_ASSIGN(JumpTableARMVIXL);
221};
222
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100223class InvokeRuntimeCallingConventionARMVIXL
224 : public CallingConvention<vixl::aarch32::Register, vixl::aarch32::SRegister> {
225 public:
226 InvokeRuntimeCallingConventionARMVIXL()
227 : CallingConvention(kRuntimeParameterCoreRegistersVIXL,
228 kRuntimeParameterCoreRegistersLengthVIXL,
229 kRuntimeParameterFpuRegistersVIXL,
230 kRuntimeParameterFpuRegistersLengthVIXL,
231 kArmPointerSize) {}
232
233 private:
234 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConventionARMVIXL);
235};
236
237class InvokeDexCallingConventionARMVIXL
238 : public CallingConvention<vixl::aarch32::Register, vixl::aarch32::SRegister> {
239 public:
240 InvokeDexCallingConventionARMVIXL()
241 : CallingConvention(kParameterCoreRegistersVIXL,
242 kParameterCoreRegistersLengthVIXL,
243 kParameterFpuRegistersVIXL,
244 kParameterFpuRegistersLengthVIXL,
245 kArmPointerSize) {}
246
247 private:
248 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionARMVIXL);
249};
250
Artem Serovcfbe9132016-10-14 15:58:56 +0100251class FieldAccessCallingConventionARMVIXL : public FieldAccessCallingConvention {
252 public:
253 FieldAccessCallingConventionARMVIXL() {}
254
255 Location GetObjectLocation() const OVERRIDE {
256 return helpers::LocationFrom(vixl::aarch32::r1);
257 }
258 Location GetFieldIndexLocation() const OVERRIDE {
259 return helpers::LocationFrom(vixl::aarch32::r0);
260 }
261 Location GetReturnLocation(Primitive::Type type) const OVERRIDE {
262 return Primitive::Is64BitType(type)
263 ? helpers::LocationFrom(vixl::aarch32::r0, vixl::aarch32::r1)
264 : helpers::LocationFrom(vixl::aarch32::r0);
265 }
266 Location GetSetValueLocation(Primitive::Type type, bool is_instance) const OVERRIDE {
267 return Primitive::Is64BitType(type)
268 ? helpers::LocationFrom(vixl::aarch32::r2, vixl::aarch32::r3)
269 : (is_instance
270 ? helpers::LocationFrom(vixl::aarch32::r2)
271 : helpers::LocationFrom(vixl::aarch32::r1));
272 }
273 Location GetFpuLocation(Primitive::Type type) const OVERRIDE {
274 return Primitive::Is64BitType(type)
275 ? helpers::LocationFrom(vixl::aarch32::s0, vixl::aarch32::s1)
276 : helpers::LocationFrom(vixl::aarch32::s0);
277 }
278
279 private:
280 DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionARMVIXL);
281};
282
Scott Wakelingfe885462016-09-22 10:24:38 +0100283class SlowPathCodeARMVIXL : public SlowPathCode {
284 public:
285 explicit SlowPathCodeARMVIXL(HInstruction* instruction)
286 : SlowPathCode(instruction), entry_label_(), exit_label_() {}
287
288 vixl::aarch32::Label* GetEntryLabel() { return &entry_label_; }
289 vixl::aarch32::Label* GetExitLabel() { return &exit_label_; }
290
291 void SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) OVERRIDE;
292 void RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) OVERRIDE;
293
294 private:
295 vixl::aarch32::Label entry_label_;
296 vixl::aarch32::Label exit_label_;
297
298 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARMVIXL);
299};
300
301class ParallelMoveResolverARMVIXL : public ParallelMoveResolverWithSwap {
302 public:
303 ParallelMoveResolverARMVIXL(ArenaAllocator* allocator, CodeGeneratorARMVIXL* codegen)
304 : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {}
305
306 void EmitMove(size_t index) OVERRIDE;
307 void EmitSwap(size_t index) OVERRIDE;
308 void SpillScratch(int reg) OVERRIDE;
309 void RestoreScratch(int reg) OVERRIDE;
310
311 ArmVIXLAssembler* GetAssembler() const;
312
313 private:
Alexandre Rames9c19bd62016-10-24 11:50:32 +0100314 void Exchange(vixl32::Register reg, int mem);
Scott Wakelingfe885462016-09-22 10:24:38 +0100315 void Exchange(int mem1, int mem2);
316
317 CodeGeneratorARMVIXL* const codegen_;
318
319 DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverARMVIXL);
320};
321
322#define DEFINE_IMPLEMENTED_INSTRUCTION_VISITOR(Name) \
323 void Visit##Name(H##Name*) OVERRIDE;
324
325#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITOR(Name) \
326 void Visit##Name(H##Name* instr) OVERRIDE { \
327 VisitUnimplemementedInstruction(instr); }
328
329class LocationsBuilderARMVIXL : public HGraphVisitor {
330 public:
331 LocationsBuilderARMVIXL(HGraph* graph, CodeGeneratorARMVIXL* codegen)
332 : HGraphVisitor(graph), codegen_(codegen) {}
333
334 FOR_EACH_IMPLEMENTED_INSTRUCTION(DEFINE_IMPLEMENTED_INSTRUCTION_VISITOR)
335
336 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITOR)
337
338 private:
339 void VisitUnimplemementedInstruction(HInstruction* instruction) {
340 LOG(FATAL) << "Unimplemented Instruction: " << instruction->DebugName();
341 }
342
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100343 void HandleInvoke(HInvoke* invoke);
Artem Serov02109dd2016-09-23 17:17:54 +0100344 void HandleBitwiseOperation(HBinaryOperation* operation, Opcode opcode);
Scott Wakelingfe885462016-09-22 10:24:38 +0100345 void HandleCondition(HCondition* condition);
Artem Serov02109dd2016-09-23 17:17:54 +0100346 void HandleIntegerRotate(LocationSummary* locations);
347 void HandleLongRotate(LocationSummary* locations);
348 void HandleShift(HBinaryOperation* operation);
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100349 void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info);
350 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Scott Wakelingfe885462016-09-22 10:24:38 +0100351
Alexandre Rames9c19bd62016-10-24 11:50:32 +0100352 Location ArithmeticZeroOrFpuRegister(HInstruction* input);
Artem Serov02109dd2016-09-23 17:17:54 +0100353 Location ArmEncodableConstantOrRegister(HInstruction* constant, Opcode opcode);
354 bool CanEncodeConstantAsImmediate(HConstant* input_cst, Opcode opcode);
355 bool CanEncodeConstantAsImmediate(uint32_t value, Opcode opcode, SetCc set_cc = kCcDontCare);
Alexandre Rames9c19bd62016-10-24 11:50:32 +0100356
Scott Wakelingfe885462016-09-22 10:24:38 +0100357 CodeGeneratorARMVIXL* const codegen_;
358 InvokeDexCallingConventionVisitorARM parameter_visitor_;
359
360 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderARMVIXL);
361};
362
363class InstructionCodeGeneratorARMVIXL : public InstructionCodeGenerator {
364 public:
365 InstructionCodeGeneratorARMVIXL(HGraph* graph, CodeGeneratorARMVIXL* codegen);
366
367 FOR_EACH_IMPLEMENTED_INSTRUCTION(DEFINE_IMPLEMENTED_INSTRUCTION_VISITOR)
368
369 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITOR)
370
371 ArmVIXLAssembler* GetAssembler() const { return assembler_; }
xueliang.zhongf51bc622016-11-04 09:23:32 +0000372 ArmVIXLMacroAssembler* GetVIXLAssembler() { return GetAssembler()->GetVIXLAssembler(); }
Scott Wakelingfe885462016-09-22 10:24:38 +0100373
374 private:
375 void VisitUnimplemementedInstruction(HInstruction* instruction) {
376 LOG(FATAL) << "Unimplemented Instruction: " << instruction->DebugName();
377 }
378
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100379 // Generate code for the given suspend check. If not null, `successor`
380 // is the block to branch to if the suspend check is not needed, and after
381 // the suspend call.
Scott Wakelingfe885462016-09-22 10:24:38 +0100382 void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor);
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100383 void GenerateClassInitializationCheck(LoadClassSlowPathARMVIXL* slow_path,
384 vixl32::Register class_reg);
Scott Wakelingfe885462016-09-22 10:24:38 +0100385 void HandleGoto(HInstruction* got, HBasicBlock* successor);
Artem Serov02109dd2016-09-23 17:17:54 +0100386 void GenerateAndConst(vixl::aarch32::Register out, vixl::aarch32::Register first, uint32_t value);
387 void GenerateOrrConst(vixl::aarch32::Register out, vixl::aarch32::Register first, uint32_t value);
388 void GenerateEorConst(vixl::aarch32::Register out, vixl::aarch32::Register first, uint32_t value);
389 void HandleBitwiseOperation(HBinaryOperation* operation);
Scott Wakelingfe885462016-09-22 10:24:38 +0100390 void HandleCondition(HCondition* condition);
Artem Serov02109dd2016-09-23 17:17:54 +0100391 void HandleIntegerRotate(HRor* ror);
392 void HandleLongRotate(HRor* ror);
393 void HandleShift(HBinaryOperation* operation);
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100394
395 void GenerateWideAtomicStore(vixl::aarch32::Register addr,
396 uint32_t offset,
397 vixl::aarch32::Register value_lo,
398 vixl::aarch32::Register value_hi,
399 vixl::aarch32::Register temp1,
400 vixl::aarch32::Register temp2,
401 HInstruction* instruction);
402 void GenerateWideAtomicLoad(vixl::aarch32::Register addr,
403 uint32_t offset,
404 vixl::aarch32::Register out_lo,
405 vixl::aarch32::Register out_hi);
406
407 void HandleFieldSet(HInstruction* instruction,
408 const FieldInfo& field_info,
409 bool value_can_be_null);
410 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
411
Artem Serovcfbe9132016-10-14 15:58:56 +0100412 // Generate a heap reference load using one register `out`:
413 //
414 // out <- *(out + offset)
415 //
416 // while honoring heap poisoning and/or read barriers (if any).
417 //
418 // Location `maybe_temp` is used when generating a read barrier and
419 // shall be a register in that case; it may be an invalid location
420 // otherwise.
421 void GenerateReferenceLoadOneRegister(HInstruction* instruction,
422 Location out,
423 uint32_t offset,
424 Location maybe_temp);
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100425 // Generate a heap reference load using two different registers
426 // `out` and `obj`:
427 //
428 // out <- *(obj + offset)
429 //
430 // while honoring heap poisoning and/or read barriers (if any).
431 //
432 // Location `maybe_temp` is used when generating a Baker's (fast
433 // path) read barrier and shall be a register in that case; it may
434 // be an invalid location otherwise.
435 void GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
436 Location out,
437 Location obj,
438 uint32_t offset,
439 Location maybe_temp);
440
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100441 // Generate a GC root reference load:
442 //
443 // root <- *(obj + offset)
444 //
445 // while honoring read barriers if `requires_read_barrier` is true.
446 void GenerateGcRootFieldLoad(HInstruction* instruction,
447 Location root,
448 vixl::aarch32::Register obj,
449 uint32_t offset,
Roland Levillain00468f32016-10-27 18:02:48 +0100450 bool requires_read_barrier);
Scott Wakelingfe885462016-09-22 10:24:38 +0100451 void GenerateTestAndBranch(HInstruction* instruction,
452 size_t condition_input_index,
453 vixl::aarch32::Label* true_target,
xueliang.zhongf51bc622016-11-04 09:23:32 +0000454 vixl::aarch32::Label* false_target,
455 bool far_target = true);
Scott Wakelingfe885462016-09-22 10:24:38 +0100456 void GenerateCompareTestAndBranch(HCondition* condition,
457 vixl::aarch32::Label* true_target,
458 vixl::aarch32::Label* false_target);
459 void GenerateVcmp(HInstruction* instruction);
460 void GenerateFPJumps(HCondition* cond,
461 vixl::aarch32::Label* true_label,
462 vixl::aarch32::Label* false_label);
463 void GenerateLongComparesAndJumps(HCondition* cond,
464 vixl::aarch32::Label* true_label,
465 vixl::aarch32::Label* false_label);
466 void DivRemOneOrMinusOne(HBinaryOperation* instruction);
467 void DivRemByPowerOfTwo(HBinaryOperation* instruction);
468 void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction);
469 void GenerateDivRemConstantIntegral(HBinaryOperation* instruction);
470
471 ArmVIXLAssembler* const assembler_;
472 CodeGeneratorARMVIXL* const codegen_;
473
474 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorARMVIXL);
475};
476
477class CodeGeneratorARMVIXL : public CodeGenerator {
478 public:
479 CodeGeneratorARMVIXL(HGraph* graph,
480 const ArmInstructionSetFeatures& isa_features,
481 const CompilerOptions& compiler_options,
482 OptimizingCompilerStats* stats = nullptr);
483
484 virtual ~CodeGeneratorARMVIXL() {}
485
486 void Initialize() OVERRIDE {
487 block_labels_.resize(GetGraph()->GetBlocks().size());
488 }
489
490 void GenerateFrameEntry() OVERRIDE;
491 void GenerateFrameExit() OVERRIDE;
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100492
Scott Wakelingfe885462016-09-22 10:24:38 +0100493 void Bind(HBasicBlock* block) OVERRIDE;
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100494
495 vixl::aarch32::Label* GetLabelOf(HBasicBlock* block) {
496 block = FirstNonEmptyBlock(block);
497 return &(block_labels_[block->GetBlockId()]);
498 }
499
Scott Wakelingfe885462016-09-22 10:24:38 +0100500 void MoveConstant(Location destination, int32_t value) OVERRIDE;
501 void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE;
502 void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE;
503
504 ArmVIXLAssembler* GetAssembler() OVERRIDE { return &assembler_; }
505
506 const ArmVIXLAssembler& GetAssembler() const OVERRIDE { return assembler_; }
507
xueliang.zhongf51bc622016-11-04 09:23:32 +0000508 ArmVIXLMacroAssembler* GetVIXLAssembler() { return GetAssembler()->GetVIXLAssembler(); }
Scott Wakelingfe885462016-09-22 10:24:38 +0100509
510 size_t GetWordSize() const OVERRIDE { return kArmWordSize; }
511
512 size_t GetFloatingPointSpillSlotSize() const OVERRIDE { return vixl::aarch32::kRegSizeInBytes; }
513
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100514 uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE {
515 vixl::aarch32::Label* block_entry_label = GetLabelOf(block);
516 DCHECK(block_entry_label->IsBound());
517 return block_entry_label->GetLocation();
518 }
519
Artem Serov551b28f2016-10-18 19:11:30 +0100520 JumpTableARMVIXL* CreateJumpTable(HPackedSwitch* switch_instr) {
521 jump_tables_.emplace_back(new (GetGraph()->GetArena()) JumpTableARMVIXL(switch_instr));
522 return jump_tables_.back().get();
523 }
524
Scott Wakelingfe885462016-09-22 10:24:38 +0100525 HGraphVisitor* GetLocationBuilder() OVERRIDE { return &location_builder_; }
526
527 HGraphVisitor* GetInstructionVisitor() OVERRIDE { return &instruction_visitor_; }
528
Artem Serov09a940d2016-11-11 16:15:11 +0000529 void FixJumpTables();
Scott Wakelingfe885462016-09-22 10:24:38 +0100530 void GenerateMemoryBarrier(MemBarrierKind kind);
531 void Finalize(CodeAllocator* allocator) OVERRIDE;
532 void SetupBlockedRegisters() const OVERRIDE;
533
Scott Wakelingfe885462016-09-22 10:24:38 +0100534 void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE;
535 void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE;
536
537 InstructionSet GetInstructionSet() const OVERRIDE { return InstructionSet::kThumb2; }
538
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100539 // Helper method to move a 32-bit value between two locations.
540 void Move32(Location destination, Location source);
541
Scott Wakelingc34dba72016-10-03 10:14:44 +0100542 void LoadFromShiftedRegOffset(Primitive::Type type,
543 Location out_loc,
544 vixl::aarch32::Register base,
545 vixl::aarch32::Register reg_index,
546 vixl::aarch32::Condition cond = vixl::aarch32::al);
547 void StoreToShiftedRegOffset(Primitive::Type type,
548 Location out_loc,
549 vixl::aarch32::Register base,
550 vixl::aarch32::Register reg_index,
551 vixl::aarch32::Condition cond = vixl::aarch32::al);
552
Scott Wakelingfe885462016-09-22 10:24:38 +0100553 const ArmInstructionSetFeatures& GetInstructionSetFeatures() const { return isa_features_; }
554
555 vixl::aarch32::Label* GetFrameEntryLabel() { return &frame_entry_label_; }
556
557 // Saves the register in the stack. Returns the size taken on stack.
558 size_t SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED,
559 uint32_t reg_id ATTRIBUTE_UNUSED) OVERRIDE {
560 UNIMPLEMENTED(INFO) << "TODO: SaveCoreRegister";
561 return 0;
562 }
563
564 // Restores the register from the stack. Returns the size taken on stack.
565 size_t RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED,
566 uint32_t reg_id ATTRIBUTE_UNUSED) OVERRIDE {
567 UNIMPLEMENTED(INFO) << "TODO: RestoreCoreRegister";
568 return 0;
569 }
570
571 size_t SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED,
572 uint32_t reg_id ATTRIBUTE_UNUSED) OVERRIDE {
573 UNIMPLEMENTED(INFO) << "TODO: SaveFloatingPointRegister";
574 return 0;
575 }
576
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100577 size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
Scott Wakelingfe885462016-09-22 10:24:38 +0100578
579 bool NeedsTwoRegisters(Primitive::Type type) const OVERRIDE {
580 return type == Primitive::kPrimDouble || type == Primitive::kPrimLong;
581 }
582
583 void ComputeSpillMask() OVERRIDE;
584
585 void GenerateImplicitNullCheck(HNullCheck* null_check) OVERRIDE;
586 void GenerateExplicitNullCheck(HNullCheck* null_check) OVERRIDE;
587
588 ParallelMoveResolver* GetMoveResolver() OVERRIDE {
589 return &move_resolver_;
590 }
591
592 // Generate code to invoke a runtime entry point.
593 void InvokeRuntime(QuickEntrypointEnum entrypoint,
594 HInstruction* instruction,
595 uint32_t dex_pc,
596 SlowPathCode* slow_path = nullptr) OVERRIDE;
597
598 // Generate code to invoke a runtime entry point, but do not record
599 // PC-related information in a stack map.
600 void InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
601 HInstruction* instruction,
602 SlowPathCode* slow_path);
603
604 void GenerateInvokeRuntime(int32_t entry_point_offset);
605
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100606 // Emit a write barrier.
607 void MarkGCCard(vixl::aarch32::Register temp,
608 vixl::aarch32::Register card,
609 vixl::aarch32::Register object,
610 vixl::aarch32::Register value,
611 bool can_be_null);
612
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100613 // Fast path implementation of ReadBarrier::Barrier for a heap
614 // reference field load when Baker's read barriers are used.
615 void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
616 Location ref,
617 vixl::aarch32::Register obj,
618 uint32_t offset,
619 Location temp,
620 bool needs_null_check);
621
622 // Factored implementation, used by GenerateFieldLoadWithBakerReadBarrier,
623 // GenerateArrayLoadWithBakerReadBarrier and some intrinsics.
624 //
625 // Load the object reference located at the address
626 // `obj + offset + (index << scale_factor)`, held by object `obj`, into
627 // `ref`, and mark it if needed.
628 //
629 // If `always_update_field` is true, the value of the reference is
630 // atomically updated in the holder (`obj`). This operation
631 // requires an extra temporary register, which must be provided as a
632 // non-null pointer (`temp2`).
633 void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
634 Location ref,
635 vixl::aarch32::Register obj,
636 uint32_t offset,
637 Location index,
638 ScaleFactor scale_factor,
639 Location temp,
640 bool needs_null_check,
641 bool always_update_field = false,
642 vixl::aarch32::Register* temp2 = nullptr);
643
644 // Generate a read barrier for a heap reference within `instruction`
645 // using a slow path.
646 //
647 // A read barrier for an object reference read from the heap is
648 // implemented as a call to the artReadBarrierSlow runtime entry
649 // point, which is passed the values in locations `ref`, `obj`, and
650 // `offset`:
651 //
652 // mirror::Object* artReadBarrierSlow(mirror::Object* ref,
653 // mirror::Object* obj,
654 // uint32_t offset);
655 //
656 // The `out` location contains the value returned by
657 // artReadBarrierSlow.
658 //
659 // When `index` is provided (i.e. for array accesses), the offset
660 // value passed to artReadBarrierSlow is adjusted to take `index`
661 // into account.
662 void GenerateReadBarrierSlow(HInstruction* instruction,
663 Location out,
664 Location ref,
665 Location obj,
666 uint32_t offset,
667 Location index = Location::NoLocation());
668
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100669 // If read barriers are enabled, generate a read barrier for a heap
670 // reference using a slow path. If heap poisoning is enabled, also
671 // unpoison the reference in `out`.
672 void MaybeGenerateReadBarrierSlow(HInstruction* instruction,
673 Location out,
674 Location ref,
675 Location obj,
676 uint32_t offset,
677 Location index = Location::NoLocation());
678
Scott Wakelingfe885462016-09-22 10:24:38 +0100679 // Check if the desired_string_load_kind is supported. If it is, return it,
680 // otherwise return a fall-back kind that should be used instead.
681 HLoadString::LoadKind GetSupportedLoadStringKind(
682 HLoadString::LoadKind desired_string_load_kind) OVERRIDE;
683
684 // Check if the desired_class_load_kind is supported. If it is, return it,
685 // otherwise return a fall-back kind that should be used instead.
686 HLoadClass::LoadKind GetSupportedLoadClassKind(
687 HLoadClass::LoadKind desired_class_load_kind) OVERRIDE;
688
689 // Check if the desired_dispatch_info is supported. If it is, return it,
690 // otherwise return a fall-back info that should be used instead.
691 HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch(
692 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100693 HInvokeStaticOrDirect* invoke) OVERRIDE;
Scott Wakelingfe885462016-09-22 10:24:38 +0100694
695 void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) OVERRIDE;
696 void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE;
697
698 void MoveFromReturnRegister(Location trg, Primitive::Type type) OVERRIDE;
699
700 void GenerateNop() OVERRIDE;
701
Scott Wakelingfe885462016-09-22 10:24:38 +0100702 private:
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100703 vixl::aarch32::Register GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
704 vixl::aarch32::Register temp);
705
Scott Wakelingfe885462016-09-22 10:24:38 +0100706 // Labels for each block that will be compiled.
707 // We use a deque so that the `vixl::aarch32::Label` objects do not move in memory.
708 ArenaDeque<vixl::aarch32::Label> block_labels_; // Indexed by block id.
709 vixl::aarch32::Label frame_entry_label_;
710
Artem Serov551b28f2016-10-18 19:11:30 +0100711 ArenaVector<std::unique_ptr<JumpTableARMVIXL>> jump_tables_;
Scott Wakelingfe885462016-09-22 10:24:38 +0100712 LocationsBuilderARMVIXL location_builder_;
713 InstructionCodeGeneratorARMVIXL instruction_visitor_;
714 ParallelMoveResolverARMVIXL move_resolver_;
715
716 ArmVIXLAssembler assembler_;
717 const ArmInstructionSetFeatures& isa_features_;
718
719 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorARMVIXL);
720};
721
722#undef FOR_EACH_IMPLEMENTED_INSTRUCTION
723#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
724#undef DEFINE_IMPLEMENTED_INSTRUCTION_VISITOR
725#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITOR
726
727
728} // namespace arm
729} // namespace art
730
731#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM_VIXL_H_