blob: 26cc7dc788ea5d72e05e2c0e1098f017bbe8c08e [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"
24#include "utils/mips64/assembler_mips64.h"
Alexey Frunzef63f5692016-12-13 17:43:11 -080025#include "utils/type_reference.h"
Alexey Frunze4dda3372015-06-01 18:31:49 -070026
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
62class InvokeDexCallingConvention : public CallingConvention<GpuRegister, FpuRegister> {
63 public:
64 InvokeDexCallingConvention()
65 : CallingConvention(kParameterCoreRegisters,
66 kParameterCoreRegistersLength,
67 kParameterFpuRegisters,
68 kParameterFpuRegistersLength,
69 kMips64PointerSize) {}
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention);
73};
74
75class InvokeDexCallingConventionVisitorMIPS64 : public InvokeDexCallingConventionVisitor {
76 public:
77 InvokeDexCallingConventionVisitorMIPS64() {}
78 virtual ~InvokeDexCallingConventionVisitorMIPS64() {}
79
80 Location GetNextLocation(Primitive::Type type) OVERRIDE;
81 Location GetReturnLocation(Primitive::Type type) const OVERRIDE;
82 Location GetMethodLocation() const OVERRIDE;
83
84 private:
85 InvokeDexCallingConvention calling_convention;
86
87 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorMIPS64);
88};
89
90class InvokeRuntimeCallingConvention : public CallingConvention<GpuRegister, FpuRegister> {
91 public:
92 InvokeRuntimeCallingConvention()
93 : CallingConvention(kRuntimeParameterCoreRegisters,
94 kRuntimeParameterCoreRegistersLength,
95 kRuntimeParameterFpuRegisters,
96 kRuntimeParameterFpuRegistersLength,
97 kMips64PointerSize) {}
98
99 Location GetReturnLocation(Primitive::Type return_type);
100
101 private:
102 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
103};
104
Calin Juravlee460d1d2015-09-29 04:52:17 +0100105class FieldAccessCallingConventionMIPS64 : public FieldAccessCallingConvention {
106 public:
107 FieldAccessCallingConventionMIPS64() {}
108
109 Location GetObjectLocation() const OVERRIDE {
110 return Location::RegisterLocation(A1);
111 }
112 Location GetFieldIndexLocation() const OVERRIDE {
113 return Location::RegisterLocation(A0);
114 }
115 Location GetReturnLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
Goran Jakovljevic8c34ec12015-10-14 11:23:48 +0200116 return Location::RegisterLocation(V0);
Calin Juravlee460d1d2015-09-29 04:52:17 +0100117 }
Alexey Frunze0cb12422017-01-25 19:30:18 -0800118 Location GetSetValueLocation(Primitive::Type type ATTRIBUTE_UNUSED,
119 bool is_instance) const OVERRIDE {
120 return is_instance
Alexey Frunze00580bd2015-11-11 13:31:12 -0800121 ? Location::RegisterLocation(A2)
Alexey Frunze0cb12422017-01-25 19:30:18 -0800122 : Location::RegisterLocation(A1);
Calin Juravlee460d1d2015-09-29 04:52:17 +0100123 }
124 Location GetFpuLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
125 return Location::FpuRegisterLocation(F0);
126 }
127
128 private:
129 DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionMIPS64);
130};
131
Alexey Frunze4dda3372015-06-01 18:31:49 -0700132class ParallelMoveResolverMIPS64 : public ParallelMoveResolverWithSwap {
133 public:
134 ParallelMoveResolverMIPS64(ArenaAllocator* allocator, CodeGeneratorMIPS64* codegen)
135 : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {}
136
137 void EmitMove(size_t index) OVERRIDE;
138 void EmitSwap(size_t index) OVERRIDE;
139 void SpillScratch(int reg) OVERRIDE;
140 void RestoreScratch(int reg) OVERRIDE;
141
142 void Exchange(int index1, int index2, bool double_slot);
143
144 Mips64Assembler* GetAssembler() const;
145
146 private:
147 CodeGeneratorMIPS64* const codegen_;
148
149 DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverMIPS64);
150};
151
152class SlowPathCodeMIPS64 : public SlowPathCode {
153 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000154 explicit SlowPathCodeMIPS64(HInstruction* instruction)
155 : SlowPathCode(instruction), entry_label_(), exit_label_() {}
Alexey Frunze4dda3372015-06-01 18:31:49 -0700156
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700157 Mips64Label* GetEntryLabel() { return &entry_label_; }
158 Mips64Label* GetExitLabel() { return &exit_label_; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700159
160 private:
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700161 Mips64Label entry_label_;
162 Mips64Label exit_label_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700163
164 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeMIPS64);
165};
166
167class LocationsBuilderMIPS64 : public HGraphVisitor {
168 public:
169 LocationsBuilderMIPS64(HGraph* graph, CodeGeneratorMIPS64* codegen)
170 : HGraphVisitor(graph), codegen_(codegen) {}
171
172#define DECLARE_VISIT_INSTRUCTION(name, super) \
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100173 void Visit##name(H##name* instr) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700174
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100175 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
176 FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(DECLARE_VISIT_INSTRUCTION)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700177
178#undef DECLARE_VISIT_INSTRUCTION
179
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100180 void VisitInstruction(HInstruction* instruction) OVERRIDE {
181 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
182 << " (id " << instruction->GetId() << ")";
183 }
184
Alexey Frunze4dda3372015-06-01 18:31:49 -0700185 private:
186 void HandleInvoke(HInvoke* invoke);
187 void HandleBinaryOp(HBinaryOperation* operation);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000188 void HandleCondition(HCondition* instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700189 void HandleShift(HBinaryOperation* operation);
190 void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info);
191 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
192
193 InvokeDexCallingConventionVisitorMIPS64 parameter_visitor_;
194
195 CodeGeneratorMIPS64* const codegen_;
196
197 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderMIPS64);
198};
199
Aart Bik42249c32016-01-07 15:33:50 -0800200class InstructionCodeGeneratorMIPS64 : public InstructionCodeGenerator {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700201 public:
202 InstructionCodeGeneratorMIPS64(HGraph* graph, CodeGeneratorMIPS64* codegen);
203
204#define DECLARE_VISIT_INSTRUCTION(name, super) \
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100205 void Visit##name(H##name* instr) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700206
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100207 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
208 FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(DECLARE_VISIT_INSTRUCTION)
Alexey Frunze4dda3372015-06-01 18:31:49 -0700209
210#undef DECLARE_VISIT_INSTRUCTION
211
Alexandre Ramesf39e0642015-06-23 11:33:45 +0100212 void VisitInstruction(HInstruction* instruction) OVERRIDE {
213 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
214 << " (id " << instruction->GetId() << ")";
215 }
216
Alexey Frunze4dda3372015-06-01 18:31:49 -0700217 Mips64Assembler* GetAssembler() const { return assembler_; }
218
Alexey Frunze0960ac52016-12-20 17:24:59 -0800219 // Compare-and-jump packed switch generates approx. 3 + 2.5 * N 32-bit
220 // instructions for N cases.
221 // Table-based packed switch generates approx. 11 32-bit instructions
222 // and N 32-bit data words for N cases.
223 // At N = 6 they come out as 18 and 17 32-bit words respectively.
224 // We switch to the table-based method starting with 7 cases.
225 static constexpr uint32_t kPackedSwitchJumpTableThreshold = 6;
226
Alexey Frunze4dda3372015-06-01 18:31:49 -0700227 private:
Alexey Frunze4dda3372015-06-01 18:31:49 -0700228 void GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, GpuRegister class_reg);
229 void GenerateMemoryBarrier(MemBarrierKind kind);
230 void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor);
231 void HandleBinaryOp(HBinaryOperation* operation);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000232 void HandleCondition(HCondition* instruction);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700233 void HandleShift(HBinaryOperation* operation);
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100234 void HandleFieldSet(HInstruction* instruction,
235 const FieldInfo& field_info,
236 bool value_can_be_null);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700237 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800238 // Generate a GC root reference load:
239 //
240 // root <- *(obj + offset)
241 //
242 // while honoring read barriers (if any).
243 void GenerateGcRootFieldLoad(HInstruction* instruction,
244 Location root,
245 GpuRegister obj,
246 uint32_t offset);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700247 void GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +0000248 size_t condition_input_index,
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700249 Mips64Label* true_target,
250 Mips64Label* false_target);
Alexey Frunzec857c742015-09-23 15:12:39 -0700251 void DivRemOneOrMinusOne(HBinaryOperation* instruction);
252 void DivRemByPowerOfTwo(HBinaryOperation* instruction);
253 void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction);
254 void GenerateDivRemIntegral(HBinaryOperation* instruction);
Alexey Frunze299a9392015-12-08 16:08:02 -0800255 void GenerateIntLongCompare(IfCondition cond, bool is64bit, LocationSummary* locations);
256 void GenerateIntLongCompareAndBranch(IfCondition cond,
257 bool is64bit,
258 LocationSummary* locations,
259 Mips64Label* label);
Tijana Jakovljevic43758192016-12-30 09:23:01 +0100260 void GenerateFpCompare(IfCondition cond,
261 bool gt_bias,
262 Primitive::Type type,
263 LocationSummary* locations);
Alexey Frunze299a9392015-12-08 16:08:02 -0800264 void GenerateFpCompareAndBranch(IfCondition cond,
265 bool gt_bias,
266 Primitive::Type type,
267 LocationSummary* locations,
268 Mips64Label* label);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000269 void HandleGoto(HInstruction* got, HBasicBlock* successor);
Alexey Frunze0960ac52016-12-20 17:24:59 -0800270 void GenPackedSwitchWithCompares(GpuRegister value_reg,
271 int32_t lower_bound,
272 uint32_t num_entries,
273 HBasicBlock* switch_block,
274 HBasicBlock* default_block);
275 void GenTableBasedPackedSwitch(GpuRegister value_reg,
276 int32_t lower_bound,
277 uint32_t num_entries,
278 HBasicBlock* switch_block,
279 HBasicBlock* default_block);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700280
281 Mips64Assembler* const assembler_;
282 CodeGeneratorMIPS64* const codegen_;
283
284 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorMIPS64);
285};
286
287class CodeGeneratorMIPS64 : public CodeGenerator {
288 public:
289 CodeGeneratorMIPS64(HGraph* graph,
290 const Mips64InstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100291 const CompilerOptions& compiler_options,
292 OptimizingCompilerStats* stats = nullptr);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700293 virtual ~CodeGeneratorMIPS64() {}
294
295 void GenerateFrameEntry() OVERRIDE;
296 void GenerateFrameExit() OVERRIDE;
297
298 void Bind(HBasicBlock* block) OVERRIDE;
299
Lazar Trsicd9672662015-09-03 17:33:01 +0200300 size_t GetWordSize() const OVERRIDE { return kMips64DoublewordSize; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700301
Lazar Trsicd9672662015-09-03 17:33:01 +0200302 size_t GetFloatingPointSpillSlotSize() const OVERRIDE { return kMips64DoublewordSize; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700303
Alexandre Ramesc01a6642016-04-15 11:54:06 +0100304 uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700305 return assembler_.GetLabelLocation(GetLabelOf(block));
Alexey Frunze4dda3372015-06-01 18:31:49 -0700306 }
307
308 HGraphVisitor* GetLocationBuilder() OVERRIDE { return &location_builder_; }
309 HGraphVisitor* GetInstructionVisitor() OVERRIDE { return &instruction_visitor_; }
310 Mips64Assembler* GetAssembler() OVERRIDE { return &assembler_; }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100311 const Mips64Assembler& GetAssembler() const OVERRIDE { return assembler_; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700312
Alexey Frunze19f6c692016-11-30 19:19:55 -0800313 // Emit linker patches.
314 void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE;
Alexey Frunze627c1a02017-01-30 19:28:14 -0800315 void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) OVERRIDE;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800316
Goran Jakovljevic8ed18262016-01-22 13:01:00 +0100317 void MarkGCCard(GpuRegister object, GpuRegister value, bool value_can_be_null);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700318
319 // Register allocation.
320
David Brazdil58282f42016-01-14 12:45:10 +0000321 void SetupBlockedRegisters() const OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700322
Roland Levillainf41f9562016-09-14 19:26:48 +0100323 size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
324 size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
325 size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
326 size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700327
328 void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE;
329 void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE;
330
331 InstructionSet GetInstructionSet() const OVERRIDE { return InstructionSet::kMips64; }
332
333 const Mips64InstructionSetFeatures& GetInstructionSetFeatures() const {
334 return isa_features_;
335 }
336
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700337 Mips64Label* GetLabelOf(HBasicBlock* block) const {
338 return CommonGetLabelOf<Mips64Label>(block_labels_, block);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700339 }
340
341 void Initialize() OVERRIDE {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700342 block_labels_ = CommonInitializeLabels<Mips64Label>();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700343 }
344
Alexey Frunzec3789802016-12-22 13:54:23 -0800345 // We prefer aligned loads and stores (less code), so spill and restore registers in slow paths
346 // at aligned locations.
347 uint32_t GetPreferredSlotsAlignment() const OVERRIDE { return kMips64DoublewordSize; }
348
Alexey Frunze4dda3372015-06-01 18:31:49 -0700349 void Finalize(CodeAllocator* allocator) OVERRIDE;
350
351 // Code generation helpers.
Calin Juravlee460d1d2015-09-29 04:52:17 +0100352 void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700353
Calin Juravle175dc732015-08-25 15:42:32 +0100354 void MoveConstant(Location destination, int32_t value) OVERRIDE;
355
Calin Juravlee460d1d2015-09-29 04:52:17 +0100356 void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE;
357
358
Alexey Frunze4dda3372015-06-01 18:31:49 -0700359 void SwapLocations(Location loc1, Location loc2, Primitive::Type type);
360
361 // Generate code to invoke a runtime entry point.
Calin Juravle175dc732015-08-25 15:42:32 +0100362 void InvokeRuntime(QuickEntrypointEnum entrypoint,
363 HInstruction* instruction,
364 uint32_t dex_pc,
Serban Constantinescufc734082016-07-19 17:18:07 +0100365 SlowPathCode* slow_path = nullptr) OVERRIDE;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700366
367 ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; }
368
Roland Levillainf41f9562016-09-14 19:26:48 +0100369 bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { return false; }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700370
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000371 // Check if the desired_string_load_kind is supported. If it is, return it,
372 // otherwise return a fall-back kind that should be used instead.
373 HLoadString::LoadKind GetSupportedLoadStringKind(
374 HLoadString::LoadKind desired_string_load_kind) OVERRIDE;
375
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100376 // Check if the desired_class_load_kind is supported. If it is, return it,
377 // otherwise return a fall-back kind that should be used instead.
378 HLoadClass::LoadKind GetSupportedLoadClassKind(
379 HLoadClass::LoadKind desired_class_load_kind) OVERRIDE;
380
Vladimir Markodc151b22015-10-15 18:02:30 +0100381 // Check if the desired_dispatch_info is supported. If it is, return it,
382 // otherwise return a fall-back info that should be used instead.
383 HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch(
384 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100385 HInvokeStaticOrDirect* invoke) OVERRIDE;
Vladimir Markodc151b22015-10-15 18:02:30 +0100386
Andreas Gampe85b62f22015-09-09 13:15:38 -0700387 void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) OVERRIDE;
Alexey Frunze53afca12015-11-05 16:34:23 -0800388 void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE;
Andreas Gampe85b62f22015-09-09 13:15:38 -0700389
390 void MoveFromReturnRegister(Location trg ATTRIBUTE_UNUSED,
391 Primitive::Type type ATTRIBUTE_UNUSED) OVERRIDE {
Chris Larsen3acee732015-11-18 13:31:08 -0800392 UNIMPLEMENTED(FATAL) << "Not implemented on MIPS64";
Andreas Gampe85b62f22015-09-09 13:15:38 -0700393 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700394
Roland Levillainf41f9562016-09-14 19:26:48 +0100395 void GenerateNop() OVERRIDE;
396 void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
397 void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
David Srbeckyc7098ff2016-02-09 14:30:11 +0000398
Alexey Frunze19f6c692016-11-30 19:19:55 -0800399 // The PcRelativePatchInfo is used for PC-relative addressing of dex cache arrays,
400 // boot image strings and method calls. The only difference is the interpretation of
401 // the offset_or_index.
402 struct PcRelativePatchInfo {
403 PcRelativePatchInfo(const DexFile& dex_file, uint32_t off_or_idx)
404 : target_dex_file(dex_file), offset_or_index(off_or_idx) { }
405 PcRelativePatchInfo(PcRelativePatchInfo&& other) = default;
406
407 const DexFile& target_dex_file;
408 // Either the dex cache array element offset or the string/type/method index.
409 uint32_t offset_or_index;
410 // Label for the auipc instruction.
411 Mips64Label pc_rel_label;
412 };
413
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000414 PcRelativePatchInfo* NewPcRelativeStringPatch(const DexFile& dex_file,
415 dex::StringIndex string_index);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800416 PcRelativePatchInfo* NewPcRelativeTypePatch(const DexFile& dex_file, dex::TypeIndex type_index);
Vladimir Marko1998cd02017-01-13 13:02:58 +0000417 PcRelativePatchInfo* NewTypeBssEntryPatch(const DexFile& dex_file, dex::TypeIndex type_index);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800418 PcRelativePatchInfo* NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file,
419 uint32_t element_offset);
420 PcRelativePatchInfo* NewPcRelativeCallPatch(const DexFile& dex_file,
421 uint32_t method_index);
Alexey Frunzef63f5692016-12-13 17:43:11 -0800422 Literal* DeduplicateBootImageStringLiteral(const DexFile& dex_file,
423 dex::StringIndex string_index);
424 Literal* DeduplicateBootImageTypeLiteral(const DexFile& dex_file, dex::TypeIndex type_index);
425 Literal* DeduplicateBootImageAddressLiteral(uint64_t address);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800426
427 void EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info, GpuRegister out);
428
Alexey Frunze627c1a02017-01-30 19:28:14 -0800429 void PatchJitRootUse(uint8_t* code,
430 const uint8_t* roots_data,
431 const Literal* literal,
432 uint64_t index_in_table) const;
433 Literal* DeduplicateJitStringLiteral(const DexFile& dex_file,
434 dex::StringIndex string_index,
435 Handle<mirror::String> handle);
436 Literal* DeduplicateJitClassLiteral(const DexFile& dex_file,
437 dex::TypeIndex type_index,
438 Handle<mirror::Class> handle);
439
Alexey Frunze4dda3372015-06-01 18:31:49 -0700440 private:
Alexey Frunzef63f5692016-12-13 17:43:11 -0800441 using Uint32ToLiteralMap = ArenaSafeMap<uint32_t, Literal*>;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800442 using Uint64ToLiteralMap = ArenaSafeMap<uint64_t, Literal*>;
443 using MethodToLiteralMap = ArenaSafeMap<MethodReference, Literal*, MethodReferenceComparator>;
Alexey Frunze627c1a02017-01-30 19:28:14 -0800444 using StringToLiteralMap = ArenaSafeMap<StringReference,
445 Literal*,
446 StringReferenceValueComparator>;
447 using TypeToLiteralMap = ArenaSafeMap<TypeReference,
448 Literal*,
449 TypeReferenceValueComparator>;
Alexey Frunzef63f5692016-12-13 17:43:11 -0800450 using BootStringToLiteralMap = ArenaSafeMap<StringReference,
451 Literal*,
452 StringReferenceValueComparator>;
453 using BootTypeToLiteralMap = ArenaSafeMap<TypeReference,
454 Literal*,
455 TypeReferenceValueComparator>;
456
457 Literal* DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800458 Literal* DeduplicateUint64Literal(uint64_t value);
459 Literal* DeduplicateMethodLiteral(MethodReference target_method, MethodToLiteralMap* map);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800460
461 PcRelativePatchInfo* NewPcRelativePatch(const DexFile& dex_file,
462 uint32_t offset_or_index,
463 ArenaDeque<PcRelativePatchInfo>* patches);
464
465 template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
466 void EmitPcRelativeLinkerPatches(const ArenaDeque<PcRelativePatchInfo>& infos,
467 ArenaVector<LinkerPatch>* linker_patches);
468
Alexey Frunze4dda3372015-06-01 18:31:49 -0700469 // Labels for each block that will be compiled.
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700470 Mips64Label* block_labels_; // Indexed by block id.
471 Mips64Label frame_entry_label_;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700472 LocationsBuilderMIPS64 location_builder_;
473 InstructionCodeGeneratorMIPS64 instruction_visitor_;
474 ParallelMoveResolverMIPS64 move_resolver_;
475 Mips64Assembler assembler_;
476 const Mips64InstructionSetFeatures& isa_features_;
477
Alexey Frunzef63f5692016-12-13 17:43:11 -0800478 // Deduplication map for 32-bit literals, used for non-patchable boot image addresses.
479 Uint32ToLiteralMap uint32_literals_;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800480 // Deduplication map for 64-bit literals, used for non-patchable method address or method code
481 // address.
482 Uint64ToLiteralMap uint64_literals_;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800483 // PC-relative patch info.
484 ArenaDeque<PcRelativePatchInfo> pc_relative_dex_cache_patches_;
Alexey Frunzef63f5692016-12-13 17:43:11 -0800485 // Deduplication map for boot string literals for kBootImageLinkTimeAddress.
486 BootStringToLiteralMap boot_image_string_patches_;
487 // PC-relative String patch info; type depends on configuration (app .bss or boot image PIC).
488 ArenaDeque<PcRelativePatchInfo> pc_relative_string_patches_;
489 // Deduplication map for boot type literals for kBootImageLinkTimeAddress.
490 BootTypeToLiteralMap boot_image_type_patches_;
Vladimir Marko1998cd02017-01-13 13:02:58 +0000491 // PC-relative type patch info for kBootImageLinkTimePcRelative.
Alexey Frunzef63f5692016-12-13 17:43:11 -0800492 ArenaDeque<PcRelativePatchInfo> pc_relative_type_patches_;
Vladimir Marko1998cd02017-01-13 13:02:58 +0000493 // PC-relative type patch info for kBssEntry.
494 ArenaDeque<PcRelativePatchInfo> type_bss_entry_patches_;
Alexey Frunzef63f5692016-12-13 17:43:11 -0800495 // Deduplication map for patchable boot image addresses.
496 Uint32ToLiteralMap boot_image_address_patches_;
Alexey Frunze627c1a02017-01-30 19:28:14 -0800497 // Patches for string root accesses in JIT compiled code.
498 StringToLiteralMap jit_string_patches_;
499 // Patches for class root accesses in JIT compiled code.
500 TypeToLiteralMap jit_class_patches_;
Alexey Frunze19f6c692016-11-30 19:19:55 -0800501
Alexey Frunze4dda3372015-06-01 18:31:49 -0700502 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorMIPS64);
503};
504
505} // namespace mips64
506} // namespace art
507
508#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS64_H_