Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [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_MIPS64_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS64_H_ |
| 19 | |
| 20 | #include "code_generator.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 21 | #include "driver/compiler_options.h" |
| 22 | #include "nodes.h" |
| 23 | #include "parallel_move_resolver.h" |
| 24 | #include "utils/mips64/assembler_mips64.h" |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 25 | #include "utils/type_reference.h" |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | namespace mips64 { |
| 29 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 30 | // InvokeDexCallingConvention registers |
| 31 | |
| 32 | static constexpr GpuRegister kParameterCoreRegisters[] = |
| 33 | { A1, A2, A3, A4, A5, A6, A7 }; |
| 34 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
| 35 | |
| 36 | static constexpr FpuRegister kParameterFpuRegisters[] = |
| 37 | { F13, F14, F15, F16, F17, F18, F19 }; |
| 38 | static constexpr size_t kParameterFpuRegistersLength = arraysize(kParameterFpuRegisters); |
| 39 | |
| 40 | |
| 41 | // InvokeRuntimeCallingConvention registers |
| 42 | |
| 43 | static constexpr GpuRegister kRuntimeParameterCoreRegisters[] = |
| 44 | { A0, A1, A2, A3, A4, A5, A6, A7 }; |
| 45 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 46 | arraysize(kRuntimeParameterCoreRegisters); |
| 47 | |
| 48 | static constexpr FpuRegister kRuntimeParameterFpuRegisters[] = |
| 49 | { F12, F13, F14, F15, F16, F17, F18, F19 }; |
| 50 | static constexpr size_t kRuntimeParameterFpuRegistersLength = |
| 51 | arraysize(kRuntimeParameterFpuRegisters); |
| 52 | |
| 53 | |
| 54 | static constexpr GpuRegister kCoreCalleeSaves[] = |
| 55 | { S0, S1, S2, S3, S4, S5, S6, S7, GP, S8, RA }; // TODO: review |
| 56 | static constexpr FpuRegister kFpuCalleeSaves[] = |
| 57 | { F24, F25, F26, F27, F28, F29, F30, F31 }; |
| 58 | |
| 59 | |
| 60 | class CodeGeneratorMIPS64; |
| 61 | |
| 62 | class 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 | |
| 75 | class 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 | |
| 90 | class 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 Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 105 | class 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 Jakovljevic | 8c34ec1 | 2015-10-14 11:23:48 +0200 | [diff] [blame] | 116 | return Location::RegisterLocation(V0); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 117 | } |
Alexey Frunze | 00580bd | 2015-11-11 13:31:12 -0800 | [diff] [blame] | 118 | Location GetSetValueLocation(Primitive::Type type, bool is_instance) const OVERRIDE { |
| 119 | return Primitive::Is64BitType(type) |
| 120 | ? Location::RegisterLocation(A2) |
| 121 | : (is_instance |
| 122 | ? Location::RegisterLocation(A2) |
| 123 | : Location::RegisterLocation(A1)); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 124 | } |
| 125 | Location GetFpuLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { |
| 126 | return Location::FpuRegisterLocation(F0); |
| 127 | } |
| 128 | |
| 129 | private: |
| 130 | DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionMIPS64); |
| 131 | }; |
| 132 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 133 | class ParallelMoveResolverMIPS64 : public ParallelMoveResolverWithSwap { |
| 134 | public: |
| 135 | ParallelMoveResolverMIPS64(ArenaAllocator* allocator, CodeGeneratorMIPS64* codegen) |
| 136 | : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {} |
| 137 | |
| 138 | void EmitMove(size_t index) OVERRIDE; |
| 139 | void EmitSwap(size_t index) OVERRIDE; |
| 140 | void SpillScratch(int reg) OVERRIDE; |
| 141 | void RestoreScratch(int reg) OVERRIDE; |
| 142 | |
| 143 | void Exchange(int index1, int index2, bool double_slot); |
| 144 | |
| 145 | Mips64Assembler* GetAssembler() const; |
| 146 | |
| 147 | private: |
| 148 | CodeGeneratorMIPS64* const codegen_; |
| 149 | |
| 150 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverMIPS64); |
| 151 | }; |
| 152 | |
| 153 | class SlowPathCodeMIPS64 : public SlowPathCode { |
| 154 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 155 | explicit SlowPathCodeMIPS64(HInstruction* instruction) |
| 156 | : SlowPathCode(instruction), entry_label_(), exit_label_() {} |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 157 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 158 | Mips64Label* GetEntryLabel() { return &entry_label_; } |
| 159 | Mips64Label* GetExitLabel() { return &exit_label_; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 160 | |
| 161 | private: |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 162 | Mips64Label entry_label_; |
| 163 | Mips64Label exit_label_; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 164 | |
| 165 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeMIPS64); |
| 166 | }; |
| 167 | |
| 168 | class LocationsBuilderMIPS64 : public HGraphVisitor { |
| 169 | public: |
| 170 | LocationsBuilderMIPS64(HGraph* graph, CodeGeneratorMIPS64* codegen) |
| 171 | : HGraphVisitor(graph), codegen_(codegen) {} |
| 172 | |
| 173 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 174 | void Visit##name(H##name* instr) OVERRIDE; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 175 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 176 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 177 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(DECLARE_VISIT_INSTRUCTION) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 178 | |
| 179 | #undef DECLARE_VISIT_INSTRUCTION |
| 180 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 181 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 182 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 183 | << " (id " << instruction->GetId() << ")"; |
| 184 | } |
| 185 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 186 | private: |
| 187 | void HandleInvoke(HInvoke* invoke); |
| 188 | void HandleBinaryOp(HBinaryOperation* operation); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 189 | void HandleCondition(HCondition* instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 190 | void HandleShift(HBinaryOperation* operation); |
| 191 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); |
| 192 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
| 193 | |
| 194 | InvokeDexCallingConventionVisitorMIPS64 parameter_visitor_; |
| 195 | |
| 196 | CodeGeneratorMIPS64* const codegen_; |
| 197 | |
| 198 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderMIPS64); |
| 199 | }; |
| 200 | |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 201 | class InstructionCodeGeneratorMIPS64 : public InstructionCodeGenerator { |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 202 | public: |
| 203 | InstructionCodeGeneratorMIPS64(HGraph* graph, CodeGeneratorMIPS64* codegen); |
| 204 | |
| 205 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 206 | void Visit##name(H##name* instr) OVERRIDE; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 207 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 208 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 209 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(DECLARE_VISIT_INSTRUCTION) |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 210 | |
| 211 | #undef DECLARE_VISIT_INSTRUCTION |
| 212 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 213 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 214 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 215 | << " (id " << instruction->GetId() << ")"; |
| 216 | } |
| 217 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 218 | Mips64Assembler* GetAssembler() const { return assembler_; } |
| 219 | |
| 220 | private: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 221 | void GenerateClassInitializationCheck(SlowPathCodeMIPS64* slow_path, GpuRegister class_reg); |
| 222 | void GenerateMemoryBarrier(MemBarrierKind kind); |
| 223 | void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor); |
| 224 | void HandleBinaryOp(HBinaryOperation* operation); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 225 | void HandleCondition(HCondition* instruction); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 226 | void HandleShift(HBinaryOperation* operation); |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 227 | void HandleFieldSet(HInstruction* instruction, |
| 228 | const FieldInfo& field_info, |
| 229 | bool value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 230 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [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 | GpuRegister obj, |
| 239 | uint32_t offset); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 240 | void GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 241 | size_t condition_input_index, |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 242 | Mips64Label* true_target, |
| 243 | Mips64Label* false_target); |
Alexey Frunze | c857c74 | 2015-09-23 15:12:39 -0700 | [diff] [blame] | 244 | void DivRemOneOrMinusOne(HBinaryOperation* instruction); |
| 245 | void DivRemByPowerOfTwo(HBinaryOperation* instruction); |
| 246 | void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); |
| 247 | void GenerateDivRemIntegral(HBinaryOperation* instruction); |
Alexey Frunze | 299a939 | 2015-12-08 16:08:02 -0800 | [diff] [blame] | 248 | void GenerateIntLongCompare(IfCondition cond, bool is64bit, LocationSummary* locations); |
| 249 | void GenerateIntLongCompareAndBranch(IfCondition cond, |
| 250 | bool is64bit, |
| 251 | LocationSummary* locations, |
| 252 | Mips64Label* label); |
| 253 | void GenerateFpCompareAndBranch(IfCondition cond, |
| 254 | bool gt_bias, |
| 255 | Primitive::Type type, |
| 256 | LocationSummary* locations, |
| 257 | Mips64Label* label); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 258 | void HandleGoto(HInstruction* got, HBasicBlock* successor); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 259 | |
| 260 | Mips64Assembler* const assembler_; |
| 261 | CodeGeneratorMIPS64* const codegen_; |
| 262 | |
| 263 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorMIPS64); |
| 264 | }; |
| 265 | |
| 266 | class CodeGeneratorMIPS64 : public CodeGenerator { |
| 267 | public: |
| 268 | CodeGeneratorMIPS64(HGraph* graph, |
| 269 | const Mips64InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 270 | const CompilerOptions& compiler_options, |
| 271 | OptimizingCompilerStats* stats = nullptr); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 272 | virtual ~CodeGeneratorMIPS64() {} |
| 273 | |
| 274 | void GenerateFrameEntry() OVERRIDE; |
| 275 | void GenerateFrameExit() OVERRIDE; |
| 276 | |
| 277 | void Bind(HBasicBlock* block) OVERRIDE; |
| 278 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 279 | size_t GetWordSize() const OVERRIDE { return kMips64DoublewordSize; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 280 | |
Lazar Trsic | d967266 | 2015-09-03 17:33:01 +0200 | [diff] [blame] | 281 | size_t GetFloatingPointSpillSlotSize() const OVERRIDE { return kMips64DoublewordSize; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 282 | |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 283 | uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 284 | return assembler_.GetLabelLocation(GetLabelOf(block)); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | HGraphVisitor* GetLocationBuilder() OVERRIDE { return &location_builder_; } |
| 288 | HGraphVisitor* GetInstructionVisitor() OVERRIDE { return &instruction_visitor_; } |
| 289 | Mips64Assembler* GetAssembler() OVERRIDE { return &assembler_; } |
Alexandre Rames | eb7b739 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 290 | const Mips64Assembler& GetAssembler() const OVERRIDE { return assembler_; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 291 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 292 | // Emit linker patches. |
| 293 | void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE; |
| 294 | |
Goran Jakovljevic | 8ed1826 | 2016-01-22 13:01:00 +0100 | [diff] [blame] | 295 | void MarkGCCard(GpuRegister object, GpuRegister value, bool value_can_be_null); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 296 | |
| 297 | // Register allocation. |
| 298 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 299 | void SetupBlockedRegisters() const OVERRIDE; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 300 | |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 301 | size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 302 | size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 303 | size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 304 | size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 305 | |
| 306 | void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 307 | void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 308 | |
| 309 | InstructionSet GetInstructionSet() const OVERRIDE { return InstructionSet::kMips64; } |
| 310 | |
| 311 | const Mips64InstructionSetFeatures& GetInstructionSetFeatures() const { |
| 312 | return isa_features_; |
| 313 | } |
| 314 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 315 | Mips64Label* GetLabelOf(HBasicBlock* block) const { |
| 316 | return CommonGetLabelOf<Mips64Label>(block_labels_, block); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void Initialize() OVERRIDE { |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 320 | block_labels_ = CommonInitializeLabels<Mips64Label>(); |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Alexey Frunze | c378980 | 2016-12-22 13:54:23 -0800 | [diff] [blame^] | 323 | // We prefer aligned loads and stores (less code), so spill and restore registers in slow paths |
| 324 | // at aligned locations. |
| 325 | uint32_t GetPreferredSlotsAlignment() const OVERRIDE { return kMips64DoublewordSize; } |
| 326 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 327 | void Finalize(CodeAllocator* allocator) OVERRIDE; |
| 328 | |
| 329 | // Code generation helpers. |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 330 | void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 331 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 332 | void MoveConstant(Location destination, int32_t value) OVERRIDE; |
| 333 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 334 | void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE; |
| 335 | |
| 336 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 337 | void SwapLocations(Location loc1, Location loc2, Primitive::Type type); |
| 338 | |
| 339 | // Generate code to invoke a runtime entry point. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 340 | void InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 341 | HInstruction* instruction, |
| 342 | uint32_t dex_pc, |
Serban Constantinescu | fc73408 | 2016-07-19 17:18:07 +0100 | [diff] [blame] | 343 | SlowPathCode* slow_path = nullptr) OVERRIDE; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 344 | |
| 345 | ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; } |
| 346 | |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 347 | bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { return false; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 348 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 349 | // Check if the desired_string_load_kind is supported. If it is, return it, |
| 350 | // otherwise return a fall-back kind that should be used instead. |
| 351 | HLoadString::LoadKind GetSupportedLoadStringKind( |
| 352 | HLoadString::LoadKind desired_string_load_kind) OVERRIDE; |
| 353 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 354 | // Check if the desired_class_load_kind is supported. If it is, return it, |
| 355 | // otherwise return a fall-back kind that should be used instead. |
| 356 | HLoadClass::LoadKind GetSupportedLoadClassKind( |
| 357 | HLoadClass::LoadKind desired_class_load_kind) OVERRIDE; |
| 358 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 359 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 360 | // otherwise return a fall-back info that should be used instead. |
| 361 | HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch( |
| 362 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 363 | HInvokeStaticOrDirect* invoke) OVERRIDE; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 364 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 365 | void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) OVERRIDE; |
Alexey Frunze | 53afca1 | 2015-11-05 16:34:23 -0800 | [diff] [blame] | 366 | void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 367 | |
| 368 | void MoveFromReturnRegister(Location trg ATTRIBUTE_UNUSED, |
| 369 | Primitive::Type type ATTRIBUTE_UNUSED) OVERRIDE { |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 370 | UNIMPLEMENTED(FATAL) << "Not implemented on MIPS64"; |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 371 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 372 | |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 373 | void GenerateNop() OVERRIDE; |
| 374 | void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE; |
| 375 | void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE; |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 376 | |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 377 | // The PcRelativePatchInfo is used for PC-relative addressing of dex cache arrays, |
| 378 | // boot image strings and method calls. The only difference is the interpretation of |
| 379 | // the offset_or_index. |
| 380 | struct PcRelativePatchInfo { |
| 381 | PcRelativePatchInfo(const DexFile& dex_file, uint32_t off_or_idx) |
| 382 | : target_dex_file(dex_file), offset_or_index(off_or_idx) { } |
| 383 | PcRelativePatchInfo(PcRelativePatchInfo&& other) = default; |
| 384 | |
| 385 | const DexFile& target_dex_file; |
| 386 | // Either the dex cache array element offset or the string/type/method index. |
| 387 | uint32_t offset_or_index; |
| 388 | // Label for the auipc instruction. |
| 389 | Mips64Label pc_rel_label; |
| 390 | }; |
| 391 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 392 | PcRelativePatchInfo* NewPcRelativeStringPatch(const DexFile& dex_file, uint32_t string_index); |
| 393 | PcRelativePatchInfo* NewPcRelativeTypePatch(const DexFile& dex_file, dex::TypeIndex type_index); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 394 | PcRelativePatchInfo* NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 395 | uint32_t element_offset); |
| 396 | PcRelativePatchInfo* NewPcRelativeCallPatch(const DexFile& dex_file, |
| 397 | uint32_t method_index); |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 398 | Literal* DeduplicateBootImageStringLiteral(const DexFile& dex_file, |
| 399 | dex::StringIndex string_index); |
| 400 | Literal* DeduplicateBootImageTypeLiteral(const DexFile& dex_file, dex::TypeIndex type_index); |
| 401 | Literal* DeduplicateBootImageAddressLiteral(uint64_t address); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 402 | |
| 403 | void EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info, GpuRegister out); |
| 404 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 405 | private: |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 406 | using Uint32ToLiteralMap = ArenaSafeMap<uint32_t, Literal*>; |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 407 | using Uint64ToLiteralMap = ArenaSafeMap<uint64_t, Literal*>; |
| 408 | using MethodToLiteralMap = ArenaSafeMap<MethodReference, Literal*, MethodReferenceComparator>; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 409 | using BootStringToLiteralMap = ArenaSafeMap<StringReference, |
| 410 | Literal*, |
| 411 | StringReferenceValueComparator>; |
| 412 | using BootTypeToLiteralMap = ArenaSafeMap<TypeReference, |
| 413 | Literal*, |
| 414 | TypeReferenceValueComparator>; |
| 415 | |
| 416 | Literal* DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map); |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 417 | Literal* DeduplicateUint64Literal(uint64_t value); |
| 418 | Literal* DeduplicateMethodLiteral(MethodReference target_method, MethodToLiteralMap* map); |
| 419 | Literal* DeduplicateMethodAddressLiteral(MethodReference target_method); |
| 420 | Literal* DeduplicateMethodCodeLiteral(MethodReference target_method); |
| 421 | |
| 422 | PcRelativePatchInfo* NewPcRelativePatch(const DexFile& dex_file, |
| 423 | uint32_t offset_or_index, |
| 424 | ArenaDeque<PcRelativePatchInfo>* patches); |
| 425 | |
| 426 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 427 | void EmitPcRelativeLinkerPatches(const ArenaDeque<PcRelativePatchInfo>& infos, |
| 428 | ArenaVector<LinkerPatch>* linker_patches); |
| 429 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 430 | // Labels for each block that will be compiled. |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 431 | Mips64Label* block_labels_; // Indexed by block id. |
| 432 | Mips64Label frame_entry_label_; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 433 | LocationsBuilderMIPS64 location_builder_; |
| 434 | InstructionCodeGeneratorMIPS64 instruction_visitor_; |
| 435 | ParallelMoveResolverMIPS64 move_resolver_; |
| 436 | Mips64Assembler assembler_; |
| 437 | const Mips64InstructionSetFeatures& isa_features_; |
| 438 | |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 439 | // Deduplication map for 32-bit literals, used for non-patchable boot image addresses. |
| 440 | Uint32ToLiteralMap uint32_literals_; |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 441 | // Deduplication map for 64-bit literals, used for non-patchable method address or method code |
| 442 | // address. |
| 443 | Uint64ToLiteralMap uint64_literals_; |
| 444 | // Method patch info, map MethodReference to a literal for method address and method code. |
| 445 | MethodToLiteralMap method_patches_; |
| 446 | MethodToLiteralMap call_patches_; |
| 447 | // PC-relative patch info. |
| 448 | ArenaDeque<PcRelativePatchInfo> pc_relative_dex_cache_patches_; |
| 449 | ArenaDeque<PcRelativePatchInfo> relative_call_patches_; |
Alexey Frunze | f63f569 | 2016-12-13 17:43:11 -0800 | [diff] [blame] | 450 | // Deduplication map for boot string literals for kBootImageLinkTimeAddress. |
| 451 | BootStringToLiteralMap boot_image_string_patches_; |
| 452 | // PC-relative String patch info; type depends on configuration (app .bss or boot image PIC). |
| 453 | ArenaDeque<PcRelativePatchInfo> pc_relative_string_patches_; |
| 454 | // Deduplication map for boot type literals for kBootImageLinkTimeAddress. |
| 455 | BootTypeToLiteralMap boot_image_type_patches_; |
| 456 | // PC-relative type patch info. |
| 457 | ArenaDeque<PcRelativePatchInfo> pc_relative_type_patches_; |
| 458 | // Deduplication map for patchable boot image addresses. |
| 459 | Uint32ToLiteralMap boot_image_address_patches_; |
Alexey Frunze | 19f6c69 | 2016-11-30 19:19:55 -0800 | [diff] [blame] | 460 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 461 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorMIPS64); |
| 462 | }; |
| 463 | |
| 464 | } // namespace mips64 |
| 465 | } // namespace art |
| 466 | |
| 467 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS64_H_ |