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" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 21 | #include "driver/compiler_options.h" |
| 22 | #include "nodes.h" |
| 23 | #include "parallel_move_resolver.h" |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 24 | #include "string_reference.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 25 | #include "utils/mips/assembler_mips.h" |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 26 | #include "utils/type_reference.h" |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | namespace mips { |
| 30 | |
| 31 | // InvokeDexCallingConvention registers |
| 32 | |
| 33 | static constexpr Register kParameterCoreRegisters[] = |
| 34 | { A1, A2, A3 }; |
| 35 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
| 36 | |
| 37 | static constexpr FRegister kParameterFpuRegisters[] = |
| 38 | { F12, F14 }; |
| 39 | static constexpr size_t kParameterFpuRegistersLength = arraysize(kParameterFpuRegisters); |
| 40 | |
| 41 | |
| 42 | // InvokeRuntimeCallingConvention registers |
| 43 | |
| 44 | static constexpr Register kRuntimeParameterCoreRegisters[] = |
| 45 | { A0, A1, A2, A3 }; |
| 46 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 47 | arraysize(kRuntimeParameterCoreRegisters); |
| 48 | |
| 49 | static constexpr FRegister kRuntimeParameterFpuRegisters[] = |
| 50 | { F12, F14}; |
| 51 | static constexpr size_t kRuntimeParameterFpuRegistersLength = |
| 52 | arraysize(kRuntimeParameterFpuRegisters); |
| 53 | |
| 54 | |
| 55 | static constexpr Register kCoreCalleeSaves[] = |
| 56 | { S0, S1, S2, S3, S4, S5, S6, S7, FP, RA }; |
| 57 | static constexpr FRegister kFpuCalleeSaves[] = |
| 58 | { F20, F22, F24, F26, F28, F30 }; |
| 59 | |
| 60 | |
| 61 | class CodeGeneratorMIPS; |
| 62 | |
| 63 | class InvokeDexCallingConvention : public CallingConvention<Register, FRegister> { |
| 64 | public: |
| 65 | InvokeDexCallingConvention() |
| 66 | : CallingConvention(kParameterCoreRegisters, |
| 67 | kParameterCoreRegistersLength, |
| 68 | kParameterFpuRegisters, |
| 69 | kParameterFpuRegistersLength, |
| 70 | kMipsPointerSize) {} |
| 71 | |
| 72 | private: |
| 73 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); |
| 74 | }; |
| 75 | |
| 76 | class InvokeDexCallingConventionVisitorMIPS : public InvokeDexCallingConventionVisitor { |
| 77 | public: |
| 78 | InvokeDexCallingConventionVisitorMIPS() {} |
| 79 | virtual ~InvokeDexCallingConventionVisitorMIPS() {} |
| 80 | |
| 81 | Location GetNextLocation(Primitive::Type type) OVERRIDE; |
| 82 | Location GetReturnLocation(Primitive::Type type) const OVERRIDE; |
| 83 | Location GetMethodLocation() const OVERRIDE; |
| 84 | |
| 85 | private: |
| 86 | InvokeDexCallingConvention calling_convention; |
| 87 | |
| 88 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorMIPS); |
| 89 | }; |
| 90 | |
| 91 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, FRegister> { |
| 92 | public: |
| 93 | InvokeRuntimeCallingConvention() |
| 94 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 95 | kRuntimeParameterCoreRegistersLength, |
| 96 | kRuntimeParameterFpuRegisters, |
| 97 | kRuntimeParameterFpuRegistersLength, |
| 98 | kMipsPointerSize) {} |
| 99 | |
| 100 | Location GetReturnLocation(Primitive::Type return_type); |
| 101 | |
| 102 | private: |
| 103 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 104 | }; |
| 105 | |
| 106 | class FieldAccessCallingConventionMIPS : public FieldAccessCallingConvention { |
| 107 | public: |
| 108 | FieldAccessCallingConventionMIPS() {} |
| 109 | |
| 110 | Location GetObjectLocation() const OVERRIDE { |
| 111 | return Location::RegisterLocation(A1); |
| 112 | } |
| 113 | Location GetFieldIndexLocation() const OVERRIDE { |
| 114 | return Location::RegisterLocation(A0); |
| 115 | } |
| 116 | Location GetReturnLocation(Primitive::Type type) const OVERRIDE { |
| 117 | return Primitive::Is64BitType(type) |
| 118 | ? Location::RegisterPairLocation(V0, V1) |
| 119 | : Location::RegisterLocation(V0); |
| 120 | } |
| 121 | Location GetSetValueLocation(Primitive::Type type, bool is_instance) const OVERRIDE { |
| 122 | return Primitive::Is64BitType(type) |
| 123 | ? Location::RegisterPairLocation(A2, A3) |
| 124 | : (is_instance ? Location::RegisterLocation(A2) : Location::RegisterLocation(A1)); |
| 125 | } |
| 126 | Location GetFpuLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE { |
| 127 | return Location::FpuRegisterLocation(F0); |
| 128 | } |
| 129 | |
| 130 | private: |
| 131 | DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionMIPS); |
| 132 | }; |
| 133 | |
| 134 | class ParallelMoveResolverMIPS : public ParallelMoveResolverWithSwap { |
| 135 | public: |
| 136 | ParallelMoveResolverMIPS(ArenaAllocator* allocator, CodeGeneratorMIPS* codegen) |
| 137 | : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {} |
| 138 | |
| 139 | void EmitMove(size_t index) OVERRIDE; |
| 140 | void EmitSwap(size_t index) OVERRIDE; |
| 141 | void SpillScratch(int reg) OVERRIDE; |
| 142 | void RestoreScratch(int reg) OVERRIDE; |
| 143 | |
| 144 | void Exchange(int index1, int index2, bool double_slot); |
| 145 | |
| 146 | MipsAssembler* GetAssembler() const; |
| 147 | |
| 148 | private: |
| 149 | CodeGeneratorMIPS* const codegen_; |
| 150 | |
| 151 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverMIPS); |
| 152 | }; |
| 153 | |
| 154 | class SlowPathCodeMIPS : public SlowPathCode { |
| 155 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 156 | explicit SlowPathCodeMIPS(HInstruction* instruction) |
| 157 | : SlowPathCode(instruction), entry_label_(), exit_label_() {} |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 158 | |
| 159 | MipsLabel* GetEntryLabel() { return &entry_label_; } |
| 160 | MipsLabel* GetExitLabel() { return &exit_label_; } |
| 161 | |
| 162 | private: |
| 163 | MipsLabel entry_label_; |
| 164 | MipsLabel exit_label_; |
| 165 | |
| 166 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeMIPS); |
| 167 | }; |
| 168 | |
| 169 | class LocationsBuilderMIPS : public HGraphVisitor { |
| 170 | public: |
| 171 | LocationsBuilderMIPS(HGraph* graph, CodeGeneratorMIPS* codegen) |
| 172 | : HGraphVisitor(graph), codegen_(codegen) {} |
| 173 | |
| 174 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| 175 | void Visit##name(H##name* instr) OVERRIDE; |
| 176 | |
| 177 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 178 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(DECLARE_VISIT_INSTRUCTION) |
| 179 | |
| 180 | #undef DECLARE_VISIT_INSTRUCTION |
| 181 | |
| 182 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 183 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 184 | << " (id " << instruction->GetId() << ")"; |
| 185 | } |
| 186 | |
| 187 | private: |
| 188 | void HandleInvoke(HInvoke* invoke); |
| 189 | void HandleBinaryOp(HBinaryOperation* operation); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 190 | void HandleCondition(HCondition* instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 191 | void HandleShift(HBinaryOperation* operation); |
| 192 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); |
| 193 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 194 | Location RegisterOrZeroConstant(HInstruction* instruction); |
| 195 | Location FpuRegisterOrConstantForStore(HInstruction* instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 196 | |
| 197 | InvokeDexCallingConventionVisitorMIPS parameter_visitor_; |
| 198 | |
| 199 | CodeGeneratorMIPS* const codegen_; |
| 200 | |
| 201 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderMIPS); |
| 202 | }; |
| 203 | |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 204 | class InstructionCodeGeneratorMIPS : public InstructionCodeGenerator { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 205 | public: |
| 206 | InstructionCodeGeneratorMIPS(HGraph* graph, CodeGeneratorMIPS* codegen); |
| 207 | |
| 208 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| 209 | void Visit##name(H##name* instr) OVERRIDE; |
| 210 | |
| 211 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 212 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(DECLARE_VISIT_INSTRUCTION) |
| 213 | |
| 214 | #undef DECLARE_VISIT_INSTRUCTION |
| 215 | |
| 216 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 217 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 218 | << " (id " << instruction->GetId() << ")"; |
| 219 | } |
| 220 | |
| 221 | MipsAssembler* GetAssembler() const { return assembler_; } |
| 222 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 223 | // Compare-and-jump packed switch generates approx. 3 + 2.5 * N 32-bit |
| 224 | // instructions for N cases. |
| 225 | // Table-based packed switch generates approx. 11 32-bit instructions |
| 226 | // and N 32-bit data words for N cases. |
| 227 | // At N = 6 they come out as 18 and 17 32-bit words respectively. |
| 228 | // We switch to the table-based method starting with 7 cases. |
| 229 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 6; |
| 230 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 231 | private: |
| 232 | void GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, Register class_reg); |
| 233 | void GenerateMemoryBarrier(MemBarrierKind kind); |
| 234 | void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor); |
| 235 | void HandleBinaryOp(HBinaryOperation* operation); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 236 | void HandleCondition(HCondition* instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 237 | void HandleShift(HBinaryOperation* operation); |
| 238 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info, uint32_t dex_pc); |
| 239 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info, uint32_t dex_pc); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 240 | // Generate a GC root reference load: |
| 241 | // |
| 242 | // root <- *(obj + offset) |
| 243 | // |
| 244 | // while honoring read barriers (if any). |
| 245 | void GenerateGcRootFieldLoad(HInstruction* instruction, |
| 246 | Location root, |
| 247 | Register obj, |
| 248 | uint32_t offset); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 249 | void GenerateIntCompare(IfCondition cond, LocationSummary* locations); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 250 | // When the function returns `false` it means that the condition holds if `dst` is non-zero |
| 251 | // and doesn't hold if `dst` is zero. If it returns `true`, the roles of zero and non-zero |
| 252 | // `dst` are exchanged. |
| 253 | bool MaterializeIntCompare(IfCondition cond, |
| 254 | LocationSummary* input_locations, |
| 255 | Register dst); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 256 | void GenerateIntCompareAndBranch(IfCondition cond, |
| 257 | LocationSummary* locations, |
| 258 | MipsLabel* label); |
| 259 | void GenerateLongCompareAndBranch(IfCondition cond, |
| 260 | LocationSummary* locations, |
| 261 | MipsLabel* label); |
Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 262 | void GenerateFpCompare(IfCondition cond, |
| 263 | bool gt_bias, |
| 264 | Primitive::Type type, |
| 265 | LocationSummary* locations); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 266 | // When the function returns `false` it means that the condition holds if the condition |
| 267 | // code flag `cc` is non-zero and doesn't hold if `cc` is zero. If it returns `true`, |
| 268 | // the roles of zero and non-zero values of the `cc` flag are exchanged. |
| 269 | bool MaterializeFpCompareR2(IfCondition cond, |
| 270 | bool gt_bias, |
| 271 | Primitive::Type type, |
| 272 | LocationSummary* input_locations, |
| 273 | int cc); |
| 274 | // When the function returns `false` it means that the condition holds if `dst` is non-zero |
| 275 | // and doesn't hold if `dst` is zero. If it returns `true`, the roles of zero and non-zero |
| 276 | // `dst` are exchanged. |
| 277 | bool MaterializeFpCompareR6(IfCondition cond, |
| 278 | bool gt_bias, |
| 279 | Primitive::Type type, |
| 280 | LocationSummary* input_locations, |
| 281 | FRegister dst); |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 282 | void GenerateFpCompareAndBranch(IfCondition cond, |
| 283 | bool gt_bias, |
| 284 | Primitive::Type type, |
| 285 | LocationSummary* locations, |
| 286 | MipsLabel* label); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 287 | void GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 288 | size_t condition_input_index, |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 289 | MipsLabel* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 290 | MipsLabel* false_target); |
Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 291 | void DivRemOneOrMinusOne(HBinaryOperation* instruction); |
| 292 | void DivRemByPowerOfTwo(HBinaryOperation* instruction); |
| 293 | void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); |
| 294 | void GenerateDivRemIntegral(HBinaryOperation* instruction); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 295 | void HandleGoto(HInstruction* got, HBasicBlock* successor); |
Alexey Frunze | 2923db7 | 2016-08-20 01:55:47 -0700 | [diff] [blame] | 296 | auto GetImplicitNullChecker(HInstruction* instruction); |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 297 | void GenPackedSwitchWithCompares(Register value_reg, |
| 298 | int32_t lower_bound, |
| 299 | uint32_t num_entries, |
| 300 | HBasicBlock* switch_block, |
| 301 | HBasicBlock* default_block); |
| 302 | void GenTableBasedPackedSwitch(Register value_reg, |
| 303 | Register constant_area, |
| 304 | int32_t lower_bound, |
| 305 | uint32_t num_entries, |
| 306 | HBasicBlock* switch_block, |
| 307 | HBasicBlock* default_block); |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 308 | void GenConditionalMoveR2(HSelect* select); |
| 309 | void GenConditionalMoveR6(HSelect* select); |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 310 | |
| 311 | MipsAssembler* const assembler_; |
| 312 | CodeGeneratorMIPS* const codegen_; |
| 313 | |
| 314 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorMIPS); |
| 315 | }; |
| 316 | |
| 317 | class CodeGeneratorMIPS : public CodeGenerator { |
| 318 | public: |
| 319 | CodeGeneratorMIPS(HGraph* graph, |
| 320 | const MipsInstructionSetFeatures& isa_features, |
| 321 | const CompilerOptions& compiler_options, |
| 322 | OptimizingCompilerStats* stats = nullptr); |
| 323 | virtual ~CodeGeneratorMIPS() {} |
| 324 | |
Alexey Frunze | 73296a7 | 2016-06-03 22:51:46 -0700 | [diff] [blame] | 325 | void ComputeSpillMask() OVERRIDE; |
Alexey Frunze | 58320ce | 2016-08-30 21:40:46 -0700 | [diff] [blame] | 326 | bool HasAllocatedCalleeSaveRegisters() const OVERRIDE; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 327 | void GenerateFrameEntry() OVERRIDE; |
| 328 | void GenerateFrameExit() OVERRIDE; |
| 329 | |
| 330 | void Bind(HBasicBlock* block) OVERRIDE; |
| 331 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 332 | void Move32(Location destination, Location source); |
| 333 | void Move64(Location destination, Location source); |
| 334 | void MoveConstant(Location location, HConstant* c); |
| 335 | |
| 336 | size_t GetWordSize() const OVERRIDE { return kMipsWordSize; } |
| 337 | |
| 338 | size_t GetFloatingPointSpillSlotSize() const OVERRIDE { return kMipsDoublewordSize; } |
| 339 | |
Alexandre Rames | c01a664 | 2016-04-15 11:54:06 +0100 | [diff] [blame] | 340 | uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 341 | return assembler_.GetLabelLocation(GetLabelOf(block)); |
| 342 | } |
| 343 | |
| 344 | HGraphVisitor* GetLocationBuilder() OVERRIDE { return &location_builder_; } |
| 345 | HGraphVisitor* GetInstructionVisitor() OVERRIDE { return &instruction_visitor_; } |
| 346 | MipsAssembler* GetAssembler() OVERRIDE { return &assembler_; } |
| 347 | const MipsAssembler& GetAssembler() const OVERRIDE { return assembler_; } |
| 348 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 349 | // Emit linker patches. |
| 350 | void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE; |
| 351 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 352 | void MarkGCCard(Register object, Register value); |
| 353 | |
| 354 | // Register allocation. |
| 355 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 356 | void SetupBlockedRegisters() const OVERRIDE; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 357 | |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 358 | size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 359 | size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 360 | size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 361 | size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 362 | void ClobberRA() { |
| 363 | clobbered_ra_ = true; |
| 364 | } |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 365 | |
| 366 | void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 367 | void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 368 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 369 | InstructionSet GetInstructionSet() const OVERRIDE { return InstructionSet::kMips; } |
| 370 | |
| 371 | const MipsInstructionSetFeatures& GetInstructionSetFeatures() const { |
| 372 | return isa_features_; |
| 373 | } |
| 374 | |
| 375 | MipsLabel* GetLabelOf(HBasicBlock* block) const { |
| 376 | return CommonGetLabelOf<MipsLabel>(block_labels_, block); |
| 377 | } |
| 378 | |
| 379 | void Initialize() OVERRIDE { |
| 380 | block_labels_ = CommonInitializeLabels<MipsLabel>(); |
| 381 | } |
| 382 | |
| 383 | void Finalize(CodeAllocator* allocator) OVERRIDE; |
| 384 | |
| 385 | // Code generation helpers. |
| 386 | |
| 387 | void MoveLocation(Location dst, Location src, Primitive::Type dst_type) OVERRIDE; |
| 388 | |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 389 | void MoveConstant(Location destination, int32_t value) OVERRIDE; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 390 | |
| 391 | void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE; |
| 392 | |
| 393 | // Generate code to invoke a runtime entry point. |
| 394 | void InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 395 | HInstruction* instruction, |
| 396 | uint32_t dex_pc, |
Serban Constantinescu | fca1666 | 2016-07-14 09:21:59 +0100 | [diff] [blame] | 397 | SlowPathCode* slow_path = nullptr) OVERRIDE; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 398 | |
| 399 | ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; } |
| 400 | |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 401 | bool NeedsTwoRegisters(Primitive::Type type) const OVERRIDE { |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 402 | return type == Primitive::kPrimLong; |
| 403 | } |
| 404 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 405 | // Check if the desired_string_load_kind is supported. If it is, return it, |
| 406 | // otherwise return a fall-back kind that should be used instead. |
| 407 | HLoadString::LoadKind GetSupportedLoadStringKind( |
| 408 | HLoadString::LoadKind desired_string_load_kind) OVERRIDE; |
| 409 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 410 | // Check if the desired_class_load_kind is supported. If it is, return it, |
| 411 | // otherwise return a fall-back kind that should be used instead. |
| 412 | HLoadClass::LoadKind GetSupportedLoadClassKind( |
| 413 | HLoadClass::LoadKind desired_class_load_kind) OVERRIDE; |
| 414 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 415 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 416 | // otherwise return a fall-back info that should be used instead. |
| 417 | HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch( |
| 418 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 419 | HInvokeStaticOrDirect* invoke) OVERRIDE; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 420 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 421 | void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp); |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 422 | void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp) OVERRIDE; |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 423 | |
| 424 | void MoveFromReturnRegister(Location trg ATTRIBUTE_UNUSED, |
| 425 | Primitive::Type type ATTRIBUTE_UNUSED) OVERRIDE { |
| 426 | UNIMPLEMENTED(FATAL) << "Not implemented on MIPS"; |
| 427 | } |
| 428 | |
Roland Levillain | f41f956 | 2016-09-14 19:26:48 +0100 | [diff] [blame] | 429 | void GenerateNop() OVERRIDE; |
| 430 | void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE; |
| 431 | void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE; |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 432 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 433 | // The PcRelativePatchInfo is used for PC-relative addressing of dex cache arrays |
| 434 | // and boot image strings. The only difference is the interpretation of the offset_or_index. |
| 435 | struct PcRelativePatchInfo { |
| 436 | PcRelativePatchInfo(const DexFile& dex_file, uint32_t off_or_idx) |
| 437 | : target_dex_file(dex_file), offset_or_index(off_or_idx) { } |
| 438 | PcRelativePatchInfo(PcRelativePatchInfo&& other) = default; |
| 439 | |
| 440 | const DexFile& target_dex_file; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 441 | // Either the dex cache array element offset or the string/type index. |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 442 | uint32_t offset_or_index; |
| 443 | // Label for the instruction loading the most significant half of the offset that's added to PC |
| 444 | // to form the base address (the least significant half is loaded with the instruction that |
| 445 | // follows). |
| 446 | MipsLabel high_label; |
| 447 | // Label for the instruction corresponding to PC+0. |
| 448 | MipsLabel pc_rel_label; |
| 449 | }; |
| 450 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 451 | PcRelativePatchInfo* NewPcRelativeStringPatch(const DexFile& dex_file, uint32_t string_index); |
| 452 | PcRelativePatchInfo* NewPcRelativeTypePatch(const DexFile& dex_file, uint32_t type_index); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 453 | PcRelativePatchInfo* NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 454 | uint32_t element_offset); |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 455 | Literal* DeduplicateBootImageStringLiteral(const DexFile& dex_file, uint32_t string_index); |
| 456 | Literal* DeduplicateBootImageTypeLiteral(const DexFile& dex_file, uint32_t type_index); |
| 457 | Literal* DeduplicateBootImageAddressLiteral(uint32_t address); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 458 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 459 | void EmitPcRelativeAddressPlaceholder(PcRelativePatchInfo* info, Register out, Register base); |
| 460 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 461 | private: |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 462 | Register GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, Register temp); |
| 463 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 464 | using Uint32ToLiteralMap = ArenaSafeMap<uint32_t, Literal*>; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 465 | using MethodToLiteralMap = ArenaSafeMap<MethodReference, Literal*, MethodReferenceComparator>; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 466 | using BootStringToLiteralMap = ArenaSafeMap<StringReference, |
| 467 | Literal*, |
| 468 | StringReferenceValueComparator>; |
| 469 | using BootTypeToLiteralMap = ArenaSafeMap<TypeReference, |
| 470 | Literal*, |
| 471 | TypeReferenceValueComparator>; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 472 | |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 473 | Literal* DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 474 | Literal* DeduplicateMethodLiteral(MethodReference target_method, MethodToLiteralMap* map); |
| 475 | Literal* DeduplicateMethodAddressLiteral(MethodReference target_method); |
| 476 | Literal* DeduplicateMethodCodeLiteral(MethodReference target_method); |
| 477 | PcRelativePatchInfo* NewPcRelativePatch(const DexFile& dex_file, |
| 478 | uint32_t offset_or_index, |
| 479 | ArenaDeque<PcRelativePatchInfo>* patches); |
| 480 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 481 | 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 Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 485 | // 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 Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 494 | // Deduplication map for 32-bit literals, used for non-patchable boot image addresses. |
| 495 | Uint32ToLiteralMap uint32_literals_; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 496 | // Method patch info, map MethodReference to a literal for method address and method code. |
| 497 | MethodToLiteralMap method_patches_; |
| 498 | MethodToLiteralMap call_patches_; |
| 499 | // PC-relative patch info for each HMipsDexCacheArraysBase. |
| 500 | ArenaDeque<PcRelativePatchInfo> pc_relative_dex_cache_patches_; |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 501 | // Deduplication map for boot string literals for kBootImageLinkTimeAddress. |
| 502 | BootStringToLiteralMap boot_image_string_patches_; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 503 | // PC-relative String patch info; type depends on configuration (app .bss or boot image PIC). |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 504 | ArenaDeque<PcRelativePatchInfo> pc_relative_string_patches_; |
| 505 | // Deduplication map for boot type literals for kBootImageLinkTimeAddress. |
| 506 | BootTypeToLiteralMap boot_image_type_patches_; |
| 507 | // PC-relative type patch info. |
| 508 | ArenaDeque<PcRelativePatchInfo> pc_relative_type_patches_; |
| 509 | // Deduplication map for patchable boot image addresses. |
| 510 | Uint32ToLiteralMap boot_image_address_patches_; |
| 511 | |
| 512 | // PC-relative loads on R2 clobber RA, which may need to be preserved explicitly in leaf methods. |
| 513 | // This is a flag set by pc_relative_fixups_mips and dex_cache_array_fixups_mips optimizations. |
| 514 | bool clobbered_ra_; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 515 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 516 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorMIPS); |
| 517 | }; |
| 518 | |
| 519 | } // namespace mips |
| 520 | } // namespace art |
| 521 | |
| 522 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS_H_ |