| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_ARM_VIXL_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM_VIXL_H_ |
| 19 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 20 | #include "base/enums.h" |
| 21 | #include "code_generator.h" |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 22 | #include "common_arm.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" |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 25 | #include "driver/compiler_options.h" |
| 26 | #include "nodes.h" |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 27 | #include "parallel_move_resolver.h" |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 28 | #include "utils/arm/assembler_arm_vixl.h" |
| 29 | |
| 30 | // TODO(VIXL): make vixl clean wrt -Wshadow. |
| 31 | #pragma GCC diagnostic push |
| 32 | #pragma GCC diagnostic ignored "-Wshadow" |
| 33 | #include "aarch32/constants-aarch32.h" |
| 34 | #include "aarch32/instructions-aarch32.h" |
| 35 | #include "aarch32/macro-assembler-aarch32.h" |
| 36 | #pragma GCC diagnostic pop |
| 37 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 38 | namespace art { |
| 39 | namespace arm { |
| 40 | |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 41 | // This constant is used as an approximate margin when emission of veneer and literal pools |
| 42 | // must be blocked. |
| 43 | static constexpr int kMaxMacroInstructionSizeInBytes = |
| 44 | 15 * vixl::aarch32::kMaxInstructionSizeInBytes; |
| 45 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 46 | static const vixl::aarch32::Register kParameterCoreRegistersVIXL[] = { |
| 47 | vixl::aarch32::r1, |
| 48 | vixl::aarch32::r2, |
| 49 | vixl::aarch32::r3 |
| 50 | }; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 51 | static const size_t kParameterCoreRegistersLengthVIXL = arraysize(kParameterCoreRegistersVIXL); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 52 | static const vixl::aarch32::SRegister kParameterFpuRegistersVIXL[] = { |
| 53 | vixl::aarch32::s0, |
| 54 | vixl::aarch32::s1, |
| 55 | vixl::aarch32::s2, |
| 56 | vixl::aarch32::s3, |
| 57 | vixl::aarch32::s4, |
| 58 | vixl::aarch32::s5, |
| 59 | vixl::aarch32::s6, |
| 60 | vixl::aarch32::s7, |
| 61 | vixl::aarch32::s8, |
| 62 | vixl::aarch32::s9, |
| 63 | vixl::aarch32::s10, |
| 64 | vixl::aarch32::s11, |
| 65 | vixl::aarch32::s12, |
| 66 | vixl::aarch32::s13, |
| 67 | vixl::aarch32::s14, |
| 68 | vixl::aarch32::s15 |
| 69 | }; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 70 | static const size_t kParameterFpuRegistersLengthVIXL = arraysize(kParameterFpuRegistersVIXL); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 71 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 72 | static const vixl::aarch32::Register kMethodRegister = vixl::aarch32::r0; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 73 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 74 | static const vixl::aarch32::Register kCoreAlwaysSpillRegister = vixl::aarch32::r5; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 75 | |
| Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 76 | // Callee saves core registers r5, r6, r7, r8 (except when emitting Baker |
| 77 | // read barriers, where it is used as Marking Register), r10, r11, and lr. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 78 | static const vixl::aarch32::RegisterList kCoreCalleeSaves = vixl::aarch32::RegisterList::Union( |
| 79 | vixl::aarch32::RegisterList(vixl::aarch32::r5, |
| 80 | vixl::aarch32::r6, |
| Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 81 | vixl::aarch32::r7), |
| 82 | // Do not consider r8 as a callee-save register with Baker read barriers. |
| 83 | ((kEmitCompilerReadBarrier && kUseBakerReadBarrier) |
| 84 | ? vixl::aarch32::RegisterList() |
| 85 | : vixl::aarch32::RegisterList(vixl::aarch32::r8)), |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 86 | vixl::aarch32::RegisterList(vixl::aarch32::r10, |
| 87 | vixl::aarch32::r11, |
| 88 | vixl::aarch32::lr)); |
| 89 | |
| 90 | // Callee saves FP registers s16 to s31 inclusive. |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 91 | static const vixl::aarch32::SRegisterList kFpuCalleeSaves = |
| 92 | vixl::aarch32::SRegisterList(vixl::aarch32::s16, 16); |
| 93 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 94 | static const vixl::aarch32::Register kRuntimeParameterCoreRegistersVIXL[] = { |
| 95 | vixl::aarch32::r0, |
| 96 | vixl::aarch32::r1, |
| 97 | vixl::aarch32::r2, |
| 98 | vixl::aarch32::r3 |
| 99 | }; |
| 100 | static const size_t kRuntimeParameterCoreRegistersLengthVIXL = |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 101 | arraysize(kRuntimeParameterCoreRegistersVIXL); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 102 | static const vixl::aarch32::SRegister kRuntimeParameterFpuRegistersVIXL[] = { |
| 103 | vixl::aarch32::s0, |
| 104 | vixl::aarch32::s1, |
| 105 | vixl::aarch32::s2, |
| 106 | vixl::aarch32::s3 |
| 107 | }; |
| 108 | static const size_t kRuntimeParameterFpuRegistersLengthVIXL = |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 109 | arraysize(kRuntimeParameterFpuRegistersVIXL); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 110 | |
| 111 | class LoadClassSlowPathARMVIXL; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 112 | class CodeGeneratorARMVIXL; |
| 113 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 114 | using VIXLInt32Literal = vixl::aarch32::Literal<int32_t>; |
| 115 | using VIXLUInt32Literal = vixl::aarch32::Literal<uint32_t>; |
| 116 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 117 | class JumpTableARMVIXL : public DeletableArenaObject<kArenaAllocSwitchTable> { |
| 118 | public: |
| 119 | explicit JumpTableARMVIXL(HPackedSwitch* switch_instr) |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 120 | : switch_instr_(switch_instr), |
| 121 | table_start_(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 122 | bb_addresses_(switch_instr->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 123 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 124 | for (uint32_t i = 0; i < num_entries; i++) { |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 125 | VIXLInt32Literal *lit = new VIXLInt32Literal(0, vixl32::RawLiteral::kManuallyPlaced); |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 126 | bb_addresses_.emplace_back(lit); |
| 127 | } |
| 128 | } |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 129 | |
| 130 | vixl::aarch32::Label* GetTableStartLabel() { return &table_start_; } |
| 131 | |
| 132 | void EmitTable(CodeGeneratorARMVIXL* codegen); |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 133 | void FixTable(CodeGeneratorARMVIXL* codegen); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 134 | |
| 135 | private: |
| 136 | HPackedSwitch* const switch_instr_; |
| 137 | vixl::aarch32::Label table_start_; |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 138 | ArenaVector<std::unique_ptr<VIXLInt32Literal>> bb_addresses_; |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 139 | |
| 140 | DISALLOW_COPY_AND_ASSIGN(JumpTableARMVIXL); |
| 141 | }; |
| 142 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 143 | class InvokeRuntimeCallingConventionARMVIXL |
| 144 | : public CallingConvention<vixl::aarch32::Register, vixl::aarch32::SRegister> { |
| 145 | public: |
| 146 | InvokeRuntimeCallingConventionARMVIXL() |
| 147 | : CallingConvention(kRuntimeParameterCoreRegistersVIXL, |
| 148 | kRuntimeParameterCoreRegistersLengthVIXL, |
| 149 | kRuntimeParameterFpuRegistersVIXL, |
| 150 | kRuntimeParameterFpuRegistersLengthVIXL, |
| 151 | kArmPointerSize) {} |
| 152 | |
| 153 | private: |
| 154 | DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConventionARMVIXL); |
| 155 | }; |
| 156 | |
| 157 | class InvokeDexCallingConventionARMVIXL |
| 158 | : public CallingConvention<vixl::aarch32::Register, vixl::aarch32::SRegister> { |
| 159 | public: |
| 160 | InvokeDexCallingConventionARMVIXL() |
| 161 | : CallingConvention(kParameterCoreRegistersVIXL, |
| 162 | kParameterCoreRegistersLengthVIXL, |
| 163 | kParameterFpuRegistersVIXL, |
| 164 | kParameterFpuRegistersLengthVIXL, |
| 165 | kArmPointerSize) {} |
| 166 | |
| 167 | private: |
| 168 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionARMVIXL); |
| 169 | }; |
| 170 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 171 | class InvokeDexCallingConventionVisitorARMVIXL : public InvokeDexCallingConventionVisitor { |
| 172 | public: |
| 173 | InvokeDexCallingConventionVisitorARMVIXL() {} |
| 174 | virtual ~InvokeDexCallingConventionVisitorARMVIXL() {} |
| 175 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 176 | Location GetNextLocation(DataType::Type type) OVERRIDE; |
| 177 | Location GetReturnLocation(DataType::Type type) const OVERRIDE; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 178 | Location GetMethodLocation() const OVERRIDE; |
| 179 | |
| 180 | private: |
| 181 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 182 | uint32_t double_index_ = 0; |
| 183 | |
| 184 | DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorARMVIXL); |
| 185 | }; |
| 186 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 187 | class FieldAccessCallingConventionARMVIXL : public FieldAccessCallingConvention { |
| 188 | public: |
| 189 | FieldAccessCallingConventionARMVIXL() {} |
| 190 | |
| 191 | Location GetObjectLocation() const OVERRIDE { |
| 192 | return helpers::LocationFrom(vixl::aarch32::r1); |
| 193 | } |
| 194 | Location GetFieldIndexLocation() const OVERRIDE { |
| 195 | return helpers::LocationFrom(vixl::aarch32::r0); |
| 196 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 197 | Location GetReturnLocation(DataType::Type type) const OVERRIDE { |
| 198 | return DataType::Is64BitType(type) |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 199 | ? helpers::LocationFrom(vixl::aarch32::r0, vixl::aarch32::r1) |
| 200 | : helpers::LocationFrom(vixl::aarch32::r0); |
| 201 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 202 | Location GetSetValueLocation(DataType::Type type, bool is_instance) const OVERRIDE { |
| 203 | return DataType::Is64BitType(type) |
| Nicolas Geoffray | a72859d | 2017-01-26 22:47:27 +0000 | [diff] [blame] | 204 | ? helpers::LocationFrom(vixl::aarch32::r2, vixl::aarch32::r3) |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 205 | : (is_instance |
| 206 | ? helpers::LocationFrom(vixl::aarch32::r2) |
| 207 | : helpers::LocationFrom(vixl::aarch32::r1)); |
| 208 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 209 | Location GetFpuLocation(DataType::Type type) const OVERRIDE { |
| 210 | return DataType::Is64BitType(type) |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 211 | ? helpers::LocationFrom(vixl::aarch32::s0, vixl::aarch32::s1) |
| 212 | : helpers::LocationFrom(vixl::aarch32::s0); |
| 213 | } |
| 214 | |
| 215 | private: |
| 216 | DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConventionARMVIXL); |
| 217 | }; |
| 218 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 219 | class SlowPathCodeARMVIXL : public SlowPathCode { |
| 220 | public: |
| 221 | explicit SlowPathCodeARMVIXL(HInstruction* instruction) |
| 222 | : SlowPathCode(instruction), entry_label_(), exit_label_() {} |
| 223 | |
| 224 | vixl::aarch32::Label* GetEntryLabel() { return &entry_label_; } |
| 225 | vixl::aarch32::Label* GetExitLabel() { return &exit_label_; } |
| 226 | |
| 227 | void SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) OVERRIDE; |
| 228 | void RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) OVERRIDE; |
| 229 | |
| 230 | private: |
| 231 | vixl::aarch32::Label entry_label_; |
| 232 | vixl::aarch32::Label exit_label_; |
| 233 | |
| 234 | DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARMVIXL); |
| 235 | }; |
| 236 | |
| 237 | class ParallelMoveResolverARMVIXL : public ParallelMoveResolverWithSwap { |
| 238 | public: |
| 239 | ParallelMoveResolverARMVIXL(ArenaAllocator* allocator, CodeGeneratorARMVIXL* codegen) |
| 240 | : ParallelMoveResolverWithSwap(allocator), codegen_(codegen) {} |
| 241 | |
| 242 | void EmitMove(size_t index) OVERRIDE; |
| 243 | void EmitSwap(size_t index) OVERRIDE; |
| 244 | void SpillScratch(int reg) OVERRIDE; |
| 245 | void RestoreScratch(int reg) OVERRIDE; |
| 246 | |
| 247 | ArmVIXLAssembler* GetAssembler() const; |
| 248 | |
| 249 | private: |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 250 | void Exchange(vixl32::Register reg, int mem); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 251 | void Exchange(int mem1, int mem2); |
| 252 | |
| 253 | CodeGeneratorARMVIXL* const codegen_; |
| 254 | |
| 255 | DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverARMVIXL); |
| 256 | }; |
| 257 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 258 | class LocationsBuilderARMVIXL : public HGraphVisitor { |
| 259 | public: |
| 260 | LocationsBuilderARMVIXL(HGraph* graph, CodeGeneratorARMVIXL* codegen) |
| 261 | : HGraphVisitor(graph), codegen_(codegen) {} |
| 262 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 263 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| 264 | void Visit##name(H##name* instr) OVERRIDE; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 265 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 266 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 267 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(DECLARE_VISIT_INSTRUCTION) |
| 268 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(DECLARE_VISIT_INSTRUCTION) |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 269 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 270 | #undef DECLARE_VISIT_INSTRUCTION |
| 271 | |
| 272 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 273 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 274 | << " (id " << instruction->GetId() << ")"; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 275 | } |
| 276 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 277 | private: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 278 | void HandleInvoke(HInvoke* invoke); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 279 | void HandleBitwiseOperation(HBinaryOperation* operation, Opcode opcode); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 280 | void HandleCondition(HCondition* condition); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 281 | void HandleIntegerRotate(LocationSummary* locations); |
| 282 | void HandleLongRotate(LocationSummary* locations); |
| 283 | void HandleShift(HBinaryOperation* operation); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 284 | void HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info); |
| 285 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 286 | |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 287 | Location ArithmeticZeroOrFpuRegister(HInstruction* input); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 288 | Location ArmEncodableConstantOrRegister(HInstruction* constant, Opcode opcode); |
| 289 | bool CanEncodeConstantAsImmediate(HConstant* input_cst, Opcode opcode); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 290 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 291 | CodeGeneratorARMVIXL* const codegen_; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 292 | InvokeDexCallingConventionVisitorARMVIXL parameter_visitor_; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 293 | |
| 294 | DISALLOW_COPY_AND_ASSIGN(LocationsBuilderARMVIXL); |
| 295 | }; |
| 296 | |
| 297 | class InstructionCodeGeneratorARMVIXL : public InstructionCodeGenerator { |
| 298 | public: |
| 299 | InstructionCodeGeneratorARMVIXL(HGraph* graph, CodeGeneratorARMVIXL* codegen); |
| 300 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 301 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| 302 | void Visit##name(H##name* instr) OVERRIDE; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 303 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 304 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION) |
| 305 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(DECLARE_VISIT_INSTRUCTION) |
| 306 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(DECLARE_VISIT_INSTRUCTION) |
| 307 | |
| 308 | #undef DECLARE_VISIT_INSTRUCTION |
| 309 | |
| 310 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 311 | LOG(FATAL) << "Unreachable instruction " << instruction->DebugName() |
| 312 | << " (id " << instruction->GetId() << ")"; |
| 313 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 314 | |
| 315 | ArmVIXLAssembler* GetAssembler() const { return assembler_; } |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 316 | ArmVIXLMacroAssembler* GetVIXLAssembler() { return GetAssembler()->GetVIXLAssembler(); } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 317 | |
| 318 | private: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 319 | // Generate code for the given suspend check. If not null, `successor` |
| 320 | // is the block to branch to if the suspend check is not needed, and after |
| 321 | // the suspend call. |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 322 | void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 323 | void GenerateClassInitializationCheck(LoadClassSlowPathARMVIXL* slow_path, |
| 324 | vixl32::Register class_reg); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 325 | void GenerateAndConst(vixl::aarch32::Register out, vixl::aarch32::Register first, uint32_t value); |
| 326 | void GenerateOrrConst(vixl::aarch32::Register out, vixl::aarch32::Register first, uint32_t value); |
| 327 | void GenerateEorConst(vixl::aarch32::Register out, vixl::aarch32::Register first, uint32_t value); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 328 | void GenerateAddLongConst(Location out, Location first, uint64_t value); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 329 | void HandleBitwiseOperation(HBinaryOperation* operation); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 330 | void HandleCondition(HCondition* condition); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 331 | void HandleIntegerRotate(HRor* ror); |
| 332 | void HandleLongRotate(HRor* ror); |
| 333 | void HandleShift(HBinaryOperation* operation); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 334 | |
| 335 | void GenerateWideAtomicStore(vixl::aarch32::Register addr, |
| 336 | uint32_t offset, |
| 337 | vixl::aarch32::Register value_lo, |
| 338 | vixl::aarch32::Register value_hi, |
| 339 | vixl::aarch32::Register temp1, |
| 340 | vixl::aarch32::Register temp2, |
| 341 | HInstruction* instruction); |
| 342 | void GenerateWideAtomicLoad(vixl::aarch32::Register addr, |
| 343 | uint32_t offset, |
| 344 | vixl::aarch32::Register out_lo, |
| 345 | vixl::aarch32::Register out_hi); |
| 346 | |
| 347 | void HandleFieldSet(HInstruction* instruction, |
| 348 | const FieldInfo& field_info, |
| 349 | bool value_can_be_null); |
| 350 | void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info); |
| 351 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 352 | void GenerateMinMaxInt(LocationSummary* locations, bool is_min); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 353 | void GenerateMinMaxLong(LocationSummary* locations, bool is_min); |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 354 | void GenerateMinMaxFloat(HInstruction* minmax, bool is_min); |
| 355 | void GenerateMinMaxDouble(HInstruction* minmax, bool is_min); |
| 356 | void GenerateMinMax(HBinaryOperation* minmax, bool is_min); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 357 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 358 | // Generate a heap reference load using one register `out`: |
| 359 | // |
| 360 | // out <- *(out + offset) |
| 361 | // |
| 362 | // while honoring heap poisoning and/or read barriers (if any). |
| 363 | // |
| 364 | // Location `maybe_temp` is used when generating a read barrier and |
| 365 | // shall be a register in that case; it may be an invalid location |
| 366 | // otherwise. |
| 367 | void GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 368 | Location out, |
| 369 | uint32_t offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 370 | Location maybe_temp, |
| 371 | ReadBarrierOption read_barrier_option); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 372 | // Generate a heap reference load using two different registers |
| 373 | // `out` and `obj`: |
| 374 | // |
| 375 | // out <- *(obj + offset) |
| 376 | // |
| 377 | // while honoring heap poisoning and/or read barriers (if any). |
| 378 | // |
| 379 | // Location `maybe_temp` is used when generating a Baker's (fast |
| 380 | // path) read barrier and shall be a register in that case; it may |
| 381 | // be an invalid location otherwise. |
| 382 | void GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 383 | Location out, |
| 384 | Location obj, |
| 385 | uint32_t offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 386 | Location maybe_temp, |
| 387 | ReadBarrierOption read_barrier_option); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 388 | // Generate a GC root reference load: |
| 389 | // |
| 390 | // root <- *(obj + offset) |
| 391 | // |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 392 | // while honoring read barriers based on read_barrier_option. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 393 | void GenerateGcRootFieldLoad(HInstruction* instruction, |
| 394 | Location root, |
| 395 | vixl::aarch32::Register obj, |
| 396 | uint32_t offset, |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 397 | ReadBarrierOption read_barrier_option); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 398 | void GenerateTestAndBranch(HInstruction* instruction, |
| 399 | size_t condition_input_index, |
| 400 | vixl::aarch32::Label* true_target, |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 401 | vixl::aarch32::Label* false_target, |
| 402 | bool far_target = true); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 403 | void GenerateCompareTestAndBranch(HCondition* condition, |
| 404 | vixl::aarch32::Label* true_target, |
| Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 405 | vixl::aarch32::Label* false_target, |
| 406 | bool is_far_target = true); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 407 | void DivRemOneOrMinusOne(HBinaryOperation* instruction); |
| 408 | void DivRemByPowerOfTwo(HBinaryOperation* instruction); |
| 409 | void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction); |
| 410 | void GenerateDivRemConstantIntegral(HBinaryOperation* instruction); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 411 | void HandleGoto(HInstruction* got, HBasicBlock* successor); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 412 | |
| Artem Serov | 8f7c410 | 2017-06-21 11:21:37 +0100 | [diff] [blame] | 413 | vixl::aarch32::MemOperand VecAddress( |
| 414 | HVecMemoryOperation* instruction, |
| 415 | // This function may acquire a scratch register. |
| 416 | vixl::aarch32::UseScratchRegisterScope* temps_scope, |
| 417 | /*out*/ vixl32::Register* scratch); |
| 418 | vixl::aarch32::AlignedMemOperand VecAddressUnaligned( |
| 419 | HVecMemoryOperation* instruction, |
| 420 | // This function may acquire a scratch register. |
| 421 | vixl::aarch32::UseScratchRegisterScope* temps_scope, |
| 422 | /*out*/ vixl32::Register* scratch); |
| 423 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 424 | ArmVIXLAssembler* const assembler_; |
| 425 | CodeGeneratorARMVIXL* const codegen_; |
| 426 | |
| 427 | DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorARMVIXL); |
| 428 | }; |
| 429 | |
| 430 | class CodeGeneratorARMVIXL : public CodeGenerator { |
| 431 | public: |
| 432 | CodeGeneratorARMVIXL(HGraph* graph, |
| 433 | const ArmInstructionSetFeatures& isa_features, |
| 434 | const CompilerOptions& compiler_options, |
| 435 | OptimizingCompilerStats* stats = nullptr); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 436 | virtual ~CodeGeneratorARMVIXL() {} |
| 437 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 438 | void GenerateFrameEntry() OVERRIDE; |
| 439 | void GenerateFrameExit() OVERRIDE; |
| 440 | void Bind(HBasicBlock* block) OVERRIDE; |
| 441 | void MoveConstant(Location destination, int32_t value) OVERRIDE; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 442 | void MoveLocation(Location dst, Location src, DataType::Type dst_type) OVERRIDE; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 443 | void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE; |
| 444 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 445 | size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 446 | size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 447 | size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 448 | size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE; |
| 449 | |
| 450 | size_t GetWordSize() const OVERRIDE { |
| 451 | return static_cast<size_t>(kArmPointerSize); |
| 452 | } |
| 453 | |
| 454 | size_t GetFloatingPointSpillSlotSize() const OVERRIDE { return vixl::aarch32::kRegSizeInBytes; } |
| 455 | |
| 456 | HGraphVisitor* GetLocationBuilder() OVERRIDE { return &location_builder_; } |
| 457 | |
| 458 | HGraphVisitor* GetInstructionVisitor() OVERRIDE { return &instruction_visitor_; } |
| 459 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 460 | ArmVIXLAssembler* GetAssembler() OVERRIDE { return &assembler_; } |
| 461 | |
| 462 | const ArmVIXLAssembler& GetAssembler() const OVERRIDE { return assembler_; } |
| 463 | |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 464 | ArmVIXLMacroAssembler* GetVIXLAssembler() { return GetAssembler()->GetVIXLAssembler(); } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 465 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 466 | uintptr_t GetAddressOf(HBasicBlock* block) OVERRIDE { |
| 467 | vixl::aarch32::Label* block_entry_label = GetLabelOf(block); |
| 468 | DCHECK(block_entry_label->IsBound()); |
| 469 | return block_entry_label->GetLocation(); |
| 470 | } |
| 471 | |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 472 | void FixJumpTables(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 473 | void SetupBlockedRegisters() const OVERRIDE; |
| 474 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 475 | void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 476 | void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE; |
| 477 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 478 | ParallelMoveResolver* GetMoveResolver() OVERRIDE { return &move_resolver_; } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 479 | InstructionSet GetInstructionSet() const OVERRIDE { return InstructionSet::kThumb2; } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 480 | // Helper method to move a 32-bit value between two locations. |
| 481 | void Move32(Location destination, Location source); |
| 482 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 483 | void LoadFromShiftedRegOffset(DataType::Type type, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 484 | Location out_loc, |
| 485 | vixl::aarch32::Register base, |
| 486 | vixl::aarch32::Register reg_index, |
| 487 | vixl::aarch32::Condition cond = vixl::aarch32::al); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 488 | void StoreToShiftedRegOffset(DataType::Type type, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 489 | Location out_loc, |
| 490 | vixl::aarch32::Register base, |
| 491 | vixl::aarch32::Register reg_index, |
| 492 | vixl::aarch32::Condition cond = vixl::aarch32::al); |
| 493 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 494 | // Generate code to invoke a runtime entry point. |
| 495 | void InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 496 | HInstruction* instruction, |
| 497 | uint32_t dex_pc, |
| 498 | SlowPathCode* slow_path = nullptr) OVERRIDE; |
| 499 | |
| 500 | // Generate code to invoke a runtime entry point, but do not record |
| 501 | // PC-related information in a stack map. |
| 502 | void InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 503 | HInstruction* instruction, |
| 504 | SlowPathCode* slow_path); |
| 505 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 506 | // Emit a write barrier. |
| 507 | void MarkGCCard(vixl::aarch32::Register temp, |
| 508 | vixl::aarch32::Register card, |
| 509 | vixl::aarch32::Register object, |
| 510 | vixl::aarch32::Register value, |
| 511 | bool can_be_null); |
| 512 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 513 | void GenerateMemoryBarrier(MemBarrierKind kind); |
| 514 | |
| 515 | vixl::aarch32::Label* GetLabelOf(HBasicBlock* block) { |
| 516 | block = FirstNonEmptyBlock(block); |
| 517 | return &(block_labels_[block->GetBlockId()]); |
| 518 | } |
| 519 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 520 | vixl32::Label* GetFinalLabel(HInstruction* instruction, vixl32::Label* final_label); |
| 521 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 522 | void Initialize() OVERRIDE { |
| 523 | block_labels_.resize(GetGraph()->GetBlocks().size()); |
| 524 | } |
| 525 | |
| 526 | void Finalize(CodeAllocator* allocator) OVERRIDE; |
| 527 | |
| 528 | const ArmInstructionSetFeatures& GetInstructionSetFeatures() const { return isa_features_; } |
| 529 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 530 | bool NeedsTwoRegisters(DataType::Type type) const OVERRIDE { |
| 531 | return type == DataType::Type::kFloat64 || type == DataType::Type::kInt64; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | void ComputeSpillMask() OVERRIDE; |
| 535 | |
| 536 | vixl::aarch32::Label* GetFrameEntryLabel() { return &frame_entry_label_; } |
| 537 | |
| 538 | // Check if the desired_string_load_kind is supported. If it is, return it, |
| 539 | // otherwise return a fall-back kind that should be used instead. |
| 540 | HLoadString::LoadKind GetSupportedLoadStringKind( |
| 541 | HLoadString::LoadKind desired_string_load_kind) OVERRIDE; |
| 542 | |
| 543 | // Check if the desired_class_load_kind is supported. If it is, return it, |
| 544 | // otherwise return a fall-back kind that should be used instead. |
| 545 | HLoadClass::LoadKind GetSupportedLoadClassKind( |
| 546 | HLoadClass::LoadKind desired_class_load_kind) OVERRIDE; |
| 547 | |
| 548 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 549 | // otherwise return a fall-back info that should be used instead. |
| 550 | HInvokeStaticOrDirect::DispatchInfo GetSupportedInvokeStaticOrDirectDispatch( |
| 551 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 552 | HInvokeStaticOrDirect* invoke) OVERRIDE; |
| 553 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 554 | void GenerateStaticOrDirectCall( |
| 555 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path = nullptr) OVERRIDE; |
| 556 | void GenerateVirtualCall( |
| 557 | HInvokeVirtual* invoke, Location temp, SlowPathCode* slow_path = nullptr) OVERRIDE; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 558 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 559 | void MoveFromReturnRegister(Location trg, DataType::Type type) OVERRIDE; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 560 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 561 | // The PcRelativePatchInfo is used for PC-relative addressing of methods/strings/types, |
| 562 | // whether through .data.bimg.rel.ro, .bss, or directly in the boot image. |
| 563 | // |
| 564 | // The PC-relative address is loaded with three instructions, |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 565 | // MOVW+MOVT to load the offset to base_reg and then ADD base_reg, PC. The offset |
| 566 | // is calculated from the ADD's effective PC, i.e. PC+4 on Thumb2. Though we |
| 567 | // currently emit these 3 instructions together, instruction scheduling could |
| 568 | // split this sequence apart, so we keep separate labels for each of them. |
| 569 | struct PcRelativePatchInfo { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 570 | PcRelativePatchInfo(const DexFile* dex_file, uint32_t off_or_idx) |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 571 | : target_dex_file(dex_file), offset_or_index(off_or_idx) { } |
| 572 | PcRelativePatchInfo(PcRelativePatchInfo&& other) = default; |
| 573 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 574 | // Target dex file or null for .data.bmig.rel.ro patches. |
| 575 | const DexFile* target_dex_file; |
| 576 | // Either the boot image offset (to write to .data.bmig.rel.ro) or string/type/method index. |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 577 | uint32_t offset_or_index; |
| 578 | vixl::aarch32::Label movw_label; |
| 579 | vixl::aarch32::Label movt_label; |
| 580 | vixl::aarch32::Label add_pc_label; |
| 581 | }; |
| 582 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 583 | PcRelativePatchInfo* NewBootImageRelRoPatch(uint32_t boot_image_offset); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 584 | PcRelativePatchInfo* NewBootImageMethodPatch(MethodReference target_method); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 585 | PcRelativePatchInfo* NewMethodBssEntryPatch(MethodReference target_method); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 586 | PcRelativePatchInfo* NewBootImageTypePatch(const DexFile& dex_file, dex::TypeIndex type_index); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 587 | PcRelativePatchInfo* NewTypeBssEntryPatch(const DexFile& dex_file, dex::TypeIndex type_index); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 588 | PcRelativePatchInfo* NewBootImageStringPatch(const DexFile& dex_file, |
| 589 | dex::StringIndex string_index); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 590 | PcRelativePatchInfo* NewStringBssEntryPatch(const DexFile& dex_file, |
| 591 | dex::StringIndex string_index); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 592 | |
| 593 | // Add a new baker read barrier patch and return the label to be bound |
| 594 | // before the BNE instruction. |
| 595 | vixl::aarch32::Label* NewBakerReadBarrierPatch(uint32_t custom_data); |
| 596 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 597 | VIXLUInt32Literal* DeduplicateBootImageAddressLiteral(uint32_t address); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 598 | VIXLUInt32Literal* DeduplicateJitStringLiteral(const DexFile& dex_file, |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 599 | dex::StringIndex string_index, |
| 600 | Handle<mirror::String> handle); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 601 | VIXLUInt32Literal* DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 602 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 603 | Handle<mirror::Class> handle); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 604 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 605 | void EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) OVERRIDE; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 606 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 607 | void EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) OVERRIDE; |
| 608 | |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 609 | // Maybe add the reserved entrypoint register as a temporary for field load. This temp |
| 610 | // is added only for AOT compilation if link-time generated thunks for fields are enabled. |
| 611 | void MaybeAddBakerCcEntrypointTempForFields(LocationSummary* locations); |
| 612 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 613 | // Fast path implementation of ReadBarrier::Barrier for a heap |
| 614 | // reference field load when Baker's read barriers are used. |
| 615 | void GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 616 | Location ref, |
| 617 | vixl::aarch32::Register obj, |
| 618 | uint32_t offset, |
| 619 | Location temp, |
| 620 | bool needs_null_check); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 621 | // Fast path implementation of ReadBarrier::Barrier for a heap |
| 622 | // reference array load when Baker's read barriers are used. |
| 623 | void GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 624 | Location ref, |
| 625 | vixl::aarch32::Register obj, |
| 626 | uint32_t data_offset, |
| 627 | Location index, |
| 628 | Location temp, |
| 629 | bool needs_null_check); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 630 | // Factored implementation, used by GenerateFieldLoadWithBakerReadBarrier, |
| 631 | // GenerateArrayLoadWithBakerReadBarrier and some intrinsics. |
| 632 | // |
| 633 | // Load the object reference located at the address |
| 634 | // `obj + offset + (index << scale_factor)`, held by object `obj`, into |
| 635 | // `ref`, and mark it if needed. |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 636 | void GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 637 | Location ref, |
| 638 | vixl::aarch32::Register obj, |
| 639 | uint32_t offset, |
| 640 | Location index, |
| 641 | ScaleFactor scale_factor, |
| 642 | Location temp, |
| Roland Levillain | ff48700 | 2017-03-07 16:50:01 +0000 | [diff] [blame] | 643 | bool needs_null_check); |
| 644 | |
| 645 | // Generate code checking whether the the reference field at the |
| 646 | // address `obj + field_offset`, held by object `obj`, needs to be |
| 647 | // marked, and if so, marking it and updating the field within `obj` |
| 648 | // with the marked value. |
| 649 | // |
| 650 | // This routine is used for the implementation of the |
| 651 | // UnsafeCASObject intrinsic with Baker read barriers. |
| 652 | // |
| 653 | // This method has a structure similar to |
| 654 | // GenerateReferenceLoadWithBakerReadBarrier, but note that argument |
| 655 | // `ref` is only as a temporary here, and thus its value should not |
| 656 | // be used afterwards. |
| 657 | void UpdateReferenceFieldWithBakerReadBarrier(HInstruction* instruction, |
| 658 | Location ref, |
| 659 | vixl::aarch32::Register obj, |
| 660 | Location field_offset, |
| 661 | Location temp, |
| 662 | bool needs_null_check, |
| 663 | vixl::aarch32::Register temp2); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 664 | |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 665 | // Generate a heap reference load (with no read barrier). |
| 666 | void GenerateRawReferenceLoad(HInstruction* instruction, |
| 667 | Location ref, |
| 668 | vixl::aarch32::Register obj, |
| 669 | uint32_t offset, |
| 670 | Location index, |
| 671 | ScaleFactor scale_factor, |
| 672 | bool needs_null_check); |
| 673 | |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 674 | // Emit code checking the status of the Marking Register, and |
| 675 | // aborting the program if MR does not match the value stored in the |
| 676 | // art::Thread object. Code is only emitted in debug mode and if |
| 677 | // CompilerOptions::EmitRunTimeChecksInDebugMode returns true. |
| 678 | // |
| 679 | // Argument `code` is used to identify the different occurrences of |
| 680 | // MaybeGenerateMarkingRegisterCheck in the code generator, and is |
| 681 | // used together with kMarkingRegisterCheckBreakCodeBaseCode to |
| 682 | // create the value passed to the BKPT instruction. Note that unlike |
| 683 | // in the ARM64 code generator, where `__LINE__` is passed as `code` |
| 684 | // argument to |
| 685 | // CodeGeneratorARM64::MaybeGenerateMarkingRegisterCheck, we cannot |
| 686 | // realistically do that here, as Encoding T1 for the BKPT |
| 687 | // instruction only accepts 8-bit immediate values. |
| 688 | // |
| 689 | // If `temp_loc` is a valid location, it is expected to be a |
| 690 | // register and will be used as a temporary to generate code; |
| 691 | // otherwise, a temporary will be fetched from the core register |
| 692 | // scratch pool. |
| 693 | virtual void MaybeGenerateMarkingRegisterCheck(int code, |
| 694 | Location temp_loc = Location::NoLocation()); |
| 695 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 696 | // Generate a read barrier for a heap reference within `instruction` |
| 697 | // using a slow path. |
| 698 | // |
| 699 | // A read barrier for an object reference read from the heap is |
| 700 | // implemented as a call to the artReadBarrierSlow runtime entry |
| 701 | // point, which is passed the values in locations `ref`, `obj`, and |
| 702 | // `offset`: |
| 703 | // |
| 704 | // mirror::Object* artReadBarrierSlow(mirror::Object* ref, |
| 705 | // mirror::Object* obj, |
| 706 | // uint32_t offset); |
| 707 | // |
| 708 | // The `out` location contains the value returned by |
| 709 | // artReadBarrierSlow. |
| 710 | // |
| 711 | // When `index` is provided (i.e. for array accesses), the offset |
| 712 | // value passed to artReadBarrierSlow is adjusted to take `index` |
| 713 | // into account. |
| 714 | void GenerateReadBarrierSlow(HInstruction* instruction, |
| 715 | Location out, |
| 716 | Location ref, |
| 717 | Location obj, |
| 718 | uint32_t offset, |
| 719 | Location index = Location::NoLocation()); |
| 720 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 721 | // If read barriers are enabled, generate a read barrier for a heap |
| 722 | // reference using a slow path. If heap poisoning is enabled, also |
| 723 | // unpoison the reference in `out`. |
| 724 | void MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 725 | Location out, |
| 726 | Location ref, |
| 727 | Location obj, |
| 728 | uint32_t offset, |
| 729 | Location index = Location::NoLocation()); |
| 730 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 731 | // Generate a read barrier for a GC root within `instruction` using |
| 732 | // a slow path. |
| 733 | // |
| 734 | // A read barrier for an object reference GC root is implemented as |
| 735 | // a call to the artReadBarrierForRootSlow runtime entry point, |
| 736 | // which is passed the value in location `root`: |
| 737 | // |
| 738 | // mirror::Object* artReadBarrierForRootSlow(GcRoot<mirror::Object>* root); |
| 739 | // |
| 740 | // The `out` location contains the value returned by |
| 741 | // artReadBarrierForRootSlow. |
| 742 | void GenerateReadBarrierForRootSlow(HInstruction* instruction, Location out, Location root); |
| 743 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 744 | void GenerateNop() OVERRIDE; |
| 745 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 746 | void GenerateImplicitNullCheck(HNullCheck* instruction) OVERRIDE; |
| 747 | void GenerateExplicitNullCheck(HNullCheck* instruction) OVERRIDE; |
| 748 | |
| 749 | JumpTableARMVIXL* CreateJumpTable(HPackedSwitch* switch_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 750 | jump_tables_.emplace_back(new (GetGraph()->GetAllocator()) JumpTableARMVIXL(switch_instr)); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 751 | return jump_tables_.back().get(); |
| 752 | } |
| 753 | void EmitJumpTables(); |
| 754 | |
| 755 | void EmitMovwMovtPlaceholder(CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 756 | vixl::aarch32::Register out); |
| 757 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 758 | // `temp` is an extra temporary register that is used for some conditions; |
| 759 | // callers may not specify it, in which case the method will use a scratch |
| 760 | // register instead. |
| 761 | void GenerateConditionWithZero(IfCondition condition, |
| 762 | vixl::aarch32::Register out, |
| 763 | vixl::aarch32::Register in, |
| 764 | vixl::aarch32::Register temp = vixl32::Register()); |
| 765 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 766 | private: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 767 | vixl::aarch32::Register GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 768 | vixl::aarch32::Register temp); |
| 769 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 770 | using Uint32ToLiteralMap = ArenaSafeMap<uint32_t, VIXLUInt32Literal*>; |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 771 | using StringToLiteralMap = ArenaSafeMap<StringReference, |
| 772 | VIXLUInt32Literal*, |
| 773 | StringReferenceValueComparator>; |
| 774 | using TypeToLiteralMap = ArenaSafeMap<TypeReference, |
| 775 | VIXLUInt32Literal*, |
| 776 | TypeReferenceValueComparator>; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 777 | |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 778 | struct BakerReadBarrierPatchInfo { |
| 779 | explicit BakerReadBarrierPatchInfo(uint32_t data) : label(), custom_data(data) { } |
| 780 | |
| 781 | vixl::aarch32::Label label; |
| 782 | uint32_t custom_data; |
| 783 | }; |
| 784 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 785 | VIXLUInt32Literal* DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 786 | PcRelativePatchInfo* NewPcRelativePatch(const DexFile* dex_file, |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 787 | uint32_t offset_or_index, |
| 788 | ArenaDeque<PcRelativePatchInfo>* patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 789 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 790 | static void EmitPcRelativeLinkerPatches(const ArenaDeque<PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 791 | ArenaVector<linker::LinkerPatch>* linker_patches); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 792 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 793 | // Labels for each block that will be compiled. |
| 794 | // We use a deque so that the `vixl::aarch32::Label` objects do not move in memory. |
| 795 | ArenaDeque<vixl::aarch32::Label> block_labels_; // Indexed by block id. |
| 796 | vixl::aarch32::Label frame_entry_label_; |
| 797 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 798 | ArenaVector<std::unique_ptr<JumpTableARMVIXL>> jump_tables_; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 799 | LocationsBuilderARMVIXL location_builder_; |
| 800 | InstructionCodeGeneratorARMVIXL instruction_visitor_; |
| 801 | ParallelMoveResolverARMVIXL move_resolver_; |
| 802 | |
| 803 | ArmVIXLAssembler assembler_; |
| 804 | const ArmInstructionSetFeatures& isa_features_; |
| 805 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 806 | // Deduplication map for 32-bit literals, used for non-patchable boot image addresses. |
| 807 | Uint32ToLiteralMap uint32_literals_; |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 808 | // PC-relative method patch info for kBootImageLinkTimePcRelative/kBootImageRelRo. |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 809 | // 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] | 810 | ArenaDeque<PcRelativePatchInfo> boot_image_method_patches_; |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 811 | // PC-relative method patch info for kBssEntry. |
| 812 | ArenaDeque<PcRelativePatchInfo> method_bss_entry_patches_; |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 813 | // PC-relative type patch info for kBootImageLinkTimePcRelative. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 814 | ArenaDeque<PcRelativePatchInfo> boot_image_type_patches_; |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 815 | // PC-relative type patch info for kBssEntry. |
| 816 | ArenaDeque<PcRelativePatchInfo> type_bss_entry_patches_; |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 817 | // PC-relative String patch info for kBootImageLinkTimePcRelative. |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 818 | ArenaDeque<PcRelativePatchInfo> boot_image_string_patches_; |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 819 | // PC-relative String patch info for kBssEntry. |
| 820 | ArenaDeque<PcRelativePatchInfo> string_bss_entry_patches_; |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 821 | // Baker read barrier patch info. |
| 822 | ArenaDeque<BakerReadBarrierPatchInfo> baker_read_barrier_patches_; |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 823 | |
| 824 | // Patches for string literals in JIT compiled code. |
| 825 | StringToLiteralMap jit_string_patches_; |
| 826 | // Patches for class literals in JIT compiled code. |
| 827 | TypeToLiteralMap jit_class_patches_; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 828 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 829 | DISALLOW_COPY_AND_ASSIGN(CodeGeneratorARMVIXL); |
| 830 | }; |
| 831 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 832 | } // namespace arm |
| 833 | } // namespace art |
| 834 | |
| 835 | #endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM_VIXL_H_ |