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