blob: ef4386bf4dfd4e666a8993b590cb32cd427322cb [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);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700236 void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor);
237 void HandleBinaryOp(HBinaryOperation* operation);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000238 void HandleCondition(HCondition* instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700239 void HandleShift(HBinaryOperation* operation);
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100240 void HandleFieldSet(HInstruction* instruction,
241 const FieldInfo& field_info,
242 bool value_can_be_null);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700243 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Alexey Frunze15958152017-02-09 19:08:30 -0800244
Aart Bik351df3e2018-03-07 11:54:57 -0800245 void GenerateMinMaxInt(LocationSummary* locations, bool is_min);
Aart Bik1f8d51b2018-02-15 10:42:37 -0800246 void GenerateMinMaxFP(LocationSummary* locations, bool is_min, DataType::Type type);
Aart Bik351df3e2018-03-07 11:54:57 -0800247 void GenerateMinMax(HBinaryOperation* minmax, bool is_min);
Aart Bik1f8d51b2018-02-15 10:42:37 -0800248
Alexey Frunze15958152017-02-09 19:08:30 -0800249 // Generate a heap reference load using one register `out`:
250 //
251 // out <- *(out + offset)
252 //
253 // while honoring heap poisoning and/or read barriers (if any).
254 //
255 // Location `maybe_temp` is used when generating a read barrier and
256 // shall be a register in that case; it may be an invalid location
257 // otherwise.
258 void GenerateReferenceLoadOneRegister(HInstruction* instruction,
259 Location out,
260 uint32_t offset,
261 Location maybe_temp,
262 ReadBarrierOption read_barrier_option);
263 // Generate a heap reference load using two different registers
264 // `out` and `obj`:
265 //
266 // out <- *(obj + offset)
267 //
268 // while honoring heap poisoning and/or read barriers (if any).
269 //
270 // Location `maybe_temp` is used when generating a Baker's (fast
271 // path) read barrier and shall be a register in that case; it may
272 // be an invalid location otherwise.
273 void GenerateReferenceLoadTwoRegisters(HInstruction* instruction,
274 Location out,
275 Location obj,
276 uint32_t offset,
277 Location maybe_temp,
278 ReadBarrierOption read_barrier_option);
279
Alexey Frunzef63f5692016-12-13 17:43:11 -0800280 // Generate a GC root reference load:
281 //
282 // root <- *(obj + offset)
283 //
284 // while honoring read barriers (if any).
285 void GenerateGcRootFieldLoad(HInstruction* instruction,
286 Location root,
287 GpuRegister obj,
Alexey Frunze15958152017-02-09 19:08:30 -0800288 uint32_t offset,
Alexey Frunze4147fcc2017-06-17 19:57:27 -0700289 ReadBarrierOption read_barrier_option,
290 Mips64Label* label_low = nullptr);
Alexey Frunze15958152017-02-09 19:08:30 -0800291
Alexey Frunze4dda3372015-06-01 18:31:49 -0700292 void GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +0000293 size_t condition_input_index,
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700294 Mips64Label* true_target,
295 Mips64Label* false_target);
Alexey Frunzec857c742015-09-23 15:12:39 -0700296 void DivRemOneOrMinusOne(HBinaryOperation* instruction);
297 void DivRemByPowerOfTwo(HBinaryOperation* instruction);
298 void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction);
299 void GenerateDivRemIntegral(HBinaryOperation* instruction);
Alexey Frunze299a9392015-12-08 16:08:02 -0800300 void GenerateIntLongCompare(IfCondition cond, bool is64bit, LocationSummary* locations);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +0200301 // When the function returns `false` it means that the condition holds if `dst` is non-zero
302 // and doesn't hold if `dst` is zero. If it returns `true`, the roles of zero and non-zero
303 // `dst` are exchanged.
304 bool MaterializeIntLongCompare(IfCondition cond,
305 bool is64bit,
306 LocationSummary* input_locations,
307 GpuRegister dst);
Alexey Frunze299a9392015-12-08 16:08:02 -0800308 void GenerateIntLongCompareAndBranch(IfCondition cond,
309 bool is64bit,
310 LocationSummary* locations,
311 Mips64Label* label);
Tijana Jakovljevic43758192016-12-30 09:23:01 +0100312 void GenerateFpCompare(IfCondition cond,
313 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100314 DataType::Type type,
Tijana Jakovljevic43758192016-12-30 09:23:01 +0100315 LocationSummary* locations);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +0200316 // When the function returns `false` it means that the condition holds if `dst` is non-zero
317 // and doesn't hold if `dst` is zero. If it returns `true`, the roles of zero and non-zero
318 // `dst` are exchanged.
319 bool MaterializeFpCompare(IfCondition cond,
320 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100321 DataType::Type type,
Goran Jakovljevic2dec9272017-08-02 11:41:26 +0200322 LocationSummary* input_locations,
323 FpuRegister dst);
Alexey Frunze299a9392015-12-08 16:08:02 -0800324 void GenerateFpCompareAndBranch(IfCondition cond,
325 bool gt_bias,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100326 DataType::Type type,
Alexey Frunze299a9392015-12-08 16:08:02 -0800327 LocationSummary* locations,
328 Mips64Label* label);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000329 void HandleGoto(HInstruction* got, HBasicBlock* successor);
Alexey Frunze0960ac52016-12-20 17:24:59 -0800330 void GenPackedSwitchWithCompares(GpuRegister value_reg,
331 int32_t lower_bound,
332 uint32_t num_entries,
333 HBasicBlock* switch_block,
334 HBasicBlock* default_block);
335 void GenTableBasedPackedSwitch(GpuRegister value_reg,
336 int32_t lower_bound,
337 uint32_t num_entries,
338 HBasicBlock* switch_block,
339 HBasicBlock* default_block);
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200340 int32_t VecAddress(LocationSummary* locations,
341 size_t size,
342 /* out */ GpuRegister* adjusted_base);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +0200343 void GenConditionalMove(HSelect* select);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700344
345 Mips64Assembler* const assembler_;
346 CodeGeneratorMIPS64* const codegen_;
347
348 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorMIPS64);
349};
350
351class CodeGeneratorMIPS64 : public CodeGenerator {
352 public:
353 CodeGeneratorMIPS64(HGraph* graph,
354 const Mips64InstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100355 const CompilerOptions& compiler_options,
356 OptimizingCompilerStats* stats = nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700357 virtual ~CodeGeneratorMIPS64() {}
358
359 void GenerateFrameEntry() OVERRIDE;
360 void GenerateFrameExit() OVERRIDE;
361
362 void Bind(HBasicBlock* block) OVERRIDE;
363
Lazar Trsicd9672662015-09-03 17:33:01 +0200364 size_t GetWordSize() const OVERRIDE { return kMips64DoublewordSize; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700365
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200366 size_t GetFloatingPointSpillSlotSize() const OVERRIDE {
367 return GetGraph()->HasSIMD()
368 ? 2 * kMips64DoublewordSize // 16 bytes for each spill.
369 : 1 * kMips64DoublewordSize; // 8 bytes for each spill.
370 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700371
Alexandre Ramesc01a6642016-04-15 11:54:06 +0100372 uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700373 return assembler_.GetLabelLocation(GetLabelOf(block));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700374 }
375
376 HGraphVisitor* GetLocationBuilder() OVERRIDE { return &location_builder_; }
377 HGraphVisitor* GetInstructionVisitor() OVERRIDE { return &instruction_visitor_; }
378 Mips64Assembler* GetAssembler() OVERRIDE { return &assembler_; }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100379 const Mips64Assembler& GetAssembler() const OVERRIDE { return assembler_; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700380
Alexey Frunze19f6c692016-11-30 19:19:55 -0800381 // Emit linker patches.
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100382 void EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) OVERRIDE;
Alexey Frunze627c1a02017-01-30 19:28:14 -0800383 void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) OVERRIDE;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800384
Alexey Frunze15958152017-02-09 19:08:30 -0800385 // Fast path implementation of ReadBarrier::Barrier for a heap
386 // reference field load when Baker's read barriers are used.
387 void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction,
388 Location ref,
389 GpuRegister obj,
390 uint32_t offset,
391 Location temp,
392 bool needs_null_check);
393 // Fast path implementation of ReadBarrier::Barrier for a heap
394 // reference array load when Baker's read barriers are used.
395 void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction,
396 Location ref,
397 GpuRegister obj,
398 uint32_t data_offset,
399 Location index,
400 Location temp,
401 bool needs_null_check);
402
403 // Factored implementation, used by GenerateFieldLoadWithBakerReadBarrier,
404 // GenerateArrayLoadWithBakerReadBarrier and some intrinsics.
405 //
406 // Load the object reference located at the address
407 // `obj + offset + (index << scale_factor)`, held by object `obj`, into
408 // `ref`, and mark it if needed.
409 //
410 // If `always_update_field` is true, the value of the reference is
411 // atomically updated in the holder (`obj`).
412 void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction,
413 Location ref,
414 GpuRegister obj,
415 uint32_t offset,
416 Location index,
417 ScaleFactor scale_factor,
418 Location temp,
419 bool needs_null_check,
420 bool always_update_field = false);
421
422 // Generate a read barrier for a heap reference within `instruction`
423 // using a slow path.
424 //
425 // A read barrier for an object reference read from the heap is
426 // implemented as a call to the artReadBarrierSlow runtime entry
427 // point, which is passed the values in locations `ref`, `obj`, and
428 // `offset`:
429 //
430 // mirror::Object* artReadBarrierSlow(mirror::Object* ref,
431 // mirror::Object* obj,
432 // uint32_t offset);
433 //
434 // The `out` location contains the value returned by
435 // artReadBarrierSlow.
436 //
437 // When `index` is provided (i.e. for array accesses), the offset
438 // value passed to artReadBarrierSlow is adjusted to take `index`
439 // into account.
440 void GenerateReadBarrierSlow(HInstruction* instruction,
441 Location out,
442 Location ref,
443 Location obj,
444 uint32_t offset,
445 Location index = Location::NoLocation());
446
447 // If read barriers are enabled, generate a read barrier for a heap
448 // reference using a slow path. If heap poisoning is enabled, also
449 // unpoison the reference in `out`.
450 void MaybeGenerateReadBarrierSlow(HInstruction* instruction,
451 Location out,
452 Location ref,
453 Location obj,
454 uint32_t offset,
455 Location index = Location::NoLocation());
456
457 // Generate a read barrier for a GC root within `instruction` using
458 // a slow path.
459 //
460 // A read barrier for an object reference GC root is implemented as
461 // a call to the artReadBarrierForRootSlow runtime entry point,
462 // which is passed the value in location `root`:
463 //
464 // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root);
465 //
466 // The `out` location contains the value returned by
467 // artReadBarrierForRootSlow.
468 void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root);
469
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100470 void MarkGCCard(GpuRegister object, GpuRegister value, bool value_can_be_null);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700471
472 // Register allocation.
473
David Brazdil58282f42016-01-14 12:45:10 +0000474 void SetupBlockedRegisters() const OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700475
Roland Levillainf41f9562016-09-14 19:26:48 +0100476 size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
477 size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
478 size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
479 size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700480
481 void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE;
482 void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE;
483
484 InstructionSet GetInstructionSet() const OVERRIDE { return InstructionSet::kMips64; }
485
486 const Mips64InstructionSetFeatures& GetInstructionSetFeatures() const {
487 return isa_features_;
488 }
489
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700490 Mips64Label* GetLabelOf(HBasicBlock* block) const {
491 return CommonGetLabelOf<Mips64Label>(block_labels_, block);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700492 }
493
494 void Initialize() OVERRIDE {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700495 block_labels_ = CommonInitializeLabels<Mips64Label>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700496 }
497
Alexey Frunzec3789802016-12-22 13:54:23 -0800498 // We prefer aligned loads and stores (less code), so spill and restore registers in slow paths
499 // at aligned locations.
500 uint32_t GetPreferredSlotsAlignment() const OVERRIDE { return kMips64DoublewordSize; }
501
Alexey Frunze4dda3372015-06-01 18:31:49 -0700502 void Finalize(CodeAllocator* allocator) OVERRIDE;
503
504 // Code generation helpers.
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100505 void MoveLocation(Location dst, Location src, DataType::Type dst_type) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700506
Calin Juravle175dc732015-08-25 15:42:32 +0100507 void MoveConstant(Location destination, int32_t value) OVERRIDE;
508
Calin Juravlee460d1d2015-09-29 04:52:17 +0100509 void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE;
510
511
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100512 void SwapLocations(Location loc1, Location loc2, DataType::Type type);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700513
514 // Generate code to invoke a runtime entry point.
Calin Juravle175dc732015-08-25 15:42:32 +0100515 void InvokeRuntime(QuickEntrypointEnum entrypoint,
516 HInstruction* instruction,
517 uint32_t dex_pc,
Serban Constantinescufc734082016-07-19 17:18:07 +0100518 SlowPathCode* slow_path = nullptr) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700519
Alexey Frunze15958152017-02-09 19:08:30 -0800520 // Generate code to invoke a runtime entry point, but do not record
521 // PC-related information in a stack map.
522 void InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset,
523 HInstruction* instruction,
524 SlowPathCode* slow_path);
525
526 void GenerateInvokeRuntime(int32_t entry_point_offset);
527
Alexey Frunze4dda3372015-06-01 18:31:49 -0700528 ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; }
529
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100530 bool NeedsTwoRegisters(DataType::Type type ATTRIBUTE_UNUSED) const OVERRIDE { return false; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700531
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000532 // Check if the desired_string_load_kind is supported. If it is, return it,
533 // otherwise return a fall-back kind that should be used instead.
534 HLoadString::LoadKind GetSupportedLoadStringKind(
535 HLoadString::LoadKind desired_string_load_kind) OVERRIDE;
536
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100537 // Check if the desired_class_load_kind is supported. If it is, return it,
538 // otherwise return a fall-back kind that should be used instead.
539 HLoadClass::LoadKind GetSupportedLoadClassKind(
540 HLoadClass::LoadKind desired_class_load_kind) OVERRIDE;
541
Vladimir Markodc151b22015-10-15 18:02:30 +0100542 // Check if the desired_dispatch_info is supported. If it is, return it,
543 // otherwise return a fall-back info that should be used instead.
544 HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch(
545 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100546 HInvokeStaticOrDirect* invoke) OVERRIDE;
Vladimir Markodc151b22015-10-15 18:02:30 +0100547
Vladimir Markoe7197bf2017-06-02 17:00:23 +0100548 void GenerateStaticOrDirectCall(
549 HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path = nullptr) OVERRIDE;
550 void GenerateVirtualCall(
551 HInvokeVirtual* invoke, Location temp, SlowPathCode* slow_path = nullptr) OVERRIDE;
Andreas Gampe85b62f22015-09-09 13:15:38 -0700552
553 void MoveFromReturnRegister(Location trg ATTRIBUTE_UNUSED,
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100554 DataType::Type type ATTRIBUTE_UNUSED) OVERRIDE {
Chris Larsen3acee732015-11-18 13:31:08 -0800555 UNIMPLEMENTED(FATAL) << "Not implemented on MIPS64";
Andreas Gampe85b62f22015-09-09 13:15:38 -0700556 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700557
Roland Levillainf41f9562016-09-14 19:26:48 +0100558 void GenerateNop() OVERRIDE;
559 void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
560 void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
David Srbeckyc7098ff2016-02-09 14:30:11 +0000561
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000562 // The PcRelativePatchInfo is used for PC-relative addressing of methods/strings/types,
563 // whether through .data.bimg.rel.ro, .bss, or directly in the boot image.
564 //
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700565 // The 16-bit halves of the 32-bit PC-relative offset are patched separately, necessitating
566 // two patches/infos. There can be more than two patches/infos if the instruction supplying
567 // the high half is shared with e.g. a slow path, while the low half is supplied by separate
568 // instructions, e.g.:
569 // auipc r1, high // patch
570 // lwu r2, low(r1) // patch
571 // beqzc r2, slow_path
572 // back:
573 // ...
574 // slow_path:
575 // ...
576 // sw r2, low(r1) // patch
577 // bc back
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000578 struct PcRelativePatchInfo : PatchInfo<Mips64Label> {
579 PcRelativePatchInfo(const DexFile* dex_file,
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700580 uint32_t off_or_idx,
581 const PcRelativePatchInfo* info_high)
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000582 : PatchInfo<Mips64Label>(dex_file, off_or_idx),
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700583 patch_info_high(info_high) { }
Alexey Frunze19f6c692016-11-30 19:19:55 -0800584
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700585 // Pointer to the info for the high half patch or nullptr if this is the high half patch info.
586 const PcRelativePatchInfo* patch_info_high;
587
588 private:
589 PcRelativePatchInfo(PcRelativePatchInfo&& other) = delete;
590 DISALLOW_COPY_AND_ASSIGN(PcRelativePatchInfo);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800591 };
592
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000593 PcRelativePatchInfo* NewBootImageMethodPatch(MethodReference target_method,
594 const PcRelativePatchInfo* info_high = nullptr);
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700595 PcRelativePatchInfo* NewMethodBssEntryPatch(MethodReference target_method,
596 const PcRelativePatchInfo* info_high = nullptr);
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000597 PcRelativePatchInfo* NewBootImageTypePatch(const DexFile& dex_file,
598 dex::TypeIndex type_index,
599 const PcRelativePatchInfo* info_high = nullptr);
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700600 PcRelativePatchInfo* NewTypeBssEntryPatch(const DexFile& dex_file,
601 dex::TypeIndex type_index,
602 const PcRelativePatchInfo* info_high = nullptr);
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000603 PcRelativePatchInfo* NewBootImageStringPatch(const DexFile& dex_file,
604 dex::StringIndex string_index,
605 const PcRelativePatchInfo* info_high = nullptr);
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100606 PcRelativePatchInfo* NewStringBssEntryPatch(const DexFile& dex_file,
607 dex::StringIndex string_index,
608 const PcRelativePatchInfo* info_high = nullptr);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800609 Literal* DeduplicateBootImageAddressLiteral(uint64_t address);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800610
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700611 void EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high,
612 GpuRegister out,
Alexey Frunze4147fcc2017-06-17 19:57:27 -0700613 PcRelativePatchInfo* info_low = nullptr);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800614
Alexey Frunze627c1a02017-01-30 19:28:14 -0800615 void PatchJitRootUse(uint8_t* code,
616 const uint8_t* roots_data,
617 const Literal* literal,
618 uint64_t index_in_table) const;
619 Literal* DeduplicateJitStringLiteral(const DexFile& dex_file,
620 dex::StringIndex string_index,
621 Handle<mirror::String> handle);
622 Literal* DeduplicateJitClassLiteral(const DexFile& dex_file,
623 dex::TypeIndex type_index,
624 Handle<mirror::Class> handle);
625
Alexey Frunze4dda3372015-06-01 18:31:49 -0700626 private:
Alexey Frunzef63f5692016-12-13 17:43:11 -0800627 using Uint32ToLiteralMap = ArenaSafeMap<uint32_t, Literal*>;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800628 using Uint64ToLiteralMap = ArenaSafeMap<uint64_t, Literal*>;
Alexey Frunze627c1a02017-01-30 19:28:14 -0800629 using StringToLiteralMap = ArenaSafeMap<StringReference,
630 Literal*,
631 StringReferenceValueComparator>;
632 using TypeToLiteralMap = ArenaSafeMap<TypeReference,
633 Literal*,
634 TypeReferenceValueComparator>;
Alexey Frunzef63f5692016-12-13 17:43:11 -0800635
636 Literal* DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800637 Literal* DeduplicateUint64Literal(uint64_t value);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800638
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000639 PcRelativePatchInfo* NewPcRelativePatch(const DexFile* dex_file,
Alexey Frunze19f6c692016-11-30 19:19:55 -0800640 uint32_t offset_or_index,
Alexey Frunze5fa5c042017-06-01 21:07:52 -0700641 const PcRelativePatchInfo* info_high,
Alexey Frunze19f6c692016-11-30 19:19:55 -0800642 ArenaDeque<PcRelativePatchInfo>* patches);
643
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100644 template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
Alexey Frunze19f6c692016-11-30 19:19:55 -0800645 void EmitPcRelativeLinkerPatches(const ArenaDeque<PcRelativePatchInfo>& infos,
Vladimir Markod8dbc8d2017-09-20 13:37:47 +0100646 ArenaVector<linker::LinkerPatch>* linker_patches);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800647
Alexey Frunze4dda3372015-06-01 18:31:49 -0700648 // Labels for each block that will be compiled.
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700649 Mips64Label* block_labels_; // Indexed by block id.
650 Mips64Label frame_entry_label_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700651 LocationsBuilderMIPS64 location_builder_;
652 InstructionCodeGeneratorMIPS64 instruction_visitor_;
653 ParallelMoveResolverMIPS64 move_resolver_;
654 Mips64Assembler assembler_;
655 const Mips64InstructionSetFeatures& isa_features_;
656
Alexey Frunzef63f5692016-12-13 17:43:11 -0800657 // Deduplication map for 32-bit literals, used for non-patchable boot image addresses.
658 Uint32ToLiteralMap uint32_literals_;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800659 // Deduplication map for 64-bit literals, used for non-patchable method address or method code
660 // address.
661 Uint64ToLiteralMap uint64_literals_;
Vladimir Marko65979462017-05-19 17:25:12 +0100662 // PC-relative method patch info for kBootImageLinkTimePcRelative.
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000663 ArenaDeque<PcRelativePatchInfo> boot_image_method_patches_;
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100664 // PC-relative method patch info for kBssEntry.
665 ArenaDeque<PcRelativePatchInfo> method_bss_entry_patches_;
Vladimir Marko1998cd02017-01-13 13:02:58 +0000666 // PC-relative type patch info for kBootImageLinkTimePcRelative.
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000667 ArenaDeque<PcRelativePatchInfo> boot_image_type_patches_;
Vladimir Marko1998cd02017-01-13 13:02:58 +0000668 // PC-relative type patch info for kBssEntry.
669 ArenaDeque<PcRelativePatchInfo> type_bss_entry_patches_;
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100670 // PC-relative String patch info; type depends on configuration (intern table or boot image PIC).
Vladimir Marko59eb30f2018-02-20 11:52:34 +0000671 ArenaDeque<PcRelativePatchInfo> boot_image_string_patches_;
Vladimir Marko6cfbdbc2017-07-25 13:26:39 +0100672 // PC-relative type patch info for kBssEntry.
673 ArenaDeque<PcRelativePatchInfo> string_bss_entry_patches_;
Vladimir Marko65979462017-05-19 17:25:12 +0100674
Alexey Frunze627c1a02017-01-30 19:28:14 -0800675 // Patches for string root accesses in JIT compiled code.
676 StringToLiteralMap jit_string_patches_;
677 // Patches for class root accesses in JIT compiled code.
678 TypeToLiteralMap jit_class_patches_;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800679
Alexey Frunze4dda3372015-06-01 18:31:49 -0700680 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorMIPS64);
681};
682
683} // namespace mips64
684} // namespace art
685
686#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS64_H_