| 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 | |
| Vladimir Marko | e272715 | 2019-10-10 10:46:42 +0100 | [diff] [blame^] | 20 | #include "base/macros.h" |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 21 | #include "code_generator.h" |
| David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 22 | #include "dex/dex_file_types.h" |
| David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 23 | #include "dex/string_reference.h" |
| 24 | #include "dex/type_reference.h" |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 25 | #include "driver/compiler_options.h" |
| 26 | #include "nodes.h" |
| 27 | #include "parallel_move_resolver.h" |
| 28 | #include "utils/mips/assembler_mips.h" |
| 29 | |
| Vladimir Marko | e272715 | 2019-10-10 10:46:42 +0100 | [diff] [blame^] | 30 | namespace art HIDDEN { |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 31 | namespace mips { |
| 32 | |
| 33 | // InvokeDexCallingConvention registers |
| 34 | |
| 35 | static constexpr Register kParameterCoreRegisters[] = |
| Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 36 | { A1, A2, A3, T0, T1 }; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 37 | static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters); |
| 38 | |
| 39 | static constexpr FRegister kParameterFpuRegisters[] = |
| Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 40 | { F8, F10, F12, F14, F16, F18 }; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 41 | static constexpr size_t kParameterFpuRegistersLength = arraysize(kParameterFpuRegisters); |
| 42 | |
| 43 | |
| 44 | // InvokeRuntimeCallingConvention registers |
| 45 | |
| 46 | static constexpr Register kRuntimeParameterCoreRegisters[] = |
| 47 | { A0, A1, A2, A3 }; |
| 48 | static constexpr size_t kRuntimeParameterCoreRegistersLength = |
| 49 | arraysize(kRuntimeParameterCoreRegisters); |
| 50 | |
| 51 | static constexpr FRegister kRuntimeParameterFpuRegisters[] = |
| Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 52 | { F12, F14 }; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 53 | static constexpr size_t kRuntimeParameterFpuRegistersLength = |
| 54 | arraysize(kRuntimeParameterFpuRegisters); |
| 55 | |
| 56 | |
| 57 | static constexpr Register kCoreCalleeSaves[] = |
| 58 | { S0, S1, S2, S3, S4, S5, S6, S7, FP, RA }; |
| 59 | static constexpr FRegister kFpuCalleeSaves[] = |
| 60 | { F20, F22, F24, F26, F28, F30 }; |
| 61 | |
| 62 | |
| 63 | class CodeGeneratorMIPS; |
| 64 | |
| Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 65 | VectorRegister VectorRegisterFrom(Location location); |
| 66 | |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 67 | class InvokeDexCallingConvention : public CallingConvention<Register, FRegister> { |
| 68 | public: |
| 69 | InvokeDexCallingConvention() |
| 70 | : CallingConvention(kParameterCoreRegisters, |
| 71 | kParameterCoreRegistersLength, |
| 72 | kParameterFpuRegisters, |
| 73 | kParameterFpuRegistersLength, |
| 74 | kMipsPointerSize) {} |
| 75 | |
| 76 | private: |
| 77 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention); |
| 78 | }; |
| 79 | |
| 80 | class InvokeDexCallingConventionVisitorMIPS : public InvokeDexCallingConventionVisitor { |
| 81 | public: |
| 82 | InvokeDexCallingConventionVisitorMIPS() {} |
| 83 | virtual ~InvokeDexCallingConventionVisitorMIPS() {} |
| 84 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 85 | Location GetNextLocation(DataType::Type type) override; |
| 86 | Location GetReturnLocation(DataType::Type type) const override; |
| 87 | Location GetMethodLocation() const override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 88 | |
| 89 | private: |
| 90 | InvokeDexCallingConvention calling_convention; |
| 91 | |
| 92 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorMIPS); |
| 93 | }; |
| 94 | |
| 95 | class InvokeRuntimeCallingConvention : public CallingConvention<Register, FRegister> { |
| 96 | public: |
| 97 | InvokeRuntimeCallingConvention() |
| 98 | : CallingConvention(kRuntimeParameterCoreRegisters, |
| 99 | kRuntimeParameterCoreRegistersLength, |
| 100 | kRuntimeParameterFpuRegisters, |
| 101 | kRuntimeParameterFpuRegistersLength, |
| 102 | kMipsPointerSize) {} |
| 103 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 104 | Location GetReturnLocation(DataType::Type return_type); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 105 | |
| 106 | private: |
| 107 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention); |
| 108 | }; |
| 109 | |
| 110 | class FieldAccessCallingConventionMIPS : public FieldAccessCallingConvention { |
| 111 | public: |
| 112 | FieldAccessCallingConventionMIPS() {} |
| 113 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 114 | Location GetObjectLocation() const override { |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 115 | return Location::RegisterLocation(A1); |
| 116 | } |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 117 | Location GetFieldIndexLocation() const override { |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 118 | return Location::RegisterLocation(A0); |
| 119 | } |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 120 | Location GetReturnLocation(DataType::Type type) const override { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 121 | return DataType::Is64BitType(type) |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 122 | ? Location::RegisterPairLocation(V0, V1) |
| 123 | : Location::RegisterLocation(V0); |
| 124 | } |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 125 | Location GetSetValueLocation(DataType::Type type, bool is_instance) const override { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 126 | return DataType::Is64BitType(type) |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 127 | ? Location::RegisterPairLocation(A2, A3) |
| 128 | : (is_instance ? Location::RegisterLocation(A2) : Location::RegisterLocation(A1)); |
| 129 | } |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 130 | Location GetFpuLocation(DataType::Type type ATTRIBUTE_UNUSED) const override { |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 131 | return Location::FpuRegisterLocation(F0); |
| 132 | } |
| 133 | |
| 134 | private: |
| 135 | DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionMIPS); |
| 136 | }; |
| 137 | |
| 138 | class ParallelMoveResolverMIPS : public ParallelMoveResolverWithSwap { |
| 139 | public: |
| 140 | ParallelMoveResolverMIPS(ArenaAllocator* allocator, CodeGeneratorMIPS* codegen) |
| 141 | : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {} |
| 142 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 143 | void EmitMove(size_t index) override; |
| 144 | void EmitSwap(size_t index) override; |
| 145 | void SpillScratch(int reg) override; |
| 146 | void RestoreScratch(int reg) override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 147 | |
| 148 | void Exchange(int index1, int index2, bool double_slot); |
| Goran Jakovljevic | e7de5ec | 2017-12-14 10:25:20 +0100 | [diff] [blame] | 149 | void ExchangeQuadSlots(int index1, int index2); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 150 | |
| 151 | MipsAssembler* GetAssembler() const; |
| 152 | |
| 153 | private: |
| 154 | CodeGeneratorMIPS* const codegen_; |
| 155 | |
| 156 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverMIPS); |
| 157 | }; |
| 158 | |
| 159 | class SlowPathCodeMIPS : public SlowPathCode { |
| 160 | public: |
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 161 | explicit SlowPathCodeMIPS(HInstruction* instruction) |
| 162 | : SlowPathCode(instruction), entry_label_(), exit_label_() {} |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 163 | |
| 164 | MipsLabel* GetEntryLabel() { return &entry_label_; } |
| 165 | MipsLabel* GetExitLabel() { return &exit_label_; } |
| 166 | |
| 167 | private: |
| 168 | MipsLabel entry_label_; |
| 169 | MipsLabel exit_label_; |
| 170 | |
| 171 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeMIPS); |
| 172 | }; |
| 173 | |
| 174 | class LocationsBuilderMIPS : public HGraphVisitor { |
| 175 | public: |
| 176 | LocationsBuilderMIPS(HGraph* graph, CodeGeneratorMIPS* codegen) |
| 177 | : HGraphVisitor(graph), codegen_(codegen) {} |
| 178 | |
| 179 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 180 | void Visit##name(H##name* instr) override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 181 | |
| 182 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 183 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(DECLARE_VISIT_INSTRUCTION) |
| 184 | |
| 185 | #undef DECLARE_VISIT_INSTRUCTION |
| 186 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 187 | void VisitInstruction(HInstruction* instruction) override { |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 188 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 189 | << " (id " << instruction->GetId() << ")"; |
| 190 | } |
| 191 | |
| 192 | private: |
| 193 | void HandleInvoke(HInvoke* invoke); |
| 194 | void HandleBinaryOp(HBinaryOperation* operation); |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 195 | void HandleCondition(HCondition* instruction); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 196 | void HandleShift(HBinaryOperation* operation); |
| 197 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); |
| 198 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
| Alexey Frunze | f58b248 | 2016-09-02 22:14:06 -0700 | [diff] [blame] | 199 | Location RegisterOrZeroConstant(HInstruction* instruction); |
| 200 | Location FpuRegisterOrConstantForStore(HInstruction* instruction); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 201 | |
| 202 | InvokeDexCallingConventionVisitorMIPS parameter_visitor_; |
| 203 | |
| 204 | CodeGeneratorMIPS* const codegen_; |
| 205 | |
| 206 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderMIPS); |
| 207 | }; |
| 208 | |
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 209 | class InstructionCodeGeneratorMIPS : public InstructionCodeGenerator { |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 210 | public: |
| 211 | InstructionCodeGeneratorMIPS(HGraph* graph, CodeGeneratorMIPS* codegen); |
| 212 | |
| 213 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 214 | void Visit##name(H##name* instr) override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 215 | |
| 216 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 217 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(DECLARE_VISIT_INSTRUCTION) |
| 218 | |
| 219 | #undef DECLARE_VISIT_INSTRUCTION |
| 220 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 221 | void VisitInstruction(HInstruction* instruction) override { |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 222 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 223 | << " (id " << instruction->GetId() << ")"; |
| 224 | } |
| 225 | |
| 226 | MipsAssembler* GetAssembler() const { return assembler_; } |
| 227 | |
| Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 228 | // Compare-and-jump packed switch generates approx. 3 + 2.5 * N 32-bit |
| 229 | // instructions for N cases. |
| 230 | // Table-based packed switch generates approx. 11 32-bit instructions |
| 231 | // and N 32-bit data words for N cases. |
| 232 | // At N = 6 they come out as 18 and 17 32-bit words respectively. |
| 233 | // We switch to the table-based method starting with 7 cases. |
| 234 | static constexpr uint32_t kPackedSwitchJumpTableThreshold = 6; |
| 235 | |
| Chris Larsen | 5633ce7 | 2017-04-10 15:47:40 -0700 | [diff] [blame] | 236 | void GenerateMemoryBarrier(MemBarrierKind kind); |
| 237 | |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 238 | private: |
| 239 | void GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path, Register class_reg); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 240 | void GenerateSuspendCheck(HSuspendCheck* check, HBasicBlock* successor); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 241 | void GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, Register temp); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 242 | void HandleBinaryOp(HBinaryOperation* operation); |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 243 | void HandleCondition(HCondition* instruction); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 244 | void HandleShift(HBinaryOperation* operation); |
| Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 245 | void HandleFieldSet(HInstruction* instruction, |
| 246 | const FieldInfo& field_info, |
| 247 | uint32_t dex_pc, |
| 248 | bool value_can_be_null); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 249 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info, uint32_t dex_pc); |
| Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 250 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 251 | void GenerateMinMaxInt(LocationSummary* locations, bool is_min, bool isR6, DataType::Type type); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 252 | void GenerateMinMaxFP(LocationSummary* locations, bool is_min, bool isR6, DataType::Type type); |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 253 | void GenerateMinMax(HBinaryOperation*, bool is_min); |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 254 | void GenerateAbsFP(LocationSummary* locations, DataType::Type type, bool isR2OrNewer, bool isR6); |
| 255 | |
| Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 256 | // Generate a heap reference load using one register `out`: |
| 257 | // |
| 258 | // out <- *(out + offset) |
| 259 | // |
| 260 | // while honoring heap poisoning and/or read barriers (if any). |
| 261 | // |
| 262 | // Location `maybe_temp` is used when generating a read barrier and |
| 263 | // shall be a register in that case; it may be an invalid location |
| 264 | // otherwise. |
| 265 | void GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 266 | Location out, |
| 267 | uint32_t offset, |
| 268 | Location maybe_temp, |
| 269 | ReadBarrierOption read_barrier_option); |
| 270 | // Generate a heap reference load using two different registers |
| 271 | // `out` and `obj`: |
| 272 | // |
| 273 | // out <- *(obj + offset) |
| 274 | // |
| 275 | // while honoring heap poisoning and/or read barriers (if any). |
| 276 | // |
| 277 | // Location `maybe_temp` is used when generating a Baker's (fast |
| 278 | // path) read barrier and shall be a register in that case; it may |
| 279 | // be an invalid location otherwise. |
| 280 | void GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 281 | Location out, |
| 282 | Location obj, |
| 283 | uint32_t offset, |
| 284 | Location maybe_temp, |
| 285 | ReadBarrierOption read_barrier_option); |
| 286 | |
| Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 287 | // Generate a GC root reference load: |
| 288 | // |
| 289 | // root <- *(obj + offset) |
| 290 | // |
| 291 | // while honoring read barriers (if any). |
| 292 | void GenerateGcRootFieldLoad(HInstruction* instruction, |
| 293 | Location root, |
| 294 | Register obj, |
| Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 295 | uint32_t offset, |
| Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 296 | ReadBarrierOption read_barrier_option, |
| 297 | MipsLabel* label_low = nullptr); |
| Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 298 | |
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 299 | void GenerateIntCompare(IfCondition cond, LocationSummary* locations); |
| Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 300 | // When the function returns `false` it means that the condition holds if `dst` is non-zero |
| 301 | // and doesn't hold if `dst` is zero. If it returns `true`, the roles of zero and non-zero |
| 302 | // `dst` are exchanged. |
| 303 | bool MaterializeIntCompare(IfCondition cond, |
| 304 | LocationSummary* input_locations, |
| 305 | Register dst); |
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 306 | void GenerateIntCompareAndBranch(IfCondition cond, |
| 307 | LocationSummary* locations, |
| 308 | MipsLabel* label); |
| Tijana Jakovljevic | 6d482aa | 2017-02-03 13:24:08 +0100 | [diff] [blame] | 309 | void GenerateLongCompare(IfCondition cond, LocationSummary* locations); |
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 310 | void GenerateLongCompareAndBranch(IfCondition cond, |
| 311 | LocationSummary* locations, |
| 312 | MipsLabel* label); |
| Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 313 | void GenerateFpCompare(IfCondition cond, |
| 314 | bool gt_bias, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 315 | DataType::Type type, |
| Alexey Frunze | 2ddb717 | 2016-09-06 17:04:55 -0700 | [diff] [blame] | 316 | LocationSummary* locations); |
| Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 317 | // When the function returns `false` it means that the condition holds if the condition |
| 318 | // code flag `cc` is non-zero and doesn't hold if `cc` is zero. If it returns `true`, |
| 319 | // the roles of zero and non-zero values of the `cc` flag are exchanged. |
| 320 | bool MaterializeFpCompareR2(IfCondition cond, |
| 321 | bool gt_bias, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 322 | DataType::Type type, |
| Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 323 | LocationSummary* input_locations, |
| 324 | int cc); |
| 325 | // When the function returns `false` it means that the condition holds if `dst` is non-zero |
| 326 | // and doesn't hold if `dst` is zero. If it returns `true`, the roles of zero and non-zero |
| 327 | // `dst` are exchanged. |
| 328 | bool MaterializeFpCompareR6(IfCondition cond, |
| 329 | bool gt_bias, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 330 | DataType::Type type, |
| Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 331 | LocationSummary* input_locations, |
| 332 | FRegister dst); |
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 333 | void GenerateFpCompareAndBranch(IfCondition cond, |
| 334 | bool gt_bias, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 335 | DataType::Type type, |
| Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 336 | LocationSummary* locations, |
| 337 | MipsLabel* label); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 338 | void GenerateTestAndBranch(HInstruction* instruction, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 339 | size_t condition_input_index, |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 340 | MipsLabel* true_target, |
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 341 | MipsLabel* false_target); |
| Alexey Frunze | 7e99e05 | 2015-11-24 19:28:01 -0800 | [diff] [blame] | 342 | void DivRemOneOrMinusOne(HBinaryOperation* instruction); |
| 343 | void DivRemByPowerOfTwo(HBinaryOperation* instruction); |
| 344 | void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); |
| 345 | void GenerateDivRemIntegral(HBinaryOperation* instruction); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 346 | void HandleGoto(HInstruction* got, HBasicBlock* successor); |
| Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 347 | void GenPackedSwitchWithCompares(Register value_reg, |
| 348 | int32_t lower_bound, |
| 349 | uint32_t num_entries, |
| 350 | HBasicBlock* switch_block, |
| 351 | HBasicBlock* default_block); |
| 352 | void GenTableBasedPackedSwitch(Register value_reg, |
| 353 | Register constant_area, |
| 354 | int32_t lower_bound, |
| 355 | uint32_t num_entries, |
| 356 | HBasicBlock* switch_block, |
| 357 | HBasicBlock* default_block); |
| Lena Djokic | 51765b0 | 2017-06-22 13:49:59 +0200 | [diff] [blame] | 358 | |
| 359 | int32_t VecAddress(LocationSummary* locations, |
| 360 | size_t size, |
| 361 | /* out */ Register* adjusted_base); |
| Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 362 | void GenConditionalMoveR2(HSelect* select); |
| 363 | void GenConditionalMoveR6(HSelect* select); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 364 | |
| 365 | MipsAssembler* const assembler_; |
| 366 | CodeGeneratorMIPS* const codegen_; |
| 367 | |
| 368 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorMIPS); |
| 369 | }; |
| 370 | |
| 371 | class CodeGeneratorMIPS : public CodeGenerator { |
| 372 | public: |
| 373 | CodeGeneratorMIPS(HGraph* graph, |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 374 | const CompilerOptions& compiler_options, |
| 375 | OptimizingCompilerStats* stats = nullptr); |
| 376 | virtual ~CodeGeneratorMIPS() {} |
| 377 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 378 | void ComputeSpillMask() override; |
| 379 | bool HasAllocatedCalleeSaveRegisters() const override; |
| 380 | void GenerateFrameEntry() override; |
| 381 | void GenerateFrameExit() override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 382 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 383 | void Bind(HBasicBlock* block) override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 384 | |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 385 | void MoveConstant(Location location, HConstant* c); |
| 386 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 387 | size_t GetWordSize() const override { return kMipsWordSize; } |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 388 | |
| Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 389 | size_t GetSlowPathFPWidth() const override { |
| Lena Djokic | ca8c295 | 2017-05-29 11:31:46 +0200 | [diff] [blame] | 390 | return GetGraph()->HasSIMD() |
| 391 | ? 2 * kMipsDoublewordSize // 16 bytes for each spill. |
| 392 | : 1 * kMipsDoublewordSize; // 8 bytes for each spill. |
| 393 | } |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 394 | |
| Artem Serov | 6a0b657 | 2019-07-26 20:38:37 +0100 | [diff] [blame] | 395 | size_t GetCalleePreservedFPWidth() const override { |
| 396 | return 1 * kMipsDoublewordSize; |
| 397 | } |
| 398 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 399 | uintptr_t GetAddressOf(HBasicBlock* block) override { |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 400 | return assembler_.GetLabelLocation(GetLabelOf(block)); |
| 401 | } |
| 402 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 403 | HGraphVisitor* GetLocationBuilder() override { return &location_builder_; } |
| 404 | HGraphVisitor* GetInstructionVisitor() override { return &instruction_visitor_; } |
| 405 | MipsAssembler* GetAssembler() override { return &assembler_; } |
| 406 | const MipsAssembler& GetAssembler() const override { return assembler_; } |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 407 | |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 408 | // Emit linker patches. |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 409 | void EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) override; |
| 410 | void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) override; |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 411 | |
| Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 412 | // Fast path implementation of ReadBarrier::Barrier for a heap |
| 413 | // reference field load when Baker's read barriers are used. |
| 414 | void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 415 | Location ref, |
| 416 | Register obj, |
| 417 | uint32_t offset, |
| 418 | Location temp, |
| 419 | bool needs_null_check); |
| 420 | // Fast path implementation of ReadBarrier::Barrier for a heap |
| 421 | // reference array load when Baker's read barriers are used. |
| 422 | void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 423 | Location ref, |
| 424 | Register obj, |
| 425 | uint32_t data_offset, |
| 426 | Location index, |
| 427 | Location temp, |
| 428 | bool needs_null_check); |
| 429 | |
| 430 | // Factored implementation, used by GenerateFieldLoadWithBakerReadBarrier, |
| 431 | // GenerateArrayLoadWithBakerReadBarrier and some intrinsics. |
| 432 | // |
| 433 | // Load the object reference located at the address |
| 434 | // `obj + offset + (index << scale_factor)`, held by object `obj`, into |
| 435 | // `ref`, and mark it if needed. |
| 436 | // |
| 437 | // If `always_update_field` is true, the value of the reference is |
| 438 | // atomically updated in the holder (`obj`). |
| 439 | void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 440 | Location ref, |
| 441 | Register obj, |
| 442 | uint32_t offset, |
| 443 | Location index, |
| 444 | ScaleFactor scale_factor, |
| 445 | Location temp, |
| 446 | bool needs_null_check, |
| 447 | bool always_update_field = false); |
| 448 | |
| 449 | // Generate a read barrier for a heap reference within `instruction` |
| 450 | // using a slow path. |
| 451 | // |
| 452 | // A read barrier for an object reference read from the heap is |
| 453 | // implemented as a call to the artReadBarrierSlow runtime entry |
| 454 | // point, which is passed the values in locations `ref`, `obj`, and |
| 455 | // `offset`: |
| 456 | // |
| 457 | // mirror::Object* artReadBarrierSlow(mirror::Object* ref, |
| 458 | // mirror::Object* obj, |
| 459 | // uint32_t offset); |
| 460 | // |
| 461 | // The `out` location contains the value returned by |
| 462 | // artReadBarrierSlow. |
| 463 | // |
| 464 | // When `index` is provided (i.e. for array accesses), the offset |
| 465 | // value passed to artReadBarrierSlow is adjusted to take `index` |
| 466 | // into account. |
| 467 | void GenerateReadBarrierSlow(HInstruction* instruction, |
| 468 | Location out, |
| 469 | Location ref, |
| 470 | Location obj, |
| 471 | uint32_t offset, |
| 472 | Location index = Location::NoLocation()); |
| 473 | |
| 474 | // If read barriers are enabled, generate a read barrier for a heap |
| 475 | // reference using a slow path. If heap poisoning is enabled, also |
| 476 | // unpoison the reference in `out`. |
| 477 | void MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 478 | Location out, |
| 479 | Location ref, |
| 480 | Location obj, |
| 481 | uint32_t offset, |
| 482 | Location index = Location::NoLocation()); |
| 483 | |
| 484 | // Generate a read barrier for a GC root within `instruction` using |
| 485 | // a slow path. |
| 486 | // |
| 487 | // A read barrier for an object reference GC root is implemented as |
| 488 | // a call to the artReadBarrierForRootSlow runtime entry point, |
| 489 | // which is passed the value in location `root`: |
| 490 | // |
| 491 | // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root); |
| 492 | // |
| 493 | // The `out` location contains the value returned by |
| 494 | // artReadBarrierForRootSlow. |
| 495 | void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root); |
| 496 | |
| Goran Jakovljevic | e114da2 | 2016-12-26 14:21:43 +0100 | [diff] [blame] | 497 | void MarkGCCard(Register object, Register value, bool value_can_be_null); |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 498 | |
| 499 | // Register allocation. |
| 500 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 501 | void SetupBlockedRegisters() const override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 502 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 503 | size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) override; |
| 504 | size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) override; |
| 505 | size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) override; |
| 506 | size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) override; |
| Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 507 | void ClobberRA() { |
| 508 | clobbered_ra_ = true; |
| 509 | } |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 510 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 511 | void DumpCoreRegister(std::ostream& stream, int reg) const override; |
| 512 | void DumpFloatingPointRegister(std::ostream& stream, int reg) const override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 513 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 514 | InstructionSet GetInstructionSet() const override { return InstructionSet::kMips; } |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 515 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 516 | const MipsInstructionSetFeatures& GetInstructionSetFeatures() const; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 517 | |
| 518 | MipsLabel* GetLabelOf(HBasicBlock* block) const { |
| 519 | return CommonGetLabelOf<MipsLabel>(block_labels_, block); |
| 520 | } |
| 521 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 522 | void Initialize() override { |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 523 | block_labels_ = CommonInitializeLabels<MipsLabel>(); |
| 524 | } |
| 525 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 526 | void Finalize(CodeAllocator* allocator) override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 527 | |
| 528 | // Code generation helpers. |
| 529 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 530 | void MoveLocation(Location dst, Location src, DataType::Type dst_type) override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 531 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 532 | void MoveConstant(Location destination, int32_t value) override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 533 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 534 | void AddLocationAsTemp(Location location, LocationSummary* locations) override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 535 | |
| 536 | // Generate code to invoke a runtime entry point. |
| 537 | void InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 538 | HInstruction* instruction, |
| 539 | uint32_t dex_pc, |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 540 | SlowPathCode* slow_path = nullptr) override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 541 | |
| Alexey Frunze | 1595815 | 2017-02-09 19:08:30 -0800 | [diff] [blame] | 542 | // Generate code to invoke a runtime entry point, but do not record |
| 543 | // PC-related information in a stack map. |
| 544 | void InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 545 | HInstruction* instruction, |
| 546 | SlowPathCode* slow_path, |
| 547 | bool direct); |
| 548 | |
| 549 | void GenerateInvokeRuntime(int32_t entry_point_offset, bool direct); |
| 550 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 551 | ParallelMoveResolver* GetMoveResolver() override { return &move_resolver_; } |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 552 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 553 | bool NeedsTwoRegisters(DataType::Type type) const override { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 554 | return type == DataType::Type::kInt64; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 555 | } |
| 556 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 557 | // Check if the desired_string_load_kind is supported. If it is, return it, |
| 558 | // otherwise return a fall-back kind that should be used instead. |
| 559 | HLoadString::LoadKind GetSupportedLoadStringKind( |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 560 | HLoadString::LoadKind desired_string_load_kind) override; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 561 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 562 | // Check if the desired_class_load_kind is supported. If it is, return it, |
| 563 | // otherwise return a fall-back kind that should be used instead. |
| 564 | HLoadClass::LoadKind GetSupportedLoadClassKind( |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 565 | HLoadClass::LoadKind desired_class_load_kind) override; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 566 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 567 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 568 | // otherwise return a fall-back info that should be used instead. |
| 569 | HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch( |
| 570 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 571 | ArtMethod* method) override; |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 572 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 573 | void GenerateStaticOrDirectCall( |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 574 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path = nullptr) override; |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 575 | void GenerateVirtualCall( |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 576 | HInvokeVirtual* invoke, Location temp, SlowPathCode* slow_path = nullptr) override; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 577 | |
| 578 | void MoveFromReturnRegister(Location trg ATTRIBUTE_UNUSED, |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 579 | DataType::Type type ATTRIBUTE_UNUSED) override { |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 580 | UNIMPLEMENTED(FATAL) << "Not implemented on MIPS"; |
| 581 | } |
| 582 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 583 | void GenerateNop() override; |
| 584 | void GenerateImplicitNullCheck(HNullCheck* instruction) override; |
| 585 | void GenerateExplicitNullCheck(HNullCheck* instruction) override; |
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 586 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 587 | // The PcRelativePatchInfo is used for PC-relative addressing of methods/strings/types, |
| 588 | // whether through .data.bimg.rel.ro, .bss, or directly in the boot image. |
| 589 | // |
| Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 590 | // The 16-bit halves of the 32-bit PC-relative offset are patched separately, necessitating |
| 591 | // two patches/infos. There can be more than two patches/infos if the instruction supplying |
| 592 | // the high half is shared with e.g. a slow path, while the low half is supplied by separate |
| 593 | // instructions, e.g.: |
| 594 | // lui r1, high // patch |
| 595 | // addu r1, r1, rbase |
| 596 | // lw r2, low(r1) // patch |
| 597 | // beqz r2, slow_path |
| 598 | // back: |
| 599 | // ... |
| 600 | // slow_path: |
| 601 | // ... |
| 602 | // sw r2, low(r1) // patch |
| 603 | // b back |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 604 | struct PcRelativePatchInfo : PatchInfo<MipsLabel> { |
| 605 | PcRelativePatchInfo(const DexFile* dex_file, |
| Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 606 | uint32_t off_or_idx, |
| 607 | const PcRelativePatchInfo* info_high) |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 608 | : PatchInfo<MipsLabel>(dex_file, off_or_idx), |
| Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 609 | pc_rel_label(), |
| 610 | patch_info_high(info_high) { } |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 611 | |
| Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 612 | // Label for the instruction corresponding to PC+0. Not bound or used in low half patches. |
| 613 | // Not bound in high half patches on R2 when using HMipsComputeBaseMethodAddress. |
| 614 | // Bound in high half patches on R2 when using the NAL instruction instead of |
| 615 | // HMipsComputeBaseMethodAddress. |
| 616 | // Bound in high half patches on R6. |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 617 | MipsLabel pc_rel_label; |
| Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 618 | // Pointer to the info for the high half patch or nullptr if this is the high half patch info. |
| 619 | const PcRelativePatchInfo* patch_info_high; |
| 620 | |
| 621 | private: |
| 622 | PcRelativePatchInfo(PcRelativePatchInfo&& other) = delete; |
| 623 | DISALLOW_COPY_AND_ASSIGN(PcRelativePatchInfo); |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 624 | }; |
| 625 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 626 | PcRelativePatchInfo* NewBootImageIntrinsicPatch(uint32_t intrinsic_data, |
| 627 | const PcRelativePatchInfo* info_high = nullptr); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 628 | PcRelativePatchInfo* NewBootImageRelRoPatch(uint32_t boot_image_offset, |
| 629 | const PcRelativePatchInfo* info_high = nullptr); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 630 | PcRelativePatchInfo* NewBootImageMethodPatch(MethodReference target_method, |
| 631 | const PcRelativePatchInfo* info_high = nullptr); |
| Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 632 | PcRelativePatchInfo* NewMethodBssEntryPatch(MethodReference target_method, |
| 633 | const PcRelativePatchInfo* info_high = nullptr); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 634 | PcRelativePatchInfo* NewBootImageTypePatch(const DexFile& dex_file, |
| 635 | dex::TypeIndex type_index, |
| 636 | const PcRelativePatchInfo* info_high = nullptr); |
| Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 637 | PcRelativePatchInfo* NewTypeBssEntryPatch(const DexFile& dex_file, |
| 638 | dex::TypeIndex type_index, |
| 639 | const PcRelativePatchInfo* info_high = nullptr); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 640 | PcRelativePatchInfo* NewBootImageStringPatch(const DexFile& dex_file, |
| 641 | dex::StringIndex string_index, |
| 642 | const PcRelativePatchInfo* info_high = nullptr); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 643 | PcRelativePatchInfo* NewStringBssEntryPatch(const DexFile& dex_file, |
| 644 | dex::StringIndex string_index, |
| 645 | const PcRelativePatchInfo* info_high = nullptr); |
| Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 646 | Literal* DeduplicateBootImageAddressLiteral(uint32_t address); |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 647 | |
| Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 648 | void EmitPcRelativeAddressPlaceholderHigh(PcRelativePatchInfo* info_high, |
| 649 | Register out, |
| Alexey Frunze | a663d9d | 2017-07-31 18:43:18 -0700 | [diff] [blame] | 650 | Register base); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 651 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 652 | void LoadBootImageAddress(Register reg, uint32_t boot_image_reference); |
| 653 | void AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, uint32_t boot_image_offset); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 654 | |
| Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 655 | // The JitPatchInfo is used for JIT string and class loads. |
| 656 | struct JitPatchInfo { |
| 657 | JitPatchInfo(const DexFile& dex_file, uint64_t idx) |
| 658 | : target_dex_file(dex_file), index(idx) { } |
| 659 | JitPatchInfo(JitPatchInfo&& other) = default; |
| 660 | |
| 661 | const DexFile& target_dex_file; |
| 662 | // String/type index. |
| 663 | uint64_t index; |
| 664 | // Label for the instruction loading the most significant half of the address. |
| Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 665 | MipsLabel high_label; |
| Alexey Frunze | 4147fcc | 2017-06-17 19:57:27 -0700 | [diff] [blame] | 666 | // Label for the instruction supplying the least significant half of the address. |
| 667 | MipsLabel low_label; |
| Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 668 | }; |
| 669 | |
| 670 | void PatchJitRootUse(uint8_t* code, |
| 671 | const uint8_t* roots_data, |
| 672 | const JitPatchInfo& info, |
| 673 | uint64_t index_in_table) const; |
| 674 | JitPatchInfo* NewJitRootStringPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 675 | dex::StringIndex string_index, |
| Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 676 | Handle<mirror::String> handle); |
| 677 | JitPatchInfo* NewJitRootClassPatch(const DexFile& dex_file, |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 678 | dex::TypeIndex type_index, |
| Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 679 | Handle<mirror::Class> handle); |
| 680 | |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 681 | private: |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 682 | Register GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, Register temp); |
| 683 | |
| Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 684 | using Uint32ToLiteralMap = ArenaSafeMap<uint32_t, Literal*>; |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 685 | |
| Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 686 | Literal* DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 687 | PcRelativePatchInfo* NewPcRelativePatch(const DexFile* dex_file, |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 688 | uint32_t offset_or_index, |
| Alexey Frunze | 5fa5c04 | 2017-06-01 21:07:52 -0700 | [diff] [blame] | 689 | const PcRelativePatchInfo* info_high, |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 690 | ArenaDeque<PcRelativePatchInfo>* patches); |
| 691 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 692 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 693 | void EmitPcRelativeLinkerPatches(const ArenaDeque<PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 694 | ArenaVector<linker::LinkerPatch>* linker_patches); |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 695 | |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 696 | // Labels for each block that will be compiled. |
| 697 | MipsLabel* block_labels_; |
| 698 | MipsLabel frame_entry_label_; |
| 699 | LocationsBuilderMIPS location_builder_; |
| 700 | InstructionCodeGeneratorMIPS instruction_visitor_; |
| 701 | ParallelMoveResolverMIPS move_resolver_; |
| 702 | MipsAssembler assembler_; |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 703 | |
| Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 704 | // Deduplication map for 32-bit literals, used for non-patchable boot image addresses. |
| 705 | Uint32ToLiteralMap uint32_literals_; |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 706 | // PC-relative method patch info for kBootImageLinkTimePcRelative. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 707 | ArenaDeque<PcRelativePatchInfo> boot_image_method_patches_; |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 708 | // PC-relative method patch info for kBssEntry. |
| 709 | ArenaDeque<PcRelativePatchInfo> method_bss_entry_patches_; |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 710 | // PC-relative type patch info for kBootImageLinkTimePcRelative. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 711 | ArenaDeque<PcRelativePatchInfo> boot_image_type_patches_; |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 712 | // PC-relative type patch info for kBssEntry. |
| 713 | ArenaDeque<PcRelativePatchInfo> type_bss_entry_patches_; |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 714 | // PC-relative String patch info for kBootImageLinkTimePcRelative. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 715 | ArenaDeque<PcRelativePatchInfo> boot_image_string_patches_; |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 716 | // PC-relative String patch info for kBssEntry. |
| 717 | ArenaDeque<PcRelativePatchInfo> string_bss_entry_patches_; |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 718 | // PC-relative patch info for IntrinsicObjects for the boot image, |
| 719 | // and for method/type/string patches for kBootImageRelRo otherwise. |
| 720 | ArenaDeque<PcRelativePatchInfo> boot_image_other_patches_; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 721 | |
| Alexey Frunze | 627c1a0 | 2017-01-30 19:28:14 -0800 | [diff] [blame] | 722 | // Patches for string root accesses in JIT compiled code. |
| 723 | ArenaDeque<JitPatchInfo> jit_string_patches_; |
| 724 | // Patches for class root accesses in JIT compiled code. |
| 725 | ArenaDeque<JitPatchInfo> jit_class_patches_; |
| Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 726 | |
| 727 | // PC-relative loads on R2 clobber RA, which may need to be preserved explicitly in leaf methods. |
| 728 | // This is a flag set by pc_relative_fixups_mips and dex_cache_array_fixups_mips optimizations. |
| 729 | bool clobbered_ra_; |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 730 | |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 731 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorMIPS); |
| 732 | }; |
| 733 | |
| 734 | } // namespace mips |
| 735 | } // namespace art |
| 736 | |
| 737 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_MIPS_H_ |