blob: 87d5a9c15a9a1abb68bcf55a23db79afc7723494 [file] [log] [blame]
Alexey Frunze4dda3372015-06-01 18:31:49 -07001/*
2 * Copyright (C) 2015 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_MIPS64_H_
18#define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS64_H_
19
20#include "code_generator.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070021#include "driver/compiler_options.h"
22#include "nodes.h"
23#include "parallel_move_resolver.h"
Mathieu Chartierdbddc222017-05-24 12:04:13 -070024#include "type_reference.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070025#include "utils/mips64/assembler_mips64.h"
26
27namespace art {
28namespace mips64 {
29
Alexey Frunze4dda3372015-06-01 18:31:49 -070030// InvokeDexCallingConvention registers
31
32static constexpr GpuRegister kParameterCoreRegisters[] =
33 { A1, A2, A3, A4, A5, A6, A7 };
34static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters);
35
36static constexpr FpuRegister kParameterFpuRegisters[] =
37 { F13, F14, F15, F16, F17, F18, F19 };
38static constexpr size_t kParameterFpuRegistersLength = arraysize(kParameterFpuRegisters);
39
40
41// InvokeRuntimeCallingConvention registers
42
43static constexpr GpuRegister kRuntimeParameterCoreRegisters[] =
44 { A0, A1, A2, A3, A4, A5, A6, A7 };
45static constexpr size_t kRuntimeParameterCoreRegistersLength =
46 arraysize(kRuntimeParameterCoreRegisters);
47
48static constexpr FpuRegister kRuntimeParameterFpuRegisters[] =
49 { F12, F13, F14, F15, F16, F17, F18, F19 };
50static constexpr size_t kRuntimeParameterFpuRegistersLength =
51 arraysize(kRuntimeParameterFpuRegisters);
52
53
54static constexpr GpuRegister kCoreCalleeSaves[] =
Alexey Frunze627c1a02017-01-30 19:28:14 -080055 { S0, S1, S2, S3, S4, S5, S6, S7, GP, S8, RA };
Alexey Frunze4dda3372015-06-01 18:31:49 -070056static constexpr FpuRegister kFpuCalleeSaves[] =
57 { F24, F25, F26, F27, F28, F29, F30, F31 };
58
59
60class CodeGeneratorMIPS64;
61
Lena Djokicca8c2952017-05-29 11:31:46 +020062VectorRegister VectorRegisterFrom(Location location);
63
Alexey Frunze4dda3372015-06-01 18:31:49 -070064class InvokeDexCallingConvention : public CallingConvention<GpuRegister, FpuRegister> {
65 public:
66 InvokeDexCallingConvention()
67 : CallingConvention(kParameterCoreRegisters,
68 kParameterCoreRegistersLength,
69 kParameterFpuRegisters,
70 kParameterFpuRegistersLength,
71 kMips64PointerSize) {}
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention);
75};
76
77class InvokeDexCallingConventionVisitorMIPS64 : public InvokeDexCallingConventionVisitor {
78 public:
79 InvokeDexCallingConventionVisitorMIPS64() {}
80 virtual ~InvokeDexCallingConventionVisitorMIPS64() {}
81
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010082 Location GetNextLocation(DataType::Type type) OVERRIDE;
83 Location GetReturnLocation(DataType::Type type) const OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -070084 Location GetMethodLocation() const OVERRIDE;
85
86 private:
87 InvokeDexCallingConvention calling_convention;
88
89 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorMIPS64);
90};
91
92class InvokeRuntimeCallingConvention : public CallingConvention<GpuRegister, FpuRegister> {
93 public:
94 InvokeRuntimeCallingConvention()
95 : CallingConvention(kRuntimeParameterCoreRegisters,
96 kRuntimeParameterCoreRegistersLength,
97 kRuntimeParameterFpuRegisters,
98 kRuntimeParameterFpuRegistersLength,
99 kMips64PointerSize) {}
100
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100101 Location GetReturnLocation(DataType::Type return_type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700102
103 private:
104 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
105};
106
Calin Juravlee460d1d2015-09-29 04:52:17 +0100107class FieldAccessCallingConventionMIPS64 : public FieldAccessCallingConvention {
108 public:
109 FieldAccessCallingConventionMIPS64() {}
110
111 Location GetObjectLocation() const OVERRIDE {
112 return Location::RegisterLocation(A1);
113 }
114 Location GetFieldIndexLocation() const OVERRIDE {
115 return Location::RegisterLocation(A0);
116 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100117 Location GetReturnLocation(DataType::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
Goran Jakovljevic8c34ec12015-10-14 11:23:48 +0200118 return Location::RegisterLocation(V0);
Calin Juravlee460d1d2015-09-29 04:52:17 +0100119 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100120 Location GetSetValueLocation(DataType::Type type ATTRIBUTE_UNUSED,
Alexey Frunze0cb12422017-01-25 19:30:18 -0800121 bool is_instance) const OVERRIDE {
122 return is_instance
Alexey Frunze00580bd2015-11-11 13:31:12 -0800123 ? Location::RegisterLocation(A2)
Alexey Frunze0cb12422017-01-25 19:30:18 -0800124 : Location::RegisterLocation(A1);
Calin Juravlee460d1d2015-09-29 04:52:17 +0100125 }
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100126 Location GetFpuLocation(DataType::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100127 return Location::FpuRegisterLocation(F0);
128 }
129
130 private:
131 DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionMIPS64);
132};
133
Alexey Frunze4dda3372015-06-01 18:31:49 -0700134class ParallelMoveResolverMIPS64 : public ParallelMoveResolverWithSwap {
135 public:
136 ParallelMoveResolverMIPS64(ArenaAllocator* allocator, CodeGeneratorMIPS64* codegen)
137 : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {}
138
139 void EmitMove(size_t index) OVERRIDE;
140 void EmitSwap(size_t index) OVERRIDE;
141 void SpillScratch(int reg) OVERRIDE;
142 void RestoreScratch(int reg) OVERRIDE;
143
144 void Exchange(int index1, int index2, bool double_slot);
Goran Jakovljevice7de5ec2017-12-14 10:25:20 +0100145 void ExchangeQuadSlots(int index1, int index2);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700146
147 Mips64Assembler* GetAssembler() const;
148
149 private:
150 CodeGeneratorMIPS64* const codegen_;
151
152 DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverMIPS64);
153};
154
155class SlowPathCodeMIPS64 : public SlowPathCode {
156 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000157 explicit SlowPathCodeMIPS64(HInstruction* instruction)
158 : SlowPathCode(instruction), entry_label_(), exit_label_() {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700159
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700160 Mips64Label* GetEntryLabel() { return &entry_label_; }
161 Mips64Label* GetExitLabel() { return &exit_label_; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700162
163 private:
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700164 Mips64Label entry_label_;
165 Mips64Label exit_label_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700166
167 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeMIPS64);
168};
169
170class LocationsBuilderMIPS64 : public HGraphVisitor {
171 public:
172 LocationsBuilderMIPS64(HGraph* graph, CodeGeneratorMIPS64* codegen)
173 : HGraphVisitor(graph), codegen_(codegen) {}
174
175#define DECLARE_VISIT_INSTRUCTION(name, super) \
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100176 void Visit##name(H##name* instr) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700177
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100178 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
179 FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(DECLARE_VISIT_INSTRUCTION)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700180
181#undef DECLARE_VISIT_INSTRUCTION
182
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100183 void VisitInstruction(HInstruction* instruction) OVERRIDE {
184 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
185 << " (id " << instruction->GetId() << ")";
186 }
187
Alexey Frunze4dda3372015-06-01 18:31:49 -0700188 private:
189 void HandleInvoke(HInvoke* invoke);
190 void HandleBinaryOp(HBinaryOperation* operation);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000191 void HandleCondition(HCondition* instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700192 void HandleShift(HBinaryOperation* operation);
193 void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info);
194 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Tijana Jakovljevicba89c342017-03-10 13:36:08 +0100195 Location RegisterOrZeroConstant(HInstruction* instruction);
196 Location FpuRegisterOrConstantForStore(HInstruction* instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700197
198 InvokeDexCallingConventionVisitorMIPS64 parameter_visitor_;
199
200 CodeGeneratorMIPS64* const codegen_;
201
202 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderMIPS64);
203};
204
Aart Bik42249c32016-01-07 15:33:50 -0800205class InstructionCodeGeneratorMIPS64 : public InstructionCodeGenerator {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700206 public:
207 InstructionCodeGeneratorMIPS64(HGraph* graph, CodeGeneratorMIPS64* codegen);
208
209#define DECLARE_VISIT_INSTRUCTION(name, super) \
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100210 void Visit##name(H##name* instr) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700211
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100212 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
213 FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(DECLARE_VISIT_INSTRUCTION)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700214
215#undef DECLARE_VISIT_INSTRUCTION
216
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100217 void VisitInstruction(HInstruction* instruction) OVERRIDE {
218 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
219 << " (id " << instruction->GetId() << ")";
220 }
221
Alexey Frunze4dda3372015-06-01 18:31:49 -0700222 Mips64Assembler* GetAssembler() const { return assembler_; }
223
Alexey Frunze0960ac52016-12-20 17:24:59 -0800224 // Compare-and-jump packed switch generates approx. 3 + 2.5 * N 32-bit
225 // instructions for N cases.
226 // Table-based packed switch generates approx. 11 32-bit instructions
227 // and N 32-bit data words for N cases.
228 // At N = 6 they come out as 18 and 17 32-bit words respectively.
229 // We switch to the table-based method starting with 7 cases.
230 static constexpr uint32_t kPackedSwitchJumpTableThreshold = 6;
231
Chris Larsen5633ce72017-04-10 15:47:40 -0700232 void GenerateMemoryBarrier(MemBarrierKind kind);
233
Alexey Frunze4dda3372015-06-01 18:31:49 -0700234 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700235 void GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, GpuRegister class_reg);
Vladimir Markoeb0ebed2018-01-10 18:26:38 +0000236 void GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, GpuRegister temp);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700237 void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor);
238 void HandleBinaryOp(HBinaryOperation* operation);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000239 void HandleCondition(HCondition* instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700240 void HandleShift(HBinaryOperation* operation);
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100241 void HandleFieldSet(HInstruction* instruction,
242 const FieldInfo& field_info,
243 bool value_can_be_null);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700244 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Alexey Frunze15958152017-02-09 19:08:30 -0800245
246 // Generate a heap reference load using one register `out`:
247 //
248 // out <- *(out + offset)
249 //
250 // while honoring heap poisoning and/or read barriers (if any).
251 //
252 // Location `maybe_temp` is used when generating a read barrier and
253 // shall be a register in that case; it may be an invalid location
254 // otherwise.
255 void GenerateReferenceLoadOneRegister(HInstruction* instruction,
256 Location out,
257 uint32_t offset,
258 Location maybe_temp,
259 ReadBarrierOption read_barrier_option);
260 // Generate a heap reference load using two different registers
261 // `out` and `obj`:
262 //
263 // out <- *(obj + offset)
264 //
265 // while honoring heap poisoning and/or read barriers (if any).
266 //
267 // Location `maybe_temp` is used when generating a Baker's (fast
268 // path) read barrier and shall be a register in that case; it may
269 // be an invalid location otherwise.
270 void GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
271 Location out,
272 Location obj,
273 uint32_t offset,
274 Location maybe_temp,
275 ReadBarrierOption read_barrier_option);
276
Alexey Frunzef63f5692016-12-13 17:43:11 -0800277 // Generate a GC root reference load:
278 //
279 // root <- *(obj + offset)
280 //
281 // while honoring read barriers (if any).
282 void GenerateGcRootFieldLoad(HInstruction* instruction,
283 Location root,
284 GpuRegister obj,
Alexey Frunze15958152017-02-09 19:08:30 -0800285 uint32_t offset,
Alexey Frunze4147fcc2017-06-17 19:57:27 -0700286 ReadBarrierOption read_barrier_option,
287 Mips64Label* label_low = nullptr);
Alexey Frunze15958152017-02-09 19:08:30 -0800288
Alexey Frunze4dda3372015-06-01 18:31:49 -0700289 void GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +0000290 size_t condition_input_index,
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700291 Mips64Label* true_target,
292 Mips64Label* false_target);
Alexey Frunzec857c742015-09-23 15:12:39 -0700293 void DivRemOneOrMinusOne(HBinaryOperation* instruction);
294 void DivRemByPowerOfTwo(HBinaryOperation* instruction);
295 void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction);
296 void GenerateDivRemIntegral(HBinaryOperation* instruction);
Alexey Frunze299a9392015-12-08 16:08:02 -0800297 void GenerateIntLongCompare(IfCondition cond, bool is64bit, LocationSummary* locations);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +0200298 // When the function returns `false` it means that the condition holds if `dst` is non-zero
299 // and doesn't hold if `dst` is zero. If it returns `true`, the roles of zero and non-zero
300 // `dst` are exchanged.
301 bool MaterializeIntLongCompare(IfCondition cond,
302 bool is64bit,
303 LocationSummary* input_locations,
304 GpuRegister dst);
Alexey Frunze299a9392015-12-08 16:08:02 -0800305 void GenerateIntLongCompareAndBranch(IfCondition cond,
306 bool is64bit,
307 LocationSummary* locations,
308 Mips64Label* label);
Tijana Jakovljevic43758192016-12-30 09:23:01 +0100309 void GenerateFpCompare(IfCondition cond,
310 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100311 DataType::Type type,
Tijana Jakovljevic43758192016-12-30 09:23:01 +0100312 LocationSummary* locations);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +0200313 // When the function returns `false` it means that the condition holds if `dst` is non-zero
314 // and doesn't hold if `dst` is zero. If it returns `true`, the roles of zero and non-zero
315 // `dst` are exchanged.
316 bool MaterializeFpCompare(IfCondition cond,
317 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100318 DataType::Type type,
Goran Jakovljevic2dec9272017-08-02 11:41:26 +0200319 LocationSummary* input_locations,
320 FpuRegister dst);
Alexey Frunze299a9392015-12-08 16:08:02 -0800321 void GenerateFpCompareAndBranch(IfCondition cond,
322 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100323 DataType::Type type,
Alexey Frunze299a9392015-12-08 16:08:02 -0800324 LocationSummary* locations,
325 Mips64Label* label);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000326 void HandleGoto(HInstruction* got, HBasicBlock* successor);
Alexey Frunze0960ac52016-12-20 17:24:59 -0800327 void GenPackedSwitchWithCompares(GpuRegister value_reg,
328 int32_t lower_bound,
329 uint32_t num_entries,
330 HBasicBlock* switch_block,
331 HBasicBlock* default_block);
332 void GenTableBasedPackedSwitch(GpuRegister value_reg,
333 int32_t lower_bound,
334 uint32_t num_entries,
335 HBasicBlock* switch_block,
336 HBasicBlock* default_block);
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200337 int32_t VecAddress(LocationSummary* locations,
338 size_t size,
339 /* out */ GpuRegister* adjusted_base);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +0200340 void GenConditionalMove(HSelect* select);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700341
342 Mips64Assembler* const assembler_;
343 CodeGeneratorMIPS64* const codegen_;
344
345 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorMIPS64);
346};
347
348class CodeGeneratorMIPS64 : public CodeGenerator {
349 public:
350 CodeGeneratorMIPS64(HGraph* graph,
351 const Mips64InstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100352 const CompilerOptions& compiler_options,
353 OptimizingCompilerStats* stats = nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700354 virtual ~CodeGeneratorMIPS64() {}
355
356 void GenerateFrameEntry() OVERRIDE;
357 void GenerateFrameExit() OVERRIDE;
358
359 void Bind(HBasicBlock* block) OVERRIDE;
360
Lazar Trsicd9672662015-09-03 17:33:01 +0200361 size_t GetWordSize() const OVERRIDE { return kMips64DoublewordSize; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700362
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200363 size_t GetFloatingPointSpillSlotSize() const OVERRIDE {
364 return GetGraph()->HasSIMD()
365 ? 2 * kMips64DoublewordSize // 16 bytes for each spill.
366 : 1 * kMips64DoublewordSize; // 8 bytes for each spill.
367 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700368
Alexandre Ramesc01a6642016-04-15 11:54:06 +0100369 uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700370 return assembler_.GetLabelLocation(GetLabelOf(block));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700371 }
372
373 HGraphVisitor* GetLocationBuilder() OVERRIDE { return &location_builder_; }
374 HGraphVisitor* GetInstructionVisitor() OVERRIDE { return &instruction_visitor_; }
375 Mips64Assembler* GetAssembler() OVERRIDE { return &assembler_; }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100376 const Mips64Assembler& GetAssembler() const OVERRIDE { return assembler_; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700377
Alexey Frunze19f6c692016-11-30 19:19:55 -0800378 // Emit linker patches.
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100379 void EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) OVERRIDE;
Alexey Frunze627c1a02017-01-30 19:28:14 -0800380 void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) OVERRIDE;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800381
Alexey Frunze15958152017-02-09 19:08:30 -0800382 // Fast path implementation of ReadBarrier::Barrier for a heap
383 // reference field load when Baker's read barriers are used.
384 void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
385 Location ref,
386 GpuRegister obj,
387 uint32_t offset,
388 Location temp,
389 bool needs_null_check);
390 // Fast path implementation of ReadBarrier::Barrier for a heap
391 // reference array load when Baker's read barriers are used.
392 void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
393 Location ref,
394 GpuRegister obj,
395 uint32_t data_offset,
396 Location index,
397 Location temp,
398 bool needs_null_check);
399
400 // Factored implementation, used by GenerateFieldLoadWithBakerReadBarrier,
401 // GenerateArrayLoadWithBakerReadBarrier and some intrinsics.
402 //
403 // Load the object reference located at the address
404 // `obj + offset + (index << scale_factor)`, held by object `obj`, into
405 // `ref`, and mark it if needed.
406 //
407 // If `always_update_field` is true, the value of the reference is
408 // atomically updated in the holder (`obj`).
409 void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
410 Location ref,
411 GpuRegister obj,
412 uint32_t offset,
413 Location index,
414 ScaleFactor scale_factor,
415 Location temp,
416 bool needs_null_check,
417 bool always_update_field = false);
418
419 // Generate a read barrier for a heap reference within `instruction`
420 // using a slow path.
421 //
422 // A read barrier for an object reference read from the heap is
423 // implemented as a call to the artReadBarrierSlow runtime entry
424 // point, which is passed the values in locations `ref`, `obj`, and
425 // `offset`:
426 //
427 // mirror::Object* artReadBarrierSlow(mirror::Object* ref,
428 // mirror::Object* obj,
429 // uint32_t offset);
430 //
431 // The `out` location contains the value returned by
432 // artReadBarrierSlow.
433 //
434 // When `index` is provided (i.e. for array accesses), the offset
435 // value passed to artReadBarrierSlow is adjusted to take `index`
436 // into account.
437 void GenerateReadBarrierSlow(HInstruction* instruction,
438 Location out,
439 Location ref,
440 Location obj,
441 uint32_t offset,
442 Location index = Location::NoLocation());
443
444 // If read barriers are enabled, generate a read barrier for a heap
445 // reference using a slow path. If heap poisoning is enabled, also
446 // unpoison the reference in `out`.
447 void MaybeGenerateReadBarrierSlow(HInstruction* instruction,
448 Location out,
449 Location ref,
450 Location obj,
451 uint32_t offset,
452 Location index = Location::NoLocation());
453
454 // Generate a read barrier for a GC root within `instruction` using
455 // a slow path.
456 //
457 // A read barrier for an object reference GC root is implemented as
458 // a call to the artReadBarrierForRootSlow runtime entry point,
459 // which is passed the value in location `root`:
460 //
461 // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root);
462 //
463 // The `out` location contains the value returned by
464 // artReadBarrierForRootSlow.
465 void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root);
466
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100467 void MarkGCCard(GpuRegister object, GpuRegister value, bool value_can_be_null);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700468
469 // Register allocation.
470
David Brazdil58282f42016-01-14 12:45:10 +0000471 void SetupBlockedRegisters() const OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700472
Roland Levillainf41f9562016-09-14 19:26:48 +0100473 size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
474 size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
475 size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
476 size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700477
478 void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE;
479 void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE;
480
481 InstructionSet GetInstructionSet() const OVERRIDE { return InstructionSet::kMips64; }
482
483 const Mips64InstructionSetFeatures& GetInstructionSetFeatures() const {
484 return isa_features_;
485 }
486
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700487 Mips64Label* GetLabelOf(HBasicBlock* block) const {
488 return CommonGetLabelOf<Mips64Label>(block_labels_, block);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700489 }
490
491 void Initialize() OVERRIDE {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700492 block_labels_ = CommonInitializeLabels<Mips64Label>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700493 }
494
Alexey Frunzec3789802016-12-22 13:54:23 -0800495 // We prefer aligned loads and stores (less code), so spill and restore registers in slow paths
496 // at aligned locations.
497 uint32_t GetPreferredSlotsAlignment() const OVERRIDE { return kMips64DoublewordSize; }
498
Alexey Frunze4dda3372015-06-01 18:31:49 -0700499 void Finalize(CodeAllocator* allocator) OVERRIDE;
500
501 // Code generation helpers.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100502 void MoveLocation(Location dst, Location src, DataType::Type dst_type) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700503
Calin Juravle175dc732015-08-25 15:42:32 +0100504 void MoveConstant(Location destination, int32_t value) OVERRIDE;
505
Calin Juravlee460d1d2015-09-29 04:52:17 +0100506 void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE;
507
508
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100509 void SwapLocations(Location loc1, Location loc2, DataType::Type type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700510
511 // Generate code to invoke a runtime entry point.
Calin Juravle175dc732015-08-25 15:42:32 +0100512 void InvokeRuntime(QuickEntrypointEnum entrypoint,
513 HInstruction* instruction,
514 uint32_t dex_pc,
Serban Constantinescufc734082016-07-19 17:18:07 +0100515 SlowPathCode* slow_path = nullptr) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700516
Alexey Frunze15958152017-02-09 19:08:30 -0800517 // Generate code to invoke a runtime entry point, but do not record
518 // PC-related information in a stack map.
519 void InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
520 HInstruction* instruction,
521 SlowPathCode* slow_path);
522
523 void GenerateInvokeRuntime(int32_t entry_point_offset);
524
Alexey Frunze4dda3372015-06-01 18:31:49 -0700525 ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; }
526
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100527 bool NeedsTwoRegisters(DataType::Type type ATTRIBUTE_UNUSED) const OVERRIDE { return false; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700528
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000529 // Check if the desired_string_load_kind is supported. If it is, return it,
530 // otherwise return a fall-back kind that should be used instead.
531 HLoadString::LoadKind GetSupportedLoadStringKind(
532 HLoadString::LoadKind desired_string_load_kind) OVERRIDE;
533
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100534 // Check if the desired_class_load_kind is supported. If it is, return it,
535 // otherwise return a fall-back kind that should be used instead.
536 HLoadClass::LoadKind GetSupportedLoadClassKind(
537 HLoadClass::LoadKind desired_class_load_kind) OVERRIDE;
538
Vladimir Markodc151b22015-10-15 18:02:30 +0100539 // Check if the desired_dispatch_info is supported. If it is, return it,
540 // otherwise return a fall-back info that should be used instead.
541 HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch(
542 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100543 HInvokeStaticOrDirect* invoke) OVERRIDE;
Vladimir Markodc151b22015-10-15 18:02:30 +0100544
Vladimir Markoe7197bf2017-06-02 17:00:23 +0100545 void GenerateStaticOrDirectCall(
546 HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path = nullptr) OVERRIDE;
547 void GenerateVirtualCall(
548 HInvokeVirtual* invoke, Location temp, SlowPathCode* slow_path = nullptr) OVERRIDE;
Andreas Gampe85b62f22015-09-09 13:15:38 -0700549
550 void MoveFromReturnRegister(Location trg ATTRIBUTE_UNUSED,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100551 DataType::Type type ATTRIBUTE_UNUSED) OVERRIDE {
Chris Larsen3acee732015-11-18 13:31:08 -0800552 UNIMPLEMENTED(FATAL) << "Not implemented on MIPS64";
Andreas Gampe85b62f22015-09-09 13:15:38 -0700553 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700554
Roland Levillainf41f9562016-09-14 19:26:48 +0100555 void GenerateNop() OVERRIDE;
556 void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
557 void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
David Srbeckyc7098ff2016-02-09 14:30:11 +0000558
Alexey Frunze19f6c692016-11-30 19:19:55 -0800559 // The PcRelativePatchInfo is used for PC-relative addressing of dex cache arrays,
560 // boot image strings and method calls. The only difference is the interpretation of
561 // the offset_or_index.
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700562 // The 16-bit halves of the 32-bit PC-relative offset are patched separately, necessitating
563 // two patches/infos. There can be more than two patches/infos if the instruction supplying
564 // the high half is shared with e.g. a slow path, while the low half is supplied by separate
565 // instructions, e.g.:
566 // auipc r1, high // patch
567 // lwu r2, low(r1) // patch
568 // beqzc r2, slow_path
569 // back:
570 // ...
571 // slow_path:
572 // ...
573 // sw r2, low(r1) // patch
574 // bc back
Alexey Frunze19f6c692016-11-30 19:19:55 -0800575 struct PcRelativePatchInfo {
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700576 PcRelativePatchInfo(const DexFile& dex_file,
577 uint32_t off_or_idx,
578 const PcRelativePatchInfo* info_high)
579 : target_dex_file(dex_file),
580 offset_or_index(off_or_idx),
581 label(),
582 patch_info_high(info_high) { }
Alexey Frunze19f6c692016-11-30 19:19:55 -0800583
584 const DexFile& target_dex_file;
585 // Either the dex cache array element offset or the string/type/method index.
586 uint32_t offset_or_index;
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700587 // Label for the instruction to patch.
588 Mips64Label label;
589 // Pointer to the info for the high half patch or nullptr if this is the high half patch info.
590 const PcRelativePatchInfo* patch_info_high;
591
592 private:
593 PcRelativePatchInfo(PcRelativePatchInfo&& other) = delete;
594 DISALLOW_COPY_AND_ASSIGN(PcRelativePatchInfo);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800595 };
596
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700597 PcRelativePatchInfo* NewPcRelativeMethodPatch(MethodReference target_method,
598 const PcRelativePatchInfo* info_high = nullptr);
599 PcRelativePatchInfo* NewMethodBssEntryPatch(MethodReference target_method,
600 const PcRelativePatchInfo* info_high = nullptr);
601 PcRelativePatchInfo* NewPcRelativeTypePatch(const DexFile& dex_file,
602 dex::TypeIndex type_index,
603 const PcRelativePatchInfo* info_high = nullptr);
604 PcRelativePatchInfo* NewTypeBssEntryPatch(const DexFile& dex_file,
605 dex::TypeIndex type_index,
606 const PcRelativePatchInfo* info_high = nullptr);
Vladimir Marko65979462017-05-19 17:25:12 +0100607 PcRelativePatchInfo* NewPcRelativeStringPatch(const DexFile& dex_file,
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700608 dex::StringIndex string_index,
609 const PcRelativePatchInfo* info_high = nullptr);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100610 PcRelativePatchInfo* NewStringBssEntryPatch(const DexFile& dex_file,
611 dex::StringIndex string_index,
612 const PcRelativePatchInfo* info_high = nullptr);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800613 Literal* DeduplicateBootImageAddressLiteral(uint64_t address);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800614
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700615 void EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high,
616 GpuRegister out,
Alexey Frunze4147fcc2017-06-17 19:57:27 -0700617 PcRelativePatchInfo* info_low = nullptr);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800618
Alexey Frunze627c1a02017-01-30 19:28:14 -0800619 void PatchJitRootUse(uint8_t* code,
620 const uint8_t* roots_data,
621 const Literal* literal,
622 uint64_t index_in_table) const;
623 Literal* DeduplicateJitStringLiteral(const DexFile& dex_file,
624 dex::StringIndex string_index,
625 Handle<mirror::String> handle);
626 Literal* DeduplicateJitClassLiteral(const DexFile& dex_file,
627 dex::TypeIndex type_index,
628 Handle<mirror::Class> handle);
629
Alexey Frunze4dda3372015-06-01 18:31:49 -0700630 private:
Alexey Frunzef63f5692016-12-13 17:43:11 -0800631 using Uint32ToLiteralMap = ArenaSafeMap<uint32_t, Literal*>;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800632 using Uint64ToLiteralMap = ArenaSafeMap<uint64_t, Literal*>;
Alexey Frunze627c1a02017-01-30 19:28:14 -0800633 using StringToLiteralMap = ArenaSafeMap<StringReference,
634 Literal*,
635 StringReferenceValueComparator>;
636 using TypeToLiteralMap = ArenaSafeMap<TypeReference,
637 Literal*,
638 TypeReferenceValueComparator>;
Alexey Frunzef63f5692016-12-13 17:43:11 -0800639
640 Literal* DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800641 Literal* DeduplicateUint64Literal(uint64_t value);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800642
643 PcRelativePatchInfo* NewPcRelativePatch(const DexFile& dex_file,
644 uint32_t offset_or_index,
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700645 const PcRelativePatchInfo* info_high,
Alexey Frunze19f6c692016-11-30 19:19:55 -0800646 ArenaDeque<PcRelativePatchInfo>* patches);
647
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100648 template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
Alexey Frunze19f6c692016-11-30 19:19:55 -0800649 void EmitPcRelativeLinkerPatches(const ArenaDeque<PcRelativePatchInfo>& infos,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100650 ArenaVector<linker::LinkerPatch>* linker_patches);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800651
Alexey Frunze4dda3372015-06-01 18:31:49 -0700652 // Labels for each block that will be compiled.
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700653 Mips64Label* block_labels_; // Indexed by block id.
654 Mips64Label frame_entry_label_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700655 LocationsBuilderMIPS64 location_builder_;
656 InstructionCodeGeneratorMIPS64 instruction_visitor_;
657 ParallelMoveResolverMIPS64 move_resolver_;
658 Mips64Assembler assembler_;
659 const Mips64InstructionSetFeatures& isa_features_;
660
Alexey Frunzef63f5692016-12-13 17:43:11 -0800661 // Deduplication map for 32-bit literals, used for non-patchable boot image addresses.
662 Uint32ToLiteralMap uint32_literals_;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800663 // Deduplication map for 64-bit literals, used for non-patchable method address or method code
664 // address.
665 Uint64ToLiteralMap uint64_literals_;
Vladimir Marko65979462017-05-19 17:25:12 +0100666 // PC-relative method patch info for kBootImageLinkTimePcRelative.
667 ArenaDeque<PcRelativePatchInfo> pc_relative_method_patches_;
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100668 // PC-relative method patch info for kBssEntry.
669 ArenaDeque<PcRelativePatchInfo> method_bss_entry_patches_;
Vladimir Marko1998cd02017-01-13 13:02:58 +0000670 // PC-relative type patch info for kBootImageLinkTimePcRelative.
Alexey Frunzef63f5692016-12-13 17:43:11 -0800671 ArenaDeque<PcRelativePatchInfo> pc_relative_type_patches_;
Vladimir Marko1998cd02017-01-13 13:02:58 +0000672 // PC-relative type patch info for kBssEntry.
673 ArenaDeque<PcRelativePatchInfo> type_bss_entry_patches_;
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100674 // PC-relative String patch info; type depends on configuration (intern table or boot image PIC).
Vladimir Marko65979462017-05-19 17:25:12 +0100675 ArenaDeque<PcRelativePatchInfo> pc_relative_string_patches_;
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100676 // PC-relative type patch info for kBssEntry.
677 ArenaDeque<PcRelativePatchInfo> string_bss_entry_patches_;
Vladimir Marko65979462017-05-19 17:25:12 +0100678
Alexey Frunze627c1a02017-01-30 19:28:14 -0800679 // Patches for string root accesses in JIT compiled code.
680 StringToLiteralMap jit_string_patches_;
681 // Patches for class root accesses in JIT compiled code.
682 TypeToLiteralMap jit_class_patches_;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800683
Alexey Frunze4dda3372015-06-01 18:31:49 -0700684 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorMIPS64);
685};
686
687} // namespace mips64
688} // namespace art
689
690#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS64_H_