blob: 9a9a8380cbfe6d59f93ed56e84ab2c394ecc1f6d [file] [log] [blame]
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001/*
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_MIPS_H_
18#define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS_H_
19
20#include "code_generator.h"
Andreas Gampe8a0128a2016-11-28 07:38:35 -080021#include "dex_file_types.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020022#include "driver/compiler_options.h"
23#include "nodes.h"
24#include "parallel_move_resolver.h"
Alexey Frunze06a46c42016-07-19 15:00:40 -070025#include "string_reference.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020026#include "utils/mips/assembler_mips.h"
Alexey Frunze06a46c42016-07-19 15:00:40 -070027#include "utils/type_reference.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020028
29namespace art {
30namespace mips {
31
32// InvokeDexCallingConvention registers
33
34static constexpr Register kParameterCoreRegisters[] =
Alexey Frunze1b8464d2016-11-12 17:22:05 -080035 { A1, A2, A3, T0, T1 };
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020036static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters);
37
38static constexpr FRegister kParameterFpuRegisters[] =
Alexey Frunze1b8464d2016-11-12 17:22:05 -080039 { F8, F10, F12, F14, F16, F18 };
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020040static constexpr size_t kParameterFpuRegistersLength = arraysize(kParameterFpuRegisters);
41
42
43// InvokeRuntimeCallingConvention registers
44
45static constexpr Register kRuntimeParameterCoreRegisters[] =
46 { A0, A1, A2, A3 };
47static constexpr size_t kRuntimeParameterCoreRegistersLength =
48 arraysize(kRuntimeParameterCoreRegisters);
49
50static constexpr FRegister kRuntimeParameterFpuRegisters[] =
Alexey Frunze1b8464d2016-11-12 17:22:05 -080051 { F12, F14 };
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020052static constexpr size_t kRuntimeParameterFpuRegistersLength =
53 arraysize(kRuntimeParameterFpuRegisters);
54
55
56static constexpr Register kCoreCalleeSaves[] =
57 { S0, S1, S2, S3, S4, S5, S6, S7, FP, RA };
58static constexpr FRegister kFpuCalleeSaves[] =
59 { F20, F22, F24, F26, F28, F30 };
60
61
62class CodeGeneratorMIPS;
63
64class InvokeDexCallingConvention : public CallingConvention<Register, FRegister> {
65 public:
66 InvokeDexCallingConvention()
67 : CallingConvention(kParameterCoreRegisters,
68 kParameterCoreRegistersLength,
69 kParameterFpuRegisters,
70 kParameterFpuRegistersLength,
71 kMipsPointerSize) {}
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention);
75};
76
77class InvokeDexCallingConventionVisitorMIPS : public InvokeDexCallingConventionVisitor {
78 public:
79 InvokeDexCallingConventionVisitorMIPS() {}
80 virtual ~InvokeDexCallingConventionVisitorMIPS() {}
81
82 Location GetNextLocation(Primitive::Type type) OVERRIDE;
83 Location GetReturnLocation(Primitive::Type type) const OVERRIDE;
84 Location GetMethodLocation() const OVERRIDE;
85
86 private:
87 InvokeDexCallingConvention calling_convention;
88
89 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorMIPS);
90};
91
92class InvokeRuntimeCallingConvention : public CallingConvention<Register, FRegister> {
93 public:
94 InvokeRuntimeCallingConvention()
95 : CallingConvention(kRuntimeParameterCoreRegisters,
96 kRuntimeParameterCoreRegistersLength,
97 kRuntimeParameterFpuRegisters,
98 kRuntimeParameterFpuRegistersLength,
99 kMipsPointerSize) {}
100
101 Location GetReturnLocation(Primitive::Type return_type);
102
103 private:
104 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
105};
106
107class FieldAccessCallingConventionMIPS : public FieldAccessCallingConvention {
108 public:
109 FieldAccessCallingConventionMIPS() {}
110
111 Location GetObjectLocation() const OVERRIDE {
112 return Location::RegisterLocation(A1);
113 }
114 Location GetFieldIndexLocation() const OVERRIDE {
115 return Location::RegisterLocation(A0);
116 }
117 Location GetReturnLocation(Primitive::Type type) const OVERRIDE {
118 return Primitive::Is64BitType(type)
119 ? Location::RegisterPairLocation(V0, V1)
120 : Location::RegisterLocation(V0);
121 }
122 Location GetSetValueLocation(Primitive::Type type, bool is_instance) const OVERRIDE {
123 return Primitive::Is64BitType(type)
124 ? Location::RegisterPairLocation(A2, A3)
125 : (is_instance ? Location::RegisterLocation(A2) : Location::RegisterLocation(A1));
126 }
127 Location GetFpuLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
128 return Location::FpuRegisterLocation(F0);
129 }
130
131 private:
132 DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionMIPS);
133};
134
135class ParallelMoveResolverMIPS : public ParallelMoveResolverWithSwap {
136 public:
137 ParallelMoveResolverMIPS(ArenaAllocator* allocator, CodeGeneratorMIPS* codegen)
138 : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {}
139
140 void EmitMove(size_t index) OVERRIDE;
141 void EmitSwap(size_t index) OVERRIDE;
142 void SpillScratch(int reg) OVERRIDE;
143 void RestoreScratch(int reg) OVERRIDE;
144
145 void Exchange(int index1, int index2, bool double_slot);
146
147 MipsAssembler* GetAssembler() const;
148
149 private:
150 CodeGeneratorMIPS* const codegen_;
151
152 DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverMIPS);
153};
154
155class SlowPathCodeMIPS : public SlowPathCode {
156 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000157 explicit SlowPathCodeMIPS(HInstruction* instruction)
158 : SlowPathCode(instruction), entry_label_(), exit_label_() {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200159
160 MipsLabel* GetEntryLabel() { return &entry_label_; }
161 MipsLabel* GetExitLabel() { return &exit_label_; }
162
163 private:
164 MipsLabel entry_label_;
165 MipsLabel exit_label_;
166
167 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeMIPS);
168};
169
170class LocationsBuilderMIPS : public HGraphVisitor {
171 public:
172 LocationsBuilderMIPS(HGraph* graph, CodeGeneratorMIPS* codegen)
173 : HGraphVisitor(graph), codegen_(codegen) {}
174
175#define DECLARE_VISIT_INSTRUCTION(name, super) \
176 void Visit##name(H##name* instr) OVERRIDE;
177
178 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
179 FOR_EACH_CONCRETE_INSTRUCTION_MIPS(DECLARE_VISIT_INSTRUCTION)
180
181#undef DECLARE_VISIT_INSTRUCTION
182
183 void VisitInstruction(HInstruction* instruction) OVERRIDE {
184 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
185 << " (id " << instruction->GetId() << ")";
186 }
187
188 private:
189 void HandleInvoke(HInvoke* invoke);
190 void HandleBinaryOp(HBinaryOperation* operation);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000191 void HandleCondition(HCondition* instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200192 void HandleShift(HBinaryOperation* operation);
193 void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info);
194 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Alexey Frunzef58b2482016-09-02 22:14:06 -0700195 Location RegisterOrZeroConstant(HInstruction* instruction);
196 Location FpuRegisterOrConstantForStore(HInstruction* instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200197
198 InvokeDexCallingConventionVisitorMIPS parameter_visitor_;
199
200 CodeGeneratorMIPS* const codegen_;
201
202 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderMIPS);
203};
204
Aart Bik42249c32016-01-07 15:33:50 -0800205class InstructionCodeGeneratorMIPS : public InstructionCodeGenerator {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200206 public:
207 InstructionCodeGeneratorMIPS(HGraph* graph, CodeGeneratorMIPS* codegen);
208
209#define DECLARE_VISIT_INSTRUCTION(name, super) \
210 void Visit##name(H##name* instr) OVERRIDE;
211
212 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
213 FOR_EACH_CONCRETE_INSTRUCTION_MIPS(DECLARE_VISIT_INSTRUCTION)
214
215#undef DECLARE_VISIT_INSTRUCTION
216
217 void VisitInstruction(HInstruction* instruction) OVERRIDE {
218 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
219 << " (id " << instruction->GetId() << ")";
220 }
221
222 MipsAssembler* GetAssembler() const { return assembler_; }
223
Alexey Frunze96b66822016-09-10 02:32:44 -0700224 // 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
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200232 private:
233 void GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, Register class_reg);
234 void GenerateMemoryBarrier(MemBarrierKind kind);
235 void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor);
236 void HandleBinaryOp(HBinaryOperation* operation);
Vladimir Marko5f7b58e2015-11-23 19:49:34 +0000237 void HandleCondition(HCondition* instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200238 void HandleShift(HBinaryOperation* operation);
239 void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info, uint32_t dex_pc);
240 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info, uint32_t dex_pc);
Alexey Frunze06a46c42016-07-19 15:00:40 -0700241 // Generate a GC root reference load:
242 //
243 // root <- *(obj + offset)
244 //
245 // while honoring read barriers (if any).
246 void GenerateGcRootFieldLoad(HInstruction* instruction,
247 Location root,
248 Register obj,
249 uint32_t offset);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800250 void GenerateIntCompare(IfCondition cond, LocationSummary* locations);
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700251 // When the function returns `false` it means that the condition holds if `dst` is non-zero
252 // and doesn't hold if `dst` is zero. If it returns `true`, the roles of zero and non-zero
253 // `dst` are exchanged.
254 bool MaterializeIntCompare(IfCondition cond,
255 LocationSummary* input_locations,
256 Register dst);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800257 void GenerateIntCompareAndBranch(IfCondition cond,
258 LocationSummary* locations,
259 MipsLabel* label);
260 void GenerateLongCompareAndBranch(IfCondition cond,
261 LocationSummary* locations,
262 MipsLabel* label);
Alexey Frunze2ddb7172016-09-06 17:04:55 -0700263 void GenerateFpCompare(IfCondition cond,
264 bool gt_bias,
265 Primitive::Type type,
266 LocationSummary* locations);
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700267 // When the function returns `false` it means that the condition holds if the condition
268 // code flag `cc` is non-zero and doesn't hold if `cc` is zero. If it returns `true`,
269 // the roles of zero and non-zero values of the `cc` flag are exchanged.
270 bool MaterializeFpCompareR2(IfCondition cond,
271 bool gt_bias,
272 Primitive::Type type,
273 LocationSummary* input_locations,
274 int cc);
275 // When the function returns `false` it means that the condition holds if `dst` is non-zero
276 // and doesn't hold if `dst` is zero. If it returns `true`, the roles of zero and non-zero
277 // `dst` are exchanged.
278 bool MaterializeFpCompareR6(IfCondition cond,
279 bool gt_bias,
280 Primitive::Type type,
281 LocationSummary* input_locations,
282 FRegister dst);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800283 void GenerateFpCompareAndBranch(IfCondition cond,
284 bool gt_bias,
285 Primitive::Type type,
286 LocationSummary* locations,
287 MipsLabel* label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200288 void GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +0000289 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200290 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +0000291 MipsLabel* false_target);
Alexey Frunze7e99e052015-11-24 19:28:01 -0800292 void DivRemOneOrMinusOne(HBinaryOperation* instruction);
293 void DivRemByPowerOfTwo(HBinaryOperation* instruction);
294 void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction);
295 void GenerateDivRemIntegral(HBinaryOperation* instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200296 void HandleGoto(HInstruction* got, HBasicBlock* successor);
Alexey Frunze2923db72016-08-20 01:55:47 -0700297 auto GetImplicitNullChecker(HInstruction* instruction);
Alexey Frunze96b66822016-09-10 02:32:44 -0700298 void GenPackedSwitchWithCompares(Register value_reg,
299 int32_t lower_bound,
300 uint32_t num_entries,
301 HBasicBlock* switch_block,
302 HBasicBlock* default_block);
303 void GenTableBasedPackedSwitch(Register value_reg,
304 Register constant_area,
305 int32_t lower_bound,
306 uint32_t num_entries,
307 HBasicBlock* switch_block,
308 HBasicBlock* default_block);
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700309 void GenConditionalMoveR2(HSelect* select);
310 void GenConditionalMoveR6(HSelect* select);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200311
312 MipsAssembler* const assembler_;
313 CodeGeneratorMIPS* const codegen_;
314
315 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorMIPS);
316};
317
318class CodeGeneratorMIPS : public CodeGenerator {
319 public:
320 CodeGeneratorMIPS(HGraph* graph,
321 const MipsInstructionSetFeatures& isa_features,
322 const CompilerOptions& compiler_options,
323 OptimizingCompilerStats* stats = nullptr);
324 virtual ~CodeGeneratorMIPS() {}
325
Alexey Frunze73296a72016-06-03 22:51:46 -0700326 void ComputeSpillMask() OVERRIDE;
Alexey Frunze58320ce2016-08-30 21:40:46 -0700327 bool HasAllocatedCalleeSaveRegisters() const OVERRIDE;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200328 void GenerateFrameEntry() OVERRIDE;
329 void GenerateFrameExit() OVERRIDE;
330
331 void Bind(HBasicBlock* block) OVERRIDE;
332
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200333 void Move32(Location destination, Location source);
334 void Move64(Location destination, Location source);
335 void MoveConstant(Location location, HConstant* c);
336
337 size_t GetWordSize() const OVERRIDE { return kMipsWordSize; }
338
339 size_t GetFloatingPointSpillSlotSize() const OVERRIDE { return kMipsDoublewordSize; }
340
Alexandre Ramesc01a6642016-04-15 11:54:06 +0100341 uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200342 return assembler_.GetLabelLocation(GetLabelOf(block));
343 }
344
345 HGraphVisitor* GetLocationBuilder() OVERRIDE { return &location_builder_; }
346 HGraphVisitor* GetInstructionVisitor() OVERRIDE { return &instruction_visitor_; }
347 MipsAssembler* GetAssembler() OVERRIDE { return &assembler_; }
348 const MipsAssembler& GetAssembler() const OVERRIDE { return assembler_; }
349
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700350 // Emit linker patches.
351 void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE;
352
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200353 void MarkGCCard(Register object, Register value);
354
355 // Register allocation.
356
David Brazdil58282f42016-01-14 12:45:10 +0000357 void SetupBlockedRegisters() const OVERRIDE;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200358
Roland Levillainf41f9562016-09-14 19:26:48 +0100359 size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
360 size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
361 size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
362 size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
Alexey Frunze06a46c42016-07-19 15:00:40 -0700363 void ClobberRA() {
364 clobbered_ra_ = true;
365 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200366
367 void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE;
368 void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE;
369
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200370 InstructionSet GetInstructionSet() const OVERRIDE { return InstructionSet::kMips; }
371
372 const MipsInstructionSetFeatures& GetInstructionSetFeatures() const {
373 return isa_features_;
374 }
375
376 MipsLabel* GetLabelOf(HBasicBlock* block) const {
377 return CommonGetLabelOf<MipsLabel>(block_labels_, block);
378 }
379
380 void Initialize() OVERRIDE {
381 block_labels_ = CommonInitializeLabels<MipsLabel>();
382 }
383
384 void Finalize(CodeAllocator* allocator) OVERRIDE;
385
386 // Code generation helpers.
387
388 void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE;
389
Roland Levillainf41f9562016-09-14 19:26:48 +0100390 void MoveConstant(Location destination, int32_t value) OVERRIDE;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200391
392 void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE;
393
394 // Generate code to invoke a runtime entry point.
395 void InvokeRuntime(QuickEntrypointEnum entrypoint,
396 HInstruction* instruction,
397 uint32_t dex_pc,
Serban Constantinescufca16662016-07-14 09:21:59 +0100398 SlowPathCode* slow_path = nullptr) OVERRIDE;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200399
400 ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; }
401
Roland Levillainf41f9562016-09-14 19:26:48 +0100402 bool NeedsTwoRegisters(Primitive::Type type) const OVERRIDE {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200403 return type == Primitive::kPrimLong;
404 }
405
Vladimir Markocac5a7e2016-02-22 10:39:50 +0000406 // Check if the desired_string_load_kind is supported. If it is, return it,
407 // otherwise return a fall-back kind that should be used instead.
408 HLoadString::LoadKind GetSupportedLoadStringKind(
409 HLoadString::LoadKind desired_string_load_kind) OVERRIDE;
410
Vladimir Markodbb7f5b2016-03-30 13:23:58 +0100411 // Check if the desired_class_load_kind is supported. If it is, return it,
412 // otherwise return a fall-back kind that should be used instead.
413 HLoadClass::LoadKind GetSupportedLoadClassKind(
414 HLoadClass::LoadKind desired_class_load_kind) OVERRIDE;
415
Vladimir Markodc151b22015-10-15 18:02:30 +0100416 // Check if the desired_dispatch_info is supported. If it is, return it,
417 // otherwise return a fall-back info that should be used instead.
418 HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch(
419 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +0100420 HInvokeStaticOrDirect* invoke) OVERRIDE;
Vladimir Markodc151b22015-10-15 18:02:30 +0100421
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200422 void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp);
Chris Larsen3acee732015-11-18 13:31:08 -0800423 void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200424
425 void MoveFromReturnRegister(Location trg ATTRIBUTE_UNUSED,
426 Primitive::Type type ATTRIBUTE_UNUSED) OVERRIDE {
427 UNIMPLEMENTED(FATAL) << "Not implemented on MIPS";
428 }
429
Roland Levillainf41f9562016-09-14 19:26:48 +0100430 void GenerateNop() OVERRIDE;
431 void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE;
432 void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE;
David Srbeckyc7098ff2016-02-09 14:30:11 +0000433
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700434 // The PcRelativePatchInfo is used for PC-relative addressing of dex cache arrays
435 // and boot image strings. The only difference is the interpretation of the offset_or_index.
436 struct PcRelativePatchInfo {
437 PcRelativePatchInfo(const DexFile& dex_file, uint32_t off_or_idx)
438 : target_dex_file(dex_file), offset_or_index(off_or_idx) { }
439 PcRelativePatchInfo(PcRelativePatchInfo&& other) = default;
440
441 const DexFile& target_dex_file;
Alexey Frunze06a46c42016-07-19 15:00:40 -0700442 // Either the dex cache array element offset or the string/type index.
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700443 uint32_t offset_or_index;
444 // Label for the instruction loading the most significant half of the offset that's added to PC
445 // to form the base address (the least significant half is loaded with the instruction that
446 // follows).
447 MipsLabel high_label;
448 // Label for the instruction corresponding to PC+0.
449 MipsLabel pc_rel_label;
450 };
451
Alexey Frunze06a46c42016-07-19 15:00:40 -0700452 PcRelativePatchInfo* NewPcRelativeStringPatch(const DexFile& dex_file, uint32_t string_index);
Andreas Gampea5b09a62016-11-17 15:21:22 -0800453 PcRelativePatchInfo* NewPcRelativeTypePatch(const DexFile& dex_file, dex::TypeIndex type_index);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700454 PcRelativePatchInfo* NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file,
455 uint32_t element_offset);
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800456 Literal* DeduplicateBootImageStringLiteral(const DexFile& dex_file,
457 dex::StringIndex string_index);
Andreas Gampea5b09a62016-11-17 15:21:22 -0800458 Literal* DeduplicateBootImageTypeLiteral(const DexFile& dex_file, dex::TypeIndex type_index);
Alexey Frunze06a46c42016-07-19 15:00:40 -0700459 Literal* DeduplicateBootImageAddressLiteral(uint32_t address);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700460
Vladimir Markoaad75c62016-10-03 08:46:48 +0000461 void EmitPcRelativeAddressPlaceholder(PcRelativePatchInfo* info, Register out, Register base);
462
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200463 private:
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700464 Register GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, Register temp);
465
Alexey Frunze06a46c42016-07-19 15:00:40 -0700466 using Uint32ToLiteralMap = ArenaSafeMap<uint32_t, Literal*>;
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700467 using MethodToLiteralMap = ArenaSafeMap<MethodReference, Literal*, MethodReferenceComparator>;
Alexey Frunze06a46c42016-07-19 15:00:40 -0700468 using BootStringToLiteralMap = ArenaSafeMap<StringReference,
469 Literal*,
470 StringReferenceValueComparator>;
471 using BootTypeToLiteralMap = ArenaSafeMap<TypeReference,
472 Literal*,
473 TypeReferenceValueComparator>;
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700474
Alexey Frunze06a46c42016-07-19 15:00:40 -0700475 Literal* DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700476 Literal* DeduplicateMethodLiteral(MethodReference target_method, MethodToLiteralMap* map);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700477 PcRelativePatchInfo* NewPcRelativePatch(const DexFile& dex_file,
478 uint32_t offset_or_index,
479 ArenaDeque<PcRelativePatchInfo>* patches);
480
Vladimir Markoaad75c62016-10-03 08:46:48 +0000481 template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
482 void EmitPcRelativeLinkerPatches(const ArenaDeque<PcRelativePatchInfo>& infos,
483 ArenaVector<LinkerPatch>* linker_patches);
484
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200485 // Labels for each block that will be compiled.
486 MipsLabel* block_labels_;
487 MipsLabel frame_entry_label_;
488 LocationsBuilderMIPS location_builder_;
489 InstructionCodeGeneratorMIPS instruction_visitor_;
490 ParallelMoveResolverMIPS move_resolver_;
491 MipsAssembler assembler_;
492 const MipsInstructionSetFeatures& isa_features_;
493
Alexey Frunze06a46c42016-07-19 15:00:40 -0700494 // Deduplication map for 32-bit literals, used for non-patchable boot image addresses.
495 Uint32ToLiteralMap uint32_literals_;
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700496 // PC-relative patch info for each HMipsDexCacheArraysBase.
497 ArenaDeque<PcRelativePatchInfo> pc_relative_dex_cache_patches_;
Alexey Frunze06a46c42016-07-19 15:00:40 -0700498 // Deduplication map for boot string literals for kBootImageLinkTimeAddress.
499 BootStringToLiteralMap boot_image_string_patches_;
Vladimir Markoaad75c62016-10-03 08:46:48 +0000500 // PC-relative String patch info; type depends on configuration (app .bss or boot image PIC).
Alexey Frunze06a46c42016-07-19 15:00:40 -0700501 ArenaDeque<PcRelativePatchInfo> pc_relative_string_patches_;
502 // Deduplication map for boot type literals for kBootImageLinkTimeAddress.
503 BootTypeToLiteralMap boot_image_type_patches_;
504 // PC-relative type patch info.
505 ArenaDeque<PcRelativePatchInfo> pc_relative_type_patches_;
506 // Deduplication map for patchable boot image addresses.
507 Uint32ToLiteralMap boot_image_address_patches_;
508
509 // PC-relative loads on R2 clobber RA, which may need to be preserved explicitly in leaf methods.
510 // This is a flag set by pc_relative_fixups_mips and dex_cache_array_fixups_mips optimizations.
511 bool clobbered_ra_;
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700512
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200513 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorMIPS);
514};
515
516} // namespace mips
517} // namespace art
518
519#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS_H_