Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1 | /* |
| 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" |
| 21 | #include "dex/compiler_enums.h" |
| 22 | #include "driver/compiler_options.h" |
| 23 | #include "nodes.h" |
| 24 | #include "parallel_move_resolver.h" |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 25 | #include "string_reference.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 26 | #include "utils/mips/assembler_mips.h" |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 27 | #include "utils/type_reference.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 28 | |
| 29 | namespace art { |
| 30 | namespace mips { |
| 31 | |
| 32 | // InvokeDexCallingConvention registers |
| 33 | |
| 34 | static constexpr Register kParameterCoreRegisters[] = |
| 35 | { A1, A2, A3 }; |
| 36 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
| 37 | |
| 38 | static constexpr FRegister kParameterFpuRegisters[] = |
| 39 | { F12, F14 }; |
| 40 | static constexpr size_t kParameterFpuRegistersLength = arraysize(kParameterFpuRegisters); |
| 41 | |
| 42 | |
| 43 | // InvokeRuntimeCallingConvention registers |
| 44 | |
| 45 | static constexpr Register kRuntimeParameterCoreRegisters[] = |
| 46 | { A0, A1, A2, A3 }; |
| 47 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 48 | arraysize(kRuntimeParameterCoreRegisters); |
| 49 | |
| 50 | static constexpr FRegister kRuntimeParameterFpuRegisters[] = |
| 51 | { F12, F14}; |
| 52 | static constexpr size_t kRuntimeParameterFpuRegistersLength = |
| 53 | arraysize(kRuntimeParameterFpuRegisters); |
| 54 | |
| 55 | |
| 56 | static constexpr Register kCoreCalleeSaves[] = |
| 57 | { S0, S1, S2, S3, S4, S5, S6, S7, FP, RA }; |
| 58 | static constexpr FRegister kFpuCalleeSaves[] = |
| 59 | { F20, F22, F24, F26, F28, F30 }; |
| 60 | |
| 61 | |
| 62 | class CodeGeneratorMIPS; |
| 63 | |
| 64 | class 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 | |
| 77 | class 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 | |
| 92 | class 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 | |
| 107 | class 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 | |
| 135 | class 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 | |
| 155 | class SlowPathCodeMIPS : public SlowPathCode { |
| 156 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 157 | explicit SlowPathCodeMIPS(HInstruction* instruction) |
| 158 | : SlowPathCode(instruction), entry_label_(), exit_label_() {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 159 | |
| 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 | |
| 170 | class 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 Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 191 | void HandleCondition(HCondition* instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 192 | void HandleShift(HBinaryOperation* operation); |
| 193 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); |
| 194 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
| 195 | |
| 196 | InvokeDexCallingConventionVisitorMIPS parameter_visitor_; |
| 197 | |
| 198 | CodeGeneratorMIPS* const codegen_; |
| 199 | |
| 200 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderMIPS); |
| 201 | }; |
| 202 | |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 203 | class InstructionCodeGeneratorMIPS : public InstructionCodeGenerator { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 204 | public: |
| 205 | InstructionCodeGeneratorMIPS(HGraph* graph, CodeGeneratorMIPS* codegen); |
| 206 | |
| 207 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| 208 | void Visit##name(H##name* instr) OVERRIDE; |
| 209 | |
| 210 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 211 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(DECLARE_VISIT_INSTRUCTION) |
| 212 | |
| 213 | #undef DECLARE_VISIT_INSTRUCTION |
| 214 | |
| 215 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 216 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 217 | << " (id " << instruction->GetId() << ")"; |
| 218 | } |
| 219 | |
| 220 | MipsAssembler* GetAssembler() const { return assembler_; } |
| 221 | |
| 222 | private: |
| 223 | void GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, Register class_reg); |
| 224 | void GenerateMemoryBarrier(MemBarrierKind kind); |
| 225 | void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor); |
| 226 | void HandleBinaryOp(HBinaryOperation* operation); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 227 | void HandleCondition(HCondition* instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 228 | void HandleShift(HBinaryOperation* operation); |
| 229 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info, uint32_t dex_pc); |
| 230 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info, uint32_t dex_pc); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 231 | // Generate a GC root reference load: |
| 232 | // |
| 233 | // root <- *(obj + offset) |
| 234 | // |
| 235 | // while honoring read barriers (if any). |
| 236 | void GenerateGcRootFieldLoad(HInstruction* instruction, |
| 237 | Location root, |
| 238 | Register obj, |
| 239 | uint32_t offset); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 240 | void GenerateIntCompare(IfCondition cond, LocationSummary* locations); |
| 241 | void GenerateIntCompareAndBranch(IfCondition cond, |
| 242 | LocationSummary* locations, |
| 243 | MipsLabel* label); |
| 244 | void GenerateLongCompareAndBranch(IfCondition cond, |
| 245 | LocationSummary* locations, |
| 246 | MipsLabel* label); |
| 247 | void GenerateFpCompareAndBranch(IfCondition cond, |
| 248 | bool gt_bias, |
| 249 | Primitive::Type type, |
| 250 | LocationSummary* locations, |
| 251 | MipsLabel* label); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 252 | void GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 253 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 254 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 255 | MipsLabel* false_target); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 256 | void DivRemOneOrMinusOne(HBinaryOperation* instruction); |
| 257 | void DivRemByPowerOfTwo(HBinaryOperation* instruction); |
| 258 | void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); |
| 259 | void GenerateDivRemIntegral(HBinaryOperation* instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 260 | void HandleGoto(HInstruction* got, HBasicBlock* successor); |
| 261 | |
| 262 | MipsAssembler* const assembler_; |
| 263 | CodeGeneratorMIPS* const codegen_; |
| 264 | |
| 265 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorMIPS); |
| 266 | }; |
| 267 | |
| 268 | class CodeGeneratorMIPS : public CodeGenerator { |
| 269 | public: |
| 270 | CodeGeneratorMIPS(HGraph* graph, |
| 271 | const MipsInstructionSetFeatures& isa_features, |
| 272 | const CompilerOptions& compiler_options, |
| 273 | OptimizingCompilerStats* stats = nullptr); |
| 274 | virtual ~CodeGeneratorMIPS() {} |
| 275 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 276 | void ComputeSpillMask() OVERRIDE; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 277 | void GenerateFrameEntry() OVERRIDE; |
| 278 | void GenerateFrameExit() OVERRIDE; |
| 279 | |
| 280 | void Bind(HBasicBlock* block) OVERRIDE; |
| 281 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 282 | void Move32(Location destination, Location source); |
| 283 | void Move64(Location destination, Location source); |
| 284 | void MoveConstant(Location location, HConstant* c); |
| 285 | |
| 286 | size_t GetWordSize() const OVERRIDE { return kMipsWordSize; } |
| 287 | |
| 288 | size_t GetFloatingPointSpillSlotSize() const OVERRIDE { return kMipsDoublewordSize; } |
| 289 | |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 290 | uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 291 | return assembler_.GetLabelLocation(GetLabelOf(block)); |
| 292 | } |
| 293 | |
| 294 | HGraphVisitor* GetLocationBuilder() OVERRIDE { return &location_builder_; } |
| 295 | HGraphVisitor* GetInstructionVisitor() OVERRIDE { return &instruction_visitor_; } |
| 296 | MipsAssembler* GetAssembler() OVERRIDE { return &assembler_; } |
| 297 | const MipsAssembler& GetAssembler() const OVERRIDE { return assembler_; } |
| 298 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 299 | // Emit linker patches. |
| 300 | void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE; |
| 301 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 302 | void MarkGCCard(Register object, Register value); |
| 303 | |
| 304 | // Register allocation. |
| 305 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 306 | void SetupBlockedRegisters() const OVERRIDE; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 307 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 308 | size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id); |
| 309 | size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id); |
| 310 | size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id); |
| 311 | size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 312 | void ClobberRA() { |
| 313 | clobbered_ra_ = true; |
| 314 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 315 | |
| 316 | void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 317 | void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 318 | |
| 319 | // Blocks all register pairs made out of blocked core registers. |
| 320 | void UpdateBlockedPairRegisters() const; |
| 321 | |
| 322 | InstructionSet GetInstructionSet() const OVERRIDE { return InstructionSet::kMips; } |
| 323 | |
| 324 | const MipsInstructionSetFeatures& GetInstructionSetFeatures() const { |
| 325 | return isa_features_; |
| 326 | } |
| 327 | |
| 328 | MipsLabel* GetLabelOf(HBasicBlock* block) const { |
| 329 | return CommonGetLabelOf<MipsLabel>(block_labels_, block); |
| 330 | } |
| 331 | |
| 332 | void Initialize() OVERRIDE { |
| 333 | block_labels_ = CommonInitializeLabels<MipsLabel>(); |
| 334 | } |
| 335 | |
| 336 | void Finalize(CodeAllocator* allocator) OVERRIDE; |
| 337 | |
| 338 | // Code generation helpers. |
| 339 | |
| 340 | void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE; |
| 341 | |
| 342 | void MoveConstant(Location destination, int32_t value); |
| 343 | |
| 344 | void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE; |
| 345 | |
| 346 | // Generate code to invoke a runtime entry point. |
| 347 | void InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 348 | HInstruction* instruction, |
| 349 | uint32_t dex_pc, |
| 350 | SlowPathCode* slow_path) OVERRIDE; |
| 351 | |
| 352 | void InvokeRuntime(int32_t offset, |
| 353 | HInstruction* instruction, |
| 354 | uint32_t dex_pc, |
| 355 | SlowPathCode* slow_path, |
| 356 | bool is_direct_entrypoint); |
| 357 | |
| 358 | ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; } |
| 359 | |
| 360 | bool NeedsTwoRegisters(Primitive::Type type) const { |
| 361 | return type == Primitive::kPrimLong; |
| 362 | } |
| 363 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 364 | // Check if the desired_string_load_kind is supported. If it is, return it, |
| 365 | // otherwise return a fall-back kind that should be used instead. |
| 366 | HLoadString::LoadKind GetSupportedLoadStringKind( |
| 367 | HLoadString::LoadKind desired_string_load_kind) OVERRIDE; |
| 368 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 369 | // Check if the desired_class_load_kind is supported. If it is, return it, |
| 370 | // otherwise return a fall-back kind that should be used instead. |
| 371 | HLoadClass::LoadKind GetSupportedLoadClassKind( |
| 372 | HLoadClass::LoadKind desired_class_load_kind) OVERRIDE; |
| 373 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 374 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 375 | // otherwise return a fall-back info that should be used instead. |
| 376 | HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch( |
| 377 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 378 | MethodReference target_method) OVERRIDE; |
| 379 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 380 | void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 381 | void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 382 | |
| 383 | void MoveFromReturnRegister(Location trg ATTRIBUTE_UNUSED, |
| 384 | Primitive::Type type ATTRIBUTE_UNUSED) OVERRIDE { |
| 385 | UNIMPLEMENTED(FATAL) << "Not implemented on MIPS"; |
| 386 | } |
| 387 | |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 388 | void GenerateNop(); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 389 | void GenerateImplicitNullCheck(HNullCheck* instruction); |
| 390 | void GenerateExplicitNullCheck(HNullCheck* instruction); |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 391 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 392 | // The PcRelativePatchInfo is used for PC-relative addressing of dex cache arrays |
| 393 | // and boot image strings. The only difference is the interpretation of the offset_or_index. |
| 394 | struct PcRelativePatchInfo { |
| 395 | PcRelativePatchInfo(const DexFile& dex_file, uint32_t off_or_idx) |
| 396 | : target_dex_file(dex_file), offset_or_index(off_or_idx) { } |
| 397 | PcRelativePatchInfo(PcRelativePatchInfo&& other) = default; |
| 398 | |
| 399 | const DexFile& target_dex_file; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 400 | // Either the dex cache array element offset or the string/type index. |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 401 | uint32_t offset_or_index; |
| 402 | // Label for the instruction loading the most significant half of the offset that's added to PC |
| 403 | // to form the base address (the least significant half is loaded with the instruction that |
| 404 | // follows). |
| 405 | MipsLabel high_label; |
| 406 | // Label for the instruction corresponding to PC+0. |
| 407 | MipsLabel pc_rel_label; |
| 408 | }; |
| 409 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 410 | PcRelativePatchInfo* NewPcRelativeStringPatch(const DexFile& dex_file, uint32_t string_index); |
| 411 | PcRelativePatchInfo* NewPcRelativeTypePatch(const DexFile& dex_file, uint32_t type_index); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 412 | PcRelativePatchInfo* NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 413 | uint32_t element_offset); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 414 | Literal* DeduplicateBootImageStringLiteral(const DexFile& dex_file, uint32_t string_index); |
| 415 | Literal* DeduplicateBootImageTypeLiteral(const DexFile& dex_file, uint32_t type_index); |
| 416 | Literal* DeduplicateBootImageAddressLiteral(uint32_t address); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 417 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 418 | private: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 419 | Register GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, Register temp); |
| 420 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 421 | using Uint32ToLiteralMap = ArenaSafeMap<uint32_t, Literal*>; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 422 | using MethodToLiteralMap = ArenaSafeMap<MethodReference, Literal*, MethodReferenceComparator>; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 423 | using BootStringToLiteralMap = ArenaSafeMap<StringReference, |
| 424 | Literal*, |
| 425 | StringReferenceValueComparator>; |
| 426 | using BootTypeToLiteralMap = ArenaSafeMap<TypeReference, |
| 427 | Literal*, |
| 428 | TypeReferenceValueComparator>; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 429 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 430 | Literal* DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 431 | Literal* DeduplicateMethodLiteral(MethodReference target_method, MethodToLiteralMap* map); |
| 432 | Literal* DeduplicateMethodAddressLiteral(MethodReference target_method); |
| 433 | Literal* DeduplicateMethodCodeLiteral(MethodReference target_method); |
| 434 | PcRelativePatchInfo* NewPcRelativePatch(const DexFile& dex_file, |
| 435 | uint32_t offset_or_index, |
| 436 | ArenaDeque<PcRelativePatchInfo>* patches); |
| 437 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 438 | // Labels for each block that will be compiled. |
| 439 | MipsLabel* block_labels_; |
| 440 | MipsLabel frame_entry_label_; |
| 441 | LocationsBuilderMIPS location_builder_; |
| 442 | InstructionCodeGeneratorMIPS instruction_visitor_; |
| 443 | ParallelMoveResolverMIPS move_resolver_; |
| 444 | MipsAssembler assembler_; |
| 445 | const MipsInstructionSetFeatures& isa_features_; |
| 446 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 447 | // Deduplication map for 32-bit literals, used for non-patchable boot image addresses. |
| 448 | Uint32ToLiteralMap uint32_literals_; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 449 | // Method patch info, map MethodReference to a literal for method address and method code. |
| 450 | MethodToLiteralMap method_patches_; |
| 451 | MethodToLiteralMap call_patches_; |
| 452 | // PC-relative patch info for each HMipsDexCacheArraysBase. |
| 453 | ArenaDeque<PcRelativePatchInfo> pc_relative_dex_cache_patches_; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame^] | 454 | // Deduplication map for boot string literals for kBootImageLinkTimeAddress. |
| 455 | BootStringToLiteralMap boot_image_string_patches_; |
| 456 | // PC-relative String patch info. |
| 457 | ArenaDeque<PcRelativePatchInfo> pc_relative_string_patches_; |
| 458 | // Deduplication map for boot type literals for kBootImageLinkTimeAddress. |
| 459 | BootTypeToLiteralMap boot_image_type_patches_; |
| 460 | // PC-relative type patch info. |
| 461 | ArenaDeque<PcRelativePatchInfo> pc_relative_type_patches_; |
| 462 | // Deduplication map for patchable boot image addresses. |
| 463 | Uint32ToLiteralMap boot_image_address_patches_; |
| 464 | |
| 465 | // PC-relative loads on R2 clobber RA, which may need to be preserved explicitly in leaf methods. |
| 466 | // This is a flag set by pc_relative_fixups_mips and dex_cache_array_fixups_mips optimizations. |
| 467 | bool clobbered_ra_; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 468 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 469 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorMIPS); |
| 470 | }; |
| 471 | |
| 472 | } // namespace mips |
| 473 | } // namespace art |
| 474 | |
| 475 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS_H_ |