| 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 | #include "code_generator_arm_vixl.h" |
| 18 | |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 19 | #include "arch/arm/asm_support_arm.h" |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 20 | #include "arch/arm/instruction_set_features_arm.h" |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 21 | #include "art_method-inl.h" |
| Andreas Gampe | 5678db5 | 2017-06-08 14:11:18 -0700 | [diff] [blame] | 22 | #include "base/bit_utils.h" |
| 23 | #include "base/bit_utils_iterator.h" |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 24 | #include "class_table.h" |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 25 | #include "code_generator_utils.h" |
| 26 | #include "common_arm.h" |
| 27 | #include "compiled_method.h" |
| 28 | #include "entrypoints/quick/quick_entrypoints.h" |
| 29 | #include "gc/accounting/card_table.h" |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 30 | #include "gc/space/image_space.h" |
| Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 31 | #include "heap_poisoning.h" |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 32 | #include "intrinsics.h" |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 33 | #include "intrinsics_arm_vixl.h" |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 34 | #include "linker/linker_patch.h" |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 35 | #include "mirror/array-inl.h" |
| 36 | #include "mirror/class-inl.h" |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 37 | #include "scoped_thread_state_change-inl.h" |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 38 | #include "thread.h" |
| 39 | #include "utils/arm/assembler_arm_vixl.h" |
| 40 | #include "utils/arm/managed_register_arm.h" |
| 41 | #include "utils/assembler.h" |
| 42 | #include "utils/stack_checks.h" |
| 43 | |
| Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 44 | namespace art { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 45 | namespace arm { |
| 46 | |
| 47 | namespace vixl32 = vixl::aarch32; |
| 48 | using namespace vixl32; // NOLINT(build/namespaces) |
| 49 | |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 50 | using helpers::DRegisterFrom; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 51 | using helpers::HighRegisterFrom; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 52 | using helpers::InputDRegisterAt; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 53 | using helpers::InputOperandAt; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 54 | using helpers::InputRegister; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 55 | using helpers::InputRegisterAt; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 56 | using helpers::InputSRegisterAt; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 57 | using helpers::InputVRegister; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 58 | using helpers::InputVRegisterAt; |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 59 | using helpers::Int32ConstantFrom; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 60 | using helpers::Int64ConstantFrom; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 61 | using helpers::LocationFrom; |
| 62 | using helpers::LowRegisterFrom; |
| 63 | using helpers::LowSRegisterFrom; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 64 | using helpers::OperandFrom; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 65 | using helpers::OutputRegister; |
| 66 | using helpers::OutputSRegister; |
| 67 | using helpers::OutputVRegister; |
| 68 | using helpers::RegisterFrom; |
| 69 | using helpers::SRegisterFrom; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 70 | using helpers::Uint64ConstantFrom; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 71 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 72 | using vixl::EmissionCheckScope; |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 73 | using vixl::ExactAssemblyScope; |
| 74 | using vixl::CodeBufferCheckScope; |
| 75 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 76 | using RegisterList = vixl32::RegisterList; |
| 77 | |
| 78 | static bool ExpectedPairLayout(Location location) { |
| 79 | // We expected this for both core and fpu register pairs. |
| 80 | return ((location.low() & 1) == 0) && (location.low() + 1 == location.high()); |
| 81 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 82 | // Use a local definition to prevent copying mistakes. |
| 83 | static constexpr size_t kArmWordSize = static_cast<size_t>(kArmPointerSize); |
| 84 | static constexpr size_t kArmBitsPerWord = kArmWordSize * kBitsPerByte; |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 85 | static constexpr uint32_t kPackedSwitchCompareJumpThreshold = 7; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 86 | |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 87 | // Reference load (except object array loads) is using LDR Rt, [Rn, #offset] which can handle |
| 88 | // offset < 4KiB. For offsets >= 4KiB, the load shall be emitted as two or more instructions. |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 89 | // For the Baker read barrier implementation using link-time generated thunks we need to split |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 90 | // the offset explicitly. |
| 91 | constexpr uint32_t kReferenceLoadMinFarOffset = 4 * KB; |
| 92 | |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 93 | // Using a base helps identify when we hit Marking Register check breakpoints. |
| 94 | constexpr int kMarkingRegisterCheckBreakCodeBaseCode = 0x10; |
| 95 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 96 | #ifdef __ |
| 97 | #error "ARM Codegen VIXL macro-assembler macro already defined." |
| 98 | #endif |
| 99 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 100 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 101 | #define __ down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()-> // NOLINT |
| 102 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, x).Int32Value() |
| 103 | |
| 104 | // Marker that code is yet to be, and must, be implemented. |
| 105 | #define TODO_VIXL32(level) LOG(level) << __PRETTY_FUNCTION__ << " unimplemented " |
| 106 | |
| Vladimir Marko | 88abba2 | 2017-05-03 17:09:25 +0100 | [diff] [blame] | 107 | static inline bool CanEmitNarrowLdr(vixl32::Register rt, vixl32::Register rn, uint32_t offset) { |
| 108 | return rt.IsLow() && rn.IsLow() && offset < 32u; |
| 109 | } |
| 110 | |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 111 | class EmitAdrCode { |
| 112 | public: |
| 113 | EmitAdrCode(ArmVIXLMacroAssembler* assembler, vixl32::Register rd, vixl32::Label* label) |
| 114 | : assembler_(assembler), rd_(rd), label_(label) { |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 115 | DCHECK(!assembler->AllowMacroInstructions()); // In ExactAssemblyScope. |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 116 | adr_location_ = assembler->GetCursorOffset(); |
| 117 | assembler->adr(EncodingSize(Wide), rd, label); |
| 118 | } |
| 119 | |
| 120 | ~EmitAdrCode() { |
| 121 | DCHECK(label_->IsBound()); |
| 122 | // The ADR emitted by the assembler does not set the Thumb mode bit we need. |
| 123 | // TODO: Maybe extend VIXL to allow ADR for return address? |
| 124 | uint8_t* raw_adr = assembler_->GetBuffer()->GetOffsetAddress<uint8_t*>(adr_location_); |
| 125 | // Expecting ADR encoding T3 with `(offset & 1) == 0`. |
| 126 | DCHECK_EQ(raw_adr[1] & 0xfbu, 0xf2u); // Check bits 24-31, except 26. |
| 127 | DCHECK_EQ(raw_adr[0] & 0xffu, 0x0fu); // Check bits 16-23. |
| 128 | DCHECK_EQ(raw_adr[3] & 0x8fu, rd_.GetCode()); // Check bits 8-11 and 15. |
| 129 | DCHECK_EQ(raw_adr[2] & 0x01u, 0x00u); // Check bit 0, i.e. the `offset & 1`. |
| 130 | // Add the Thumb mode bit. |
| 131 | raw_adr[2] |= 0x01u; |
| 132 | } |
| 133 | |
| 134 | private: |
| 135 | ArmVIXLMacroAssembler* const assembler_; |
| 136 | vixl32::Register rd_; |
| 137 | vixl32::Label* const label_; |
| 138 | int32_t adr_location_; |
| 139 | }; |
| 140 | |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 141 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { |
| 142 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 143 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 144 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 145 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() |
| 146 | // that the the kPrimNot result register is the same as the first argument register. |
| 147 | return caller_saves; |
| 148 | } |
| 149 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 150 | // SaveLiveRegisters and RestoreLiveRegisters from SlowPathCodeARM operate on sets of S registers, |
| 151 | // for each live D registers they treat two corresponding S registers as live ones. |
| 152 | // |
| 153 | // Two following functions (SaveContiguousSRegisterList, RestoreContiguousSRegisterList) build |
| 154 | // from a list of contiguous S registers a list of contiguous D registers (processing first/last |
| 155 | // S registers corner cases) and save/restore this new list treating them as D registers. |
| 156 | // - decreasing code size |
| 157 | // - avoiding hazards on Cortex-A57, when a pair of S registers for an actual live D register is |
| 158 | // restored and then used in regular non SlowPath code as D register. |
| 159 | // |
| 160 | // For the following example (v means the S register is live): |
| 161 | // D names: | D0 | D1 | D2 | D4 | ... |
| 162 | // S names: | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 | ... |
| 163 | // Live? | | v | v | v | v | v | v | | ... |
| 164 | // |
| 165 | // S1 and S6 will be saved/restored independently; D registers list (D1, D2) will be processed |
| 166 | // as D registers. |
| 167 | // |
| 168 | // TODO(VIXL): All this code should be unnecessary once the VIXL AArch32 backend provides helpers |
| 169 | // for lists of floating-point registers. |
| 170 | static size_t SaveContiguousSRegisterList(size_t first, |
| 171 | size_t last, |
| 172 | CodeGenerator* codegen, |
| 173 | size_t stack_offset) { |
| 174 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 175 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 176 | DCHECK_LE(first, last); |
| 177 | if ((first == last) && (first == 0)) { |
| 178 | __ Vstr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 179 | return stack_offset + kSRegSizeInBytes; |
| 180 | } |
| 181 | if (first % 2 == 1) { |
| 182 | __ Vstr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 183 | stack_offset += kSRegSizeInBytes; |
| 184 | } |
| 185 | |
| 186 | bool save_last = false; |
| 187 | if (last % 2 == 0) { |
| 188 | save_last = true; |
| 189 | --last; |
| 190 | } |
| 191 | |
| 192 | if (first < last) { |
| 193 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 194 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 195 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 196 | |
| 197 | if (number_of_d_regs == 1) { |
| 198 | __ Vstr(d_reg, MemOperand(sp, stack_offset)); |
| 199 | } else if (number_of_d_regs > 1) { |
| 200 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 201 | vixl32::Register base = sp; |
| 202 | if (stack_offset != 0) { |
| 203 | base = temps.Acquire(); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 204 | __ Add(base, sp, Operand::From(stack_offset)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 205 | } |
| 206 | __ Vstm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 207 | } |
| 208 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 209 | } |
| 210 | |
| 211 | if (save_last) { |
| 212 | __ Vstr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 213 | stack_offset += kSRegSizeInBytes; |
| 214 | } |
| 215 | |
| 216 | return stack_offset; |
| 217 | } |
| 218 | |
| 219 | static size_t RestoreContiguousSRegisterList(size_t first, |
| 220 | size_t last, |
| 221 | CodeGenerator* codegen, |
| 222 | size_t stack_offset) { |
| 223 | static_assert(kSRegSizeInBytes == kArmWordSize, "Broken assumption on reg/word sizes."); |
| 224 | static_assert(kDRegSizeInBytes == 2 * kArmWordSize, "Broken assumption on reg/word sizes."); |
| 225 | DCHECK_LE(first, last); |
| 226 | if ((first == last) && (first == 0)) { |
| 227 | __ Vldr(vixl32::SRegister(first), MemOperand(sp, stack_offset)); |
| 228 | return stack_offset + kSRegSizeInBytes; |
| 229 | } |
| 230 | if (first % 2 == 1) { |
| 231 | __ Vldr(vixl32::SRegister(first++), MemOperand(sp, stack_offset)); |
| 232 | stack_offset += kSRegSizeInBytes; |
| 233 | } |
| 234 | |
| 235 | bool restore_last = false; |
| 236 | if (last % 2 == 0) { |
| 237 | restore_last = true; |
| 238 | --last; |
| 239 | } |
| 240 | |
| 241 | if (first < last) { |
| 242 | vixl32::DRegister d_reg = vixl32::DRegister(first / 2); |
| 243 | DCHECK_EQ((last - first + 1) % 2, 0u); |
| 244 | size_t number_of_d_regs = (last - first + 1) / 2; |
| 245 | if (number_of_d_regs == 1) { |
| 246 | __ Vldr(d_reg, MemOperand(sp, stack_offset)); |
| 247 | } else if (number_of_d_regs > 1) { |
| 248 | UseScratchRegisterScope temps(down_cast<CodeGeneratorARMVIXL*>(codegen)->GetVIXLAssembler()); |
| 249 | vixl32::Register base = sp; |
| 250 | if (stack_offset != 0) { |
| 251 | base = temps.Acquire(); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 252 | __ Add(base, sp, Operand::From(stack_offset)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 253 | } |
| 254 | __ Vldm(F64, base, NO_WRITE_BACK, DRegisterList(d_reg, number_of_d_regs)); |
| 255 | } |
| 256 | stack_offset += number_of_d_regs * kDRegSizeInBytes; |
| 257 | } |
| 258 | |
| 259 | if (restore_last) { |
| 260 | __ Vldr(vixl32::SRegister(last + 1), MemOperand(sp, stack_offset)); |
| 261 | stack_offset += kSRegSizeInBytes; |
| 262 | } |
| 263 | |
| 264 | return stack_offset; |
| 265 | } |
| 266 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 267 | static LoadOperandType GetLoadOperandType(DataType::Type type) { |
| 268 | switch (type) { |
| 269 | case DataType::Type::kReference: |
| 270 | return kLoadWord; |
| 271 | case DataType::Type::kBool: |
| 272 | case DataType::Type::kUint8: |
| 273 | return kLoadUnsignedByte; |
| 274 | case DataType::Type::kInt8: |
| 275 | return kLoadSignedByte; |
| 276 | case DataType::Type::kUint16: |
| 277 | return kLoadUnsignedHalfword; |
| 278 | case DataType::Type::kInt16: |
| 279 | return kLoadSignedHalfword; |
| 280 | case DataType::Type::kInt32: |
| 281 | return kLoadWord; |
| 282 | case DataType::Type::kInt64: |
| 283 | return kLoadWordPair; |
| 284 | case DataType::Type::kFloat32: |
| 285 | return kLoadSWord; |
| 286 | case DataType::Type::kFloat64: |
| 287 | return kLoadDWord; |
| 288 | default: |
| 289 | LOG(FATAL) << "Unreachable type " << type; |
| 290 | UNREACHABLE(); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | static StoreOperandType GetStoreOperandType(DataType::Type type) { |
| 295 | switch (type) { |
| 296 | case DataType::Type::kReference: |
| 297 | return kStoreWord; |
| 298 | case DataType::Type::kBool: |
| 299 | case DataType::Type::kUint8: |
| 300 | case DataType::Type::kInt8: |
| 301 | return kStoreByte; |
| 302 | case DataType::Type::kUint16: |
| 303 | case DataType::Type::kInt16: |
| 304 | return kStoreHalfword; |
| 305 | case DataType::Type::kInt32: |
| 306 | return kStoreWord; |
| 307 | case DataType::Type::kInt64: |
| 308 | return kStoreWordPair; |
| 309 | case DataType::Type::kFloat32: |
| 310 | return kStoreSWord; |
| 311 | case DataType::Type::kFloat64: |
| 312 | return kStoreDWord; |
| 313 | default: |
| 314 | LOG(FATAL) << "Unreachable type " << type; |
| 315 | UNREACHABLE(); |
| 316 | } |
| 317 | } |
| 318 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 319 | void SlowPathCodeARMVIXL::SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 320 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 321 | size_t orig_offset = stack_offset; |
| 322 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 323 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 324 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 325 | // If the register holds an object, update the stack mask. |
| 326 | if (locations->RegisterContainsObject(i)) { |
| 327 | locations->SetStackBit(stack_offset / kVRegSize); |
| 328 | } |
| 329 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 330 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 331 | saved_core_stack_offsets_[i] = stack_offset; |
| 332 | stack_offset += kArmWordSize; |
| 333 | } |
| 334 | |
| 335 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 336 | arm_codegen->GetAssembler()->StoreRegisterList(core_spills, orig_offset); |
| 337 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 338 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 339 | orig_offset = stack_offset; |
| 340 | for (uint32_t i : LowToHighBits(fp_spills)) { |
| 341 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 342 | saved_fpu_stack_offsets_[i] = stack_offset; |
| 343 | stack_offset += kArmWordSize; |
| 344 | } |
| 345 | |
| 346 | stack_offset = orig_offset; |
| 347 | while (fp_spills != 0u) { |
| 348 | uint32_t begin = CTZ(fp_spills); |
| 349 | uint32_t tmp = fp_spills + (1u << begin); |
| 350 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 351 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 352 | stack_offset = SaveContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 353 | } |
| 354 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 355 | } |
| 356 | |
| 357 | void SlowPathCodeARMVIXL::RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) { |
| 358 | size_t stack_offset = codegen->GetFirstRegisterSlotInSlowPath(); |
| 359 | size_t orig_offset = stack_offset; |
| 360 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 361 | const uint32_t core_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ true); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 362 | for (uint32_t i : LowToHighBits(core_spills)) { |
| 363 | DCHECK_LT(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 364 | DCHECK_LT(i, kMaximumNumberOfExpectedRegisters); |
| 365 | stack_offset += kArmWordSize; |
| 366 | } |
| 367 | |
| 368 | // TODO(VIXL): Check the coherency of stack_offset after this with a test. |
| 369 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 370 | arm_codegen->GetAssembler()->LoadRegisterList(core_spills, orig_offset); |
| 371 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 372 | uint32_t fp_spills = codegen->GetSlowPathSpills(locations, /* core_registers= */ false); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 373 | while (fp_spills != 0u) { |
| 374 | uint32_t begin = CTZ(fp_spills); |
| 375 | uint32_t tmp = fp_spills + (1u << begin); |
| 376 | fp_spills &= tmp; // Clear the contiguous range of 1s. |
| 377 | uint32_t end = (tmp == 0u) ? 32u : CTZ(tmp); // CTZ(0) is undefined. |
| 378 | stack_offset = RestoreContiguousSRegisterList(begin, end - 1, codegen, stack_offset); |
| 379 | } |
| 380 | DCHECK_LE(stack_offset, codegen->GetFrameSize() - codegen->FrameEntrySpillSize()); |
| 381 | } |
| 382 | |
| 383 | class NullCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 384 | public: |
| 385 | explicit NullCheckSlowPathARMVIXL(HNullCheck* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 386 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 387 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 388 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 389 | __ Bind(GetEntryLabel()); |
| 390 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 391 | // Live registers will be restored in the catch block if caught. |
| 392 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 393 | } |
| 394 | arm_codegen->InvokeRuntime(kQuickThrowNullPointer, |
| 395 | instruction_, |
| 396 | instruction_->GetDexPc(), |
| 397 | this); |
| 398 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
| 399 | } |
| 400 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 401 | bool IsFatal() const override { return true; } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 402 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 403 | const char* GetDescription() const override { return "NullCheckSlowPathARMVIXL"; } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 404 | |
| 405 | private: |
| 406 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARMVIXL); |
| 407 | }; |
| 408 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 409 | class DivZeroCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 410 | public: |
| 411 | explicit DivZeroCheckSlowPathARMVIXL(HDivZeroCheck* instruction) |
| 412 | : SlowPathCodeARMVIXL(instruction) {} |
| 413 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 414 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 415 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 416 | __ Bind(GetEntryLabel()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 417 | arm_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 418 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
| 419 | } |
| 420 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 421 | bool IsFatal() const override { return true; } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 422 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 423 | const char* GetDescription() const override { return "DivZeroCheckSlowPathARMVIXL"; } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 424 | |
| 425 | private: |
| 426 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARMVIXL); |
| 427 | }; |
| 428 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 429 | class SuspendCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 430 | public: |
| 431 | SuspendCheckSlowPathARMVIXL(HSuspendCheck* instruction, HBasicBlock* successor) |
| 432 | : SlowPathCodeARMVIXL(instruction), successor_(successor) {} |
| 433 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 434 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 435 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 436 | __ Bind(GetEntryLabel()); |
| 437 | arm_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
| 438 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
| 439 | if (successor_ == nullptr) { |
| 440 | __ B(GetReturnLabel()); |
| 441 | } else { |
| 442 | __ B(arm_codegen->GetLabelOf(successor_)); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | vixl32::Label* GetReturnLabel() { |
| 447 | DCHECK(successor_ == nullptr); |
| 448 | return &return_label_; |
| 449 | } |
| 450 | |
| 451 | HBasicBlock* GetSuccessor() const { |
| 452 | return successor_; |
| 453 | } |
| 454 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 455 | const char* GetDescription() const override { return "SuspendCheckSlowPathARMVIXL"; } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 456 | |
| 457 | private: |
| 458 | // If not null, the block to branch to after the suspend check. |
| 459 | HBasicBlock* const successor_; |
| 460 | |
| 461 | // If `successor_` is null, the label to branch to after the suspend check. |
| 462 | vixl32::Label return_label_; |
| 463 | |
| 464 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARMVIXL); |
| 465 | }; |
| 466 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 467 | class BoundsCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 468 | public: |
| 469 | explicit BoundsCheckSlowPathARMVIXL(HBoundsCheck* instruction) |
| 470 | : SlowPathCodeARMVIXL(instruction) {} |
| 471 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 472 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 473 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 474 | LocationSummary* locations = instruction_->GetLocations(); |
| 475 | |
| 476 | __ Bind(GetEntryLabel()); |
| 477 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 478 | // Live registers will be restored in the catch block if caught. |
| 479 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 480 | } |
| 481 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 482 | // move resolver. |
| 483 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 484 | codegen->EmitParallelMoves( |
| 485 | locations->InAt(0), |
| 486 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 487 | DataType::Type::kInt32, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 488 | locations->InAt(1), |
| 489 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 490 | DataType::Type::kInt32); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 491 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 492 | ? kQuickThrowStringBounds |
| 493 | : kQuickThrowArrayBounds; |
| 494 | arm_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
| 495 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
| 496 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
| 497 | } |
| 498 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 499 | bool IsFatal() const override { return true; } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 500 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 501 | const char* GetDescription() const override { return "BoundsCheckSlowPathARMVIXL"; } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 502 | |
| 503 | private: |
| 504 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARMVIXL); |
| 505 | }; |
| 506 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 507 | class LoadClassSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 508 | public: |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 509 | LoadClassSlowPathARMVIXL(HLoadClass* cls, HInstruction* at) |
| 510 | : SlowPathCodeARMVIXL(at), cls_(cls) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 511 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 512 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 513 | } |
| 514 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 515 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 516 | LocationSummary* locations = instruction_->GetLocations(); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 517 | Location out = locations->Out(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 518 | const uint32_t dex_pc = instruction_->GetDexPc(); |
| 519 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); |
| 520 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 521 | |
| 522 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 523 | __ Bind(GetEntryLabel()); |
| 524 | SaveLiveRegisters(codegen, locations); |
| 525 | |
| 526 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 527 | if (must_resolve_type) { |
| 528 | DCHECK(IsSameDexFile(cls_->GetDexFile(), arm_codegen->GetGraph()->GetDexFile())); |
| 529 | dex::TypeIndex type_index = cls_->GetTypeIndex(); |
| 530 | __ Mov(calling_convention.GetRegisterAt(0), type_index.index_); |
| Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 531 | arm_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); |
| 532 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 533 | // If we also must_do_clinit, the resolved type is now in the correct register. |
| 534 | } else { |
| 535 | DCHECK(must_do_clinit); |
| 536 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); |
| 537 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), source); |
| 538 | } |
| 539 | if (must_do_clinit) { |
| 540 | arm_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); |
| 541 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | // Move the class to the desired location. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 545 | if (out.IsValid()) { |
| 546 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 547 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 548 | } |
| 549 | RestoreLiveRegisters(codegen, locations); |
| 550 | __ B(GetExitLabel()); |
| 551 | } |
| 552 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 553 | const char* GetDescription() const override { return "LoadClassSlowPathARMVIXL"; } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 554 | |
| 555 | private: |
| 556 | // The class this slow path will load. |
| 557 | HLoadClass* const cls_; |
| 558 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 559 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARMVIXL); |
| 560 | }; |
| 561 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 562 | class LoadStringSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 563 | public: |
| 564 | explicit LoadStringSlowPathARMVIXL(HLoadString* instruction) |
| 565 | : SlowPathCodeARMVIXL(instruction) {} |
| 566 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 567 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 568 | DCHECK(instruction_->IsLoadString()); |
| 569 | DCHECK_EQ(instruction_->AsLoadString()->GetLoadKind(), HLoadString::LoadKind::kBssEntry); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 570 | LocationSummary* locations = instruction_->GetLocations(); |
| 571 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 572 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 573 | |
| 574 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 575 | __ Bind(GetEntryLabel()); |
| 576 | SaveLiveRegisters(codegen, locations); |
| 577 | |
| 578 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 579 | __ Mov(calling_convention.GetRegisterAt(0), string_index.index_); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 580 | arm_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 581 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 582 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 583 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| 584 | RestoreLiveRegisters(codegen, locations); |
| 585 | |
| 586 | __ B(GetExitLabel()); |
| 587 | } |
| 588 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 589 | const char* GetDescription() const override { return "LoadStringSlowPathARMVIXL"; } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 590 | |
| 591 | private: |
| 592 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARMVIXL); |
| 593 | }; |
| 594 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 595 | class TypeCheckSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 596 | public: |
| 597 | TypeCheckSlowPathARMVIXL(HInstruction* instruction, bool is_fatal) |
| 598 | : SlowPathCodeARMVIXL(instruction), is_fatal_(is_fatal) {} |
| 599 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 600 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 601 | LocationSummary* locations = instruction_->GetLocations(); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 602 | DCHECK(instruction_->IsCheckCast() |
| 603 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 604 | |
| 605 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 606 | __ Bind(GetEntryLabel()); |
| 607 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 608 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 609 | SaveLiveRegisters(codegen, locations); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 613 | // move resolver. |
| 614 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 615 | |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 616 | codegen->EmitParallelMoves(locations->InAt(0), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 617 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 618 | DataType::Type::kReference, |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 619 | locations->InAt(1), |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 620 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 621 | DataType::Type::kReference); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 622 | if (instruction_->IsInstanceOf()) { |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 623 | arm_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
| 624 | instruction_, |
| 625 | instruction_->GetDexPc(), |
| 626 | this); |
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 627 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 628 | arm_codegen->Move32(locations->Out(), LocationFrom(r0)); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 629 | } else { |
| 630 | DCHECK(instruction_->IsCheckCast()); |
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 631 | arm_codegen->InvokeRuntime(kQuickCheckInstanceOf, |
| 632 | instruction_, |
| 633 | instruction_->GetDexPc(), |
| 634 | this); |
| 635 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | if (!is_fatal_) { |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 639 | RestoreLiveRegisters(codegen, locations); |
| 640 | __ B(GetExitLabel()); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 644 | const char* GetDescription() const override { return "TypeCheckSlowPathARMVIXL"; } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 645 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 646 | bool IsFatal() const override { return is_fatal_; } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 647 | |
| 648 | private: |
| 649 | const bool is_fatal_; |
| 650 | |
| 651 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARMVIXL); |
| 652 | }; |
| 653 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 654 | class DeoptimizationSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 655 | public: |
| 656 | explicit DeoptimizationSlowPathARMVIXL(HDeoptimize* instruction) |
| 657 | : SlowPathCodeARMVIXL(instruction) {} |
| 658 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 659 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 660 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 661 | __ Bind(GetEntryLabel()); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 662 | LocationSummary* locations = instruction_->GetLocations(); |
| 663 | SaveLiveRegisters(codegen, locations); |
| 664 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 665 | __ Mov(calling_convention.GetRegisterAt(0), |
| 666 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); |
| 667 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 668 | arm_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 669 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 670 | } |
| 671 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 672 | const char* GetDescription() const override { return "DeoptimizationSlowPathARMVIXL"; } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 673 | |
| 674 | private: |
| 675 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARMVIXL); |
| 676 | }; |
| 677 | |
| 678 | class ArraySetSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 679 | public: |
| 680 | explicit ArraySetSlowPathARMVIXL(HInstruction* instruction) : SlowPathCodeARMVIXL(instruction) {} |
| 681 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 682 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 683 | LocationSummary* locations = instruction_->GetLocations(); |
| 684 | __ Bind(GetEntryLabel()); |
| 685 | SaveLiveRegisters(codegen, locations); |
| 686 | |
| 687 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 688 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 689 | parallel_move.AddMove( |
| 690 | locations->InAt(0), |
| 691 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 692 | DataType::Type::kReference, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 693 | nullptr); |
| 694 | parallel_move.AddMove( |
| 695 | locations->InAt(1), |
| 696 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 697 | DataType::Type::kInt32, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 698 | nullptr); |
| 699 | parallel_move.AddMove( |
| 700 | locations->InAt(2), |
| 701 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 702 | DataType::Type::kReference, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 703 | nullptr); |
| 704 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 705 | |
| 706 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 707 | arm_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
| 708 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
| 709 | RestoreLiveRegisters(codegen, locations); |
| 710 | __ B(GetExitLabel()); |
| 711 | } |
| 712 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 713 | const char* GetDescription() const override { return "ArraySetSlowPathARMVIXL"; } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 714 | |
| 715 | private: |
| 716 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathARMVIXL); |
| 717 | }; |
| 718 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 719 | // Slow path generating a read barrier for a heap reference. |
| 720 | class ReadBarrierForHeapReferenceSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 721 | public: |
| 722 | ReadBarrierForHeapReferenceSlowPathARMVIXL(HInstruction* instruction, |
| 723 | Location out, |
| 724 | Location ref, |
| 725 | Location obj, |
| 726 | uint32_t offset, |
| 727 | Location index) |
| 728 | : SlowPathCodeARMVIXL(instruction), |
| 729 | out_(out), |
| 730 | ref_(ref), |
| 731 | obj_(obj), |
| 732 | offset_(offset), |
| 733 | index_(index) { |
| 734 | DCHECK(kEmitCompilerReadBarrier); |
| 735 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 736 | // has been overwritten by (or after) the heap object reference load |
| 737 | // to be instrumented, e.g.: |
| 738 | // |
| 739 | // __ LoadFromOffset(kLoadWord, out, out, offset); |
| 740 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
| 741 | // |
| 742 | // In that case, we have lost the information about the original |
| 743 | // object, and the emitted read barrier cannot work properly. |
| 744 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 745 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 746 | } |
| 747 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 748 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 749 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 750 | LocationSummary* locations = instruction_->GetLocations(); |
| 751 | vixl32::Register reg_out = RegisterFrom(out_); |
| 752 | DCHECK(locations->CanCall()); |
| 753 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 754 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 755 | instruction_->IsStaticFieldGet() || |
| 756 | instruction_->IsArrayGet() || |
| 757 | instruction_->IsInstanceOf() || |
| 758 | instruction_->IsCheckCast() || |
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 759 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 760 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 761 | << instruction_->DebugName(); |
| 762 | // The read barrier instrumentation of object ArrayGet |
| 763 | // instructions does not support the HIntermediateAddress |
| 764 | // instruction. |
| 765 | DCHECK(!(instruction_->IsArrayGet() && |
| 766 | instruction_->AsArrayGet()->GetArray()->IsIntermediateAddress())); |
| 767 | |
| 768 | __ Bind(GetEntryLabel()); |
| 769 | SaveLiveRegisters(codegen, locations); |
| 770 | |
| 771 | // We may have to change the index's value, but as `index_` is a |
| 772 | // constant member (like other "inputs" of this slow path), |
| 773 | // introduce a copy of it, `index`. |
| 774 | Location index = index_; |
| 775 | if (index_.IsValid()) { |
| 776 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
| 777 | if (instruction_->IsArrayGet()) { |
| 778 | // Compute the actual memory offset and store it in `index`. |
| 779 | vixl32::Register index_reg = RegisterFrom(index_); |
| 780 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg.GetCode())); |
| 781 | if (codegen->IsCoreCalleeSaveRegister(index_reg.GetCode())) { |
| 782 | // We are about to change the value of `index_reg` (see the |
| Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 783 | // calls to art::arm::ArmVIXLMacroAssembler::Lsl and |
| 784 | // art::arm::ArmVIXLMacroAssembler::Add below), but it has |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 785 | // not been saved by the previous call to |
| 786 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 787 | // callee-save register -- |
| 788 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 789 | // callee-save registers, as it has been designed with the |
| 790 | // assumption that callee-save registers are supposed to be |
| 791 | // handled by the called function. So, as a callee-save |
| 792 | // register, `index_reg` _would_ eventually be saved onto |
| 793 | // the stack, but it would be too late: we would have |
| 794 | // changed its value earlier. Therefore, we manually save |
| 795 | // it here into another freely available register, |
| 796 | // `free_reg`, chosen of course among the caller-save |
| 797 | // registers (as a callee-save `free_reg` register would |
| 798 | // exhibit the same problem). |
| 799 | // |
| 800 | // Note we could have requested a temporary register from |
| 801 | // the register allocator instead; but we prefer not to, as |
| 802 | // this is a slow path, and we know we can find a |
| 803 | // caller-save register that is available. |
| 804 | vixl32::Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 805 | __ Mov(free_reg, index_reg); |
| 806 | index_reg = free_reg; |
| 807 | index = LocationFrom(index_reg); |
| 808 | } else { |
| 809 | // The initial register stored in `index_` has already been |
| 810 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 811 | // (as it is not a callee-save register), so we can freely |
| 812 | // use it. |
| 813 | } |
| 814 | // Shifting the index value contained in `index_reg` by the scale |
| 815 | // factor (2) cannot overflow in practice, as the runtime is |
| 816 | // unable to allocate object arrays with a size larger than |
| 817 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 818 | __ Lsl(index_reg, index_reg, TIMES_4); |
| 819 | static_assert( |
| 820 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 821 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 822 | __ Add(index_reg, index_reg, offset_); |
| 823 | } else { |
| 824 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 825 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 826 | // (as in the case of ArrayGet), as it is actually an offset |
| 827 | // to an object field within an object. |
| 828 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
| 829 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 830 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 831 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 832 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 833 | DCHECK_EQ(offset_, 0U); |
| 834 | DCHECK(index_.IsRegisterPair()); |
| 835 | // UnsafeGet's offset location is a register pair, the low |
| 836 | // part contains the correct offset. |
| 837 | index = index_.ToLow(); |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | // We're moving two or three locations to locations that could |
| 842 | // overlap, so we need a parallel move resolver. |
| 843 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 844 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 845 | parallel_move.AddMove(ref_, |
| 846 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 847 | DataType::Type::kReference, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 848 | nullptr); |
| 849 | parallel_move.AddMove(obj_, |
| 850 | LocationFrom(calling_convention.GetRegisterAt(1)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 851 | DataType::Type::kReference, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 852 | nullptr); |
| 853 | if (index.IsValid()) { |
| 854 | parallel_move.AddMove(index, |
| 855 | LocationFrom(calling_convention.GetRegisterAt(2)), |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 856 | DataType::Type::kInt32, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 857 | nullptr); |
| 858 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 859 | } else { |
| 860 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 861 | __ Mov(calling_convention.GetRegisterAt(2), offset_); |
| 862 | } |
| 863 | arm_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
| 864 | CheckEntrypointTypes< |
| 865 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 866 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 867 | |
| 868 | RestoreLiveRegisters(codegen, locations); |
| 869 | __ B(GetExitLabel()); |
| 870 | } |
| 871 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 872 | const char* GetDescription() const override { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 873 | return "ReadBarrierForHeapReferenceSlowPathARMVIXL"; |
| 874 | } |
| 875 | |
| 876 | private: |
| 877 | vixl32::Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 878 | uint32_t ref = RegisterFrom(ref_).GetCode(); |
| 879 | uint32_t obj = RegisterFrom(obj_).GetCode(); |
| 880 | for (uint32_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 881 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 882 | return vixl32::Register(i); |
| 883 | } |
| 884 | } |
| 885 | // We shall never fail to find a free caller-save register, as |
| 886 | // there are more than two core caller-save registers on ARM |
| 887 | // (meaning it is possible to find one which is different from |
| 888 | // `ref` and `obj`). |
| 889 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 890 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 891 | UNREACHABLE(); |
| 892 | } |
| 893 | |
| 894 | const Location out_; |
| 895 | const Location ref_; |
| 896 | const Location obj_; |
| 897 | const uint32_t offset_; |
| 898 | // An additional location containing an index to an array. |
| 899 | // Only used for HArrayGet and the UnsafeGetObject & |
| 900 | // UnsafeGetObjectVolatile intrinsics. |
| 901 | const Location index_; |
| 902 | |
| 903 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathARMVIXL); |
| 904 | }; |
| 905 | |
| 906 | // Slow path generating a read barrier for a GC root. |
| 907 | class ReadBarrierForRootSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 908 | public: |
| 909 | ReadBarrierForRootSlowPathARMVIXL(HInstruction* instruction, Location out, Location root) |
| 910 | : SlowPathCodeARMVIXL(instruction), out_(out), root_(root) { |
| 911 | DCHECK(kEmitCompilerReadBarrier); |
| 912 | } |
| 913 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 914 | void EmitNativeCode(CodeGenerator* codegen) override { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 915 | LocationSummary* locations = instruction_->GetLocations(); |
| 916 | vixl32::Register reg_out = RegisterFrom(out_); |
| 917 | DCHECK(locations->CanCall()); |
| 918 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out.GetCode())); |
| 919 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 920 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 921 | << instruction_->DebugName(); |
| 922 | |
| 923 | __ Bind(GetEntryLabel()); |
| 924 | SaveLiveRegisters(codegen, locations); |
| 925 | |
| 926 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 927 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 928 | arm_codegen->Move32(LocationFrom(calling_convention.GetRegisterAt(0)), root_); |
| 929 | arm_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
| 930 | instruction_, |
| 931 | instruction_->GetDexPc(), |
| 932 | this); |
| 933 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 934 | arm_codegen->Move32(out_, LocationFrom(r0)); |
| 935 | |
| 936 | RestoreLiveRegisters(codegen, locations); |
| 937 | __ B(GetExitLabel()); |
| 938 | } |
| 939 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 940 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathARMVIXL"; } |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 941 | |
| 942 | private: |
| 943 | const Location out_; |
| 944 | const Location root_; |
| 945 | |
| 946 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathARMVIXL); |
| 947 | }; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 948 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 949 | inline vixl32::Condition ARMCondition(IfCondition cond) { |
| 950 | switch (cond) { |
| 951 | case kCondEQ: return eq; |
| 952 | case kCondNE: return ne; |
| 953 | case kCondLT: return lt; |
| 954 | case kCondLE: return le; |
| 955 | case kCondGT: return gt; |
| 956 | case kCondGE: return ge; |
| 957 | case kCondB: return lo; |
| 958 | case kCondBE: return ls; |
| 959 | case kCondA: return hi; |
| 960 | case kCondAE: return hs; |
| 961 | } |
| 962 | LOG(FATAL) << "Unreachable"; |
| 963 | UNREACHABLE(); |
| 964 | } |
| 965 | |
| 966 | // Maps signed condition to unsigned condition. |
| 967 | inline vixl32::Condition ARMUnsignedCondition(IfCondition cond) { |
| 968 | switch (cond) { |
| 969 | case kCondEQ: return eq; |
| 970 | case kCondNE: return ne; |
| 971 | // Signed to unsigned. |
| 972 | case kCondLT: return lo; |
| 973 | case kCondLE: return ls; |
| 974 | case kCondGT: return hi; |
| 975 | case kCondGE: return hs; |
| 976 | // Unsigned remain unchanged. |
| 977 | case kCondB: return lo; |
| 978 | case kCondBE: return ls; |
| 979 | case kCondA: return hi; |
| 980 | case kCondAE: return hs; |
| 981 | } |
| 982 | LOG(FATAL) << "Unreachable"; |
| 983 | UNREACHABLE(); |
| 984 | } |
| 985 | |
| 986 | inline vixl32::Condition ARMFPCondition(IfCondition cond, bool gt_bias) { |
| 987 | // The ARM condition codes can express all the necessary branches, see the |
| 988 | // "Meaning (floating-point)" column in the table A8-1 of the ARMv7 reference manual. |
| 989 | // There is no dex instruction or HIR that would need the missing conditions |
| 990 | // "equal or unordered" or "not equal". |
| 991 | switch (cond) { |
| 992 | case kCondEQ: return eq; |
| 993 | case kCondNE: return ne /* unordered */; |
| 994 | case kCondLT: return gt_bias ? cc : lt /* unordered */; |
| 995 | case kCondLE: return gt_bias ? ls : le /* unordered */; |
| 996 | case kCondGT: return gt_bias ? hi /* unordered */ : gt; |
| 997 | case kCondGE: return gt_bias ? cs /* unordered */ : ge; |
| 998 | default: |
| 999 | LOG(FATAL) << "UNREACHABLE"; |
| 1000 | UNREACHABLE(); |
| 1001 | } |
| 1002 | } |
| 1003 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1004 | inline ShiftType ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) { |
| 1005 | switch (op_kind) { |
| 1006 | case HDataProcWithShifterOp::kASR: return ShiftType::ASR; |
| 1007 | case HDataProcWithShifterOp::kLSL: return ShiftType::LSL; |
| 1008 | case HDataProcWithShifterOp::kLSR: return ShiftType::LSR; |
| 1009 | default: |
| 1010 | LOG(FATAL) << "Unexpected op kind " << op_kind; |
| 1011 | UNREACHABLE(); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1015 | void CodeGeneratorARMVIXL::DumpCoreRegister(std::ostream& stream, int reg) const { |
| 1016 | stream << vixl32::Register(reg); |
| 1017 | } |
| 1018 | |
| 1019 | void CodeGeneratorARMVIXL::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
| 1020 | stream << vixl32::SRegister(reg); |
| 1021 | } |
| 1022 | |
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 1023 | const ArmInstructionSetFeatures& CodeGeneratorARMVIXL::GetInstructionSetFeatures() const { |
| 1024 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsArmInstructionSetFeatures(); |
| 1025 | } |
| 1026 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1027 | static uint32_t ComputeSRegisterListMask(const SRegisterList& regs) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1028 | uint32_t mask = 0; |
| 1029 | for (uint32_t i = regs.GetFirstSRegister().GetCode(); |
| 1030 | i <= regs.GetLastSRegister().GetCode(); |
| 1031 | ++i) { |
| 1032 | mask |= (1 << i); |
| 1033 | } |
| 1034 | return mask; |
| 1035 | } |
| 1036 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1037 | // Saves the register in the stack. Returns the size taken on stack. |
| 1038 | size_t CodeGeneratorARMVIXL::SaveCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1039 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1040 | TODO_VIXL32(FATAL); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1041 | UNREACHABLE(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | // Restores the register from the stack. Returns the size taken on stack. |
| 1045 | size_t CodeGeneratorARMVIXL::RestoreCoreRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1046 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1047 | TODO_VIXL32(FATAL); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1048 | UNREACHABLE(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | size_t CodeGeneratorARMVIXL::SaveFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1052 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1053 | TODO_VIXL32(FATAL); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1054 | UNREACHABLE(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | size_t CodeGeneratorARMVIXL::RestoreFloatingPointRegister(size_t stack_index ATTRIBUTE_UNUSED, |
| 1058 | uint32_t reg_id ATTRIBUTE_UNUSED) { |
| 1059 | TODO_VIXL32(FATAL); |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1060 | UNREACHABLE(); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1063 | static void GenerateDataProcInstruction(HInstruction::InstructionKind kind, |
| 1064 | vixl32::Register out, |
| 1065 | vixl32::Register first, |
| 1066 | const Operand& second, |
| 1067 | CodeGeneratorARMVIXL* codegen) { |
| 1068 | if (second.IsImmediate() && second.GetImmediate() == 0) { |
| 1069 | const Operand in = kind == HInstruction::kAnd |
| 1070 | ? Operand(0) |
| 1071 | : Operand(first); |
| 1072 | |
| 1073 | __ Mov(out, in); |
| 1074 | } else { |
| 1075 | switch (kind) { |
| 1076 | case HInstruction::kAdd: |
| 1077 | __ Add(out, first, second); |
| 1078 | break; |
| 1079 | case HInstruction::kAnd: |
| 1080 | __ And(out, first, second); |
| 1081 | break; |
| 1082 | case HInstruction::kOr: |
| 1083 | __ Orr(out, first, second); |
| 1084 | break; |
| 1085 | case HInstruction::kSub: |
| 1086 | __ Sub(out, first, second); |
| 1087 | break; |
| 1088 | case HInstruction::kXor: |
| 1089 | __ Eor(out, first, second); |
| 1090 | break; |
| 1091 | default: |
| 1092 | LOG(FATAL) << "Unexpected instruction kind: " << kind; |
| 1093 | UNREACHABLE(); |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | static void GenerateDataProc(HInstruction::InstructionKind kind, |
| 1099 | const Location& out, |
| 1100 | const Location& first, |
| 1101 | const Operand& second_lo, |
| 1102 | const Operand& second_hi, |
| 1103 | CodeGeneratorARMVIXL* codegen) { |
| 1104 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1105 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1106 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1107 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1108 | |
| 1109 | if (kind == HInstruction::kAdd) { |
| 1110 | __ Adds(out_lo, first_lo, second_lo); |
| 1111 | __ Adc(out_hi, first_hi, second_hi); |
| 1112 | } else if (kind == HInstruction::kSub) { |
| 1113 | __ Subs(out_lo, first_lo, second_lo); |
| 1114 | __ Sbc(out_hi, first_hi, second_hi); |
| 1115 | } else { |
| 1116 | GenerateDataProcInstruction(kind, out_lo, first_lo, second_lo, codegen); |
| 1117 | GenerateDataProcInstruction(kind, out_hi, first_hi, second_hi, codegen); |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | static Operand GetShifterOperand(vixl32::Register rm, ShiftType shift, uint32_t shift_imm) { |
| 1122 | return shift_imm == 0 ? Operand(rm) : Operand(rm, shift, shift_imm); |
| 1123 | } |
| 1124 | |
| 1125 | static void GenerateLongDataProc(HDataProcWithShifterOp* instruction, |
| 1126 | CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1127 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1128 | DCHECK(HDataProcWithShifterOp::IsShiftOp(instruction->GetOpKind())); |
| 1129 | |
| 1130 | const LocationSummary* const locations = instruction->GetLocations(); |
| 1131 | const uint32_t shift_value = instruction->GetShiftAmount(); |
| 1132 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 1133 | const Location first = locations->InAt(0); |
| 1134 | const Location second = locations->InAt(1); |
| 1135 | const Location out = locations->Out(); |
| 1136 | const vixl32::Register first_hi = HighRegisterFrom(first); |
| 1137 | const vixl32::Register first_lo = LowRegisterFrom(first); |
| 1138 | const vixl32::Register out_hi = HighRegisterFrom(out); |
| 1139 | const vixl32::Register out_lo = LowRegisterFrom(out); |
| 1140 | const vixl32::Register second_hi = HighRegisterFrom(second); |
| 1141 | const vixl32::Register second_lo = LowRegisterFrom(second); |
| 1142 | const ShiftType shift = ShiftFromOpKind(instruction->GetOpKind()); |
| 1143 | |
| 1144 | if (shift_value >= 32) { |
| 1145 | if (shift == ShiftType::LSL) { |
| 1146 | GenerateDataProcInstruction(kind, |
| 1147 | out_hi, |
| 1148 | first_hi, |
| 1149 | Operand(second_lo, ShiftType::LSL, shift_value - 32), |
| 1150 | codegen); |
| 1151 | GenerateDataProcInstruction(kind, out_lo, first_lo, 0, codegen); |
| 1152 | } else if (shift == ShiftType::ASR) { |
| 1153 | GenerateDataProc(kind, |
| 1154 | out, |
| 1155 | first, |
| 1156 | GetShifterOperand(second_hi, ShiftType::ASR, shift_value - 32), |
| 1157 | Operand(second_hi, ShiftType::ASR, 31), |
| 1158 | codegen); |
| 1159 | } else { |
| 1160 | DCHECK_EQ(shift, ShiftType::LSR); |
| 1161 | GenerateDataProc(kind, |
| 1162 | out, |
| 1163 | first, |
| 1164 | GetShifterOperand(second_hi, ShiftType::LSR, shift_value - 32), |
| 1165 | 0, |
| 1166 | codegen); |
| 1167 | } |
| 1168 | } else { |
| 1169 | DCHECK_GT(shift_value, 1U); |
| 1170 | DCHECK_LT(shift_value, 32U); |
| 1171 | |
| 1172 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1173 | |
| 1174 | if (shift == ShiftType::LSL) { |
| 1175 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1176 | // Location::kOutputOverlap; not applicable to other cases. |
| 1177 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1178 | GenerateDataProcInstruction(kind, |
| 1179 | out_hi, |
| 1180 | first_hi, |
| 1181 | Operand(second_hi, ShiftType::LSL, shift_value), |
| 1182 | codegen); |
| 1183 | GenerateDataProcInstruction(kind, |
| 1184 | out_hi, |
| 1185 | out_hi, |
| 1186 | Operand(second_lo, ShiftType::LSR, 32 - shift_value), |
| 1187 | codegen); |
| 1188 | GenerateDataProcInstruction(kind, |
| 1189 | out_lo, |
| 1190 | first_lo, |
| 1191 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1192 | codegen); |
| 1193 | } else { |
| 1194 | const vixl32::Register temp = temps.Acquire(); |
| 1195 | |
| 1196 | __ Lsl(temp, second_hi, shift_value); |
| 1197 | __ Orr(temp, temp, Operand(second_lo, ShiftType::LSR, 32 - shift_value)); |
| 1198 | GenerateDataProc(kind, |
| 1199 | out, |
| 1200 | first, |
| 1201 | Operand(second_lo, ShiftType::LSL, shift_value), |
| 1202 | temp, |
| 1203 | codegen); |
| 1204 | } |
| 1205 | } else { |
| 1206 | DCHECK(shift == ShiftType::ASR || shift == ShiftType::LSR); |
| 1207 | |
| 1208 | // We are not doing this for HInstruction::kAdd because the output will require |
| 1209 | // Location::kOutputOverlap; not applicable to other cases. |
| 1210 | if (kind == HInstruction::kOr || kind == HInstruction::kXor) { |
| 1211 | GenerateDataProcInstruction(kind, |
| 1212 | out_lo, |
| 1213 | first_lo, |
| 1214 | Operand(second_lo, ShiftType::LSR, shift_value), |
| 1215 | codegen); |
| 1216 | GenerateDataProcInstruction(kind, |
| 1217 | out_lo, |
| 1218 | out_lo, |
| 1219 | Operand(second_hi, ShiftType::LSL, 32 - shift_value), |
| 1220 | codegen); |
| 1221 | GenerateDataProcInstruction(kind, |
| 1222 | out_hi, |
| 1223 | first_hi, |
| 1224 | Operand(second_hi, shift, shift_value), |
| 1225 | codegen); |
| 1226 | } else { |
| 1227 | const vixl32::Register temp = temps.Acquire(); |
| 1228 | |
| 1229 | __ Lsr(temp, second_lo, shift_value); |
| 1230 | __ Orr(temp, temp, Operand(second_hi, ShiftType::LSL, 32 - shift_value)); |
| 1231 | GenerateDataProc(kind, |
| 1232 | out, |
| 1233 | first, |
| 1234 | temp, |
| 1235 | Operand(second_hi, shift, shift_value), |
| 1236 | codegen); |
| 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1242 | static void GenerateVcmp(HInstruction* instruction, CodeGeneratorARMVIXL* codegen) { |
| 1243 | const Location rhs_loc = instruction->GetLocations()->InAt(1); |
| 1244 | if (rhs_loc.IsConstant()) { |
| 1245 | // 0.0 is the only immediate that can be encoded directly in |
| 1246 | // a VCMP instruction. |
| 1247 | // |
| 1248 | // Both the JLS (section 15.20.1) and the JVMS (section 6.5) |
| 1249 | // specify that in a floating-point comparison, positive zero |
| 1250 | // and negative zero are considered equal, so we can use the |
| 1251 | // literal 0.0 for both cases here. |
| 1252 | // |
| 1253 | // Note however that some methods (Float.equal, Float.compare, |
| 1254 | // Float.compareTo, Double.equal, Double.compare, |
| 1255 | // Double.compareTo, Math.max, Math.min, StrictMath.max, |
| 1256 | // StrictMath.min) consider 0.0 to be (strictly) greater than |
| 1257 | // -0.0. So if we ever translate calls to these methods into a |
| 1258 | // HCompare instruction, we must handle the -0.0 case with |
| 1259 | // care here. |
| 1260 | DCHECK(rhs_loc.GetConstant()->IsArithmeticZero()); |
| 1261 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1262 | const DataType::Type type = instruction->InputAt(0)->GetType(); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1263 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1264 | if (type == DataType::Type::kFloat32) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1265 | __ Vcmp(F32, InputSRegisterAt(instruction, 0), 0.0); |
| 1266 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1267 | DCHECK_EQ(type, DataType::Type::kFloat64); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1268 | __ Vcmp(F64, InputDRegisterAt(instruction, 0), 0.0); |
| 1269 | } |
| 1270 | } else { |
| 1271 | __ Vcmp(InputVRegisterAt(instruction, 0), InputVRegisterAt(instruction, 1)); |
| 1272 | } |
| 1273 | } |
| 1274 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1275 | static int64_t AdjustConstantForCondition(int64_t value, |
| 1276 | IfCondition* condition, |
| 1277 | IfCondition* opposite) { |
| 1278 | if (value == 1) { |
| 1279 | if (*condition == kCondB) { |
| 1280 | value = 0; |
| 1281 | *condition = kCondEQ; |
| 1282 | *opposite = kCondNE; |
| 1283 | } else if (*condition == kCondAE) { |
| 1284 | value = 0; |
| 1285 | *condition = kCondNE; |
| 1286 | *opposite = kCondEQ; |
| 1287 | } |
| 1288 | } else if (value == -1) { |
| 1289 | if (*condition == kCondGT) { |
| 1290 | value = 0; |
| 1291 | *condition = kCondGE; |
| 1292 | *opposite = kCondLT; |
| 1293 | } else if (*condition == kCondLE) { |
| 1294 | value = 0; |
| 1295 | *condition = kCondLT; |
| 1296 | *opposite = kCondGE; |
| 1297 | } |
| 1298 | } |
| 1299 | |
| 1300 | return value; |
| 1301 | } |
| 1302 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1303 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTestConstant( |
| 1304 | HCondition* condition, |
| 1305 | bool invert, |
| 1306 | CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1307 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1308 | |
| 1309 | const LocationSummary* const locations = condition->GetLocations(); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1310 | IfCondition cond = condition->GetCondition(); |
| 1311 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1312 | |
| 1313 | if (invert) { |
| 1314 | std::swap(cond, opposite); |
| 1315 | } |
| 1316 | |
| 1317 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1318 | const Location left = locations->InAt(0); |
| 1319 | const Location right = locations->InAt(1); |
| 1320 | |
| 1321 | DCHECK(right.IsConstant()); |
| 1322 | |
| 1323 | const vixl32::Register left_high = HighRegisterFrom(left); |
| 1324 | const vixl32::Register left_low = LowRegisterFrom(left); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1325 | int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), &cond, &opposite); |
| 1326 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1327 | |
| 1328 | // Comparisons against 0 are common enough to deserve special attention. |
| 1329 | if (value == 0) { |
| 1330 | switch (cond) { |
| 1331 | case kCondNE: |
| 1332 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 1333 | case kCondA: |
| 1334 | ret = std::make_pair(ne, eq); |
| 1335 | FALLTHROUGH_INTENDED; |
| 1336 | case kCondEQ: |
| 1337 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 1338 | case kCondBE: |
| 1339 | __ Orrs(temps.Acquire(), left_low, left_high); |
| 1340 | return ret; |
| 1341 | case kCondLT: |
| 1342 | case kCondGE: |
| 1343 | __ Cmp(left_high, 0); |
| 1344 | return std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| 1345 | // Trivially true or false. |
| 1346 | case kCondB: |
| 1347 | ret = std::make_pair(ne, eq); |
| 1348 | FALLTHROUGH_INTENDED; |
| 1349 | case kCondAE: |
| 1350 | __ Cmp(left_low, left_low); |
| 1351 | return ret; |
| 1352 | default: |
| 1353 | break; |
| 1354 | } |
| 1355 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1356 | |
| 1357 | switch (cond) { |
| 1358 | case kCondEQ: |
| 1359 | case kCondNE: |
| 1360 | case kCondB: |
| 1361 | case kCondBE: |
| 1362 | case kCondA: |
| 1363 | case kCondAE: { |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1364 | const uint32_t value_low = Low32Bits(value); |
| 1365 | Operand operand_low(value_low); |
| 1366 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1367 | __ Cmp(left_high, High32Bits(value)); |
| 1368 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1369 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1370 | // we must ensure that the operands corresponding to the least significant |
| 1371 | // halves of the inputs fit into a 16-bit CMP encoding. |
| 1372 | if (!left_low.IsLow() || !IsUint<8>(value_low)) { |
| 1373 | operand_low = Operand(temps.Acquire()); |
| 1374 | __ Mov(LeaveFlags, operand_low.GetBaseRegister(), value_low); |
| 1375 | } |
| 1376 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1377 | // We use the scope because of the IT block that follows. |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1378 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1379 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1380 | CodeBufferCheckScope::kExactSize); |
| 1381 | |
| 1382 | __ it(eq); |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1383 | __ cmp(eq, left_low, operand_low); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1384 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1385 | break; |
| 1386 | } |
| 1387 | case kCondLE: |
| 1388 | case kCondGT: |
| 1389 | // Trivially true or false. |
| 1390 | if (value == std::numeric_limits<int64_t>::max()) { |
| 1391 | __ Cmp(left_low, left_low); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1392 | ret = cond == kCondLE ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1393 | break; |
| 1394 | } |
| 1395 | |
| 1396 | if (cond == kCondLE) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1397 | DCHECK_EQ(opposite, kCondGT); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1398 | cond = kCondLT; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1399 | opposite = kCondGE; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1400 | } else { |
| 1401 | DCHECK_EQ(cond, kCondGT); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1402 | DCHECK_EQ(opposite, kCondLE); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1403 | cond = kCondGE; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1404 | opposite = kCondLT; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | value++; |
| 1408 | FALLTHROUGH_INTENDED; |
| 1409 | case kCondGE: |
| 1410 | case kCondLT: { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1411 | __ Cmp(left_low, Low32Bits(value)); |
| 1412 | __ Sbcs(temps.Acquire(), left_high, High32Bits(value)); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1413 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1414 | break; |
| 1415 | } |
| 1416 | default: |
| 1417 | LOG(FATAL) << "Unreachable"; |
| 1418 | UNREACHABLE(); |
| 1419 | } |
| 1420 | |
| 1421 | return ret; |
| 1422 | } |
| 1423 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1424 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateLongTest( |
| 1425 | HCondition* condition, |
| 1426 | bool invert, |
| 1427 | CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1428 | DCHECK_EQ(condition->GetLeft()->GetType(), DataType::Type::kInt64); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1429 | |
| 1430 | const LocationSummary* const locations = condition->GetLocations(); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1431 | IfCondition cond = condition->GetCondition(); |
| 1432 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1433 | |
| 1434 | if (invert) { |
| 1435 | std::swap(cond, opposite); |
| 1436 | } |
| 1437 | |
| 1438 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1439 | Location left = locations->InAt(0); |
| 1440 | Location right = locations->InAt(1); |
| 1441 | |
| 1442 | DCHECK(right.IsRegisterPair()); |
| 1443 | |
| 1444 | switch (cond) { |
| 1445 | case kCondEQ: |
| 1446 | case kCondNE: |
| 1447 | case kCondB: |
| 1448 | case kCondBE: |
| 1449 | case kCondA: |
| 1450 | case kCondAE: { |
| 1451 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); |
| 1452 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1453 | // We use the scope because of the IT block that follows. |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1454 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1455 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1456 | CodeBufferCheckScope::kExactSize); |
| 1457 | |
| 1458 | __ it(eq); |
| 1459 | __ cmp(eq, LowRegisterFrom(left), LowRegisterFrom(right)); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1460 | ret = std::make_pair(ARMUnsignedCondition(cond), ARMUnsignedCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1461 | break; |
| 1462 | } |
| 1463 | case kCondLE: |
| 1464 | case kCondGT: |
| 1465 | if (cond == kCondLE) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1466 | DCHECK_EQ(opposite, kCondGT); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1467 | cond = kCondGE; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1468 | opposite = kCondLT; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1469 | } else { |
| 1470 | DCHECK_EQ(cond, kCondGT); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1471 | DCHECK_EQ(opposite, kCondLE); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1472 | cond = kCondLT; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1473 | opposite = kCondGE; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | std::swap(left, right); |
| 1477 | FALLTHROUGH_INTENDED; |
| 1478 | case kCondGE: |
| 1479 | case kCondLT: { |
| 1480 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1481 | |
| 1482 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); |
| 1483 | __ Sbcs(temps.Acquire(), HighRegisterFrom(left), HighRegisterFrom(right)); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1484 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1485 | break; |
| 1486 | } |
| 1487 | default: |
| 1488 | LOG(FATAL) << "Unreachable"; |
| 1489 | UNREACHABLE(); |
| 1490 | } |
| 1491 | |
| 1492 | return ret; |
| 1493 | } |
| 1494 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1495 | static std::pair<vixl32::Condition, vixl32::Condition> GenerateTest(HCondition* condition, |
| 1496 | bool invert, |
| 1497 | CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1498 | const DataType::Type type = condition->GetLeft()->GetType(); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1499 | IfCondition cond = condition->GetCondition(); |
| 1500 | IfCondition opposite = condition->GetOppositeCondition(); |
| 1501 | std::pair<vixl32::Condition, vixl32::Condition> ret(eq, ne); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1502 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1503 | if (invert) { |
| 1504 | std::swap(cond, opposite); |
| 1505 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1506 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1507 | if (type == DataType::Type::kInt64) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1508 | ret = condition->GetLocations()->InAt(1).IsConstant() |
| 1509 | ? GenerateLongTestConstant(condition, invert, codegen) |
| 1510 | : GenerateLongTest(condition, invert, codegen); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1511 | } else if (DataType::IsFloatingPointType(type)) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1512 | GenerateVcmp(condition, codegen); |
| 1513 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 1514 | ret = std::make_pair(ARMFPCondition(cond, condition->IsGtBias()), |
| 1515 | ARMFPCondition(opposite, condition->IsGtBias())); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1516 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1517 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 1518 | __ Cmp(InputRegisterAt(condition, 0), InputOperandAt(condition, 1)); |
| 1519 | ret = std::make_pair(ARMCondition(cond), ARMCondition(opposite)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | return ret; |
| 1523 | } |
| 1524 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1525 | static void GenerateConditionGeneric(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1526 | const vixl32::Register out = OutputRegister(cond); |
| 1527 | const auto condition = GenerateTest(cond, false, codegen); |
| 1528 | |
| 1529 | __ Mov(LeaveFlags, out, 0); |
| 1530 | |
| 1531 | if (out.IsLow()) { |
| 1532 | // We use the scope because of the IT block that follows. |
| 1533 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1534 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1535 | CodeBufferCheckScope::kExactSize); |
| 1536 | |
| 1537 | __ it(condition.first); |
| 1538 | __ mov(condition.first, out, 1); |
| 1539 | } else { |
| 1540 | vixl32::Label done_label; |
| 1541 | vixl32::Label* const final_label = codegen->GetFinalLabel(cond, &done_label); |
| 1542 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1543 | __ B(condition.second, final_label, /* is_far_target= */ false); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1544 | __ Mov(out, 1); |
| 1545 | |
| 1546 | if (done_label.IsReferenced()) { |
| 1547 | __ Bind(&done_label); |
| 1548 | } |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | static void GenerateEqualLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1553 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1554 | |
| 1555 | const LocationSummary* const locations = cond->GetLocations(); |
| 1556 | IfCondition condition = cond->GetCondition(); |
| 1557 | const vixl32::Register out = OutputRegister(cond); |
| 1558 | const Location left = locations->InAt(0); |
| 1559 | const Location right = locations->InAt(1); |
| 1560 | vixl32::Register left_high = HighRegisterFrom(left); |
| 1561 | vixl32::Register left_low = LowRegisterFrom(left); |
| 1562 | vixl32::Register temp; |
| 1563 | UseScratchRegisterScope temps(codegen->GetVIXLAssembler()); |
| 1564 | |
| 1565 | if (right.IsConstant()) { |
| 1566 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1567 | const int64_t value = AdjustConstantForCondition(Int64ConstantFrom(right), |
| 1568 | &condition, |
| 1569 | &opposite); |
| 1570 | Operand right_high = High32Bits(value); |
| 1571 | Operand right_low = Low32Bits(value); |
| 1572 | |
| 1573 | // The output uses Location::kNoOutputOverlap. |
| 1574 | if (out.Is(left_high)) { |
| 1575 | std::swap(left_low, left_high); |
| 1576 | std::swap(right_low, right_high); |
| 1577 | } |
| 1578 | |
| 1579 | __ Sub(out, left_low, right_low); |
| 1580 | temp = temps.Acquire(); |
| 1581 | __ Sub(temp, left_high, right_high); |
| 1582 | } else { |
| 1583 | DCHECK(right.IsRegisterPair()); |
| 1584 | temp = temps.Acquire(); |
| 1585 | __ Sub(temp, left_high, HighRegisterFrom(right)); |
| 1586 | __ Sub(out, left_low, LowRegisterFrom(right)); |
| 1587 | } |
| 1588 | |
| 1589 | // Need to check after calling AdjustConstantForCondition(). |
| 1590 | DCHECK(condition == kCondEQ || condition == kCondNE) << condition; |
| 1591 | |
| 1592 | if (condition == kCondNE && out.IsLow()) { |
| 1593 | __ Orrs(out, out, temp); |
| 1594 | |
| 1595 | // We use the scope because of the IT block that follows. |
| 1596 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1597 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1598 | CodeBufferCheckScope::kExactSize); |
| 1599 | |
| 1600 | __ it(ne); |
| 1601 | __ mov(ne, out, 1); |
| 1602 | } else { |
| 1603 | __ Orr(out, out, temp); |
| 1604 | codegen->GenerateConditionWithZero(condition, out, out, temp); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1608 | static void GenerateConditionLong(HCondition* cond, CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1609 | DCHECK_EQ(cond->GetLeft()->GetType(), DataType::Type::kInt64); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1610 | |
| 1611 | const LocationSummary* const locations = cond->GetLocations(); |
| 1612 | IfCondition condition = cond->GetCondition(); |
| 1613 | const vixl32::Register out = OutputRegister(cond); |
| 1614 | const Location left = locations->InAt(0); |
| 1615 | const Location right = locations->InAt(1); |
| 1616 | |
| 1617 | if (right.IsConstant()) { |
| 1618 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1619 | |
| 1620 | // Comparisons against 0 are common enough to deserve special attention. |
| 1621 | if (AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite) == 0) { |
| 1622 | switch (condition) { |
| 1623 | case kCondNE: |
| 1624 | case kCondA: |
| 1625 | if (out.IsLow()) { |
| 1626 | // We only care if both input registers are 0 or not. |
| 1627 | __ Orrs(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 1628 | |
| 1629 | // We use the scope because of the IT block that follows. |
| 1630 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1631 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1632 | CodeBufferCheckScope::kExactSize); |
| 1633 | |
| 1634 | __ it(ne); |
| 1635 | __ mov(ne, out, 1); |
| 1636 | return; |
| 1637 | } |
| 1638 | |
| 1639 | FALLTHROUGH_INTENDED; |
| 1640 | case kCondEQ: |
| 1641 | case kCondBE: |
| 1642 | // We only care if both input registers are 0 or not. |
| 1643 | __ Orr(out, LowRegisterFrom(left), HighRegisterFrom(left)); |
| 1644 | codegen->GenerateConditionWithZero(condition, out, out); |
| 1645 | return; |
| 1646 | case kCondLT: |
| 1647 | case kCondGE: |
| 1648 | // We only care about the sign bit. |
| 1649 | FALLTHROUGH_INTENDED; |
| 1650 | case kCondAE: |
| 1651 | case kCondB: |
| 1652 | codegen->GenerateConditionWithZero(condition, out, HighRegisterFrom(left)); |
| 1653 | return; |
| 1654 | case kCondLE: |
| 1655 | case kCondGT: |
| 1656 | default: |
| 1657 | break; |
| 1658 | } |
| 1659 | } |
| 1660 | } |
| 1661 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1662 | // If `out` is a low register, then the GenerateConditionGeneric() |
| 1663 | // function generates a shorter code sequence that is still branchless. |
| 1664 | if ((condition == kCondEQ || condition == kCondNE) && !out.IsLow()) { |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1665 | GenerateEqualLong(cond, codegen); |
| 1666 | return; |
| 1667 | } |
| 1668 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 1669 | GenerateConditionGeneric(cond, codegen); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1670 | } |
| 1671 | |
| Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 1672 | static void GenerateConditionIntegralOrNonPrimitive(HCondition* cond, |
| 1673 | CodeGeneratorARMVIXL* codegen) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1674 | const DataType::Type type = cond->GetLeft()->GetType(); |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1675 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1676 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1677 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1678 | if (type == DataType::Type::kInt64) { |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 1679 | GenerateConditionLong(cond, codegen); |
| 1680 | return; |
| 1681 | } |
| 1682 | |
| 1683 | IfCondition condition = cond->GetCondition(); |
| 1684 | vixl32::Register in = InputRegisterAt(cond, 0); |
| 1685 | const vixl32::Register out = OutputRegister(cond); |
| 1686 | const Location right = cond->GetLocations()->InAt(1); |
| 1687 | int64_t value; |
| 1688 | |
| 1689 | if (right.IsConstant()) { |
| 1690 | IfCondition opposite = cond->GetOppositeCondition(); |
| 1691 | |
| 1692 | value = AdjustConstantForCondition(Int64ConstantFrom(right), &condition, &opposite); |
| 1693 | |
| 1694 | // Comparisons against 0 are common enough to deserve special attention. |
| 1695 | if (value == 0) { |
| 1696 | switch (condition) { |
| 1697 | case kCondNE: |
| 1698 | case kCondA: |
| 1699 | if (out.IsLow() && out.Is(in)) { |
| 1700 | __ Cmp(out, 0); |
| 1701 | |
| 1702 | // We use the scope because of the IT block that follows. |
| 1703 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1704 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1705 | CodeBufferCheckScope::kExactSize); |
| 1706 | |
| 1707 | __ it(ne); |
| 1708 | __ mov(ne, out, 1); |
| 1709 | return; |
| 1710 | } |
| 1711 | |
| 1712 | FALLTHROUGH_INTENDED; |
| 1713 | case kCondEQ: |
| 1714 | case kCondBE: |
| 1715 | case kCondLT: |
| 1716 | case kCondGE: |
| 1717 | case kCondAE: |
| 1718 | case kCondB: |
| 1719 | codegen->GenerateConditionWithZero(condition, out, in); |
| 1720 | return; |
| 1721 | case kCondLE: |
| 1722 | case kCondGT: |
| 1723 | default: |
| 1724 | break; |
| 1725 | } |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | if (condition == kCondEQ || condition == kCondNE) { |
| 1730 | Operand operand(0); |
| 1731 | |
| 1732 | if (right.IsConstant()) { |
| 1733 | operand = Operand::From(value); |
| 1734 | } else if (out.Is(RegisterFrom(right))) { |
| 1735 | // Avoid 32-bit instructions if possible. |
| 1736 | operand = InputOperandAt(cond, 0); |
| 1737 | in = RegisterFrom(right); |
| 1738 | } else { |
| 1739 | operand = InputOperandAt(cond, 1); |
| 1740 | } |
| 1741 | |
| 1742 | if (condition == kCondNE && out.IsLow()) { |
| 1743 | __ Subs(out, in, operand); |
| 1744 | |
| 1745 | // We use the scope because of the IT block that follows. |
| 1746 | ExactAssemblyScope guard(codegen->GetVIXLAssembler(), |
| 1747 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 1748 | CodeBufferCheckScope::kExactSize); |
| 1749 | |
| 1750 | __ it(ne); |
| 1751 | __ mov(ne, out, 1); |
| 1752 | } else { |
| 1753 | __ Sub(out, in, operand); |
| 1754 | codegen->GenerateConditionWithZero(condition, out, out); |
| 1755 | } |
| 1756 | |
| 1757 | return; |
| 1758 | } |
| 1759 | |
| 1760 | GenerateConditionGeneric(cond, codegen); |
| 1761 | } |
| 1762 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1763 | static bool CanEncodeConstantAs8BitImmediate(HConstant* constant) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1764 | const DataType::Type type = constant->GetType(); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1765 | bool ret = false; |
| 1766 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1767 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1768 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1769 | if (type == DataType::Type::kInt64) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1770 | const uint64_t value = Uint64ConstantFrom(constant); |
| 1771 | |
| 1772 | ret = IsUint<8>(Low32Bits(value)) && IsUint<8>(High32Bits(value)); |
| 1773 | } else { |
| 1774 | ret = IsUint<8>(Int32ConstantFrom(constant)); |
| 1775 | } |
| 1776 | |
| 1777 | return ret; |
| 1778 | } |
| 1779 | |
| 1780 | static Location Arm8BitEncodableConstantOrRegister(HInstruction* constant) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1781 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1782 | |
| 1783 | if (constant->IsConstant() && CanEncodeConstantAs8BitImmediate(constant->AsConstant())) { |
| 1784 | return Location::ConstantLocation(constant->AsConstant()); |
| 1785 | } |
| 1786 | |
| 1787 | return Location::RequiresRegister(); |
| 1788 | } |
| 1789 | |
| 1790 | static bool CanGenerateConditionalMove(const Location& out, const Location& src) { |
| 1791 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 1792 | // we check that we are not dealing with floating-point output (there is no |
| 1793 | // 16-bit VMOV encoding). |
| 1794 | if (!out.IsRegister() && !out.IsRegisterPair()) { |
| 1795 | return false; |
| 1796 | } |
| 1797 | |
| 1798 | // For constants, we also check that the output is in one or two low registers, |
| 1799 | // and that the constants fit in an 8-bit unsigned integer, so that a 16-bit |
| 1800 | // MOV encoding can be used. |
| 1801 | if (src.IsConstant()) { |
| 1802 | if (!CanEncodeConstantAs8BitImmediate(src.GetConstant())) { |
| 1803 | return false; |
| 1804 | } |
| 1805 | |
| 1806 | if (out.IsRegister()) { |
| 1807 | if (!RegisterFrom(out).IsLow()) { |
| 1808 | return false; |
| 1809 | } |
| 1810 | } else { |
| 1811 | DCHECK(out.IsRegisterPair()); |
| 1812 | |
| 1813 | if (!HighRegisterFrom(out).IsLow()) { |
| 1814 | return false; |
| 1815 | } |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | return true; |
| 1820 | } |
| 1821 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1822 | #undef __ |
| 1823 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1824 | vixl32::Label* CodeGeneratorARMVIXL::GetFinalLabel(HInstruction* instruction, |
| 1825 | vixl32::Label* final_label) { |
| 1826 | DCHECK(!instruction->IsControlFlow() && !instruction->IsSuspendCheck()); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1827 | DCHECK(!instruction->IsInvoke() || !instruction->GetLocations()->CanCall()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 1828 | |
| 1829 | const HBasicBlock* const block = instruction->GetBlock(); |
| 1830 | const HLoopInformation* const info = block->GetLoopInformation(); |
| 1831 | HInstruction* const next = instruction->GetNext(); |
| 1832 | |
| 1833 | // Avoid a branch to a branch. |
| 1834 | if (next->IsGoto() && (info == nullptr || |
| 1835 | !info->IsBackEdge(*block) || |
| 1836 | !info->HasSuspendCheck())) { |
| 1837 | final_label = GetLabelOf(next->AsGoto()->GetSuccessor()); |
| 1838 | } |
| 1839 | |
| 1840 | return final_label; |
| 1841 | } |
| 1842 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1843 | CodeGeneratorARMVIXL::CodeGeneratorARMVIXL(HGraph* graph, |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1844 | const CompilerOptions& compiler_options, |
| 1845 | OptimizingCompilerStats* stats) |
| 1846 | : CodeGenerator(graph, |
| 1847 | kNumberOfCoreRegisters, |
| 1848 | kNumberOfSRegisters, |
| 1849 | kNumberOfRegisterPairs, |
| 1850 | kCoreCalleeSaves.GetList(), |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 1851 | ComputeSRegisterListMask(kFpuCalleeSaves), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1852 | compiler_options, |
| 1853 | stats), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1854 | block_labels_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1855 | jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1856 | location_builder_(graph, this), |
| 1857 | instruction_visitor_(graph, this), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1858 | move_resolver_(graph->GetAllocator(), this), |
| 1859 | assembler_(graph->GetAllocator()), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1860 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1861 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1862 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1863 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1864 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1865 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 1866 | boot_image_other_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1867 | call_entrypoint_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1868 | baker_read_barrier_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 1869 | uint32_literals_(std::less<uint32_t>(), |
| 1870 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1871 | jit_string_patches_(StringReferenceValueComparator(), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1872 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 1873 | jit_class_patches_(TypeReferenceValueComparator(), |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1874 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), |
| 1875 | jit_baker_read_barrier_slow_paths_(std::less<uint32_t>(), |
| 1876 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1877 | // Always save the LR register to mimic Quick. |
| 1878 | AddAllocatedRegister(Location::RegisterLocation(LR)); |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 1879 | // Give D30 and D31 as scratch register to VIXL. The register allocator only works on |
| 1880 | // S0-S31, which alias to D0-D15. |
| 1881 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d31); |
| 1882 | GetVIXLAssembler()->GetScratchVRegisterList()->Combine(d30); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1883 | } |
| 1884 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1885 | void JumpTableARMVIXL::EmitTable(CodeGeneratorARMVIXL* codegen) { |
| 1886 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1887 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1888 | |
| 1889 | // We are about to use the assembler to place literals directly. Make sure we have enough |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1890 | // underlying code buffer and we have generated a jump table of the right size, using |
| 1891 | // codegen->GetVIXLAssembler()->GetBuffer().Align(); |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1892 | ExactAssemblyScope aas(codegen->GetVIXLAssembler(), |
| 1893 | num_entries * sizeof(int32_t), |
| 1894 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1895 | // TODO(VIXL): Check that using lower case bind is fine here. |
| 1896 | codegen->GetVIXLAssembler()->bind(&table_start_); |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1897 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1898 | codegen->GetVIXLAssembler()->place(bb_addresses_[i].get()); |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | void JumpTableARMVIXL::FixTable(CodeGeneratorARMVIXL* codegen) { |
| 1903 | uint32_t num_entries = switch_instr_->GetNumEntries(); |
| 1904 | DCHECK_GE(num_entries, kPackedSwitchCompareJumpThreshold); |
| 1905 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1906 | const ArenaVector<HBasicBlock*>& successors = switch_instr_->GetBlock()->GetSuccessors(); |
| 1907 | for (uint32_t i = 0; i < num_entries; i++) { |
| 1908 | vixl32::Label* target_label = codegen->GetLabelOf(successors[i]); |
| 1909 | DCHECK(target_label->IsBound()); |
| 1910 | int32_t jump_offset = target_label->GetLocation() - table_start_.GetLocation(); |
| 1911 | // When doing BX to address we need to have lower bit set to 1 in T32. |
| 1912 | if (codegen->GetVIXLAssembler()->IsUsingT32()) { |
| 1913 | jump_offset++; |
| 1914 | } |
| 1915 | DCHECK_GT(jump_offset, std::numeric_limits<int32_t>::min()); |
| 1916 | DCHECK_LE(jump_offset, std::numeric_limits<int32_t>::max()); |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1917 | |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1918 | bb_addresses_[i].get()->UpdateValue(jump_offset, codegen->GetVIXLAssembler()->GetBuffer()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1919 | } |
| 1920 | } |
| 1921 | |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1922 | void CodeGeneratorARMVIXL::FixJumpTables() { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1923 | for (auto&& jump_table : jump_tables_) { |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1924 | jump_table->FixTable(this); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 1925 | } |
| 1926 | } |
| 1927 | |
| Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 1928 | #define __ reinterpret_cast<ArmVIXLAssembler*>(GetAssembler())->GetVIXLAssembler()-> // NOLINT |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1929 | |
| 1930 | void CodeGeneratorARMVIXL::Finalize(CodeAllocator* allocator) { |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 1931 | FixJumpTables(); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1932 | |
| 1933 | // Emit JIT baker read barrier slow paths. |
| 1934 | DCHECK(Runtime::Current()->UseJitCompilation() || jit_baker_read_barrier_slow_paths_.empty()); |
| 1935 | for (auto& entry : jit_baker_read_barrier_slow_paths_) { |
| 1936 | uint32_t encoded_data = entry.first; |
| 1937 | vixl::aarch32::Label* slow_path_entry = &entry.second.label; |
| 1938 | __ Bind(slow_path_entry); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1939 | CompileBakerReadBarrierThunk(*GetAssembler(), encoded_data, /* debug_name= */ nullptr); |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1942 | GetAssembler()->FinalizeCode(); |
| 1943 | CodeGenerator::Finalize(allocator); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 1944 | |
| 1945 | // Verify Baker read barrier linker patches. |
| 1946 | if (kIsDebugBuild) { |
| 1947 | ArrayRef<const uint8_t> code = allocator->GetMemory(); |
| 1948 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| 1949 | DCHECK(info.label.IsBound()); |
| 1950 | uint32_t literal_offset = info.label.GetLocation(); |
| 1951 | DCHECK_ALIGNED(literal_offset, 2u); |
| 1952 | |
| 1953 | auto GetInsn16 = [&code](uint32_t offset) { |
| 1954 | DCHECK_ALIGNED(offset, 2u); |
| 1955 | return (static_cast<uint32_t>(code[offset + 0]) << 0) + |
| 1956 | (static_cast<uint32_t>(code[offset + 1]) << 8); |
| 1957 | }; |
| 1958 | auto GetInsn32 = [=](uint32_t offset) { |
| 1959 | return (GetInsn16(offset) << 16) + (GetInsn16(offset + 2u) << 0); |
| 1960 | }; |
| 1961 | |
| 1962 | uint32_t encoded_data = info.custom_data; |
| 1963 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 1964 | // Check that the next instruction matches the expected LDR. |
| 1965 | switch (kind) { |
| 1966 | case BakerReadBarrierKind::kField: { |
| 1967 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 1968 | if (width == BakerReadBarrierWidth::kWide) { |
| 1969 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1970 | uint32_t next_insn = GetInsn32(literal_offset + 4u); |
| 1971 | // LDR (immediate), encoding T3, with correct base_reg. |
| 1972 | CheckValidReg((next_insn >> 12) & 0xfu); // Check destination register. |
| 1973 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1974 | CHECK_EQ(next_insn & 0xffff0000u, 0xf8d00000u | (base_reg << 16)); |
| 1975 | } else { |
| 1976 | DCHECK_GE(code.size() - literal_offset, 6u); |
| 1977 | uint32_t next_insn = GetInsn16(literal_offset + 4u); |
| 1978 | // LDR (immediate), encoding T1, with correct base_reg. |
| 1979 | CheckValidReg(next_insn & 0x7u); // Check destination register. |
| 1980 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1981 | CHECK_EQ(next_insn & 0xf838u, 0x6800u | (base_reg << 3)); |
| 1982 | } |
| 1983 | break; |
| 1984 | } |
| 1985 | case BakerReadBarrierKind::kArray: { |
| 1986 | DCHECK_GE(code.size() - literal_offset, 8u); |
| 1987 | uint32_t next_insn = GetInsn32(literal_offset + 4u); |
| 1988 | // LDR (register) with correct base_reg, S=1 and option=011 (LDR Wt, [Xn, Xm, LSL #2]). |
| 1989 | CheckValidReg((next_insn >> 12) & 0xfu); // Check destination register. |
| 1990 | const uint32_t base_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 1991 | CHECK_EQ(next_insn & 0xffff0ff0u, 0xf8500020u | (base_reg << 16)); |
| 1992 | CheckValidReg(next_insn & 0xf); // Check index register |
| 1993 | break; |
| 1994 | } |
| 1995 | case BakerReadBarrierKind::kGcRoot: { |
| 1996 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 1997 | if (width == BakerReadBarrierWidth::kWide) { |
| 1998 | DCHECK_GE(literal_offset, 4u); |
| 1999 | uint32_t prev_insn = GetInsn32(literal_offset - 4u); |
| Vladimir Marko | f28be43 | 2018-08-14 12:20:51 +0000 | [diff] [blame] | 2000 | // LDR (immediate), encoding T3, with correct root_reg. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2001 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| Vladimir Marko | f28be43 | 2018-08-14 12:20:51 +0000 | [diff] [blame] | 2002 | CHECK_EQ(prev_insn & 0xfff0f000u, 0xf8d00000u | (root_reg << 12)); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2003 | } else { |
| 2004 | DCHECK_GE(literal_offset, 2u); |
| 2005 | uint32_t prev_insn = GetInsn16(literal_offset - 2u); |
| 2006 | // LDR (immediate), encoding T1, with correct root_reg. |
| 2007 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2008 | CHECK_EQ(prev_insn & 0xf807u, 0x6800u | root_reg); |
| 2009 | } |
| 2010 | break; |
| 2011 | } |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 2012 | case BakerReadBarrierKind::kUnsafeCas: { |
| 2013 | DCHECK_GE(literal_offset, 4u); |
| 2014 | uint32_t prev_insn = GetInsn32(literal_offset - 4u); |
| 2015 | // ADD (register), encoding T3, with correct root_reg. |
| 2016 | const uint32_t root_reg = BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 2017 | CHECK_EQ(prev_insn & 0xfff0fff0u, 0xeb000000u | (root_reg << 8)); |
| 2018 | break; |
| 2019 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 2020 | default: |
| 2021 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 2022 | UNREACHABLE(); |
| 2023 | } |
| 2024 | } |
| 2025 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | void CodeGeneratorARMVIXL::SetupBlockedRegisters() const { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2029 | // Stack register, LR and PC are always reserved. |
| 2030 | blocked_core_registers_[SP] = true; |
| 2031 | blocked_core_registers_[LR] = true; |
| 2032 | blocked_core_registers_[PC] = true; |
| 2033 | |
| Roland Levillain | 6d729a7 | 2017-06-30 18:34:01 +0100 | [diff] [blame] | 2034 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2035 | // Reserve marking register. |
| 2036 | blocked_core_registers_[MR] = true; |
| 2037 | } |
| 2038 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2039 | // Reserve thread register. |
| 2040 | blocked_core_registers_[TR] = true; |
| 2041 | |
| 2042 | // Reserve temp register. |
| 2043 | blocked_core_registers_[IP] = true; |
| 2044 | |
| 2045 | if (GetGraph()->IsDebuggable()) { |
| 2046 | // Stubs do not save callee-save floating point registers. If the graph |
| 2047 | // is debuggable, we need to deal with these registers differently. For |
| 2048 | // now, just block them. |
| 2049 | for (uint32_t i = kFpuCalleeSaves.GetFirstSRegister().GetCode(); |
| 2050 | i <= kFpuCalleeSaves.GetLastSRegister().GetCode(); |
| 2051 | ++i) { |
| 2052 | blocked_fpu_registers_[i] = true; |
| 2053 | } |
| 2054 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2055 | } |
| 2056 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2057 | InstructionCodeGeneratorARMVIXL::InstructionCodeGeneratorARMVIXL(HGraph* graph, |
| 2058 | CodeGeneratorARMVIXL* codegen) |
| 2059 | : InstructionCodeGenerator(graph, codegen), |
| 2060 | assembler_(codegen->GetAssembler()), |
| 2061 | codegen_(codegen) {} |
| 2062 | |
| 2063 | void CodeGeneratorARMVIXL::ComputeSpillMask() { |
| 2064 | core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_; |
| Vladimir Marko | 460f054 | 2019-07-04 14:02:08 +0100 | [diff] [blame] | 2065 | DCHECK_NE(core_spill_mask_ & (1u << kLrCode), 0u) |
| 2066 | << "At least the return address register must be saved"; |
| 2067 | // 16-bit PUSH/POP (T1) can save/restore just the LR/PC. |
| 2068 | DCHECK(GetVIXLAssembler()->IsUsingT32()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2069 | fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_; |
| 2070 | // We use vpush and vpop for saving and restoring floating point registers, which take |
| 2071 | // a SRegister and the number of registers to save/restore after that SRegister. We |
| 2072 | // therefore update the `fpu_spill_mask_` to also contain those registers not allocated, |
| 2073 | // but in the range. |
| 2074 | if (fpu_spill_mask_ != 0) { |
| 2075 | uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_); |
| 2076 | uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_); |
| 2077 | for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) { |
| 2078 | fpu_spill_mask_ |= (1 << i); |
| 2079 | } |
| 2080 | } |
| 2081 | } |
| 2082 | |
| 2083 | void CodeGeneratorARMVIXL::GenerateFrameEntry() { |
| 2084 | bool skip_overflow_check = |
| 2085 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm); |
| 2086 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
| 2087 | __ Bind(&frame_entry_label_); |
| 2088 | |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 2089 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 2090 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2091 | vixl32::Register temp = temps.Acquire(); |
| Mathieu Chartier | 7f8678e | 2019-08-30 16:22:28 -0700 | [diff] [blame] | 2092 | static_assert(ArtMethod::MaxCounter() == 0xFFFF, "asm is probably wrong"); |
| 2093 | // Load with sign extend to set the high bits for integer overflow check. |
| Nicolas Geoffray | 7ab0777 | 2019-08-30 08:26:59 +0000 | [diff] [blame] | 2094 | __ Ldrh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2095 | __ Add(temp, temp, 1); |
| Mathieu Chartier | 7f8678e | 2019-08-30 16:22:28 -0700 | [diff] [blame] | 2096 | // Subtract one if the counter would overflow. |
| 2097 | __ Sub(temp, temp, Operand(temp, ShiftType::LSR, 16)); |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 2098 | __ Strh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2099 | } |
| 2100 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2101 | if (HasEmptyFrame()) { |
| David Srbecky | 3002184 | 2019-02-13 14:19:36 +0000 | [diff] [blame] | 2102 | // Ensure that the CFI opcode list is not empty. |
| 2103 | GetAssembler()->cfi().Nop(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2104 | return; |
| 2105 | } |
| 2106 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2107 | if (!skip_overflow_check) { |
| xueliang.zhong | 1004955 | 2018-01-31 17:10:36 +0000 | [diff] [blame] | 2108 | // Using r4 instead of IP saves 2 bytes. |
| Nicolas Geoffray | 1a4f3ca | 2018-01-25 14:07:15 +0000 | [diff] [blame] | 2109 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| xueliang.zhong | 1004955 | 2018-01-31 17:10:36 +0000 | [diff] [blame] | 2110 | vixl32::Register temp; |
| 2111 | // TODO: Remove this check when R4 is made a callee-save register |
| 2112 | // in ART compiled code (b/72801708). Currently we need to make |
| 2113 | // sure r4 is not blocked, e.g. in special purpose |
| 2114 | // TestCodeGeneratorARMVIXL; also asserting that r4 is available |
| 2115 | // here. |
| 2116 | if (!blocked_core_registers_[R4]) { |
| 2117 | for (vixl32::Register reg : kParameterCoreRegistersVIXL) { |
| 2118 | DCHECK(!reg.Is(r4)); |
| 2119 | } |
| 2120 | DCHECK(!kCoreCalleeSaves.Includes(r4)); |
| 2121 | temp = r4; |
| 2122 | } else { |
| 2123 | temp = temps.Acquire(); |
| 2124 | } |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 2125 | __ Sub(temp, sp, Operand::From(GetStackOverflowReservedBytes(InstructionSet::kArm))); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2126 | // The load must immediately precede RecordPcInfo. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 2127 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2128 | vixl32::kMaxInstructionSizeInBytes, |
| 2129 | CodeBufferCheckScope::kMaximumSize); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2130 | __ ldr(temp, MemOperand(temp)); |
| 2131 | RecordPcInfo(nullptr, 0); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2132 | } |
| 2133 | |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2134 | uint32_t frame_size = GetFrameSize(); |
| 2135 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 2136 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 2137 | if ((fpu_spill_mask_ == 0u || IsPowerOfTwo(fpu_spill_mask_)) && |
| 2138 | core_spills_offset <= 3u * kArmWordSize) { |
| 2139 | // Do a single PUSH for core registers including the method and up to two |
| 2140 | // filler registers. Then store the single FP spill if any. |
| 2141 | // (The worst case is when the method is not required and we actually |
| 2142 | // store 3 extra registers but they are stored in the same properly |
| 2143 | // aligned 16-byte chunk where we're already writing anyway.) |
| 2144 | DCHECK_EQ(kMethodRegister.GetCode(), 0u); |
| 2145 | uint32_t extra_regs = MaxInt<uint32_t>(core_spills_offset / kArmWordSize); |
| 2146 | DCHECK_LT(MostSignificantBit(extra_regs), LeastSignificantBit(core_spill_mask_)); |
| 2147 | __ Push(RegisterList(core_spill_mask_ | extra_regs)); |
| 2148 | GetAssembler()->cfi().AdjustCFAOffset(frame_size); |
| 2149 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2150 | core_spills_offset, |
| 2151 | core_spill_mask_, |
| 2152 | kArmWordSize); |
| 2153 | if (fpu_spill_mask_ != 0u) { |
| 2154 | DCHECK(IsPowerOfTwo(fpu_spill_mask_)); |
| 2155 | vixl::aarch32::SRegister sreg(LeastSignificantBit(fpu_spill_mask_)); |
| 2156 | GetAssembler()->StoreSToOffset(sreg, sp, fp_spills_offset); |
| 2157 | GetAssembler()->cfi().RelOffset(DWARFReg(sreg), /*offset=*/ fp_spills_offset); |
| 2158 | } |
| 2159 | } else { |
| 2160 | __ Push(RegisterList(core_spill_mask_)); |
| 2161 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(core_spill_mask_)); |
| 2162 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(kMethodRegister), |
| 2163 | /*offset=*/ 0, |
| 2164 | core_spill_mask_, |
| 2165 | kArmWordSize); |
| 2166 | if (fpu_spill_mask_ != 0) { |
| 2167 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2168 | |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2169 | // Check that list is contiguous. |
| 2170 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2171 | |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2172 | __ Vpush(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2173 | GetAssembler()->cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_)); |
| 2174 | GetAssembler()->cfi().RelOffsetForMany(DWARFReg(s0), |
| 2175 | /*offset=*/ 0, |
| 2176 | fpu_spill_mask_, |
| 2177 | kArmWordSize); |
| 2178 | } |
| Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2179 | |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2180 | // Adjust SP and save the current method if we need it. Note that we do |
| 2181 | // not save the method in HCurrentMethod, as the instruction might have |
| 2182 | // been removed in the SSA graph. |
| 2183 | if (RequiresCurrentMethod() && fp_spills_offset <= 3 * kArmWordSize) { |
| 2184 | DCHECK_EQ(kMethodRegister.GetCode(), 0u); |
| 2185 | __ Push(RegisterList(MaxInt<uint32_t>(fp_spills_offset / kArmWordSize))); |
| 2186 | GetAssembler()->cfi().AdjustCFAOffset(fp_spills_offset); |
| 2187 | } else { |
| 2188 | __ Sub(sp, sp, dchecked_integral_cast<int32_t>(fp_spills_offset)); |
| 2189 | GetAssembler()->cfi().AdjustCFAOffset(fp_spills_offset); |
| 2190 | if (RequiresCurrentMethod()) { |
| 2191 | GetAssembler()->StoreToOffset(kStoreWord, kMethodRegister, sp, 0); |
| 2192 | } |
| 2193 | } |
| Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 2194 | } |
| Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 2195 | |
| 2196 | if (GetGraph()->HasShouldDeoptimizeFlag()) { |
| 2197 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2198 | vixl32::Register temp = temps.Acquire(); |
| 2199 | // Initialize should_deoptimize flag to 0. |
| 2200 | __ Mov(temp, 0); |
| 2201 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2202 | } |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 2203 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2204 | MaybeGenerateMarkingRegisterCheck(/* code= */ 1); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | void CodeGeneratorARMVIXL::GenerateFrameExit() { |
| 2208 | if (HasEmptyFrame()) { |
| 2209 | __ Bx(lr); |
| 2210 | return; |
| 2211 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2212 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2213 | // Pop LR into PC to return. |
| 2214 | DCHECK_NE(core_spill_mask_ & (1 << kLrCode), 0U); |
| 2215 | uint32_t pop_mask = (core_spill_mask_ & (~(1 << kLrCode))) | 1 << kPcCode; |
| Vladimir Marko | 1a225a7 | 2019-07-05 13:37:42 +0100 | [diff] [blame] | 2216 | |
| 2217 | uint32_t frame_size = GetFrameSize(); |
| 2218 | uint32_t core_spills_offset = frame_size - GetCoreSpillSize(); |
| 2219 | uint32_t fp_spills_offset = frame_size - FrameEntrySpillSize(); |
| 2220 | if ((fpu_spill_mask_ == 0u || IsPowerOfTwo(fpu_spill_mask_)) && |
| 2221 | // r4 is blocked by TestCodeGeneratorARMVIXL used by some tests. |
| 2222 | core_spills_offset <= (blocked_core_registers_[r4.GetCode()] ? 2u : 3u) * kArmWordSize) { |
| 2223 | // Load the FP spill if any and then do a single POP including the method |
| 2224 | // and up to two filler registers. If we have no FP spills, this also has |
| 2225 | // the advantage that we do not need to emit CFI directives. |
| 2226 | if (fpu_spill_mask_ != 0u) { |
| 2227 | DCHECK(IsPowerOfTwo(fpu_spill_mask_)); |
| 2228 | vixl::aarch32::SRegister sreg(LeastSignificantBit(fpu_spill_mask_)); |
| 2229 | GetAssembler()->cfi().RememberState(); |
| 2230 | GetAssembler()->LoadSFromOffset(sreg, sp, fp_spills_offset); |
| 2231 | GetAssembler()->cfi().Restore(DWARFReg(sreg)); |
| 2232 | } |
| 2233 | // Clobber registers r2-r4 as they are caller-save in ART managed ABI and |
| 2234 | // never hold the return value. |
| 2235 | uint32_t extra_regs = MaxInt<uint32_t>(core_spills_offset / kArmWordSize) << r2.GetCode(); |
| 2236 | DCHECK_EQ(extra_regs & kCoreCalleeSaves.GetList(), 0u); |
| 2237 | DCHECK_LT(MostSignificantBit(extra_regs), LeastSignificantBit(pop_mask)); |
| 2238 | __ Pop(RegisterList(pop_mask | extra_regs)); |
| 2239 | if (fpu_spill_mask_ != 0u) { |
| 2240 | GetAssembler()->cfi().RestoreState(); |
| 2241 | } |
| 2242 | } else { |
| 2243 | GetAssembler()->cfi().RememberState(); |
| 2244 | __ Add(sp, sp, fp_spills_offset); |
| 2245 | GetAssembler()->cfi().AdjustCFAOffset(-dchecked_integral_cast<int32_t>(fp_spills_offset)); |
| 2246 | if (fpu_spill_mask_ != 0) { |
| 2247 | uint32_t first = LeastSignificantBit(fpu_spill_mask_); |
| 2248 | |
| 2249 | // Check that list is contiguous. |
| 2250 | DCHECK_EQ(fpu_spill_mask_ >> CTZ(fpu_spill_mask_), ~0u >> (32 - POPCOUNT(fpu_spill_mask_))); |
| 2251 | |
| 2252 | __ Vpop(SRegisterList(vixl32::SRegister(first), POPCOUNT(fpu_spill_mask_))); |
| 2253 | GetAssembler()->cfi().AdjustCFAOffset( |
| 2254 | -static_cast<int>(kArmWordSize) * POPCOUNT(fpu_spill_mask_)); |
| 2255 | GetAssembler()->cfi().RestoreMany(DWARFReg(vixl32::SRegister(0)), fpu_spill_mask_); |
| 2256 | } |
| 2257 | __ Pop(RegisterList(pop_mask)); |
| 2258 | GetAssembler()->cfi().RestoreState(); |
| 2259 | GetAssembler()->cfi().DefCFAOffset(GetFrameSize()); |
| 2260 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | void CodeGeneratorARMVIXL::Bind(HBasicBlock* block) { |
| 2264 | __ Bind(GetLabelOf(block)); |
| 2265 | } |
| 2266 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2267 | Location InvokeDexCallingConventionVisitorARMVIXL::GetNextLocation(DataType::Type type) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2268 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2269 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2270 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2271 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2272 | case DataType::Type::kInt8: |
| 2273 | case DataType::Type::kUint16: |
| 2274 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2275 | case DataType::Type::kInt32: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2276 | uint32_t index = gp_index_++; |
| 2277 | uint32_t stack_index = stack_index_++; |
| 2278 | if (index < calling_convention.GetNumberOfRegisters()) { |
| 2279 | return LocationFrom(calling_convention.GetRegisterAt(index)); |
| 2280 | } else { |
| 2281 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2282 | } |
| 2283 | } |
| 2284 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2285 | case DataType::Type::kInt64: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2286 | uint32_t index = gp_index_; |
| 2287 | uint32_t stack_index = stack_index_; |
| 2288 | gp_index_ += 2; |
| 2289 | stack_index_ += 2; |
| 2290 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2291 | if (calling_convention.GetRegisterAt(index).Is(r1)) { |
| 2292 | // Skip R1, and use R2_R3 instead. |
| 2293 | gp_index_++; |
| 2294 | index++; |
| 2295 | } |
| 2296 | } |
| 2297 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
| 2298 | DCHECK_EQ(calling_convention.GetRegisterAt(index).GetCode() + 1, |
| 2299 | calling_convention.GetRegisterAt(index + 1).GetCode()); |
| 2300 | |
| 2301 | return LocationFrom(calling_convention.GetRegisterAt(index), |
| 2302 | calling_convention.GetRegisterAt(index + 1)); |
| 2303 | } else { |
| 2304 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2305 | } |
| 2306 | } |
| 2307 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2308 | case DataType::Type::kFloat32: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2309 | uint32_t stack_index = stack_index_++; |
| 2310 | if (float_index_ % 2 == 0) { |
| 2311 | float_index_ = std::max(double_index_, float_index_); |
| 2312 | } |
| 2313 | if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) { |
| 2314 | return LocationFrom(calling_convention.GetFpuRegisterAt(float_index_++)); |
| 2315 | } else { |
| 2316 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2317 | } |
| 2318 | } |
| 2319 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2320 | case DataType::Type::kFloat64: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2321 | double_index_ = std::max(double_index_, RoundUp(float_index_, 2)); |
| 2322 | uint32_t stack_index = stack_index_; |
| 2323 | stack_index_ += 2; |
| 2324 | if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) { |
| 2325 | uint32_t index = double_index_; |
| 2326 | double_index_ += 2; |
| 2327 | Location result = LocationFrom( |
| 2328 | calling_convention.GetFpuRegisterAt(index), |
| 2329 | calling_convention.GetFpuRegisterAt(index + 1)); |
| 2330 | DCHECK(ExpectedPairLayout(result)); |
| 2331 | return result; |
| 2332 | } else { |
| 2333 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index)); |
| 2334 | } |
| 2335 | } |
| 2336 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2337 | case DataType::Type::kUint32: |
| 2338 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2339 | case DataType::Type::kVoid: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2340 | LOG(FATAL) << "Unexpected parameter type " << type; |
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 2341 | UNREACHABLE(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2342 | } |
| 2343 | return Location::NoLocation(); |
| 2344 | } |
| 2345 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2346 | Location InvokeDexCallingConventionVisitorARMVIXL::GetReturnLocation(DataType::Type type) const { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2347 | switch (type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2348 | case DataType::Type::kReference: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2349 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2350 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2351 | case DataType::Type::kInt8: |
| 2352 | case DataType::Type::kUint16: |
| 2353 | case DataType::Type::kInt16: |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2354 | case DataType::Type::kUint32: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2355 | case DataType::Type::kInt32: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2356 | return LocationFrom(r0); |
| 2357 | } |
| 2358 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2359 | case DataType::Type::kFloat32: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2360 | return LocationFrom(s0); |
| 2361 | } |
| 2362 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 2363 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2364 | case DataType::Type::kInt64: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2365 | return LocationFrom(r0, r1); |
| 2366 | } |
| 2367 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2368 | case DataType::Type::kFloat64: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2369 | return LocationFrom(s0, s1); |
| 2370 | } |
| 2371 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2372 | case DataType::Type::kVoid: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2373 | return Location::NoLocation(); |
| 2374 | } |
| 2375 | |
| 2376 | UNREACHABLE(); |
| 2377 | } |
| 2378 | |
| 2379 | Location InvokeDexCallingConventionVisitorARMVIXL::GetMethodLocation() const { |
| 2380 | return LocationFrom(kMethodRegister); |
| 2381 | } |
| 2382 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2383 | void CodeGeneratorARMVIXL::Move32(Location destination, Location source) { |
| 2384 | if (source.Equals(destination)) { |
| 2385 | return; |
| 2386 | } |
| 2387 | if (destination.IsRegister()) { |
| 2388 | if (source.IsRegister()) { |
| 2389 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 2390 | } else if (source.IsFpuRegister()) { |
| 2391 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| 2392 | } else { |
| 2393 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2394 | RegisterFrom(destination), |
| 2395 | sp, |
| 2396 | source.GetStackIndex()); |
| 2397 | } |
| 2398 | } else if (destination.IsFpuRegister()) { |
| 2399 | if (source.IsRegister()) { |
| 2400 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| 2401 | } else if (source.IsFpuRegister()) { |
| 2402 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 2403 | } else { |
| 2404 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 2405 | } |
| 2406 | } else { |
| 2407 | DCHECK(destination.IsStackSlot()) << destination; |
| 2408 | if (source.IsRegister()) { |
| 2409 | GetAssembler()->StoreToOffset(kStoreWord, |
| 2410 | RegisterFrom(source), |
| 2411 | sp, |
| 2412 | destination.GetStackIndex()); |
| 2413 | } else if (source.IsFpuRegister()) { |
| 2414 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 2415 | } else { |
| 2416 | DCHECK(source.IsStackSlot()) << source; |
| 2417 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2418 | vixl32::Register temp = temps.Acquire(); |
| 2419 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 2420 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 2421 | } |
| 2422 | } |
| 2423 | } |
| 2424 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2425 | void CodeGeneratorARMVIXL::MoveConstant(Location location, int32_t value) { |
| 2426 | DCHECK(location.IsRegister()); |
| 2427 | __ Mov(RegisterFrom(location), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2428 | } |
| 2429 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2430 | void CodeGeneratorARMVIXL::MoveLocation(Location dst, Location src, DataType::Type dst_type) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2431 | // TODO(VIXL): Maybe refactor to have the 'move' implementation here and use it in |
| 2432 | // `ParallelMoveResolverARMVIXL::EmitMove`, as is done in the `arm64` backend. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2433 | HParallelMove move(GetGraph()->GetAllocator()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2434 | move.AddMove(src, dst, dst_type, nullptr); |
| 2435 | GetMoveResolver()->EmitNativeCode(&move); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2436 | } |
| 2437 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 2438 | void CodeGeneratorARMVIXL::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 2439 | if (location.IsRegister()) { |
| 2440 | locations->AddTemp(location); |
| 2441 | } else if (location.IsRegisterPair()) { |
| 2442 | locations->AddTemp(LocationFrom(LowRegisterFrom(location))); |
| 2443 | locations->AddTemp(LocationFrom(HighRegisterFrom(location))); |
| 2444 | } else { |
| 2445 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 2446 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | void CodeGeneratorARMVIXL::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 2450 | HInstruction* instruction, |
| 2451 | uint32_t dex_pc, |
| 2452 | SlowPathCode* slow_path) { |
| 2453 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 2454 | |
| 2455 | ThreadOffset32 entrypoint_offset = GetThreadOffset<kArmPointerSize>(entrypoint); |
| 2456 | // Reduce code size for AOT by using shared trampolines for slow path runtime calls across the |
| 2457 | // entire oat file. This adds an extra branch and we do not want to slow down the main path. |
| 2458 | // For JIT, thunk sharing is per-method, so the gains would be smaller or even negative. |
| 2459 | if (slow_path == nullptr || Runtime::Current()->UseJitCompilation()) { |
| 2460 | __ Ldr(lr, MemOperand(tr, entrypoint_offset.Int32Value())); |
| 2461 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 2462 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 2463 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2464 | vixl32::k16BitT32InstructionSizeInBytes, |
| 2465 | CodeBufferCheckScope::kExactSize); |
| 2466 | __ blx(lr); |
| 2467 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2468 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2469 | } |
| 2470 | } else { |
| 2471 | // Ensure the pc position is recorded immediately after the `bl` instruction. |
| 2472 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 2473 | vixl32::k32BitT32InstructionSizeInBytes, |
| 2474 | CodeBufferCheckScope::kExactSize); |
| 2475 | EmitEntrypointThunkCall(entrypoint_offset); |
| 2476 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 2477 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 2478 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | void CodeGeneratorARMVIXL::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 2483 | HInstruction* instruction, |
| 2484 | SlowPathCode* slow_path) { |
| 2485 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 2486 | __ Ldr(lr, MemOperand(tr, entry_point_offset)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2487 | __ Blx(lr); |
| 2488 | } |
| 2489 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2490 | void InstructionCodeGeneratorARMVIXL::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2491 | if (successor->IsExitBlock()) { |
| 2492 | DCHECK(got->GetPrevious()->AlwaysThrows()); |
| 2493 | return; // no code needed |
| 2494 | } |
| 2495 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2496 | HBasicBlock* block = got->GetBlock(); |
| 2497 | HInstruction* previous = got->GetPrevious(); |
| 2498 | HLoopInformation* info = block->GetLoopInformation(); |
| 2499 | |
| 2500 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 2501 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { |
| 2502 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2503 | vixl32::Register temp = temps.Acquire(); |
| 2504 | __ Push(vixl32::Register(kMethodRegister)); |
| 2505 | GetAssembler()->LoadFromOffset(kLoadWord, kMethodRegister, sp, kArmWordSize); |
| Mathieu Chartier | 7f8678e | 2019-08-30 16:22:28 -0700 | [diff] [blame] | 2506 | // Load with sign extend to set the high bits for integer overflow check. |
| Nicolas Geoffray | 7ab0777 | 2019-08-30 08:26:59 +0000 | [diff] [blame] | 2507 | __ Ldrh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2508 | __ Add(temp, temp, 1); |
| Mathieu Chartier | 7f8678e | 2019-08-30 16:22:28 -0700 | [diff] [blame] | 2509 | // Subtract one if the counter would overflow. |
| 2510 | __ Sub(temp, temp, Operand(temp, ShiftType::LSR, 16)); |
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 2511 | __ Strh(temp, MemOperand(kMethodRegister, ArtMethod::HotnessCountOffset().Int32Value())); |
| 2512 | __ Pop(vixl32::Register(kMethodRegister)); |
| 2513 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2514 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 2515 | return; |
| 2516 | } |
| 2517 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 2518 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2519 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 2); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2520 | } |
| 2521 | if (!codegen_->GoesToNextBlock(block, successor)) { |
| 2522 | __ B(codegen_->GetLabelOf(successor)); |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | void LocationsBuilderARMVIXL::VisitGoto(HGoto* got) { |
| 2527 | got->SetLocations(nullptr); |
| 2528 | } |
| 2529 | |
| 2530 | void InstructionCodeGeneratorARMVIXL::VisitGoto(HGoto* got) { |
| 2531 | HandleGoto(got, got->GetSuccessor()); |
| 2532 | } |
| 2533 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2534 | void LocationsBuilderARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2535 | try_boundary->SetLocations(nullptr); |
| 2536 | } |
| 2537 | |
| 2538 | void InstructionCodeGeneratorARMVIXL::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 2539 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 2540 | if (!successor->IsExitBlock()) { |
| 2541 | HandleGoto(try_boundary, successor); |
| 2542 | } |
| 2543 | } |
| 2544 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2545 | void LocationsBuilderARMVIXL::VisitExit(HExit* exit) { |
| 2546 | exit->SetLocations(nullptr); |
| 2547 | } |
| 2548 | |
| 2549 | void InstructionCodeGeneratorARMVIXL::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
| 2550 | } |
| 2551 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2552 | void InstructionCodeGeneratorARMVIXL::GenerateCompareTestAndBranch(HCondition* condition, |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2553 | vixl32::Label* true_target, |
| 2554 | vixl32::Label* false_target, |
| Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2555 | bool is_far_target) { |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2556 | if (true_target == false_target) { |
| 2557 | DCHECK(true_target != nullptr); |
| 2558 | __ B(true_target); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2559 | return; |
| 2560 | } |
| 2561 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2562 | vixl32::Label* non_fallthrough_target; |
| 2563 | bool invert; |
| 2564 | bool emit_both_branches; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2565 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2566 | if (true_target == nullptr) { |
| 2567 | // The true target is fallthrough. |
| 2568 | DCHECK(false_target != nullptr); |
| 2569 | non_fallthrough_target = false_target; |
| 2570 | invert = true; |
| 2571 | emit_both_branches = false; |
| 2572 | } else { |
| 2573 | non_fallthrough_target = true_target; |
| 2574 | invert = false; |
| 2575 | // Either the false target is fallthrough, or there is no fallthrough |
| 2576 | // and both branches must be emitted. |
| 2577 | emit_both_branches = (false_target != nullptr); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2578 | } |
| 2579 | |
| Anton Kirilov | 23b752b | 2017-07-20 14:40:44 +0100 | [diff] [blame] | 2580 | const auto cond = GenerateTest(condition, invert, codegen_); |
| 2581 | |
| 2582 | __ B(cond.first, non_fallthrough_target, is_far_target); |
| 2583 | |
| 2584 | if (emit_both_branches) { |
| 2585 | // No target falls through, we need to branch. |
| 2586 | __ B(false_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2587 | } |
| 2588 | } |
| 2589 | |
| 2590 | void InstructionCodeGeneratorARMVIXL::GenerateTestAndBranch(HInstruction* instruction, |
| 2591 | size_t condition_input_index, |
| 2592 | vixl32::Label* true_target, |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2593 | vixl32::Label* false_target, |
| 2594 | bool far_target) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2595 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 2596 | |
| 2597 | if (true_target == nullptr && false_target == nullptr) { |
| 2598 | // Nothing to do. The code always falls through. |
| 2599 | return; |
| 2600 | } else if (cond->IsIntConstant()) { |
| 2601 | // Constant condition, statically compared against "true" (integer value 1). |
| 2602 | if (cond->AsIntConstant()->IsTrue()) { |
| 2603 | if (true_target != nullptr) { |
| 2604 | __ B(true_target); |
| 2605 | } |
| 2606 | } else { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 2607 | DCHECK(cond->AsIntConstant()->IsFalse()) << Int32ConstantFrom(cond); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2608 | if (false_target != nullptr) { |
| 2609 | __ B(false_target); |
| 2610 | } |
| 2611 | } |
| 2612 | return; |
| 2613 | } |
| 2614 | |
| 2615 | // The following code generates these patterns: |
| 2616 | // (1) true_target == nullptr && false_target != nullptr |
| 2617 | // - opposite condition true => branch to false_target |
| 2618 | // (2) true_target != nullptr && false_target == nullptr |
| 2619 | // - condition true => branch to true_target |
| 2620 | // (3) true_target != nullptr && false_target != nullptr |
| 2621 | // - condition true => branch to true_target |
| 2622 | // - branch to false_target |
| 2623 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 2624 | // Condition has been materialized, compare the output to 0. |
| 2625 | if (kIsDebugBuild) { |
| 2626 | Location cond_val = instruction->GetLocations()->InAt(condition_input_index); |
| 2627 | DCHECK(cond_val.IsRegister()); |
| 2628 | } |
| 2629 | if (true_target == nullptr) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2630 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, condition_input_index), |
| 2631 | false_target, |
| 2632 | far_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2633 | } else { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2634 | __ CompareAndBranchIfNonZero(InputRegisterAt(instruction, condition_input_index), |
| 2635 | true_target, |
| 2636 | far_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2637 | } |
| 2638 | } else { |
| 2639 | // Condition has not been materialized. Use its inputs as the comparison and |
| 2640 | // its condition as the branch condition. |
| 2641 | HCondition* condition = cond->AsCondition(); |
| 2642 | |
| 2643 | // If this is a long or FP comparison that has been folded into |
| 2644 | // the HCondition, generate the comparison directly. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2645 | DataType::Type type = condition->InputAt(0)->GetType(); |
| 2646 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { |
| Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2647 | GenerateCompareTestAndBranch(condition, true_target, false_target, far_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2648 | return; |
| 2649 | } |
| 2650 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2651 | vixl32::Label* non_fallthrough_target; |
| 2652 | vixl32::Condition arm_cond = vixl32::Condition::None(); |
| 2653 | const vixl32::Register left = InputRegisterAt(cond, 0); |
| 2654 | const Operand right = InputOperandAt(cond, 1); |
| 2655 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2656 | if (true_target == nullptr) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2657 | arm_cond = ARMCondition(condition->GetOppositeCondition()); |
| 2658 | non_fallthrough_target = false_target; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2659 | } else { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2660 | arm_cond = ARMCondition(condition->GetCondition()); |
| 2661 | non_fallthrough_target = true_target; |
| 2662 | } |
| 2663 | |
| 2664 | if (right.IsImmediate() && right.GetImmediate() == 0 && (arm_cond.Is(ne) || arm_cond.Is(eq))) { |
| 2665 | if (arm_cond.Is(eq)) { |
| Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2666 | __ CompareAndBranchIfZero(left, non_fallthrough_target, far_target); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2667 | } else { |
| 2668 | DCHECK(arm_cond.Is(ne)); |
| Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2669 | __ CompareAndBranchIfNonZero(left, non_fallthrough_target, far_target); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2670 | } |
| 2671 | } else { |
| 2672 | __ Cmp(left, right); |
| Anton Kirilov | fd52253 | 2017-05-10 12:46:57 +0100 | [diff] [blame] | 2673 | __ B(arm_cond, non_fallthrough_target, far_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 2678 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 2679 | if (true_target != nullptr && false_target != nullptr) { |
| 2680 | __ B(false_target); |
| 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | void LocationsBuilderARMVIXL::VisitIf(HIf* if_instr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2685 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2686 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
| 2687 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | void InstructionCodeGeneratorARMVIXL::VisitIf(HIf* if_instr) { |
| 2692 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 2693 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2694 | vixl32::Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 2695 | nullptr : codegen_->GetLabelOf(true_successor); |
| 2696 | vixl32::Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 2697 | nullptr : codegen_->GetLabelOf(false_successor); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2698 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2699 | } |
| 2700 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2701 | void LocationsBuilderARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2702 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2703 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 2704 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2705 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 2706 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2707 | locations->SetCustomSlowPathCallerSaves(caller_saves); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2708 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
| 2709 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2710 | } |
| 2711 | } |
| 2712 | |
| 2713 | void InstructionCodeGeneratorARMVIXL::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 2714 | SlowPathCodeARMVIXL* slow_path = |
| 2715 | deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathARMVIXL>(deoptimize); |
| 2716 | GenerateTestAndBranch(deoptimize, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2717 | /* condition_input_index= */ 0, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2718 | slow_path->GetEntryLabel(), |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2719 | /* false_target= */ nullptr); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 2720 | } |
| 2721 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2722 | void LocationsBuilderARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2723 | LocationSummary* locations = new (GetGraph()->GetAllocator()) |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 2724 | LocationSummary(flag, LocationSummary::kNoCall); |
| 2725 | locations->SetOut(Location::RequiresRegister()); |
| 2726 | } |
| 2727 | |
| 2728 | void InstructionCodeGeneratorARMVIXL::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { |
| 2729 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 2730 | OutputRegister(flag), |
| 2731 | sp, |
| 2732 | codegen_->GetStackOffsetOfShouldDeoptimizeFlag()); |
| 2733 | } |
| 2734 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2735 | void LocationsBuilderARMVIXL::VisitSelect(HSelect* select) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2736 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2737 | const bool is_floating_point = DataType::IsFloatingPointType(select->GetType()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2738 | |
| 2739 | if (is_floating_point) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2740 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2741 | locations->SetInAt(1, Location::FpuRegisterOrConstant(select->GetTrueValue())); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2742 | } else { |
| 2743 | locations->SetInAt(0, Location::RequiresRegister()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2744 | locations->SetInAt(1, Arm8BitEncodableConstantOrRegister(select->GetTrueValue())); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2745 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2746 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2747 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2748 | locations->SetInAt(2, Location::RegisterOrConstant(select->GetCondition())); |
| 2749 | // The code generator handles overlap with the values, but not with the condition. |
| 2750 | locations->SetOut(Location::SameAsFirstInput()); |
| 2751 | } else if (is_floating_point) { |
| 2752 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 2753 | } else { |
| 2754 | if (!locations->InAt(1).IsConstant()) { |
| 2755 | locations->SetInAt(0, Arm8BitEncodableConstantOrRegister(select->GetFalseValue())); |
| 2756 | } |
| 2757 | |
| 2758 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2759 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | void InstructionCodeGeneratorARMVIXL::VisitSelect(HSelect* select) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2763 | HInstruction* const condition = select->GetCondition(); |
| 2764 | const LocationSummary* const locations = select->GetLocations(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2765 | const DataType::Type type = select->GetType(); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2766 | const Location first = locations->InAt(0); |
| 2767 | const Location out = locations->Out(); |
| 2768 | const Location second = locations->InAt(1); |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2769 | |
| 2770 | // In the unlucky case the output of this instruction overlaps |
| 2771 | // with an input of an "emitted-at-use-site" condition, and |
| 2772 | // the output of this instruction is not one of its inputs, we'll |
| 2773 | // need to fallback to branches instead of conditional ARM instructions. |
| 2774 | bool output_overlaps_with_condition_inputs = |
| 2775 | !IsBooleanValueOrMaterializedCondition(condition) && |
| 2776 | !out.Equals(first) && |
| 2777 | !out.Equals(second) && |
| 2778 | (condition->GetLocations()->InAt(0).Equals(out) || |
| 2779 | condition->GetLocations()->InAt(1).Equals(out)); |
| 2780 | DCHECK(!output_overlaps_with_condition_inputs || condition->IsCondition()); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2781 | Location src; |
| 2782 | |
| 2783 | if (condition->IsIntConstant()) { |
| 2784 | if (condition->AsIntConstant()->IsFalse()) { |
| 2785 | src = first; |
| 2786 | } else { |
| 2787 | src = second; |
| 2788 | } |
| 2789 | |
| 2790 | codegen_->MoveLocation(out, src, type); |
| 2791 | return; |
| 2792 | } |
| 2793 | |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2794 | if (!DataType::IsFloatingPointType(type) && !output_overlaps_with_condition_inputs) { |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2795 | bool invert = false; |
| 2796 | |
| 2797 | if (out.Equals(second)) { |
| 2798 | src = first; |
| 2799 | invert = true; |
| 2800 | } else if (out.Equals(first)) { |
| 2801 | src = second; |
| 2802 | } else if (second.IsConstant()) { |
| 2803 | DCHECK(CanEncodeConstantAs8BitImmediate(second.GetConstant())); |
| 2804 | src = second; |
| 2805 | } else if (first.IsConstant()) { |
| 2806 | DCHECK(CanEncodeConstantAs8BitImmediate(first.GetConstant())); |
| 2807 | src = first; |
| 2808 | invert = true; |
| 2809 | } else { |
| 2810 | src = second; |
| 2811 | } |
| 2812 | |
| 2813 | if (CanGenerateConditionalMove(out, src)) { |
| 2814 | if (!out.Equals(first) && !out.Equals(second)) { |
| 2815 | codegen_->MoveLocation(out, src.Equals(first) ? second : first, type); |
| 2816 | } |
| 2817 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2818 | std::pair<vixl32::Condition, vixl32::Condition> cond(eq, ne); |
| 2819 | |
| 2820 | if (IsBooleanValueOrMaterializedCondition(condition)) { |
| 2821 | __ Cmp(InputRegisterAt(select, 2), 0); |
| 2822 | cond = invert ? std::make_pair(eq, ne) : std::make_pair(ne, eq); |
| 2823 | } else { |
| 2824 | cond = GenerateTest(condition->AsCondition(), invert, codegen_); |
| 2825 | } |
| 2826 | |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2827 | const size_t instr_count = out.IsRegisterPair() ? 4 : 2; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2828 | // We use the scope because of the IT block that follows. |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2829 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 2830 | instr_count * vixl32::k16BitT32InstructionSizeInBytes, |
| 2831 | CodeBufferCheckScope::kExactSize); |
| 2832 | |
| 2833 | if (out.IsRegister()) { |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2834 | __ it(cond.first); |
| 2835 | __ mov(cond.first, RegisterFrom(out), OperandFrom(src, type)); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2836 | } else { |
| 2837 | DCHECK(out.IsRegisterPair()); |
| 2838 | |
| 2839 | Operand operand_high(0); |
| 2840 | Operand operand_low(0); |
| 2841 | |
| 2842 | if (src.IsConstant()) { |
| 2843 | const int64_t value = Int64ConstantFrom(src); |
| 2844 | |
| 2845 | operand_high = High32Bits(value); |
| 2846 | operand_low = Low32Bits(value); |
| 2847 | } else { |
| 2848 | DCHECK(src.IsRegisterPair()); |
| 2849 | operand_high = HighRegisterFrom(src); |
| 2850 | operand_low = LowRegisterFrom(src); |
| 2851 | } |
| 2852 | |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 2853 | __ it(cond.first); |
| 2854 | __ mov(cond.first, LowRegisterFrom(out), operand_low); |
| 2855 | __ it(cond.first); |
| 2856 | __ mov(cond.first, HighRegisterFrom(out), operand_high); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2857 | } |
| 2858 | |
| 2859 | return; |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | vixl32::Label* false_target = nullptr; |
| 2864 | vixl32::Label* true_target = nullptr; |
| 2865 | vixl32::Label select_end; |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2866 | vixl32::Label other_case; |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2867 | vixl32::Label* const target = codegen_->GetFinalLabel(select, &select_end); |
| 2868 | |
| 2869 | if (out.Equals(second)) { |
| 2870 | true_target = target; |
| 2871 | src = first; |
| 2872 | } else { |
| 2873 | false_target = target; |
| 2874 | src = second; |
| 2875 | |
| 2876 | if (!out.Equals(first)) { |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2877 | if (output_overlaps_with_condition_inputs) { |
| 2878 | false_target = &other_case; |
| 2879 | } else { |
| 2880 | codegen_->MoveLocation(out, first, type); |
| 2881 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2882 | } |
| 2883 | } |
| 2884 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2885 | GenerateTestAndBranch(select, 2, true_target, false_target, /* far_target= */ false); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2886 | codegen_->MoveLocation(out, src, type); |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2887 | if (output_overlaps_with_condition_inputs) { |
| 2888 | __ B(target); |
| 2889 | __ Bind(&other_case); |
| 2890 | codegen_->MoveLocation(out, first, type); |
| 2891 | } |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 2892 | |
| 2893 | if (select_end.IsReferenced()) { |
| 2894 | __ Bind(&select_end); |
| 2895 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 2896 | } |
| 2897 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2898 | void LocationsBuilderARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2899 | new (GetGraph()->GetAllocator()) LocationSummary(info); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | void InstructionCodeGeneratorARMVIXL::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 2903 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
| 2904 | } |
| 2905 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2906 | void CodeGeneratorARMVIXL::GenerateNop() { |
| 2907 | __ Nop(); |
| 2908 | } |
| 2909 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 2910 | // `temp` is an extra temporary register that is used for some conditions; |
| 2911 | // callers may not specify it, in which case the method will use a scratch |
| 2912 | // register instead. |
| 2913 | void CodeGeneratorARMVIXL::GenerateConditionWithZero(IfCondition condition, |
| 2914 | vixl32::Register out, |
| 2915 | vixl32::Register in, |
| 2916 | vixl32::Register temp) { |
| 2917 | switch (condition) { |
| 2918 | case kCondEQ: |
| 2919 | // x <= 0 iff x == 0 when the comparison is unsigned. |
| 2920 | case kCondBE: |
| 2921 | if (!temp.IsValid() || (out.IsLow() && !out.Is(in))) { |
| 2922 | temp = out; |
| 2923 | } |
| 2924 | |
| 2925 | // Avoid 32-bit instructions if possible; note that `in` and `temp` must be |
| 2926 | // different as well. |
| 2927 | if (in.IsLow() && temp.IsLow() && !in.Is(temp)) { |
| 2928 | // temp = - in; only 0 sets the carry flag. |
| 2929 | __ Rsbs(temp, in, 0); |
| 2930 | |
| 2931 | if (out.Is(in)) { |
| 2932 | std::swap(in, temp); |
| 2933 | } |
| 2934 | |
| 2935 | // out = - in + in + carry = carry |
| 2936 | __ Adc(out, temp, in); |
| 2937 | } else { |
| 2938 | // If `in` is 0, then it has 32 leading zeros, and less than that otherwise. |
| 2939 | __ Clz(out, in); |
| 2940 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 2941 | // the same operation on 32 yields 1. |
| 2942 | __ Lsr(out, out, 5); |
| 2943 | } |
| 2944 | |
| 2945 | break; |
| 2946 | case kCondNE: |
| 2947 | // x > 0 iff x != 0 when the comparison is unsigned. |
| 2948 | case kCondA: { |
| 2949 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 2950 | |
| 2951 | if (out.Is(in)) { |
| 2952 | if (!temp.IsValid() || in.Is(temp)) { |
| 2953 | temp = temps.Acquire(); |
| 2954 | } |
| 2955 | } else if (!temp.IsValid() || !temp.IsLow()) { |
| 2956 | temp = out; |
| 2957 | } |
| 2958 | |
| 2959 | // temp = in - 1; only 0 does not set the carry flag. |
| 2960 | __ Subs(temp, in, 1); |
| 2961 | // out = in + ~temp + carry = in + (-(in - 1) - 1) + carry = in - in + 1 - 1 + carry = carry |
| 2962 | __ Sbc(out, in, temp); |
| 2963 | break; |
| 2964 | } |
| 2965 | case kCondGE: |
| 2966 | __ Mvn(out, in); |
| 2967 | in = out; |
| 2968 | FALLTHROUGH_INTENDED; |
| 2969 | case kCondLT: |
| 2970 | // We only care about the sign bit. |
| 2971 | __ Lsr(out, in, 31); |
| 2972 | break; |
| 2973 | case kCondAE: |
| 2974 | // Trivially true. |
| 2975 | __ Mov(out, 1); |
| 2976 | break; |
| 2977 | case kCondB: |
| 2978 | // Trivially false. |
| 2979 | __ Mov(out, 0); |
| 2980 | break; |
| 2981 | default: |
| 2982 | LOG(FATAL) << "Unexpected condition " << condition; |
| 2983 | UNREACHABLE(); |
| 2984 | } |
| 2985 | } |
| 2986 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 2987 | void LocationsBuilderARMVIXL::HandleCondition(HCondition* cond) { |
| 2988 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2989 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); |
| Nicolas Geoffray | 7b05c5f | 2018-09-21 11:31:38 +0100 | [diff] [blame] | 2990 | const DataType::Type type = cond->InputAt(0)->GetType(); |
| 2991 | if (DataType::IsFloatingPointType(type)) { |
| 2992 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2993 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(cond->InputAt(1))); |
| 2994 | } else { |
| 2995 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2996 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 2997 | } |
| 2998 | if (!cond->IsEmittedAtUseSite()) { |
| 2999 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | void InstructionCodeGeneratorARMVIXL::HandleCondition(HCondition* cond) { |
| 3004 | if (cond->IsEmittedAtUseSite()) { |
| 3005 | return; |
| 3006 | } |
| 3007 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3008 | const DataType::Type type = cond->GetLeft()->GetType(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3009 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3010 | if (DataType::IsFloatingPointType(type)) { |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3011 | GenerateConditionGeneric(cond, codegen_); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3012 | return; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3013 | } |
| 3014 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3015 | DCHECK(DataType::IsIntegralType(type) || type == DataType::Type::kReference) << type; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3016 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3017 | const IfCondition condition = cond->GetCondition(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3018 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3019 | // A condition with only one boolean input, or two boolean inputs without being equality or |
| 3020 | // inequality results from transformations done by the instruction simplifier, and is handled |
| 3021 | // as a regular condition with integral inputs. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3022 | if (type == DataType::Type::kBool && |
| 3023 | cond->GetRight()->GetType() == DataType::Type::kBool && |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3024 | (condition == kCondEQ || condition == kCondNE)) { |
| 3025 | vixl32::Register left = InputRegisterAt(cond, 0); |
| 3026 | const vixl32::Register out = OutputRegister(cond); |
| 3027 | const Location right_loc = cond->GetLocations()->InAt(1); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3028 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3029 | // The constant case is handled by the instruction simplifier. |
| 3030 | DCHECK(!right_loc.IsConstant()); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3031 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3032 | vixl32::Register right = RegisterFrom(right_loc); |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3033 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3034 | // Avoid 32-bit instructions if possible. |
| 3035 | if (out.Is(right)) { |
| 3036 | std::swap(left, right); |
| 3037 | } |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3038 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3039 | __ Eor(out, left, right); |
| 3040 | |
| 3041 | if (condition == kCondEQ) { |
| 3042 | __ Eor(out, out, 1); |
| 3043 | } |
| 3044 | |
| 3045 | return; |
| Anton Kirilov | 217b2ce | 2017-03-16 11:47:12 +0000 | [diff] [blame] | 3046 | } |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 3047 | |
| Anton Kirilov | 5601d4e | 2017-05-11 19:33:50 +0100 | [diff] [blame] | 3048 | GenerateConditionIntegralOrNonPrimitive(cond, codegen_); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | void LocationsBuilderARMVIXL::VisitEqual(HEqual* comp) { |
| 3052 | HandleCondition(comp); |
| 3053 | } |
| 3054 | |
| 3055 | void InstructionCodeGeneratorARMVIXL::VisitEqual(HEqual* comp) { |
| 3056 | HandleCondition(comp); |
| 3057 | } |
| 3058 | |
| 3059 | void LocationsBuilderARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3060 | HandleCondition(comp); |
| 3061 | } |
| 3062 | |
| 3063 | void InstructionCodeGeneratorARMVIXL::VisitNotEqual(HNotEqual* comp) { |
| 3064 | HandleCondition(comp); |
| 3065 | } |
| 3066 | |
| 3067 | void LocationsBuilderARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3068 | HandleCondition(comp); |
| 3069 | } |
| 3070 | |
| 3071 | void InstructionCodeGeneratorARMVIXL::VisitLessThan(HLessThan* comp) { |
| 3072 | HandleCondition(comp); |
| 3073 | } |
| 3074 | |
| 3075 | void LocationsBuilderARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3076 | HandleCondition(comp); |
| 3077 | } |
| 3078 | |
| 3079 | void InstructionCodeGeneratorARMVIXL::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 3080 | HandleCondition(comp); |
| 3081 | } |
| 3082 | |
| 3083 | void LocationsBuilderARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3084 | HandleCondition(comp); |
| 3085 | } |
| 3086 | |
| 3087 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThan(HGreaterThan* comp) { |
| 3088 | HandleCondition(comp); |
| 3089 | } |
| 3090 | |
| 3091 | void LocationsBuilderARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3092 | HandleCondition(comp); |
| 3093 | } |
| 3094 | |
| 3095 | void InstructionCodeGeneratorARMVIXL::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 3096 | HandleCondition(comp); |
| 3097 | } |
| 3098 | |
| 3099 | void LocationsBuilderARMVIXL::VisitBelow(HBelow* comp) { |
| 3100 | HandleCondition(comp); |
| 3101 | } |
| 3102 | |
| 3103 | void InstructionCodeGeneratorARMVIXL::VisitBelow(HBelow* comp) { |
| 3104 | HandleCondition(comp); |
| 3105 | } |
| 3106 | |
| 3107 | void LocationsBuilderARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3108 | HandleCondition(comp); |
| 3109 | } |
| 3110 | |
| 3111 | void InstructionCodeGeneratorARMVIXL::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 3112 | HandleCondition(comp); |
| 3113 | } |
| 3114 | |
| 3115 | void LocationsBuilderARMVIXL::VisitAbove(HAbove* comp) { |
| 3116 | HandleCondition(comp); |
| 3117 | } |
| 3118 | |
| 3119 | void InstructionCodeGeneratorARMVIXL::VisitAbove(HAbove* comp) { |
| 3120 | HandleCondition(comp); |
| 3121 | } |
| 3122 | |
| 3123 | void LocationsBuilderARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3124 | HandleCondition(comp); |
| 3125 | } |
| 3126 | |
| 3127 | void InstructionCodeGeneratorARMVIXL::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 3128 | HandleCondition(comp); |
| 3129 | } |
| 3130 | |
| 3131 | void LocationsBuilderARMVIXL::VisitIntConstant(HIntConstant* constant) { |
| 3132 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3133 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3134 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3135 | } |
| 3136 | |
| 3137 | void InstructionCodeGeneratorARMVIXL::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
| 3138 | // Will be generated at use site. |
| 3139 | } |
| 3140 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3141 | void LocationsBuilderARMVIXL::VisitNullConstant(HNullConstant* constant) { |
| 3142 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3143 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3144 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3145 | } |
| 3146 | |
| 3147 | void InstructionCodeGeneratorARMVIXL::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
| 3148 | // Will be generated at use site. |
| 3149 | } |
| 3150 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3151 | void LocationsBuilderARMVIXL::VisitLongConstant(HLongConstant* constant) { |
| 3152 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3153 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3154 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3155 | } |
| 3156 | |
| 3157 | void InstructionCodeGeneratorARMVIXL::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
| 3158 | // Will be generated at use site. |
| 3159 | } |
| 3160 | |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3161 | void LocationsBuilderARMVIXL::VisitFloatConstant(HFloatConstant* constant) { |
| 3162 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3163 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3164 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3165 | } |
| 3166 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3167 | void InstructionCodeGeneratorARMVIXL::VisitFloatConstant( |
| 3168 | HFloatConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3169 | // Will be generated at use site. |
| 3170 | } |
| 3171 | |
| 3172 | void LocationsBuilderARMVIXL::VisitDoubleConstant(HDoubleConstant* constant) { |
| 3173 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3174 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3175 | locations->SetOut(Location::ConstantLocation(constant)); |
| 3176 | } |
| 3177 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3178 | void InstructionCodeGeneratorARMVIXL::VisitDoubleConstant( |
| 3179 | HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 3180 | // Will be generated at use site. |
| 3181 | } |
| 3182 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 3183 | void LocationsBuilderARMVIXL::VisitConstructorFence(HConstructorFence* constructor_fence) { |
| 3184 | constructor_fence->SetLocations(nullptr); |
| 3185 | } |
| 3186 | |
| 3187 | void InstructionCodeGeneratorARMVIXL::VisitConstructorFence( |
| 3188 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { |
| 3189 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3190 | } |
| 3191 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3192 | void LocationsBuilderARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3193 | memory_barrier->SetLocations(nullptr); |
| 3194 | } |
| 3195 | |
| 3196 | void InstructionCodeGeneratorARMVIXL::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 3197 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 3198 | } |
| 3199 | |
| 3200 | void LocationsBuilderARMVIXL::VisitReturnVoid(HReturnVoid* ret) { |
| 3201 | ret->SetLocations(nullptr); |
| 3202 | } |
| 3203 | |
| 3204 | void InstructionCodeGeneratorARMVIXL::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
| 3205 | codegen_->GenerateFrameExit(); |
| 3206 | } |
| 3207 | |
| 3208 | void LocationsBuilderARMVIXL::VisitReturn(HReturn* ret) { |
| 3209 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3210 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3211 | locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType())); |
| 3212 | } |
| 3213 | |
| 3214 | void InstructionCodeGeneratorARMVIXL::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) { |
| 3215 | codegen_->GenerateFrameExit(); |
| 3216 | } |
| 3217 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3218 | void LocationsBuilderARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3219 | // The trampoline uses the same calling convention as dex calling conventions, |
| 3220 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 3221 | // the method_idx. |
| 3222 | HandleInvoke(invoke); |
| 3223 | } |
| 3224 | |
| 3225 | void InstructionCodeGeneratorARMVIXL::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 3226 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3227 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 3); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3228 | } |
| 3229 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3230 | void LocationsBuilderARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3231 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3232 | // art::PrepareForRegisterAllocation. |
| 3233 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3234 | |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3235 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3236 | if (intrinsic.TryDispatch(invoke)) { |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3237 | return; |
| 3238 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3239 | |
| 3240 | HandleInvoke(invoke); |
| 3241 | } |
| 3242 | |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3243 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARMVIXL* codegen) { |
| 3244 | if (invoke->GetLocations()->Intrinsified()) { |
| 3245 | IntrinsicCodeGeneratorARMVIXL intrinsic(codegen); |
| 3246 | intrinsic.Dispatch(invoke); |
| 3247 | return true; |
| 3248 | } |
| 3249 | return false; |
| 3250 | } |
| 3251 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3252 | void InstructionCodeGeneratorARMVIXL::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
| 3253 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 3254 | // art::PrepareForRegisterAllocation. |
| 3255 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
| 3256 | |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3257 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3258 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 4); |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3259 | return; |
| 3260 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3261 | |
| 3262 | LocationSummary* locations = invoke->GetLocations(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3263 | codegen_->GenerateStaticOrDirectCall( |
| 3264 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3265 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3266 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 5); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | void LocationsBuilderARMVIXL::HandleInvoke(HInvoke* invoke) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 3270 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3271 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
| 3272 | } |
| 3273 | |
| 3274 | void LocationsBuilderARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3275 | IntrinsicLocationsBuilderARMVIXL intrinsic(codegen_); |
| 3276 | if (intrinsic.TryDispatch(invoke)) { |
| 3277 | return; |
| 3278 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3279 | |
| 3280 | HandleInvoke(invoke); |
| 3281 | } |
| 3282 | |
| 3283 | void InstructionCodeGeneratorARMVIXL::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3284 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3285 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 6); |
| Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3286 | return; |
| 3287 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3288 | |
| 3289 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3290 | DCHECK(!codegen_->IsLeafMethod()); |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3291 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3292 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 7); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3293 | } |
| 3294 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3295 | void LocationsBuilderARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3296 | HandleInvoke(invoke); |
| 3297 | // Add the hidden argument. |
| 3298 | invoke->GetLocations()->AddTemp(LocationFrom(r12)); |
| 3299 | } |
| 3300 | |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3301 | void CodeGeneratorARMVIXL::MaybeGenerateInlineCacheCheck(HInstruction* instruction, |
| 3302 | vixl32::Register klass) { |
| 3303 | DCHECK_EQ(r0.GetCode(), klass.GetCode()); |
| Nicolas Geoffray | 20036d8 | 2019-11-28 16:15:00 +0000 | [diff] [blame^] | 3304 | // We know the destination of an intrinsic, so no need to record inline |
| 3305 | // caches. |
| 3306 | if (!instruction->GetLocations()->Intrinsified() && |
| 3307 | GetCompilerOptions().IsBaseline() && |
| 3308 | !Runtime::Current()->IsAotCompiler()) { |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3309 | DCHECK(!instruction->GetEnvironment()->IsFromInlinedInvoke()); |
| 3310 | ScopedObjectAccess soa(Thread::Current()); |
| 3311 | ProfilingInfo* info = GetGraph()->GetArtMethod()->GetProfilingInfo(kRuntimePointerSize); |
| 3312 | InlineCache* cache = info->GetInlineCache(instruction->GetDexPc()); |
| 3313 | uint32_t address = reinterpret_cast32<uint32_t>(cache); |
| 3314 | vixl32::Label done; |
| 3315 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3316 | temps.Exclude(ip); |
| 3317 | __ Mov(r4, address); |
| 3318 | __ Ldr(ip, MemOperand(r4, InlineCache::ClassesOffset().Int32Value())); |
| 3319 | // Fast path for a monomorphic cache. |
| 3320 | __ Cmp(klass, ip); |
| 3321 | __ B(eq, &done, /* is_far_target= */ false); |
| 3322 | InvokeRuntime(kQuickUpdateInlineCache, instruction, instruction->GetDexPc()); |
| 3323 | __ Bind(&done); |
| 3324 | } |
| 3325 | } |
| 3326 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3327 | void InstructionCodeGeneratorARMVIXL::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 3328 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
| 3329 | LocationSummary* locations = invoke->GetLocations(); |
| 3330 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 3331 | vixl32::Register hidden_reg = RegisterFrom(locations->GetTemp(1)); |
| 3332 | Location receiver = locations->InAt(0); |
| 3333 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3334 | |
| 3335 | DCHECK(!receiver.IsStackSlot()); |
| 3336 | |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3337 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| 3338 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3339 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 3340 | vixl32::kMaxInstructionSizeInBytes, |
| 3341 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3342 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 3343 | __ ldr(temp, MemOperand(RegisterFrom(receiver), class_offset)); |
| 3344 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3345 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3346 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 3347 | // emit a read barrier for the previous class reference load. |
| 3348 | // However this is not required in practice, as this is an |
| 3349 | // intermediate/temporary reference and because the current |
| 3350 | // concurrent copying collector keeps the from-space memory |
| 3351 | // intact/accessible until the end of the marking phase (the |
| 3352 | // concurrent copying collector may not in the future). |
| 3353 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3354 | |
| 3355 | // If we're compiling baseline, update the inline cache. |
| 3356 | codegen_->MaybeGenerateInlineCacheCheck(invoke, temp); |
| 3357 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3358 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3359 | temp, |
| 3360 | temp, |
| 3361 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 3362 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3363 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 3364 | invoke->GetImtIndex(), kArmPointerSize)); |
| 3365 | // temp = temp->GetImtEntryAt(method_offset); |
| 3366 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 3367 | uint32_t entry_point = |
| 3368 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value(); |
| 3369 | // LR = temp->GetEntryPoint(); |
| 3370 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| 3371 | |
| 3372 | // Set the hidden (in r12) argument. It is done here, right before a BLX to prevent other |
| 3373 | // instruction from clobbering it as they might use r12 as a scratch register. |
| 3374 | DCHECK(hidden_reg.Is(r12)); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 3375 | |
| 3376 | { |
| 3377 | // The VIXL macro assembler may clobber any of the scratch registers that are available to it, |
| 3378 | // so it checks if the application is using them (by passing them to the macro assembler |
| 3379 | // methods). The following application of UseScratchRegisterScope corrects VIXL's notion of |
| 3380 | // what is available, and is the opposite of the standard usage: Instead of requesting a |
| 3381 | // temporary location, it imposes an external constraint (i.e. a specific register is reserved |
| 3382 | // for the hidden argument). Note that this works even if VIXL needs a scratch register itself |
| 3383 | // (to materialize the constant), since the destination register becomes available for such use |
| 3384 | // internally for the duration of the macro instruction. |
| 3385 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 3386 | temps.Exclude(hidden_reg); |
| 3387 | __ Mov(hidden_reg, invoke->GetDexMethodIndex()); |
| 3388 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3389 | { |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3390 | // Ensure the pc position is recorded immediately after the `blx` instruction. |
| 3391 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 3392 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3393 | vixl32::k16BitT32InstructionSizeInBytes, |
| 3394 | CodeBufferCheckScope::kExactSize); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3395 | // LR(); |
| 3396 | __ blx(lr); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3397 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 3398 | DCHECK(!codegen_->IsLeafMethod()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3399 | } |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 3400 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3401 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 8); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 3402 | } |
| 3403 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3404 | void LocationsBuilderARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3405 | HandleInvoke(invoke); |
| 3406 | } |
| 3407 | |
| 3408 | void InstructionCodeGeneratorARMVIXL::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { |
| 3409 | codegen_->GenerateInvokePolymorphicCall(invoke); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3410 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 9); |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 3411 | } |
| 3412 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3413 | void LocationsBuilderARMVIXL::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 3414 | HandleInvoke(invoke); |
| 3415 | } |
| 3416 | |
| 3417 | void InstructionCodeGeneratorARMVIXL::VisitInvokeCustom(HInvokeCustom* invoke) { |
| 3418 | codegen_->GenerateInvokeCustomCall(invoke); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3419 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 10); |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 3420 | } |
| 3421 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3422 | void LocationsBuilderARMVIXL::VisitNeg(HNeg* neg) { |
| 3423 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3424 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3425 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3426 | case DataType::Type::kInt32: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3427 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3428 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3429 | break; |
| 3430 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3431 | case DataType::Type::kInt64: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3432 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3433 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 3434 | break; |
| 3435 | } |
| 3436 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3437 | case DataType::Type::kFloat32: |
| 3438 | case DataType::Type::kFloat64: |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3439 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3440 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3441 | break; |
| 3442 | |
| 3443 | default: |
| 3444 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3445 | } |
| 3446 | } |
| 3447 | |
| 3448 | void InstructionCodeGeneratorARMVIXL::VisitNeg(HNeg* neg) { |
| 3449 | LocationSummary* locations = neg->GetLocations(); |
| 3450 | Location out = locations->Out(); |
| 3451 | Location in = locations->InAt(0); |
| 3452 | switch (neg->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3453 | case DataType::Type::kInt32: |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3454 | __ Rsb(OutputRegister(neg), InputRegisterAt(neg, 0), 0); |
| 3455 | break; |
| 3456 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3457 | case DataType::Type::kInt64: |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3458 | // out.lo = 0 - in.lo (and update the carry/borrow (C) flag) |
| 3459 | __ Rsbs(LowRegisterFrom(out), LowRegisterFrom(in), 0); |
| 3460 | // We cannot emit an RSC (Reverse Subtract with Carry) |
| 3461 | // instruction here, as it does not exist in the Thumb-2 |
| 3462 | // instruction set. We use the following approach |
| 3463 | // using SBC and SUB instead. |
| 3464 | // |
| 3465 | // out.hi = -C |
| 3466 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(out)); |
| 3467 | // out.hi = out.hi - in.hi |
| 3468 | __ Sub(HighRegisterFrom(out), HighRegisterFrom(out), HighRegisterFrom(in)); |
| 3469 | break; |
| 3470 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3471 | case DataType::Type::kFloat32: |
| 3472 | case DataType::Type::kFloat64: |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 3473 | __ Vneg(OutputVRegister(neg), InputVRegister(neg)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 3474 | break; |
| 3475 | |
| 3476 | default: |
| 3477 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 3478 | } |
| 3479 | } |
| 3480 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3481 | void LocationsBuilderARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3482 | DataType::Type result_type = conversion->GetResultType(); |
| 3483 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3484 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3485 | << input_type << " -> " << result_type; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3486 | |
| 3487 | // The float-to-long, double-to-long and long-to-float type conversions |
| 3488 | // rely on a call to the runtime. |
| 3489 | LocationSummary::CallKind call_kind = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3490 | (((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) |
| 3491 | && result_type == DataType::Type::kInt64) |
| 3492 | || (input_type == DataType::Type::kInt64 && result_type == DataType::Type::kFloat32)) |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3493 | ? LocationSummary::kCallOnMainOnly |
| 3494 | : LocationSummary::kNoCall; |
| 3495 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3496 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3497 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3498 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3499 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3500 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3501 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3502 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3503 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; |
| 3504 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3505 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3506 | break; |
| 3507 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3508 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3509 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3510 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3511 | locations->SetInAt(0, Location::Any()); |
| 3512 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3513 | break; |
| 3514 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3515 | case DataType::Type::kFloat32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3516 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3517 | locations->SetOut(Location::RequiresRegister()); |
| 3518 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3519 | break; |
| 3520 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3521 | case DataType::Type::kFloat64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3522 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3523 | locations->SetOut(Location::RequiresRegister()); |
| 3524 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3525 | break; |
| 3526 | |
| 3527 | default: |
| 3528 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3529 | << " to " << result_type; |
| 3530 | } |
| 3531 | break; |
| 3532 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3533 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3534 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3535 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3536 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3537 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3538 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3539 | case DataType::Type::kInt16: |
| 3540 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3541 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3542 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3543 | break; |
| 3544 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3545 | case DataType::Type::kFloat32: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3546 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3547 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 3548 | locations->SetOut(LocationFrom(r0, r1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3549 | break; |
| 3550 | } |
| 3551 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3552 | case DataType::Type::kFloat64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3553 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3554 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0), |
| 3555 | calling_convention.GetFpuRegisterAt(1))); |
| 3556 | locations->SetOut(LocationFrom(r0, r1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3557 | break; |
| 3558 | } |
| 3559 | |
| 3560 | default: |
| 3561 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3562 | << " to " << result_type; |
| 3563 | } |
| 3564 | break; |
| 3565 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3566 | case DataType::Type::kFloat32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3567 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3568 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3569 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3570 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3571 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3572 | case DataType::Type::kInt16: |
| 3573 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3574 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3575 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3576 | break; |
| 3577 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3578 | case DataType::Type::kInt64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3579 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3580 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0), |
| 3581 | calling_convention.GetRegisterAt(1))); |
| 3582 | locations->SetOut(LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3583 | break; |
| 3584 | } |
| 3585 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3586 | case DataType::Type::kFloat64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3587 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3588 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3589 | break; |
| 3590 | |
| 3591 | default: |
| 3592 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3593 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3594 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3595 | break; |
| 3596 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3597 | case DataType::Type::kFloat64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3598 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3599 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3600 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3601 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3602 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3603 | case DataType::Type::kInt16: |
| 3604 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3605 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3606 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3607 | break; |
| 3608 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3609 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3610 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3611 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3612 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3613 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3614 | break; |
| 3615 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3616 | case DataType::Type::kFloat32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3617 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3618 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3619 | break; |
| 3620 | |
| 3621 | default: |
| 3622 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3623 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3624 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3625 | break; |
| 3626 | |
| 3627 | default: |
| 3628 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3629 | << " to " << result_type; |
| 3630 | } |
| 3631 | } |
| 3632 | |
| 3633 | void InstructionCodeGeneratorARMVIXL::VisitTypeConversion(HTypeConversion* conversion) { |
| 3634 | LocationSummary* locations = conversion->GetLocations(); |
| 3635 | Location out = locations->Out(); |
| 3636 | Location in = locations->InAt(0); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3637 | DataType::Type result_type = conversion->GetResultType(); |
| 3638 | DataType::Type input_type = conversion->GetInputType(); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3639 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) |
| 3640 | << input_type << " -> " << result_type; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3641 | switch (result_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3642 | case DataType::Type::kUint8: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3643 | switch (input_type) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3644 | case DataType::Type::kInt8: |
| 3645 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3646 | case DataType::Type::kInt16: |
| 3647 | case DataType::Type::kInt32: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3648 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3649 | break; |
| 3650 | case DataType::Type::kInt64: |
| 3651 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3652 | break; |
| 3653 | |
| 3654 | default: |
| 3655 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3656 | << " to " << result_type; |
| 3657 | } |
| 3658 | break; |
| 3659 | |
| 3660 | case DataType::Type::kInt8: |
| 3661 | switch (input_type) { |
| 3662 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3663 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3664 | case DataType::Type::kInt16: |
| 3665 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3666 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 8); |
| 3667 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3668 | case DataType::Type::kInt64: |
| 3669 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 8); |
| 3670 | break; |
| 3671 | |
| 3672 | default: |
| 3673 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3674 | << " to " << result_type; |
| 3675 | } |
| 3676 | break; |
| 3677 | |
| 3678 | case DataType::Type::kUint16: |
| 3679 | switch (input_type) { |
| 3680 | case DataType::Type::kInt8: |
| 3681 | case DataType::Type::kInt16: |
| 3682 | case DataType::Type::kInt32: |
| 3683 | __ Ubfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3684 | break; |
| 3685 | case DataType::Type::kInt64: |
| 3686 | __ Ubfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3687 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3688 | |
| 3689 | default: |
| 3690 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3691 | << " to " << result_type; |
| 3692 | } |
| 3693 | break; |
| 3694 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3695 | case DataType::Type::kInt16: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3696 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3697 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3698 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3699 | __ Sbfx(OutputRegister(conversion), InputRegisterAt(conversion, 0), 0, 16); |
| 3700 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3701 | case DataType::Type::kInt64: |
| 3702 | __ Sbfx(OutputRegister(conversion), LowRegisterFrom(in), 0, 16); |
| 3703 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3704 | |
| 3705 | default: |
| 3706 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3707 | << " to " << result_type; |
| 3708 | } |
| 3709 | break; |
| 3710 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3711 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3712 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3713 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3714 | DCHECK(out.IsRegister()); |
| 3715 | if (in.IsRegisterPair()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3716 | __ Mov(OutputRegister(conversion), LowRegisterFrom(in)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3717 | } else if (in.IsDoubleStackSlot()) { |
| 3718 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 3719 | OutputRegister(conversion), |
| 3720 | sp, |
| 3721 | in.GetStackIndex()); |
| 3722 | } else { |
| 3723 | DCHECK(in.IsConstant()); |
| 3724 | DCHECK(in.GetConstant()->IsLongConstant()); |
| Vladimir Marko | ba1a48e | 2017-04-13 11:50:14 +0100 | [diff] [blame] | 3725 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 3726 | __ Mov(OutputRegister(conversion), static_cast<int32_t>(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3727 | } |
| 3728 | break; |
| 3729 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3730 | case DataType::Type::kFloat32: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3731 | vixl32::SRegister temp = LowSRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3732 | __ Vcvt(S32, F32, temp, InputSRegisterAt(conversion, 0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3733 | __ Vmov(OutputRegister(conversion), temp); |
| 3734 | break; |
| 3735 | } |
| 3736 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3737 | case DataType::Type::kFloat64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3738 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3739 | __ Vcvt(S32, F64, temp_s, DRegisterFrom(in)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3740 | __ Vmov(OutputRegister(conversion), temp_s); |
| 3741 | break; |
| 3742 | } |
| 3743 | |
| 3744 | default: |
| 3745 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3746 | << " to " << result_type; |
| 3747 | } |
| 3748 | break; |
| 3749 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3750 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3751 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3752 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3753 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3754 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3755 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3756 | case DataType::Type::kInt16: |
| 3757 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3758 | DCHECK(out.IsRegisterPair()); |
| 3759 | DCHECK(in.IsRegister()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3760 | __ Mov(LowRegisterFrom(out), InputRegisterAt(conversion, 0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3761 | // Sign extension. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3762 | __ Asr(HighRegisterFrom(out), LowRegisterFrom(out), 31); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3763 | break; |
| 3764 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3765 | case DataType::Type::kFloat32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3766 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
| 3767 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
| 3768 | break; |
| 3769 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3770 | case DataType::Type::kFloat64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3771 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
| 3772 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
| 3773 | break; |
| 3774 | |
| 3775 | default: |
| 3776 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3777 | << " to " << result_type; |
| 3778 | } |
| 3779 | break; |
| 3780 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3781 | case DataType::Type::kFloat32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3782 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3783 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3784 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3785 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3786 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3787 | case DataType::Type::kInt16: |
| 3788 | case DataType::Type::kInt32: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3789 | __ Vmov(OutputSRegister(conversion), InputRegisterAt(conversion, 0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3790 | __ Vcvt(F32, S32, OutputSRegister(conversion), OutputSRegister(conversion)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3791 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3792 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3793 | case DataType::Type::kInt64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3794 | codegen_->InvokeRuntime(kQuickL2f, conversion, conversion->GetDexPc()); |
| 3795 | CheckEntrypointTypes<kQuickL2f, float, int64_t>(); |
| 3796 | break; |
| 3797 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3798 | case DataType::Type::kFloat64: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3799 | __ Vcvt(F32, F64, OutputSRegister(conversion), DRegisterFrom(in)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3800 | break; |
| 3801 | |
| 3802 | default: |
| 3803 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3804 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3805 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3806 | break; |
| 3807 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3808 | case DataType::Type::kFloat64: |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3809 | switch (input_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3810 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3811 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3812 | case DataType::Type::kInt8: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 3813 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3814 | case DataType::Type::kInt16: |
| 3815 | case DataType::Type::kInt32: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3816 | __ Vmov(LowSRegisterFrom(out), InputRegisterAt(conversion, 0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3817 | __ Vcvt(F64, S32, DRegisterFrom(out), LowSRegisterFrom(out)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3818 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3819 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3820 | case DataType::Type::kInt64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3821 | vixl32::Register low = LowRegisterFrom(in); |
| 3822 | vixl32::Register high = HighRegisterFrom(in); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3823 | vixl32::SRegister out_s = LowSRegisterFrom(out); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3824 | vixl32::DRegister out_d = DRegisterFrom(out); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3825 | vixl32::SRegister temp_s = LowSRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3826 | vixl32::DRegister temp_d = DRegisterFrom(locations->GetTemp(0)); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3827 | vixl32::DRegister constant_d = DRegisterFrom(locations->GetTemp(1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3828 | |
| 3829 | // temp_d = int-to-double(high) |
| 3830 | __ Vmov(temp_s, high); |
| Scott Wakeling | fb0b7d4 | 2016-10-28 16:11:08 +0100 | [diff] [blame] | 3831 | __ Vcvt(F64, S32, temp_d, temp_s); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3832 | // constant_d = k2Pow32EncodingForDouble |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3833 | __ Vmov(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3834 | // out_d = unsigned-to-double(low) |
| 3835 | __ Vmov(out_s, low); |
| 3836 | __ Vcvt(F64, U32, out_d, out_s); |
| 3837 | // out_d += temp_d * constant_d |
| 3838 | __ Vmla(F64, out_d, temp_d, constant_d); |
| 3839 | break; |
| 3840 | } |
| 3841 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3842 | case DataType::Type::kFloat32: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 3843 | __ Vcvt(F64, F32, DRegisterFrom(out), InputSRegisterAt(conversion, 0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3844 | break; |
| 3845 | |
| 3846 | default: |
| 3847 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3848 | << " to " << result_type; |
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 3849 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3850 | break; |
| 3851 | |
| 3852 | default: |
| 3853 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 3854 | << " to " << result_type; |
| 3855 | } |
| 3856 | } |
| 3857 | |
| 3858 | void LocationsBuilderARMVIXL::VisitAdd(HAdd* add) { |
| 3859 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3860 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3861 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3862 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3863 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3864 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 3865 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3866 | break; |
| 3867 | } |
| 3868 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3869 | case DataType::Type::kInt64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3870 | locations->SetInAt(0, Location::RequiresRegister()); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3871 | locations->SetInAt(1, ArmEncodableConstantOrRegister(add->InputAt(1), ADD)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3872 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3873 | break; |
| 3874 | } |
| 3875 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3876 | case DataType::Type::kFloat32: |
| 3877 | case DataType::Type::kFloat64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3878 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3879 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3880 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3881 | break; |
| 3882 | } |
| 3883 | |
| 3884 | default: |
| 3885 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 3886 | } |
| 3887 | } |
| 3888 | |
| 3889 | void InstructionCodeGeneratorARMVIXL::VisitAdd(HAdd* add) { |
| 3890 | LocationSummary* locations = add->GetLocations(); |
| 3891 | Location out = locations->Out(); |
| 3892 | Location first = locations->InAt(0); |
| 3893 | Location second = locations->InAt(1); |
| 3894 | |
| 3895 | switch (add->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3896 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3897 | __ Add(OutputRegister(add), InputRegisterAt(add, 0), InputOperandAt(add, 1)); |
| 3898 | } |
| 3899 | break; |
| 3900 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3901 | case DataType::Type::kInt64: { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3902 | if (second.IsConstant()) { |
| 3903 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3904 | GenerateAddLongConst(out, first, value); |
| 3905 | } else { |
| 3906 | DCHECK(second.IsRegisterPair()); |
| 3907 | __ Adds(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 3908 | __ Adc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 3909 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3910 | break; |
| 3911 | } |
| 3912 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3913 | case DataType::Type::kFloat32: |
| 3914 | case DataType::Type::kFloat64: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3915 | __ Vadd(OutputVRegister(add), InputVRegisterAt(add, 0), InputVRegisterAt(add, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3916 | break; |
| 3917 | |
| 3918 | default: |
| 3919 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 3920 | } |
| 3921 | } |
| 3922 | |
| 3923 | void LocationsBuilderARMVIXL::VisitSub(HSub* sub) { |
| 3924 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3925 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3926 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3927 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3928 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3929 | locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1))); |
| 3930 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3931 | break; |
| 3932 | } |
| 3933 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3934 | case DataType::Type::kInt64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3935 | locations->SetInAt(0, Location::RequiresRegister()); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3936 | locations->SetInAt(1, ArmEncodableConstantOrRegister(sub->InputAt(1), SUB)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3937 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3938 | break; |
| 3939 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3940 | case DataType::Type::kFloat32: |
| 3941 | case DataType::Type::kFloat64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3942 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3943 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3944 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 3945 | break; |
| 3946 | } |
| 3947 | default: |
| 3948 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 3949 | } |
| 3950 | } |
| 3951 | |
| 3952 | void InstructionCodeGeneratorARMVIXL::VisitSub(HSub* sub) { |
| 3953 | LocationSummary* locations = sub->GetLocations(); |
| 3954 | Location out = locations->Out(); |
| 3955 | Location first = locations->InAt(0); |
| 3956 | Location second = locations->InAt(1); |
| 3957 | switch (sub->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3958 | case DataType::Type::kInt32: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3959 | __ Sub(OutputRegister(sub), InputRegisterAt(sub, 0), InputOperandAt(sub, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3960 | break; |
| 3961 | } |
| 3962 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3963 | case DataType::Type::kInt64: { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 3964 | if (second.IsConstant()) { |
| 3965 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 3966 | GenerateAddLongConst(out, first, -value); |
| 3967 | } else { |
| 3968 | DCHECK(second.IsRegisterPair()); |
| 3969 | __ Subs(LowRegisterFrom(out), LowRegisterFrom(first), LowRegisterFrom(second)); |
| 3970 | __ Sbc(HighRegisterFrom(out), HighRegisterFrom(first), HighRegisterFrom(second)); |
| 3971 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3972 | break; |
| 3973 | } |
| 3974 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3975 | case DataType::Type::kFloat32: |
| 3976 | case DataType::Type::kFloat64: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 3977 | __ Vsub(OutputVRegister(sub), InputVRegisterAt(sub, 0), InputVRegisterAt(sub, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3978 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3979 | |
| 3980 | default: |
| 3981 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
| 3982 | } |
| 3983 | } |
| 3984 | |
| 3985 | void LocationsBuilderARMVIXL::VisitMul(HMul* mul) { |
| 3986 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3987 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3988 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3989 | case DataType::Type::kInt32: |
| 3990 | case DataType::Type::kInt64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3991 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3992 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3993 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3994 | break; |
| 3995 | } |
| 3996 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3997 | case DataType::Type::kFloat32: |
| 3998 | case DataType::Type::kFloat64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 3999 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4000 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4001 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4002 | break; |
| 4003 | } |
| 4004 | |
| 4005 | default: |
| 4006 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4007 | } |
| 4008 | } |
| 4009 | |
| 4010 | void InstructionCodeGeneratorARMVIXL::VisitMul(HMul* mul) { |
| 4011 | LocationSummary* locations = mul->GetLocations(); |
| 4012 | Location out = locations->Out(); |
| 4013 | Location first = locations->InAt(0); |
| 4014 | Location second = locations->InAt(1); |
| 4015 | switch (mul->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4016 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4017 | __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1)); |
| 4018 | break; |
| 4019 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4020 | case DataType::Type::kInt64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4021 | vixl32::Register out_hi = HighRegisterFrom(out); |
| 4022 | vixl32::Register out_lo = LowRegisterFrom(out); |
| 4023 | vixl32::Register in1_hi = HighRegisterFrom(first); |
| 4024 | vixl32::Register in1_lo = LowRegisterFrom(first); |
| 4025 | vixl32::Register in2_hi = HighRegisterFrom(second); |
| 4026 | vixl32::Register in2_lo = LowRegisterFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4027 | |
| 4028 | // Extra checks to protect caused by the existence of R1_R2. |
| 4029 | // The algorithm is wrong if out.hi is either in1.lo or in2.lo: |
| 4030 | // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4031 | DCHECK(!out_hi.Is(in1_lo)); |
| 4032 | DCHECK(!out_hi.Is(in2_lo)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4033 | |
| 4034 | // input: in1 - 64 bits, in2 - 64 bits |
| 4035 | // output: out |
| 4036 | // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 4037 | // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 4038 | // parts: out.lo = (in1.lo * in2.lo)[31:0] |
| 4039 | |
| 4040 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4041 | vixl32::Register temp = temps.Acquire(); |
| 4042 | // temp <- in1.lo * in2.hi |
| 4043 | __ Mul(temp, in1_lo, in2_hi); |
| 4044 | // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 4045 | __ Mla(out_hi, in1_hi, in2_lo, temp); |
| 4046 | // out.lo <- (in1.lo * in2.lo)[31:0]; |
| 4047 | __ Umull(out_lo, temp, in1_lo, in2_lo); |
| 4048 | // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4049 | __ Add(out_hi, out_hi, temp); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4050 | break; |
| 4051 | } |
| 4052 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4053 | case DataType::Type::kFloat32: |
| 4054 | case DataType::Type::kFloat64: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4055 | __ Vmul(OutputVRegister(mul), InputVRegisterAt(mul, 0), InputVRegisterAt(mul, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4056 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4057 | |
| 4058 | default: |
| 4059 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
| 4060 | } |
| 4061 | } |
| 4062 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4063 | void InstructionCodeGeneratorARMVIXL::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 4064 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4065 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4066 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4067 | Location second = instruction->GetLocations()->InAt(1); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4068 | DCHECK(second.IsConstant()); |
| 4069 | |
| 4070 | vixl32::Register out = OutputRegister(instruction); |
| 4071 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4072 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4073 | DCHECK(imm == 1 || imm == -1); |
| 4074 | |
| 4075 | if (instruction->IsRem()) { |
| 4076 | __ Mov(out, 0); |
| 4077 | } else { |
| 4078 | if (imm == 1) { |
| 4079 | __ Mov(out, dividend); |
| 4080 | } else { |
| 4081 | __ Rsb(out, dividend, 0); |
| 4082 | } |
| 4083 | } |
| 4084 | } |
| 4085 | |
| 4086 | void InstructionCodeGeneratorARMVIXL::DivRemByPowerOfTwo(HBinaryOperation* instruction) { |
| 4087 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4088 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4089 | |
| 4090 | LocationSummary* locations = instruction->GetLocations(); |
| 4091 | Location second = locations->InAt(1); |
| 4092 | DCHECK(second.IsConstant()); |
| 4093 | |
| 4094 | vixl32::Register out = OutputRegister(instruction); |
| 4095 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4096 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4097 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4098 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
| 4099 | int ctz_imm = CTZ(abs_imm); |
| 4100 | |
| 4101 | if (ctz_imm == 1) { |
| 4102 | __ Lsr(temp, dividend, 32 - ctz_imm); |
| 4103 | } else { |
| 4104 | __ Asr(temp, dividend, 31); |
| 4105 | __ Lsr(temp, temp, 32 - ctz_imm); |
| 4106 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4107 | __ Add(out, temp, dividend); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4108 | |
| 4109 | if (instruction->IsDiv()) { |
| 4110 | __ Asr(out, out, ctz_imm); |
| 4111 | if (imm < 0) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4112 | __ Rsb(out, out, 0); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4113 | } |
| 4114 | } else { |
| 4115 | __ Ubfx(out, out, 0, ctz_imm); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4116 | __ Sub(out, out, temp); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4117 | } |
| 4118 | } |
| 4119 | |
| 4120 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 4121 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4122 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4123 | |
| 4124 | LocationSummary* locations = instruction->GetLocations(); |
| 4125 | Location second = locations->InAt(1); |
| 4126 | DCHECK(second.IsConstant()); |
| 4127 | |
| 4128 | vixl32::Register out = OutputRegister(instruction); |
| 4129 | vixl32::Register dividend = InputRegisterAt(instruction, 0); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4130 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(0)); |
| 4131 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(1)); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4132 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4133 | |
| 4134 | int64_t magic; |
| 4135 | int shift; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4136 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4137 | |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 4138 | // TODO(VIXL): Change the static cast to Operand::From() after VIXL is fixed. |
| 4139 | __ Mov(temp1, static_cast<int32_t>(magic)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4140 | __ Smull(temp2, temp1, dividend, temp1); |
| 4141 | |
| 4142 | if (imm > 0 && magic < 0) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4143 | __ Add(temp1, temp1, dividend); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4144 | } else if (imm < 0 && magic > 0) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4145 | __ Sub(temp1, temp1, dividend); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | if (shift != 0) { |
| 4149 | __ Asr(temp1, temp1, shift); |
| 4150 | } |
| 4151 | |
| 4152 | if (instruction->IsDiv()) { |
| 4153 | __ Sub(out, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4154 | } else { |
| 4155 | __ Sub(temp1, temp1, Operand(temp1, vixl32::Shift(ASR), 31)); |
| 4156 | // TODO: Strength reduction for mls. |
| 4157 | __ Mov(temp2, imm); |
| 4158 | __ Mls(out, temp1, temp2, dividend); |
| 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | void InstructionCodeGeneratorARMVIXL::GenerateDivRemConstantIntegral( |
| 4163 | HBinaryOperation* instruction) { |
| 4164 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4165 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4166 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4167 | Location second = instruction->GetLocations()->InAt(1); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4168 | DCHECK(second.IsConstant()); |
| 4169 | |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4170 | int32_t imm = Int32ConstantFrom(second); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4171 | if (imm == 0) { |
| 4172 | // Do not generate anything. DivZeroCheck would prevent any code to be executed. |
| 4173 | } else if (imm == 1 || imm == -1) { |
| 4174 | DivRemOneOrMinusOne(instruction); |
| 4175 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { |
| 4176 | DivRemByPowerOfTwo(instruction); |
| 4177 | } else { |
| 4178 | DCHECK(imm <= -2 || imm >= 2); |
| 4179 | GenerateDivRemWithAnyConstant(instruction); |
| 4180 | } |
| 4181 | } |
| 4182 | |
| 4183 | void LocationsBuilderARMVIXL::VisitDiv(HDiv* div) { |
| 4184 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4185 | if (div->GetResultType() == DataType::Type::kInt64) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4186 | // pLdiv runtime call. |
| 4187 | call_kind = LocationSummary::kCallOnMainOnly; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4188 | } else if (div->GetResultType() == DataType::Type::kInt32 && div->InputAt(1)->IsConstant()) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4189 | // sdiv will be replaced by other instruction sequence. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4190 | } else if (div->GetResultType() == DataType::Type::kInt32 && |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4191 | !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4192 | // pIdivmod runtime call. |
| 4193 | call_kind = LocationSummary::kCallOnMainOnly; |
| 4194 | } |
| 4195 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4196 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4197 | |
| 4198 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4199 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4200 | if (div->InputAt(1)->IsConstant()) { |
| 4201 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4202 | locations->SetInAt(1, Location::ConstantLocation(div->InputAt(1)->AsConstant())); |
| 4203 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4204 | int32_t value = Int32ConstantFrom(div->InputAt(1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4205 | if (value == 1 || value == 0 || value == -1) { |
| 4206 | // No temp register required. |
| 4207 | } else { |
| 4208 | locations->AddTemp(Location::RequiresRegister()); |
| 4209 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4210 | locations->AddTemp(Location::RequiresRegister()); |
| 4211 | } |
| 4212 | } |
| 4213 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4214 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4215 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4216 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4217 | } else { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4218 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4219 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4220 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4221 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4222 | // we only need the former. |
| 4223 | locations->SetOut(LocationFrom(r0)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4224 | } |
| 4225 | break; |
| 4226 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4227 | case DataType::Type::kInt64: { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4228 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4229 | locations->SetInAt(0, LocationFrom( |
| 4230 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4231 | locations->SetInAt(1, LocationFrom( |
| 4232 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4233 | locations->SetOut(LocationFrom(r0, r1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4234 | break; |
| 4235 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4236 | case DataType::Type::kFloat32: |
| 4237 | case DataType::Type::kFloat64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4238 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4239 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4240 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4241 | break; |
| 4242 | } |
| 4243 | |
| 4244 | default: |
| 4245 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | void InstructionCodeGeneratorARMVIXL::VisitDiv(HDiv* div) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4250 | Location lhs = div->GetLocations()->InAt(0); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4251 | Location rhs = div->GetLocations()->InAt(1); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4252 | |
| 4253 | switch (div->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4254 | case DataType::Type::kInt32: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4255 | if (rhs.IsConstant()) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4256 | GenerateDivRemConstantIntegral(div); |
| 4257 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4258 | __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1)); |
| 4259 | } else { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4260 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4261 | DCHECK(calling_convention.GetRegisterAt(0).Is(RegisterFrom(lhs))); |
| 4262 | DCHECK(calling_convention.GetRegisterAt(1).Is(RegisterFrom(rhs))); |
| 4263 | DCHECK(r0.Is(OutputRegister(div))); |
| 4264 | |
| 4265 | codegen_->InvokeRuntime(kQuickIdivmod, div, div->GetDexPc()); |
| 4266 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4267 | } |
| 4268 | break; |
| 4269 | } |
| 4270 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4271 | case DataType::Type::kInt64: { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 4272 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4273 | DCHECK(calling_convention.GetRegisterAt(0).Is(LowRegisterFrom(lhs))); |
| 4274 | DCHECK(calling_convention.GetRegisterAt(1).Is(HighRegisterFrom(lhs))); |
| 4275 | DCHECK(calling_convention.GetRegisterAt(2).Is(LowRegisterFrom(rhs))); |
| 4276 | DCHECK(calling_convention.GetRegisterAt(3).Is(HighRegisterFrom(rhs))); |
| 4277 | DCHECK(LowRegisterFrom(div->GetLocations()->Out()).Is(r0)); |
| 4278 | DCHECK(HighRegisterFrom(div->GetLocations()->Out()).Is(r1)); |
| 4279 | |
| 4280 | codegen_->InvokeRuntime(kQuickLdiv, div, div->GetDexPc()); |
| 4281 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4282 | break; |
| 4283 | } |
| 4284 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4285 | case DataType::Type::kFloat32: |
| 4286 | case DataType::Type::kFloat64: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4287 | __ Vdiv(OutputVRegister(div), InputVRegisterAt(div, 0), InputVRegisterAt(div, 1)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4288 | break; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4289 | |
| 4290 | default: |
| 4291 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 4292 | } |
| 4293 | } |
| 4294 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4295 | void LocationsBuilderARMVIXL::VisitRem(HRem* rem) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4296 | DataType::Type type = rem->GetResultType(); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4297 | |
| 4298 | // Most remainders are implemented in the runtime. |
| 4299 | LocationSummary::CallKind call_kind = LocationSummary::kCallOnMainOnly; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4300 | if (rem->GetResultType() == DataType::Type::kInt32 && rem->InputAt(1)->IsConstant()) { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4301 | // sdiv will be replaced by other instruction sequence. |
| 4302 | call_kind = LocationSummary::kNoCall; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4303 | } else if ((rem->GetResultType() == DataType::Type::kInt32) |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4304 | && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4305 | // Have hardware divide instruction for int, do it with three instructions. |
| 4306 | call_kind = LocationSummary::kNoCall; |
| 4307 | } |
| 4308 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4309 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4310 | |
| 4311 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4312 | case DataType::Type::kInt32: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4313 | if (rem->InputAt(1)->IsConstant()) { |
| 4314 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4315 | locations->SetInAt(1, Location::ConstantLocation(rem->InputAt(1)->AsConstant())); |
| 4316 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4317 | int32_t value = Int32ConstantFrom(rem->InputAt(1)); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4318 | if (value == 1 || value == 0 || value == -1) { |
| 4319 | // No temp register required. |
| 4320 | } else { |
| 4321 | locations->AddTemp(Location::RequiresRegister()); |
| 4322 | if (!IsPowerOfTwo(AbsOrMin(value))) { |
| 4323 | locations->AddTemp(Location::RequiresRegister()); |
| 4324 | } |
| 4325 | } |
| 4326 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4327 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4328 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4329 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4330 | locations->AddTemp(Location::RequiresRegister()); |
| 4331 | } else { |
| 4332 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4333 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 4334 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 4335 | // Note: divmod will compute both the quotient and the remainder as the pair R0 and R1, but |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4336 | // we only need the latter. |
| 4337 | locations->SetOut(LocationFrom(r1)); |
| 4338 | } |
| 4339 | break; |
| 4340 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4341 | case DataType::Type::kInt64: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4342 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4343 | locations->SetInAt(0, LocationFrom( |
| 4344 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 4345 | locations->SetInAt(1, LocationFrom( |
| 4346 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 4347 | // The runtime helper puts the output in R2,R3. |
| 4348 | locations->SetOut(LocationFrom(r2, r3)); |
| 4349 | break; |
| 4350 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4351 | case DataType::Type::kFloat32: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4352 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4353 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 4354 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 4355 | locations->SetOut(LocationFrom(s0)); |
| 4356 | break; |
| 4357 | } |
| 4358 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4359 | case DataType::Type::kFloat64: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4360 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4361 | locations->SetInAt(0, LocationFrom( |
| 4362 | calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1))); |
| 4363 | locations->SetInAt(1, LocationFrom( |
| 4364 | calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3))); |
| 4365 | locations->SetOut(LocationFrom(s0, s1)); |
| 4366 | break; |
| 4367 | } |
| 4368 | |
| 4369 | default: |
| 4370 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4371 | } |
| 4372 | } |
| 4373 | |
| 4374 | void InstructionCodeGeneratorARMVIXL::VisitRem(HRem* rem) { |
| 4375 | LocationSummary* locations = rem->GetLocations(); |
| 4376 | Location second = locations->InAt(1); |
| 4377 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4378 | DataType::Type type = rem->GetResultType(); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4379 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4380 | case DataType::Type::kInt32: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4381 | vixl32::Register reg1 = InputRegisterAt(rem, 0); |
| 4382 | vixl32::Register out_reg = OutputRegister(rem); |
| 4383 | if (second.IsConstant()) { |
| 4384 | GenerateDivRemConstantIntegral(rem); |
| 4385 | } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) { |
| 4386 | vixl32::Register reg2 = RegisterFrom(second); |
| 4387 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4388 | |
| 4389 | // temp = reg1 / reg2 (integer division) |
| 4390 | // dest = reg1 - temp * reg2 |
| 4391 | __ Sdiv(temp, reg1, reg2); |
| 4392 | __ Mls(out_reg, temp, reg2, reg1); |
| 4393 | } else { |
| 4394 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 4395 | DCHECK(reg1.Is(calling_convention.GetRegisterAt(0))); |
| 4396 | DCHECK(RegisterFrom(second).Is(calling_convention.GetRegisterAt(1))); |
| 4397 | DCHECK(out_reg.Is(r1)); |
| 4398 | |
| 4399 | codegen_->InvokeRuntime(kQuickIdivmod, rem, rem->GetDexPc()); |
| 4400 | CheckEntrypointTypes<kQuickIdivmod, int32_t, int32_t, int32_t>(); |
| 4401 | } |
| 4402 | break; |
| 4403 | } |
| 4404 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4405 | case DataType::Type::kInt64: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4406 | codegen_->InvokeRuntime(kQuickLmod, rem, rem->GetDexPc()); |
| 4407 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
| 4408 | break; |
| 4409 | } |
| 4410 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4411 | case DataType::Type::kFloat32: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4412 | codegen_->InvokeRuntime(kQuickFmodf, rem, rem->GetDexPc()); |
| 4413 | CheckEntrypointTypes<kQuickFmodf, float, float, float>(); |
| 4414 | break; |
| 4415 | } |
| 4416 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4417 | case DataType::Type::kFloat64: { |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4418 | codegen_->InvokeRuntime(kQuickFmod, rem, rem->GetDexPc()); |
| 4419 | CheckEntrypointTypes<kQuickFmod, double, double, double>(); |
| 4420 | break; |
| 4421 | } |
| 4422 | |
| 4423 | default: |
| 4424 | LOG(FATAL) << "Unexpected rem type " << type; |
| 4425 | } |
| 4426 | } |
| 4427 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4428 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { |
| 4429 | LocationSummary* locations = new (allocator) LocationSummary(minmax); |
| 4430 | switch (minmax->GetResultType()) { |
| 4431 | case DataType::Type::kInt32: |
| 4432 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4433 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4434 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4435 | break; |
| 4436 | case DataType::Type::kInt64: |
| 4437 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4438 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4439 | locations->SetOut(Location::SameAsFirstInput()); |
| 4440 | break; |
| 4441 | case DataType::Type::kFloat32: |
| 4442 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4443 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4444 | locations->SetOut(Location::SameAsFirstInput()); |
| 4445 | locations->AddTemp(Location::RequiresRegister()); |
| 4446 | break; |
| 4447 | case DataType::Type::kFloat64: |
| 4448 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4449 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4450 | locations->SetOut(Location::SameAsFirstInput()); |
| 4451 | break; |
| 4452 | default: |
| 4453 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); |
| 4454 | } |
| 4455 | } |
| 4456 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4457 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxInt(LocationSummary* locations, bool is_min) { |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4458 | Location op1_loc = locations->InAt(0); |
| 4459 | Location op2_loc = locations->InAt(1); |
| 4460 | Location out_loc = locations->Out(); |
| 4461 | |
| 4462 | vixl32::Register op1 = RegisterFrom(op1_loc); |
| 4463 | vixl32::Register op2 = RegisterFrom(op2_loc); |
| 4464 | vixl32::Register out = RegisterFrom(out_loc); |
| 4465 | |
| 4466 | __ Cmp(op1, op2); |
| 4467 | |
| 4468 | { |
| 4469 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 4470 | 3 * kMaxInstructionSizeInBytes, |
| 4471 | CodeBufferCheckScope::kMaximumSize); |
| 4472 | |
| 4473 | __ ite(is_min ? lt : gt); |
| 4474 | __ mov(is_min ? lt : gt, out, op1); |
| 4475 | __ mov(is_min ? ge : le, out, op2); |
| 4476 | } |
| 4477 | } |
| 4478 | |
| 4479 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxLong(LocationSummary* locations, bool is_min) { |
| 4480 | Location op1_loc = locations->InAt(0); |
| 4481 | Location op2_loc = locations->InAt(1); |
| 4482 | Location out_loc = locations->Out(); |
| 4483 | |
| 4484 | // Optimization: don't generate any code if inputs are the same. |
| 4485 | if (op1_loc.Equals(op2_loc)) { |
| 4486 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4487 | return; |
| 4488 | } |
| 4489 | |
| 4490 | vixl32::Register op1_lo = LowRegisterFrom(op1_loc); |
| 4491 | vixl32::Register op1_hi = HighRegisterFrom(op1_loc); |
| 4492 | vixl32::Register op2_lo = LowRegisterFrom(op2_loc); |
| 4493 | vixl32::Register op2_hi = HighRegisterFrom(op2_loc); |
| 4494 | vixl32::Register out_lo = LowRegisterFrom(out_loc); |
| 4495 | vixl32::Register out_hi = HighRegisterFrom(out_loc); |
| 4496 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4497 | const vixl32::Register temp = temps.Acquire(); |
| 4498 | |
| 4499 | DCHECK(op1_lo.Is(out_lo)); |
| 4500 | DCHECK(op1_hi.Is(out_hi)); |
| 4501 | |
| 4502 | // Compare op1 >= op2, or op1 < op2. |
| 4503 | __ Cmp(out_lo, op2_lo); |
| 4504 | __ Sbcs(temp, out_hi, op2_hi); |
| 4505 | |
| 4506 | // Now GE/LT condition code is correct for the long comparison. |
| 4507 | { |
| 4508 | vixl32::ConditionType cond = is_min ? ge : lt; |
| 4509 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4510 | 3 * kMaxInstructionSizeInBytes, |
| 4511 | CodeBufferCheckScope::kMaximumSize); |
| 4512 | __ itt(cond); |
| 4513 | __ mov(cond, out_lo, op2_lo); |
| 4514 | __ mov(cond, out_hi, op2_hi); |
| 4515 | } |
| 4516 | } |
| 4517 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4518 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxFloat(HInstruction* minmax, bool is_min) { |
| 4519 | LocationSummary* locations = minmax->GetLocations(); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4520 | Location op1_loc = locations->InAt(0); |
| 4521 | Location op2_loc = locations->InAt(1); |
| 4522 | Location out_loc = locations->Out(); |
| 4523 | |
| 4524 | // Optimization: don't generate any code if inputs are the same. |
| 4525 | if (op1_loc.Equals(op2_loc)) { |
| 4526 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 4527 | return; |
| 4528 | } |
| 4529 | |
| 4530 | vixl32::SRegister op1 = SRegisterFrom(op1_loc); |
| 4531 | vixl32::SRegister op2 = SRegisterFrom(op2_loc); |
| 4532 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 4533 | |
| 4534 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4535 | const vixl32::Register temp1 = temps.Acquire(); |
| 4536 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(0)); |
| 4537 | vixl32::Label nan, done; |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4538 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4539 | |
| 4540 | DCHECK(op1.Is(out)); |
| 4541 | |
| 4542 | __ Vcmp(op1, op2); |
| 4543 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4544 | __ B(vs, &nan, /* is_far_target= */ false); // if un-ordered, go to NaN handling. |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4545 | |
| 4546 | // op1 <> op2 |
| 4547 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4548 | { |
| 4549 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4550 | 2 * kMaxInstructionSizeInBytes, |
| 4551 | CodeBufferCheckScope::kMaximumSize); |
| 4552 | __ it(cond); |
| 4553 | __ vmov(cond, F32, out, op2); |
| 4554 | } |
| 4555 | // for <>(not equal), we've done min/max calculation. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4556 | __ B(ne, final_label, /* is_far_target= */ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4557 | |
| 4558 | // handle op1 == op2, max(+0.0,-0.0), min(+0.0,-0.0). |
| 4559 | __ Vmov(temp1, op1); |
| 4560 | __ Vmov(temp2, op2); |
| 4561 | if (is_min) { |
| 4562 | __ Orr(temp1, temp1, temp2); |
| 4563 | } else { |
| 4564 | __ And(temp1, temp1, temp2); |
| 4565 | } |
| 4566 | __ Vmov(out, temp1); |
| 4567 | __ B(final_label); |
| 4568 | |
| 4569 | // handle NaN input. |
| 4570 | __ Bind(&nan); |
| 4571 | __ Movt(temp1, High16Bits(kNanFloat)); // 0x7FC0xxxx is a NaN. |
| 4572 | __ Vmov(out, temp1); |
| 4573 | |
| 4574 | if (done.IsReferenced()) { |
| 4575 | __ Bind(&done); |
| 4576 | } |
| 4577 | } |
| 4578 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4579 | void InstructionCodeGeneratorARMVIXL::GenerateMinMaxDouble(HInstruction* minmax, bool is_min) { |
| 4580 | LocationSummary* locations = minmax->GetLocations(); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4581 | Location op1_loc = locations->InAt(0); |
| 4582 | Location op2_loc = locations->InAt(1); |
| 4583 | Location out_loc = locations->Out(); |
| 4584 | |
| 4585 | // Optimization: don't generate any code if inputs are the same. |
| 4586 | if (op1_loc.Equals(op2_loc)) { |
| 4587 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in. |
| 4588 | return; |
| 4589 | } |
| 4590 | |
| 4591 | vixl32::DRegister op1 = DRegisterFrom(op1_loc); |
| 4592 | vixl32::DRegister op2 = DRegisterFrom(op2_loc); |
| 4593 | vixl32::DRegister out = DRegisterFrom(out_loc); |
| 4594 | vixl32::Label handle_nan_eq, done; |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4595 | vixl32::Label* final_label = codegen_->GetFinalLabel(minmax, &done); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4596 | |
| 4597 | DCHECK(op1.Is(out)); |
| 4598 | |
| 4599 | __ Vcmp(op1, op2); |
| 4600 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4601 | __ B(vs, &handle_nan_eq, /* is_far_target= */ false); // if un-ordered, go to NaN handling. |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4602 | |
| 4603 | // op1 <> op2 |
| 4604 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 4605 | { |
| 4606 | ExactAssemblyScope it_scope(GetVIXLAssembler(), |
| 4607 | 2 * kMaxInstructionSizeInBytes, |
| 4608 | CodeBufferCheckScope::kMaximumSize); |
| 4609 | __ it(cond); |
| 4610 | __ vmov(cond, F64, out, op2); |
| 4611 | } |
| 4612 | // for <>(not equal), we've done min/max calculation. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4613 | __ B(ne, final_label, /* is_far_target= */ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4614 | |
| 4615 | // handle op1 == op2, max(+0.0,-0.0). |
| 4616 | if (!is_min) { |
| 4617 | __ Vand(F64, out, op1, op2); |
| 4618 | __ B(final_label); |
| 4619 | } |
| 4620 | |
| 4621 | // handle op1 == op2, min(+0.0,-0.0), NaN input. |
| 4622 | __ Bind(&handle_nan_eq); |
| 4623 | __ Vorr(F64, out, op1, op2); // assemble op1/-0.0/NaN. |
| 4624 | |
| 4625 | if (done.IsReferenced()) { |
| 4626 | __ Bind(&done); |
| 4627 | } |
| 4628 | } |
| 4629 | |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4630 | void InstructionCodeGeneratorARMVIXL::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { |
| 4631 | DataType::Type type = minmax->GetResultType(); |
| 4632 | switch (type) { |
| 4633 | case DataType::Type::kInt32: |
| 4634 | GenerateMinMaxInt(minmax->GetLocations(), is_min); |
| 4635 | break; |
| 4636 | case DataType::Type::kInt64: |
| 4637 | GenerateMinMaxLong(minmax->GetLocations(), is_min); |
| 4638 | break; |
| 4639 | case DataType::Type::kFloat32: |
| 4640 | GenerateMinMaxFloat(minmax, is_min); |
| 4641 | break; |
| 4642 | case DataType::Type::kFloat64: |
| 4643 | GenerateMinMaxDouble(minmax, is_min); |
| 4644 | break; |
| 4645 | default: |
| 4646 | LOG(FATAL) << "Unexpected type for HMinMax " << type; |
| 4647 | } |
| 4648 | } |
| 4649 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4650 | void LocationsBuilderARMVIXL::VisitMin(HMin* min) { |
| 4651 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); |
| 4652 | } |
| 4653 | |
| 4654 | void InstructionCodeGeneratorARMVIXL::VisitMin(HMin* min) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4655 | GenerateMinMax(min, /*is_min*/ true); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | void LocationsBuilderARMVIXL::VisitMax(HMax* max) { |
| 4659 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); |
| 4660 | } |
| 4661 | |
| 4662 | void InstructionCodeGeneratorARMVIXL::VisitMax(HMax* max) { |
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4663 | GenerateMinMax(max, /*is_min*/ false); |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4664 | } |
| 4665 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4666 | void LocationsBuilderARMVIXL::VisitAbs(HAbs* abs) { |
| 4667 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); |
| 4668 | switch (abs->GetResultType()) { |
| 4669 | case DataType::Type::kInt32: |
| 4670 | case DataType::Type::kInt64: |
| 4671 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4672 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4673 | locations->AddTemp(Location::RequiresRegister()); |
| 4674 | break; |
| 4675 | case DataType::Type::kFloat32: |
| 4676 | case DataType::Type::kFloat64: |
| 4677 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4678 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4679 | break; |
| 4680 | default: |
| 4681 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 4682 | } |
| 4683 | } |
| 4684 | |
| 4685 | void InstructionCodeGeneratorARMVIXL::VisitAbs(HAbs* abs) { |
| 4686 | LocationSummary* locations = abs->GetLocations(); |
| 4687 | switch (abs->GetResultType()) { |
| 4688 | case DataType::Type::kInt32: { |
| 4689 | vixl32::Register in_reg = RegisterFrom(locations->InAt(0)); |
| 4690 | vixl32::Register out_reg = RegisterFrom(locations->Out()); |
| 4691 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 4692 | __ Asr(mask, in_reg, 31); |
| 4693 | __ Add(out_reg, in_reg, mask); |
| 4694 | __ Eor(out_reg, out_reg, mask); |
| 4695 | break; |
| 4696 | } |
| 4697 | case DataType::Type::kInt64: { |
| 4698 | Location in = locations->InAt(0); |
| 4699 | vixl32::Register in_reg_lo = LowRegisterFrom(in); |
| 4700 | vixl32::Register in_reg_hi = HighRegisterFrom(in); |
| 4701 | Location output = locations->Out(); |
| 4702 | vixl32::Register out_reg_lo = LowRegisterFrom(output); |
| 4703 | vixl32::Register out_reg_hi = HighRegisterFrom(output); |
| 4704 | DCHECK(!out_reg_lo.Is(in_reg_hi)) << "Diagonal overlap unexpected."; |
| 4705 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 4706 | __ Asr(mask, in_reg_hi, 31); |
| 4707 | __ Adds(out_reg_lo, in_reg_lo, mask); |
| 4708 | __ Adc(out_reg_hi, in_reg_hi, mask); |
| 4709 | __ Eor(out_reg_lo, out_reg_lo, mask); |
| 4710 | __ Eor(out_reg_hi, out_reg_hi, mask); |
| 4711 | break; |
| 4712 | } |
| 4713 | case DataType::Type::kFloat32: |
| 4714 | case DataType::Type::kFloat64: |
| 4715 | __ Vabs(OutputVRegister(abs), InputVRegisterAt(abs, 0)); |
| 4716 | break; |
| 4717 | default: |
| 4718 | LOG(FATAL) << "Unexpected type for abs operation " << abs->GetResultType(); |
| 4719 | } |
| 4720 | } |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 4721 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4722 | void LocationsBuilderARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 4723 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4724 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | void InstructionCodeGeneratorARMVIXL::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 4728 | DivZeroCheckSlowPathARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4729 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathARMVIXL(instruction); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4730 | codegen_->AddSlowPath(slow_path); |
| 4731 | |
| 4732 | LocationSummary* locations = instruction->GetLocations(); |
| 4733 | Location value = locations->InAt(0); |
| 4734 | |
| 4735 | switch (instruction->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4736 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4737 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4738 | case DataType::Type::kInt8: |
| 4739 | case DataType::Type::kUint16: |
| 4740 | case DataType::Type::kInt16: |
| 4741 | case DataType::Type::kInt32: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4742 | if (value.IsRegister()) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 4743 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4744 | } else { |
| 4745 | DCHECK(value.IsConstant()) << value; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4746 | if (Int32ConstantFrom(value) == 0) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4747 | __ B(slow_path->GetEntryLabel()); |
| 4748 | } |
| 4749 | } |
| 4750 | break; |
| 4751 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4752 | case DataType::Type::kInt64: { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4753 | if (value.IsRegisterPair()) { |
| 4754 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 4755 | vixl32::Register temp = temps.Acquire(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 4756 | __ Orrs(temp, LowRegisterFrom(value), HighRegisterFrom(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4757 | __ B(eq, slow_path->GetEntryLabel()); |
| 4758 | } else { |
| 4759 | DCHECK(value.IsConstant()) << value; |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4760 | if (Int64ConstantFrom(value) == 0) { |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 4761 | __ B(slow_path->GetEntryLabel()); |
| 4762 | } |
| 4763 | } |
| 4764 | break; |
| 4765 | } |
| 4766 | default: |
| 4767 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 4768 | } |
| 4769 | } |
| 4770 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4771 | void InstructionCodeGeneratorARMVIXL::HandleIntegerRotate(HRor* ror) { |
| 4772 | LocationSummary* locations = ror->GetLocations(); |
| 4773 | vixl32::Register in = InputRegisterAt(ror, 0); |
| 4774 | Location rhs = locations->InAt(1); |
| 4775 | vixl32::Register out = OutputRegister(ror); |
| 4776 | |
| 4777 | if (rhs.IsConstant()) { |
| 4778 | // Arm32 and Thumb2 assemblers require a rotation on the interval [1,31], |
| 4779 | // so map all rotations to a +ve. equivalent in that range. |
| 4780 | // (e.g. left *or* right by -2 bits == 30 bits in the same direction.) |
| 4781 | uint32_t rot = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()) & 0x1F; |
| 4782 | if (rot) { |
| 4783 | // Rotate, mapping left rotations to right equivalents if necessary. |
| 4784 | // (e.g. left by 2 bits == right by 30.) |
| 4785 | __ Ror(out, in, rot); |
| 4786 | } else if (!out.Is(in)) { |
| 4787 | __ Mov(out, in); |
| 4788 | } |
| 4789 | } else { |
| 4790 | __ Ror(out, in, RegisterFrom(rhs)); |
| 4791 | } |
| 4792 | } |
| 4793 | |
| 4794 | // Gain some speed by mapping all Long rotates onto equivalent pairs of Integer |
| 4795 | // rotates by swapping input regs (effectively rotating by the first 32-bits of |
| 4796 | // a larger rotation) or flipping direction (thus treating larger right/left |
| 4797 | // rotations as sub-word sized rotations in the other direction) as appropriate. |
| 4798 | void InstructionCodeGeneratorARMVIXL::HandleLongRotate(HRor* ror) { |
| 4799 | LocationSummary* locations = ror->GetLocations(); |
| 4800 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 4801 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 4802 | Location rhs = locations->InAt(1); |
| 4803 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 4804 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 4805 | |
| 4806 | if (rhs.IsConstant()) { |
| 4807 | uint64_t rot = CodeGenerator::GetInt64ValueOf(rhs.GetConstant()); |
| 4808 | // Map all rotations to +ve. equivalents on the interval [0,63]. |
| 4809 | rot &= kMaxLongShiftDistance; |
| 4810 | // For rotates over a word in size, 'pre-rotate' by 32-bits to keep rotate |
| 4811 | // logic below to a simple pair of binary orr. |
| 4812 | // (e.g. 34 bits == in_reg swap + 2 bits right.) |
| 4813 | if (rot >= kArmBitsPerWord) { |
| 4814 | rot -= kArmBitsPerWord; |
| 4815 | std::swap(in_reg_hi, in_reg_lo); |
| 4816 | } |
| 4817 | // Rotate, or mov to out for zero or word size rotations. |
| 4818 | if (rot != 0u) { |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4819 | __ Lsr(out_reg_hi, in_reg_hi, Operand::From(rot)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4820 | __ Orr(out_reg_hi, out_reg_hi, Operand(in_reg_lo, ShiftType::LSL, kArmBitsPerWord - rot)); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 4821 | __ Lsr(out_reg_lo, in_reg_lo, Operand::From(rot)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4822 | __ Orr(out_reg_lo, out_reg_lo, Operand(in_reg_hi, ShiftType::LSL, kArmBitsPerWord - rot)); |
| 4823 | } else { |
| 4824 | __ Mov(out_reg_lo, in_reg_lo); |
| 4825 | __ Mov(out_reg_hi, in_reg_hi); |
| 4826 | } |
| 4827 | } else { |
| 4828 | vixl32::Register shift_right = RegisterFrom(locations->GetTemp(0)); |
| 4829 | vixl32::Register shift_left = RegisterFrom(locations->GetTemp(1)); |
| 4830 | vixl32::Label end; |
| 4831 | vixl32::Label shift_by_32_plus_shift_right; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4832 | vixl32::Label* final_label = codegen_->GetFinalLabel(ror, &end); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4833 | |
| 4834 | __ And(shift_right, RegisterFrom(rhs), 0x1F); |
| 4835 | __ Lsrs(shift_left, RegisterFrom(rhs), 6); |
| Scott Wakeling | bffdc70 | 2016-12-07 17:46:03 +0000 | [diff] [blame] | 4836 | __ Rsb(LeaveFlags, shift_left, shift_right, Operand::From(kArmBitsPerWord)); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4837 | __ B(cc, &shift_by_32_plus_shift_right, /* is_far_target= */ false); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4838 | |
| 4839 | // out_reg_hi = (reg_hi << shift_left) | (reg_lo >> shift_right). |
| 4840 | // out_reg_lo = (reg_lo << shift_left) | (reg_hi >> shift_right). |
| 4841 | __ Lsl(out_reg_hi, in_reg_hi, shift_left); |
| 4842 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4843 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4844 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4845 | __ Lsr(shift_left, in_reg_hi, shift_right); |
| 4846 | __ Add(out_reg_lo, out_reg_lo, shift_left); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4847 | __ B(final_label); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4848 | |
| 4849 | __ Bind(&shift_by_32_plus_shift_right); // Shift by 32+shift_right. |
| 4850 | // out_reg_hi = (reg_hi >> shift_right) | (reg_lo << shift_left). |
| 4851 | // out_reg_lo = (reg_lo >> shift_right) | (reg_hi << shift_left). |
| 4852 | __ Lsr(out_reg_hi, in_reg_hi, shift_right); |
| 4853 | __ Lsl(out_reg_lo, in_reg_lo, shift_left); |
| 4854 | __ Add(out_reg_hi, out_reg_hi, out_reg_lo); |
| 4855 | __ Lsr(out_reg_lo, in_reg_lo, shift_right); |
| 4856 | __ Lsl(shift_right, in_reg_hi, shift_left); |
| 4857 | __ Add(out_reg_lo, out_reg_lo, shift_right); |
| 4858 | |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 4859 | if (end.IsReferenced()) { |
| 4860 | __ Bind(&end); |
| 4861 | } |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4862 | } |
| 4863 | } |
| 4864 | |
| 4865 | void LocationsBuilderARMVIXL::VisitRor(HRor* ror) { |
| 4866 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4867 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4868 | switch (ror->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4869 | case DataType::Type::kInt32: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4870 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4871 | locations->SetInAt(1, Location::RegisterOrConstant(ror->InputAt(1))); |
| 4872 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4873 | break; |
| 4874 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4875 | case DataType::Type::kInt64: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4876 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4877 | if (ror->InputAt(1)->IsConstant()) { |
| 4878 | locations->SetInAt(1, Location::ConstantLocation(ror->InputAt(1)->AsConstant())); |
| 4879 | } else { |
| 4880 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4881 | locations->AddTemp(Location::RequiresRegister()); |
| 4882 | locations->AddTemp(Location::RequiresRegister()); |
| 4883 | } |
| 4884 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4885 | break; |
| 4886 | } |
| 4887 | default: |
| 4888 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 4889 | } |
| 4890 | } |
| 4891 | |
| 4892 | void InstructionCodeGeneratorARMVIXL::VisitRor(HRor* ror) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4893 | DataType::Type type = ror->GetResultType(); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4894 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4895 | case DataType::Type::kInt32: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4896 | HandleIntegerRotate(ror); |
| 4897 | break; |
| 4898 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4899 | case DataType::Type::kInt64: { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 4900 | HandleLongRotate(ror); |
| 4901 | break; |
| 4902 | } |
| 4903 | default: |
| 4904 | LOG(FATAL) << "Unexpected operation type " << type; |
| 4905 | UNREACHABLE(); |
| 4906 | } |
| 4907 | } |
| 4908 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4909 | void LocationsBuilderARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4910 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4911 | |
| 4912 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4913 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4914 | |
| 4915 | switch (op->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4916 | case DataType::Type::kInt32: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4917 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4918 | if (op->InputAt(1)->IsConstant()) { |
| 4919 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4920 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4921 | } else { |
| 4922 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4923 | // Make the output overlap, as it will be used to hold the masked |
| 4924 | // second input. |
| 4925 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4926 | } |
| 4927 | break; |
| 4928 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4929 | case DataType::Type::kInt64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4930 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4931 | if (op->InputAt(1)->IsConstant()) { |
| 4932 | locations->SetInAt(1, Location::ConstantLocation(op->InputAt(1)->AsConstant())); |
| 4933 | // For simplicity, use kOutputOverlap even though we only require that low registers |
| 4934 | // don't clash with high registers which the register allocator currently guarantees. |
| 4935 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4936 | } else { |
| 4937 | locations->SetInAt(1, Location::RequiresRegister()); |
| 4938 | locations->AddTemp(Location::RequiresRegister()); |
| 4939 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 4940 | } |
| 4941 | break; |
| 4942 | } |
| 4943 | default: |
| 4944 | LOG(FATAL) << "Unexpected operation type " << op->GetResultType(); |
| 4945 | } |
| 4946 | } |
| 4947 | |
| 4948 | void InstructionCodeGeneratorARMVIXL::HandleShift(HBinaryOperation* op) { |
| 4949 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 4950 | |
| 4951 | LocationSummary* locations = op->GetLocations(); |
| 4952 | Location out = locations->Out(); |
| 4953 | Location first = locations->InAt(0); |
| 4954 | Location second = locations->InAt(1); |
| 4955 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4956 | DataType::Type type = op->GetResultType(); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4957 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4958 | case DataType::Type::kInt32: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4959 | vixl32::Register out_reg = OutputRegister(op); |
| 4960 | vixl32::Register first_reg = InputRegisterAt(op, 0); |
| 4961 | if (second.IsRegister()) { |
| 4962 | vixl32::Register second_reg = RegisterFrom(second); |
| 4963 | // ARM doesn't mask the shift count so we need to do it ourselves. |
| 4964 | __ And(out_reg, second_reg, kMaxIntShiftDistance); |
| 4965 | if (op->IsShl()) { |
| 4966 | __ Lsl(out_reg, first_reg, out_reg); |
| 4967 | } else if (op->IsShr()) { |
| 4968 | __ Asr(out_reg, first_reg, out_reg); |
| 4969 | } else { |
| 4970 | __ Lsr(out_reg, first_reg, out_reg); |
| 4971 | } |
| 4972 | } else { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 4973 | int32_t cst = Int32ConstantFrom(second); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4974 | uint32_t shift_value = cst & kMaxIntShiftDistance; |
| 4975 | if (shift_value == 0) { // ARM does not support shifting with 0 immediate. |
| 4976 | __ Mov(out_reg, first_reg); |
| 4977 | } else if (op->IsShl()) { |
| 4978 | __ Lsl(out_reg, first_reg, shift_value); |
| 4979 | } else if (op->IsShr()) { |
| 4980 | __ Asr(out_reg, first_reg, shift_value); |
| 4981 | } else { |
| 4982 | __ Lsr(out_reg, first_reg, shift_value); |
| 4983 | } |
| 4984 | } |
| 4985 | break; |
| 4986 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4987 | case DataType::Type::kInt64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 4988 | vixl32::Register o_h = HighRegisterFrom(out); |
| 4989 | vixl32::Register o_l = LowRegisterFrom(out); |
| 4990 | |
| 4991 | vixl32::Register high = HighRegisterFrom(first); |
| 4992 | vixl32::Register low = LowRegisterFrom(first); |
| 4993 | |
| 4994 | if (second.IsRegister()) { |
| 4995 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 4996 | |
| 4997 | vixl32::Register second_reg = RegisterFrom(second); |
| 4998 | |
| 4999 | if (op->IsShl()) { |
| 5000 | __ And(o_l, second_reg, kMaxLongShiftDistance); |
| 5001 | // Shift the high part |
| 5002 | __ Lsl(o_h, high, o_l); |
| 5003 | // Shift the low part and `or` what overflew on the high part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5004 | __ Rsb(temp, o_l, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5005 | __ Lsr(temp, low, temp); |
| 5006 | __ Orr(o_h, o_h, temp); |
| 5007 | // If the shift is > 32 bits, override the high part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5008 | __ Subs(temp, o_l, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5009 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5010 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5011 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5012 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5013 | __ it(pl); |
| 5014 | __ lsl(pl, o_h, low, temp); |
| 5015 | } |
| 5016 | // Shift the low part |
| 5017 | __ Lsl(o_l, low, o_l); |
| 5018 | } else if (op->IsShr()) { |
| 5019 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5020 | // Shift the low part |
| 5021 | __ Lsr(o_l, low, o_h); |
| 5022 | // Shift the high part and `or` what underflew on the low part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5023 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5024 | __ Lsl(temp, high, temp); |
| 5025 | __ Orr(o_l, o_l, temp); |
| 5026 | // If the shift is > 32 bits, override the low part |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5027 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5028 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5029 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5030 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5031 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5032 | __ it(pl); |
| 5033 | __ asr(pl, o_l, high, temp); |
| 5034 | } |
| 5035 | // Shift the high part |
| 5036 | __ Asr(o_h, high, o_h); |
| 5037 | } else { |
| 5038 | __ And(o_h, second_reg, kMaxLongShiftDistance); |
| 5039 | // same as Shr except we use `Lsr`s and not `Asr`s |
| 5040 | __ Lsr(o_l, low, o_h); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5041 | __ Rsb(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5042 | __ Lsl(temp, high, temp); |
| 5043 | __ Orr(o_l, o_l, temp); |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5044 | __ Subs(temp, o_h, Operand::From(kArmBitsPerWord)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5045 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5046 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 5047 | 2 * vixl32::kMaxInstructionSizeInBytes, |
| 5048 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5049 | __ it(pl); |
| 5050 | __ lsr(pl, o_l, high, temp); |
| 5051 | } |
| 5052 | __ Lsr(o_h, high, o_h); |
| 5053 | } |
| 5054 | } else { |
| 5055 | // Register allocator doesn't create partial overlap. |
| 5056 | DCHECK(!o_l.Is(high)); |
| 5057 | DCHECK(!o_h.Is(low)); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 5058 | int32_t cst = Int32ConstantFrom(second); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5059 | uint32_t shift_value = cst & kMaxLongShiftDistance; |
| 5060 | if (shift_value > 32) { |
| 5061 | if (op->IsShl()) { |
| 5062 | __ Lsl(o_h, low, shift_value - 32); |
| 5063 | __ Mov(o_l, 0); |
| 5064 | } else if (op->IsShr()) { |
| 5065 | __ Asr(o_l, high, shift_value - 32); |
| 5066 | __ Asr(o_h, high, 31); |
| 5067 | } else { |
| 5068 | __ Lsr(o_l, high, shift_value - 32); |
| 5069 | __ Mov(o_h, 0); |
| 5070 | } |
| 5071 | } else if (shift_value == 32) { |
| 5072 | if (op->IsShl()) { |
| 5073 | __ Mov(o_h, low); |
| 5074 | __ Mov(o_l, 0); |
| 5075 | } else if (op->IsShr()) { |
| 5076 | __ Mov(o_l, high); |
| 5077 | __ Asr(o_h, high, 31); |
| 5078 | } else { |
| 5079 | __ Mov(o_l, high); |
| 5080 | __ Mov(o_h, 0); |
| 5081 | } |
| 5082 | } else if (shift_value == 1) { |
| 5083 | if (op->IsShl()) { |
| 5084 | __ Lsls(o_l, low, 1); |
| 5085 | __ Adc(o_h, high, high); |
| 5086 | } else if (op->IsShr()) { |
| 5087 | __ Asrs(o_h, high, 1); |
| 5088 | __ Rrx(o_l, low); |
| 5089 | } else { |
| 5090 | __ Lsrs(o_h, high, 1); |
| 5091 | __ Rrx(o_l, low); |
| 5092 | } |
| Nicolas Geoffray | 9b195cc | 2019-04-02 08:29:00 +0100 | [diff] [blame] | 5093 | } else if (shift_value == 0) { |
| 5094 | __ Mov(o_l, low); |
| 5095 | __ Mov(o_h, high); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5096 | } else { |
| Nicolas Geoffray | 9b195cc | 2019-04-02 08:29:00 +0100 | [diff] [blame] | 5097 | DCHECK(0 < shift_value && shift_value < 32) << shift_value; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5098 | if (op->IsShl()) { |
| 5099 | __ Lsl(o_h, high, shift_value); |
| 5100 | __ Orr(o_h, o_h, Operand(low, ShiftType::LSR, 32 - shift_value)); |
| 5101 | __ Lsl(o_l, low, shift_value); |
| 5102 | } else if (op->IsShr()) { |
| 5103 | __ Lsr(o_l, low, shift_value); |
| 5104 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5105 | __ Asr(o_h, high, shift_value); |
| 5106 | } else { |
| 5107 | __ Lsr(o_l, low, shift_value); |
| 5108 | __ Orr(o_l, o_l, Operand(high, ShiftType::LSL, 32 - shift_value)); |
| 5109 | __ Lsr(o_h, high, shift_value); |
| 5110 | } |
| 5111 | } |
| 5112 | } |
| 5113 | break; |
| 5114 | } |
| 5115 | default: |
| 5116 | LOG(FATAL) << "Unexpected operation type " << type; |
| 5117 | UNREACHABLE(); |
| 5118 | } |
| 5119 | } |
| 5120 | |
| 5121 | void LocationsBuilderARMVIXL::VisitShl(HShl* shl) { |
| 5122 | HandleShift(shl); |
| 5123 | } |
| 5124 | |
| 5125 | void InstructionCodeGeneratorARMVIXL::VisitShl(HShl* shl) { |
| 5126 | HandleShift(shl); |
| 5127 | } |
| 5128 | |
| 5129 | void LocationsBuilderARMVIXL::VisitShr(HShr* shr) { |
| 5130 | HandleShift(shr); |
| 5131 | } |
| 5132 | |
| 5133 | void InstructionCodeGeneratorARMVIXL::VisitShr(HShr* shr) { |
| 5134 | HandleShift(shr); |
| 5135 | } |
| 5136 | |
| 5137 | void LocationsBuilderARMVIXL::VisitUShr(HUShr* ushr) { |
| 5138 | HandleShift(ushr); |
| 5139 | } |
| 5140 | |
| 5141 | void InstructionCodeGeneratorARMVIXL::VisitUShr(HUShr* ushr) { |
| 5142 | HandleShift(ushr); |
| 5143 | } |
| 5144 | |
| 5145 | void LocationsBuilderARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5146 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5147 | instruction, LocationSummary::kCallOnMainOnly); |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5148 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 5149 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5150 | locations->SetOut(LocationFrom(r0)); |
| 5151 | } |
| 5152 | |
| 5153 | void InstructionCodeGeneratorARMVIXL::VisitNewInstance(HNewInstance* instruction) { |
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 5154 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
| 5155 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5156 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 11); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | void LocationsBuilderARMVIXL::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5160 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 5161 | instruction, LocationSummary::kCallOnMainOnly); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5162 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5163 | locations->SetOut(LocationFrom(r0)); |
| Nicolas Geoffray | 8c7c4f1 | 2017-01-26 10:13:11 +0000 | [diff] [blame] | 5164 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 5165 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | void InstructionCodeGeneratorARMVIXL::VisitNewArray(HNewArray* instruction) { |
| Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 5169 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. |
| 5170 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); |
| Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5171 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 5172 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); |
| Artem Serov | 7b3672e | 2017-02-03 17:30:34 +0000 | [diff] [blame] | 5173 | DCHECK(!codegen_->IsLeafMethod()); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5174 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 12); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5175 | } |
| 5176 | |
| 5177 | void LocationsBuilderARMVIXL::VisitParameterValue(HParameterValue* instruction) { |
| 5178 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5179 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5180 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 5181 | if (location.IsStackSlot()) { |
| 5182 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5183 | } else if (location.IsDoubleStackSlot()) { |
| 5184 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 5185 | } |
| 5186 | locations->SetOut(location); |
| 5187 | } |
| 5188 | |
| 5189 | void InstructionCodeGeneratorARMVIXL::VisitParameterValue( |
| 5190 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 5191 | // Nothing to do, the parameter is already at its location. |
| 5192 | } |
| 5193 | |
| 5194 | void LocationsBuilderARMVIXL::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 5195 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5196 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5197 | locations->SetOut(LocationFrom(kMethodRegister)); |
| 5198 | } |
| 5199 | |
| 5200 | void InstructionCodeGeneratorARMVIXL::VisitCurrentMethod( |
| 5201 | HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
| 5202 | // Nothing to do, the method is already at its location. |
| 5203 | } |
| 5204 | |
| 5205 | void LocationsBuilderARMVIXL::VisitNot(HNot* not_) { |
| 5206 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5207 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5208 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5209 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5210 | } |
| 5211 | |
| 5212 | void InstructionCodeGeneratorARMVIXL::VisitNot(HNot* not_) { |
| 5213 | LocationSummary* locations = not_->GetLocations(); |
| 5214 | Location out = locations->Out(); |
| 5215 | Location in = locations->InAt(0); |
| 5216 | switch (not_->GetResultType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5217 | case DataType::Type::kInt32: |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5218 | __ Mvn(OutputRegister(not_), InputRegisterAt(not_, 0)); |
| 5219 | break; |
| 5220 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5221 | case DataType::Type::kInt64: |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5222 | __ Mvn(LowRegisterFrom(out), LowRegisterFrom(in)); |
| 5223 | __ Mvn(HighRegisterFrom(out), HighRegisterFrom(in)); |
| 5224 | break; |
| 5225 | |
| 5226 | default: |
| 5227 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 5228 | } |
| 5229 | } |
| 5230 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5231 | void LocationsBuilderARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5232 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5233 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5234 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5235 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5236 | } |
| 5237 | |
| 5238 | void InstructionCodeGeneratorARMVIXL::VisitBooleanNot(HBooleanNot* bool_not) { |
| 5239 | __ Eor(OutputRegister(bool_not), InputRegister(bool_not), 1); |
| 5240 | } |
| 5241 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5242 | void LocationsBuilderARMVIXL::VisitCompare(HCompare* compare) { |
| 5243 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5244 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5245 | switch (compare->InputAt(0)->GetType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5246 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5247 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5248 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5249 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5250 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5251 | case DataType::Type::kInt32: |
| 5252 | case DataType::Type::kInt64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5253 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5254 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5255 | // Output overlaps because it is written before doing the low comparison. |
| 5256 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 5257 | break; |
| 5258 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5259 | case DataType::Type::kFloat32: |
| 5260 | case DataType::Type::kFloat64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5261 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 5262 | locations->SetInAt(1, ArithmeticZeroOrFpuRegister(compare->InputAt(1))); |
| 5263 | locations->SetOut(Location::RequiresRegister()); |
| 5264 | break; |
| 5265 | } |
| 5266 | default: |
| 5267 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 5268 | } |
| 5269 | } |
| 5270 | |
| 5271 | void InstructionCodeGeneratorARMVIXL::VisitCompare(HCompare* compare) { |
| 5272 | LocationSummary* locations = compare->GetLocations(); |
| 5273 | vixl32::Register out = OutputRegister(compare); |
| 5274 | Location left = locations->InAt(0); |
| 5275 | Location right = locations->InAt(1); |
| 5276 | |
| 5277 | vixl32::Label less, greater, done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5278 | vixl32::Label* final_label = codegen_->GetFinalLabel(compare, &done); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5279 | DataType::Type type = compare->InputAt(0)->GetType(); |
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 5280 | vixl32::Condition less_cond = vixl32::Condition::None(); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5281 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5282 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5283 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5284 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5285 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5286 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5287 | case DataType::Type::kInt32: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5288 | // Emit move to `out` before the `Cmp`, as `Mov` might affect the status flags. |
| 5289 | __ Mov(out, 0); |
| 5290 | __ Cmp(RegisterFrom(left), RegisterFrom(right)); // Signed compare. |
| 5291 | less_cond = lt; |
| 5292 | break; |
| 5293 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5294 | case DataType::Type::kInt64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5295 | __ Cmp(HighRegisterFrom(left), HighRegisterFrom(right)); // Signed compare. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5296 | __ B(lt, &less, /* is_far_target= */ false); |
| 5297 | __ B(gt, &greater, /* is_far_target= */ false); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5298 | // Emit move to `out` before the last `Cmp`, as `Mov` might affect the status flags. |
| 5299 | __ Mov(out, 0); |
| 5300 | __ Cmp(LowRegisterFrom(left), LowRegisterFrom(right)); // Unsigned compare. |
| 5301 | less_cond = lo; |
| 5302 | break; |
| 5303 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5304 | case DataType::Type::kFloat32: |
| 5305 | case DataType::Type::kFloat64: { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5306 | __ Mov(out, 0); |
| Donghui Bai | 426b49c | 2016-11-08 14:55:38 +0800 | [diff] [blame] | 5307 | GenerateVcmp(compare, codegen_); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5308 | // To branch on the FP compare result we transfer FPSCR to APSR (encoded as PC in VMRS). |
| 5309 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 5310 | less_cond = ARMFPCondition(kCondLT, compare->IsGtBias()); |
| 5311 | break; |
| 5312 | } |
| 5313 | default: |
| 5314 | LOG(FATAL) << "Unexpected compare type " << type; |
| 5315 | UNREACHABLE(); |
| 5316 | } |
| 5317 | |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5318 | __ B(eq, final_label, /* is_far_target= */ false); |
| 5319 | __ B(less_cond, &less, /* is_far_target= */ false); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5320 | |
| 5321 | __ Bind(&greater); |
| 5322 | __ Mov(out, 1); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5323 | __ B(final_label); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5324 | |
| 5325 | __ Bind(&less); |
| 5326 | __ Mov(out, -1); |
| 5327 | |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 5328 | if (done.IsReferenced()) { |
| 5329 | __ Bind(&done); |
| 5330 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | void LocationsBuilderARMVIXL::VisitPhi(HPhi* instruction) { |
| 5334 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5335 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5336 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
| 5337 | locations->SetInAt(i, Location::Any()); |
| 5338 | } |
| 5339 | locations->SetOut(Location::Any()); |
| 5340 | } |
| 5341 | |
| 5342 | void InstructionCodeGeneratorARMVIXL::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
| 5343 | LOG(FATAL) << "Unreachable"; |
| 5344 | } |
| 5345 | |
| 5346 | void CodeGeneratorARMVIXL::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 5347 | // TODO (ported from quick): revisit ARM barrier kinds. |
| 5348 | DmbOptions flavor = DmbOptions::ISH; // Quiet C++ warnings. |
| 5349 | switch (kind) { |
| 5350 | case MemBarrierKind::kAnyStore: |
| 5351 | case MemBarrierKind::kLoadAny: |
| 5352 | case MemBarrierKind::kAnyAny: { |
| 5353 | flavor = DmbOptions::ISH; |
| 5354 | break; |
| 5355 | } |
| 5356 | case MemBarrierKind::kStoreStore: { |
| 5357 | flavor = DmbOptions::ISHST; |
| 5358 | break; |
| 5359 | } |
| 5360 | default: |
| 5361 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
| 5362 | } |
| 5363 | __ Dmb(flavor); |
| 5364 | } |
| 5365 | |
| 5366 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicLoad(vixl32::Register addr, |
| 5367 | uint32_t offset, |
| 5368 | vixl32::Register out_lo, |
| 5369 | vixl32::Register out_hi) { |
| 5370 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5371 | if (offset != 0) { |
| 5372 | vixl32::Register temp = temps.Acquire(); |
| 5373 | __ Add(temp, addr, offset); |
| 5374 | addr = temp; |
| 5375 | } |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5376 | __ Ldrexd(out_lo, out_hi, MemOperand(addr)); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5377 | } |
| 5378 | |
| 5379 | void InstructionCodeGeneratorARMVIXL::GenerateWideAtomicStore(vixl32::Register addr, |
| 5380 | uint32_t offset, |
| 5381 | vixl32::Register value_lo, |
| 5382 | vixl32::Register value_hi, |
| 5383 | vixl32::Register temp1, |
| 5384 | vixl32::Register temp2, |
| 5385 | HInstruction* instruction) { |
| 5386 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 5387 | vixl32::Label fail; |
| 5388 | if (offset != 0) { |
| 5389 | vixl32::Register temp = temps.Acquire(); |
| 5390 | __ Add(temp, addr, offset); |
| 5391 | addr = temp; |
| 5392 | } |
| 5393 | __ Bind(&fail); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5394 | { |
| 5395 | // Ensure the pc position is recorded immediately after the `ldrexd` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5396 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5397 | vixl32::kMaxInstructionSizeInBytes, |
| 5398 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5399 | // We need a load followed by store. (The address used in a STREX instruction must |
| 5400 | // be the same as the address in the most recently executed LDREX instruction.) |
| 5401 | __ ldrexd(temp1, temp2, MemOperand(addr)); |
| 5402 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5403 | } |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 5404 | __ Strexd(temp1, value_lo, value_hi, MemOperand(addr)); |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5405 | __ CompareAndBranchIfNonZero(temp1, &fail); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5406 | } |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5407 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5408 | void LocationsBuilderARMVIXL::HandleFieldSet( |
| 5409 | HInstruction* instruction, const FieldInfo& field_info) { |
| 5410 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5411 | |
| 5412 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5413 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5414 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5415 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5416 | DataType::Type field_type = field_info.GetFieldType(); |
| 5417 | if (DataType::IsFloatingPointType(field_type)) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5418 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 5419 | } else { |
| 5420 | locations->SetInAt(1, Location::RequiresRegister()); |
| 5421 | } |
| 5422 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5423 | bool is_wide = field_type == DataType::Type::kInt64 || field_type == DataType::Type::kFloat64; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5424 | bool generate_volatile = field_info.IsVolatile() |
| 5425 | && is_wide |
| 5426 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5427 | bool needs_write_barrier = |
| 5428 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5429 | // Temporary registers for the write barrier. |
| 5430 | // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark. |
| 5431 | if (needs_write_barrier) { |
| 5432 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
| 5433 | locations->AddTemp(Location::RequiresRegister()); |
| 5434 | } else if (generate_volatile) { |
| 5435 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5436 | // - registers need to be consecutive |
| 5437 | // - the first register should be even but not R14. |
| 5438 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5439 | // revisit this if we ever enable ARM encoding. |
| 5440 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5441 | |
| 5442 | locations->AddTemp(Location::RequiresRegister()); |
| 5443 | locations->AddTemp(Location::RequiresRegister()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5444 | if (field_type == DataType::Type::kFloat64) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5445 | // For doubles we need two more registers to copy the value. |
| 5446 | locations->AddTemp(LocationFrom(r2)); |
| 5447 | locations->AddTemp(LocationFrom(r3)); |
| 5448 | } |
| 5449 | } |
| 5450 | } |
| 5451 | |
| 5452 | void InstructionCodeGeneratorARMVIXL::HandleFieldSet(HInstruction* instruction, |
| 5453 | const FieldInfo& field_info, |
| 5454 | bool value_can_be_null) { |
| 5455 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 5456 | |
| 5457 | LocationSummary* locations = instruction->GetLocations(); |
| 5458 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5459 | Location value = locations->InAt(1); |
| 5460 | |
| 5461 | bool is_volatile = field_info.IsVolatile(); |
| 5462 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5463 | DataType::Type field_type = field_info.GetFieldType(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5464 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5465 | bool needs_write_barrier = |
| 5466 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
| 5467 | |
| 5468 | if (is_volatile) { |
| 5469 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 5470 | } |
| 5471 | |
| 5472 | switch (field_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5473 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5474 | case DataType::Type::kUint8: |
| 5475 | case DataType::Type::kInt8: |
| 5476 | case DataType::Type::kUint16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5477 | case DataType::Type::kInt16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5478 | case DataType::Type::kInt32: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5479 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5480 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5481 | StoreOperandType operand_type = GetStoreOperandType(field_type); |
| 5482 | GetAssembler()->StoreToOffset(operand_type, RegisterFrom(value), base, offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5483 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5484 | break; |
| 5485 | } |
| 5486 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5487 | case DataType::Type::kReference: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5488 | vixl32::Register value_reg = RegisterFrom(value); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5489 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 5490 | // Note that in the case where `value` is a null reference, |
| 5491 | // we do not enter this block, as a null reference does not |
| 5492 | // need poisoning. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5493 | DCHECK_EQ(field_type, DataType::Type::kReference); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5494 | value_reg = RegisterFrom(locations->GetTemp(0)); |
| 5495 | __ Mov(value_reg, RegisterFrom(value)); |
| 5496 | GetAssembler()->PoisonHeapReference(value_reg); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5497 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5498 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5499 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5500 | GetAssembler()->StoreToOffset(kStoreWord, value_reg, base, offset); |
| 5501 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5502 | break; |
| 5503 | } |
| 5504 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5505 | case DataType::Type::kInt64: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5506 | if (is_volatile && !atomic_ldrd_strd) { |
| 5507 | GenerateWideAtomicStore(base, |
| 5508 | offset, |
| 5509 | LowRegisterFrom(value), |
| 5510 | HighRegisterFrom(value), |
| 5511 | RegisterFrom(locations->GetTemp(0)), |
| 5512 | RegisterFrom(locations->GetTemp(1)), |
| 5513 | instruction); |
| 5514 | } else { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5515 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5516 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5517 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), base, offset); |
| 5518 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5519 | } |
| 5520 | break; |
| 5521 | } |
| 5522 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5523 | case DataType::Type::kFloat32: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5524 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5525 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5526 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), base, offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5527 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5528 | break; |
| 5529 | } |
| 5530 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5531 | case DataType::Type::kFloat64: { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5532 | vixl32::DRegister value_reg = DRegisterFrom(value); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5533 | if (is_volatile && !atomic_ldrd_strd) { |
| 5534 | vixl32::Register value_reg_lo = RegisterFrom(locations->GetTemp(0)); |
| 5535 | vixl32::Register value_reg_hi = RegisterFrom(locations->GetTemp(1)); |
| 5536 | |
| 5537 | __ Vmov(value_reg_lo, value_reg_hi, value_reg); |
| 5538 | |
| 5539 | GenerateWideAtomicStore(base, |
| 5540 | offset, |
| 5541 | value_reg_lo, |
| 5542 | value_reg_hi, |
| 5543 | RegisterFrom(locations->GetTemp(2)), |
| 5544 | RegisterFrom(locations->GetTemp(3)), |
| 5545 | instruction); |
| 5546 | } else { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5547 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5548 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5549 | GetAssembler()->StoreDToOffset(value_reg, base, offset); |
| 5550 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5551 | } |
| 5552 | break; |
| 5553 | } |
| 5554 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5555 | case DataType::Type::kUint32: |
| 5556 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5557 | case DataType::Type::kVoid: |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5558 | LOG(FATAL) << "Unreachable type " << field_type; |
| 5559 | UNREACHABLE(); |
| 5560 | } |
| 5561 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5562 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 5563 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 5564 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 5565 | codegen_->MarkGCCard(temp, card, base, RegisterFrom(value), value_can_be_null); |
| 5566 | } |
| 5567 | |
| 5568 | if (is_volatile) { |
| 5569 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 5570 | } |
| 5571 | } |
| 5572 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5573 | void LocationsBuilderARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5574 | const FieldInfo& field_info) { |
| 5575 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5576 | |
| 5577 | bool object_field_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5578 | kEmitCompilerReadBarrier && (field_info.GetFieldType() == DataType::Type::kReference); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5579 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5580 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 5581 | object_field_get_with_read_barrier |
| 5582 | ? LocationSummary::kCallOnSlowPath |
| 5583 | : LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5584 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5585 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 5586 | } |
| 5587 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5588 | |
| 5589 | bool volatile_for_double = field_info.IsVolatile() |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5590 | && (field_info.GetFieldType() == DataType::Type::kFloat64) |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5591 | && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| 5592 | // The output overlaps in case of volatile long: we don't want the |
| 5593 | // code generated by GenerateWideAtomicLoad to overwrite the |
| 5594 | // object's location. Likewise, in the case of an object field get |
| 5595 | // with read barriers enabled, we do not want the load to overwrite |
| 5596 | // the object's location, as we need it to emit the read barrier. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5597 | bool overlap = |
| 5598 | (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) || |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5599 | object_field_get_with_read_barrier; |
| 5600 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5601 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5602 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5603 | } else { |
| 5604 | locations->SetOut(Location::RequiresRegister(), |
| 5605 | (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 5606 | } |
| 5607 | if (volatile_for_double) { |
| 5608 | // ARM encoding have some additional constraints for ldrexd/strexd: |
| 5609 | // - registers need to be consecutive |
| 5610 | // - the first register should be even but not R14. |
| 5611 | // We don't test for ARM yet, and the assertion makes sure that we |
| 5612 | // revisit this if we ever enable ARM encoding. |
| 5613 | DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet()); |
| 5614 | locations->AddTemp(Location::RequiresRegister()); |
| 5615 | locations->AddTemp(Location::RequiresRegister()); |
| 5616 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 5617 | // We need a temporary register for the read barrier load in |
| 5618 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier() |
| 5619 | // only if the offset is too big. |
| 5620 | if (field_info.GetFieldOffset().Uint32Value() >= kReferenceLoadMinFarOffset) { |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 5621 | locations->AddTemp(Location::RequiresRegister()); |
| 5622 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5623 | } |
| 5624 | } |
| 5625 | |
| 5626 | Location LocationsBuilderARMVIXL::ArithmeticZeroOrFpuRegister(HInstruction* input) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5627 | DCHECK(DataType::IsFloatingPointType(input->GetType())) << input->GetType(); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 5628 | if ((input->IsFloatConstant() && (input->AsFloatConstant()->IsArithmeticZero())) || |
| 5629 | (input->IsDoubleConstant() && (input->AsDoubleConstant()->IsArithmeticZero()))) { |
| 5630 | return Location::ConstantLocation(input->AsConstant()); |
| 5631 | } else { |
| 5632 | return Location::RequiresFpuRegister(); |
| 5633 | } |
| 5634 | } |
| 5635 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5636 | Location LocationsBuilderARMVIXL::ArmEncodableConstantOrRegister(HInstruction* constant, |
| 5637 | Opcode opcode) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5638 | DCHECK(!DataType::IsFloatingPointType(constant->GetType())); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5639 | if (constant->IsConstant() && |
| 5640 | CanEncodeConstantAsImmediate(constant->AsConstant(), opcode)) { |
| 5641 | return Location::ConstantLocation(constant->AsConstant()); |
| 5642 | } |
| 5643 | return Location::RequiresRegister(); |
| 5644 | } |
| 5645 | |
| Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5646 | static bool CanEncode32BitConstantAsImmediate( |
| 5647 | CodeGeneratorARMVIXL* codegen, |
| 5648 | uint32_t value, |
| 5649 | Opcode opcode, |
| 5650 | vixl32::FlagsUpdate flags_update = vixl32::FlagsUpdate::DontCare) { |
| 5651 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 5652 | if (assembler->ShifterOperandCanHold(opcode, value, flags_update)) { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5653 | return true; |
| 5654 | } |
| 5655 | Opcode neg_opcode = kNoOperand; |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5656 | uint32_t neg_value = 0; |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5657 | switch (opcode) { |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5658 | case AND: neg_opcode = BIC; neg_value = ~value; break; |
| 5659 | case ORR: neg_opcode = ORN; neg_value = ~value; break; |
| 5660 | case ADD: neg_opcode = SUB; neg_value = -value; break; |
| 5661 | case ADC: neg_opcode = SBC; neg_value = ~value; break; |
| 5662 | case SUB: neg_opcode = ADD; neg_value = -value; break; |
| 5663 | case SBC: neg_opcode = ADC; neg_value = ~value; break; |
| 5664 | case MOV: neg_opcode = MVN; neg_value = ~value; break; |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5665 | default: |
| 5666 | return false; |
| 5667 | } |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5668 | |
| Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5669 | if (assembler->ShifterOperandCanHold(neg_opcode, neg_value, flags_update)) { |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 5670 | return true; |
| 5671 | } |
| 5672 | |
| 5673 | return opcode == AND && IsPowerOfTwo(value + 1); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 5674 | } |
| 5675 | |
| Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 5676 | bool LocationsBuilderARMVIXL::CanEncodeConstantAsImmediate(HConstant* input_cst, Opcode opcode) { |
| 5677 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(input_cst)); |
| 5678 | if (DataType::Is64BitType(input_cst->GetType())) { |
| 5679 | Opcode high_opcode = opcode; |
| 5680 | vixl32::FlagsUpdate low_flags_update = vixl32::FlagsUpdate::DontCare; |
| 5681 | switch (opcode) { |
| 5682 | case SUB: |
| 5683 | // Flip the operation to an ADD. |
| 5684 | value = -value; |
| 5685 | opcode = ADD; |
| 5686 | FALLTHROUGH_INTENDED; |
| 5687 | case ADD: |
| 5688 | if (Low32Bits(value) == 0u) { |
| 5689 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), opcode); |
| 5690 | } |
| 5691 | high_opcode = ADC; |
| 5692 | low_flags_update = vixl32::FlagsUpdate::SetFlags; |
| 5693 | break; |
| 5694 | default: |
| 5695 | break; |
| 5696 | } |
| 5697 | return CanEncode32BitConstantAsImmediate(codegen_, High32Bits(value), high_opcode) && |
| 5698 | CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode, low_flags_update); |
| 5699 | } else { |
| 5700 | return CanEncode32BitConstantAsImmediate(codegen_, Low32Bits(value), opcode); |
| 5701 | } |
| 5702 | } |
| 5703 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5704 | void InstructionCodeGeneratorARMVIXL::HandleFieldGet(HInstruction* instruction, |
| 5705 | const FieldInfo& field_info) { |
| 5706 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
| 5707 | |
| 5708 | LocationSummary* locations = instruction->GetLocations(); |
| 5709 | vixl32::Register base = InputRegisterAt(instruction, 0); |
| 5710 | Location out = locations->Out(); |
| 5711 | bool is_volatile = field_info.IsVolatile(); |
| 5712 | bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd(); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5713 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); |
| 5714 | DataType::Type load_type = instruction->GetType(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5715 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 5716 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5717 | switch (load_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5718 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5719 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5720 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5721 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5722 | case DataType::Type::kInt16: |
| 5723 | case DataType::Type::kInt32: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5724 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5725 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5726 | LoadOperandType operand_type = GetLoadOperandType(load_type); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5727 | GetAssembler()->LoadFromOffset(operand_type, RegisterFrom(out), base, offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5728 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5729 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5730 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5731 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5732 | case DataType::Type::kReference: { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5733 | // /* HeapReference<Object> */ out = *(base + offset) |
| 5734 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 5735 | Location maybe_temp = (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location(); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5736 | // Note that a potential implicit null check is handled in this |
| 5737 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier call. |
| 5738 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5739 | instruction, out, base, offset, maybe_temp, /* needs_null_check= */ true); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 5740 | if (is_volatile) { |
| 5741 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5742 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5743 | } else { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5744 | { |
| 5745 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5746 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 5747 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(out), base, offset); |
| 5748 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5749 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5750 | if (is_volatile) { |
| 5751 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5752 | } |
| 5753 | // If read barriers are enabled, emit read barriers other than |
| 5754 | // Baker's using a slow path (and also unpoison the loaded |
| 5755 | // reference, if heap poisoning is enabled). |
| 5756 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, locations->InAt(0), offset); |
| 5757 | } |
| 5758 | break; |
| 5759 | } |
| 5760 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5761 | case DataType::Type::kInt64: { |
| 5762 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5763 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5764 | if (is_volatile && !atomic_ldrd_strd) { |
| 5765 | GenerateWideAtomicLoad(base, offset, LowRegisterFrom(out), HighRegisterFrom(out)); |
| 5766 | } else { |
| 5767 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out), base, offset); |
| 5768 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5769 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5770 | break; |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5771 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5772 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5773 | case DataType::Type::kFloat32: { |
| 5774 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5775 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5776 | GetAssembler()->LoadSFromOffset(SRegisterFrom(out), base, offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5777 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5778 | break; |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5779 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5780 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5781 | case DataType::Type::kFloat64: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 5782 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 5783 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5784 | vixl32::DRegister out_dreg = DRegisterFrom(out); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5785 | if (is_volatile && !atomic_ldrd_strd) { |
| 5786 | vixl32::Register lo = RegisterFrom(locations->GetTemp(0)); |
| 5787 | vixl32::Register hi = RegisterFrom(locations->GetTemp(1)); |
| 5788 | GenerateWideAtomicLoad(base, offset, lo, hi); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5789 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5790 | __ Vmov(out_dreg, lo, hi); |
| 5791 | } else { |
| 5792 | GetAssembler()->LoadDFromOffset(out_dreg, base, offset); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5793 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5794 | } |
| 5795 | break; |
| 5796 | } |
| 5797 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5798 | case DataType::Type::kUint32: |
| 5799 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5800 | case DataType::Type::kVoid: |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5801 | LOG(FATAL) << "Unreachable type " << load_type; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5802 | UNREACHABLE(); |
| 5803 | } |
| 5804 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5805 | if (is_volatile) { |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5806 | if (load_type == DataType::Type::kReference) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5807 | // Memory barriers, in the case of references, are also handled |
| 5808 | // in the previous switch statement. |
| 5809 | } else { |
| 5810 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 5811 | } |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | void LocationsBuilderARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5816 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5817 | } |
| 5818 | |
| 5819 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 5820 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5821 | } |
| 5822 | |
| 5823 | void LocationsBuilderARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5824 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5825 | } |
| 5826 | |
| 5827 | void InstructionCodeGeneratorARMVIXL::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 5828 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5829 | } |
| 5830 | |
| 5831 | void LocationsBuilderARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5832 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5833 | } |
| 5834 | |
| 5835 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 5836 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 5837 | } |
| 5838 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5839 | void LocationsBuilderARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5840 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 5841 | } |
| 5842 | |
| 5843 | void InstructionCodeGeneratorARMVIXL::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 5844 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
| 5845 | } |
| 5846 | |
| Vladimir Marko | 552a134 | 2017-10-31 10:56:47 +0000 | [diff] [blame] | 5847 | void LocationsBuilderARMVIXL::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5848 | codegen_->CreateStringBuilderAppendLocations(instruction, LocationFrom(r0)); |
| 5849 | } |
| 5850 | |
| 5851 | void InstructionCodeGeneratorARMVIXL::VisitStringBuilderAppend(HStringBuilderAppend* instruction) { |
| 5852 | __ Mov(r0, instruction->GetFormat()->GetValue()); |
| 5853 | codegen_->InvokeRuntime(kQuickStringBuilderAppend, instruction, instruction->GetDexPc()); |
| 5854 | } |
| 5855 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 5856 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5857 | HUnresolvedInstanceFieldGet* instruction) { |
| 5858 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5859 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5860 | instruction, instruction->GetFieldType(), calling_convention); |
| 5861 | } |
| 5862 | |
| 5863 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldGet( |
| 5864 | HUnresolvedInstanceFieldGet* instruction) { |
| 5865 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5866 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5867 | instruction->GetFieldType(), |
| 5868 | instruction->GetFieldIndex(), |
| 5869 | instruction->GetDexPc(), |
| 5870 | calling_convention); |
| 5871 | } |
| 5872 | |
| 5873 | void LocationsBuilderARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5874 | HUnresolvedInstanceFieldSet* instruction) { |
| 5875 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5876 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5877 | instruction, instruction->GetFieldType(), calling_convention); |
| 5878 | } |
| 5879 | |
| 5880 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedInstanceFieldSet( |
| 5881 | HUnresolvedInstanceFieldSet* instruction) { |
| 5882 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5883 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5884 | instruction->GetFieldType(), |
| 5885 | instruction->GetFieldIndex(), |
| 5886 | instruction->GetDexPc(), |
| 5887 | calling_convention); |
| 5888 | } |
| 5889 | |
| 5890 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5891 | HUnresolvedStaticFieldGet* instruction) { |
| 5892 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5893 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5894 | instruction, instruction->GetFieldType(), calling_convention); |
| 5895 | } |
| 5896 | |
| 5897 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldGet( |
| 5898 | HUnresolvedStaticFieldGet* instruction) { |
| 5899 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5900 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5901 | instruction->GetFieldType(), |
| 5902 | instruction->GetFieldIndex(), |
| 5903 | instruction->GetDexPc(), |
| 5904 | calling_convention); |
| 5905 | } |
| 5906 | |
| 5907 | void LocationsBuilderARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5908 | HUnresolvedStaticFieldSet* instruction) { |
| 5909 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5910 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 5911 | instruction, instruction->GetFieldType(), calling_convention); |
| 5912 | } |
| 5913 | |
| 5914 | void InstructionCodeGeneratorARMVIXL::VisitUnresolvedStaticFieldSet( |
| 5915 | HUnresolvedStaticFieldSet* instruction) { |
| 5916 | FieldAccessCallingConventionARMVIXL calling_convention; |
| 5917 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5918 | instruction->GetFieldType(), |
| 5919 | instruction->GetFieldIndex(), |
| 5920 | instruction->GetDexPc(), |
| 5921 | calling_convention); |
| 5922 | } |
| 5923 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5924 | void LocationsBuilderARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 5925 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5926 | locations->SetInAt(0, Location::RequiresRegister()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5927 | } |
| 5928 | |
| 5929 | void CodeGeneratorARMVIXL::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5930 | if (CanMoveNullCheckToUser(instruction)) { |
| 5931 | return; |
| 5932 | } |
| 5933 | |
| 5934 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 5935 | // Ensure the pc position is recorded immediately after the `ldr` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 5936 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 5937 | vixl32::kMaxInstructionSizeInBytes, |
| 5938 | CodeBufferCheckScope::kMaximumSize); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5939 | __ ldr(temps.Acquire(), MemOperand(InputRegisterAt(instruction, 0))); |
| 5940 | RecordPcInfo(instruction, instruction->GetDexPc()); |
| 5941 | } |
| 5942 | |
| 5943 | void CodeGeneratorARMVIXL::GenerateExplicitNullCheck(HNullCheck* instruction) { |
| 5944 | NullCheckSlowPathARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5945 | new (GetScopedAllocator()) NullCheckSlowPathARMVIXL(instruction); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5946 | AddSlowPath(slow_path); |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 5947 | __ CompareAndBranchIfZero(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 5948 | } |
| 5949 | |
| 5950 | void InstructionCodeGeneratorARMVIXL::VisitNullCheck(HNullCheck* instruction) { |
| 5951 | codegen_->GenerateNullCheck(instruction); |
| 5952 | } |
| 5953 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5954 | void CodeGeneratorARMVIXL::LoadFromShiftedRegOffset(DataType::Type type, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5955 | Location out_loc, |
| 5956 | vixl32::Register base, |
| 5957 | vixl32::Register reg_index, |
| 5958 | vixl32::Condition cond) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5959 | uint32_t shift_count = DataType::SizeShift(type); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5960 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5961 | |
| 5962 | switch (type) { |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5963 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5964 | case DataType::Type::kUint8: |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5965 | __ Ldrb(cond, RegisterFrom(out_loc), mem_address); |
| 5966 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5967 | case DataType::Type::kInt8: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5968 | __ Ldrsb(cond, RegisterFrom(out_loc), mem_address); |
| 5969 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5970 | case DataType::Type::kUint16: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5971 | __ Ldrh(cond, RegisterFrom(out_loc), mem_address); |
| 5972 | break; |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5973 | case DataType::Type::kInt16: |
| 5974 | __ Ldrsh(cond, RegisterFrom(out_loc), mem_address); |
| 5975 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5976 | case DataType::Type::kReference: |
| 5977 | case DataType::Type::kInt32: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5978 | __ Ldr(cond, RegisterFrom(out_loc), mem_address); |
| 5979 | break; |
| 5980 | // T32 doesn't support LoadFromShiftedRegOffset mem address mode for these types. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5981 | case DataType::Type::kInt64: |
| 5982 | case DataType::Type::kFloat32: |
| 5983 | case DataType::Type::kFloat64: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5984 | default: |
| 5985 | LOG(FATAL) << "Unreachable type " << type; |
| 5986 | UNREACHABLE(); |
| 5987 | } |
| 5988 | } |
| 5989 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5990 | void CodeGeneratorARMVIXL::StoreToShiftedRegOffset(DataType::Type type, |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5991 | Location loc, |
| 5992 | vixl32::Register base, |
| 5993 | vixl32::Register reg_index, |
| 5994 | vixl32::Condition cond) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5995 | uint32_t shift_count = DataType::SizeShift(type); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 5996 | MemOperand mem_address(base, reg_index, vixl32::LSL, shift_count); |
| 5997 | |
| 5998 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5999 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6000 | case DataType::Type::kUint8: |
| 6001 | case DataType::Type::kInt8: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6002 | __ Strb(cond, RegisterFrom(loc), mem_address); |
| 6003 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6004 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6005 | case DataType::Type::kInt16: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6006 | __ Strh(cond, RegisterFrom(loc), mem_address); |
| 6007 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6008 | case DataType::Type::kReference: |
| 6009 | case DataType::Type::kInt32: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6010 | __ Str(cond, RegisterFrom(loc), mem_address); |
| 6011 | break; |
| 6012 | // T32 doesn't support StoreToShiftedRegOffset mem address mode for these types. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6013 | case DataType::Type::kInt64: |
| 6014 | case DataType::Type::kFloat32: |
| 6015 | case DataType::Type::kFloat64: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6016 | default: |
| 6017 | LOG(FATAL) << "Unreachable type " << type; |
| 6018 | UNREACHABLE(); |
| 6019 | } |
| 6020 | } |
| 6021 | |
| 6022 | void LocationsBuilderARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| 6023 | bool object_array_get_with_read_barrier = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6024 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6025 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6026 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, |
| 6027 | object_array_get_with_read_barrier |
| 6028 | ? LocationSummary::kCallOnSlowPath |
| 6029 | : LocationSummary::kNoCall); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6030 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6031 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6032 | } |
| 6033 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6034 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6035 | if (DataType::IsFloatingPointType(instruction->GetType())) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6036 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 6037 | } else { |
| 6038 | // The output overlaps in the case of an object array get with |
| 6039 | // read barriers enabled: we do not want the move to overwrite the |
| 6040 | // array's location, as we need it to emit the read barrier. |
| 6041 | locations->SetOut( |
| 6042 | Location::RequiresRegister(), |
| 6043 | object_array_get_with_read_barrier ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 6044 | } |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6045 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6046 | if (instruction->GetIndex()->IsConstant()) { |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6047 | // Array loads with constant index are treated as field loads. |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6048 | // We need a temporary register for the read barrier load in |
| 6049 | // CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier() |
| 6050 | // only if the offset is too big. |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6051 | uint32_t offset = CodeGenerator::GetArrayDataOffset(instruction); |
| 6052 | uint32_t index = instruction->GetIndex()->AsIntConstant()->GetValue(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6053 | offset += index << DataType::SizeShift(DataType::Type::kReference); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6054 | if (offset >= kReferenceLoadMinFarOffset) { |
| 6055 | locations->AddTemp(Location::RequiresRegister()); |
| 6056 | } |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6057 | } else { |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 6058 | // We need a non-scratch temporary for the array data pointer in |
| 6059 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(). |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6060 | locations->AddTemp(Location::RequiresRegister()); |
| 6061 | } |
| 6062 | } else if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 6063 | // Also need a temporary for String compression feature. |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6064 | locations->AddTemp(Location::RequiresRegister()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6065 | } |
| 6066 | } |
| 6067 | |
| 6068 | void InstructionCodeGeneratorARMVIXL::VisitArrayGet(HArrayGet* instruction) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6069 | LocationSummary* locations = instruction->GetLocations(); |
| 6070 | Location obj_loc = locations->InAt(0); |
| 6071 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6072 | Location index = locations->InAt(1); |
| 6073 | Location out_loc = locations->Out(); |
| 6074 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6075 | DataType::Type type = instruction->GetType(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6076 | const bool maybe_compressed_char_at = mirror::kUseStringCompression && |
| 6077 | instruction->IsStringCharAt(); |
| 6078 | HInstruction* array_instr = instruction->GetArray(); |
| 6079 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6080 | |
| 6081 | switch (type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6082 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6083 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6084 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6085 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6086 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6087 | case DataType::Type::kInt32: { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6088 | vixl32::Register length; |
| 6089 | if (maybe_compressed_char_at) { |
| 6090 | length = RegisterFrom(locations->GetTemp(0)); |
| 6091 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6092 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6093 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6094 | GetAssembler()->LoadFromOffset(kLoadWord, length, obj, count_offset); |
| 6095 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6096 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6097 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6098 | int32_t const_index = Int32ConstantFrom(index); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6099 | if (maybe_compressed_char_at) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6100 | vixl32::Label uncompressed_load, done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6101 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6102 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6103 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6104 | "Expecting 0=compressed, 1=uncompressed"); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6105 | __ B(cs, &uncompressed_load, /* is_far_target= */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6106 | GetAssembler()->LoadFromOffset(kLoadUnsignedByte, |
| 6107 | RegisterFrom(out_loc), |
| 6108 | obj, |
| 6109 | data_offset + const_index); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6110 | __ B(final_label); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6111 | __ Bind(&uncompressed_load); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6112 | GetAssembler()->LoadFromOffset(GetLoadOperandType(DataType::Type::kUint16), |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6113 | RegisterFrom(out_loc), |
| 6114 | obj, |
| 6115 | data_offset + (const_index << 1)); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6116 | if (done.IsReferenced()) { |
| 6117 | __ Bind(&done); |
| 6118 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6119 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6120 | uint32_t full_offset = data_offset + (const_index << DataType::SizeShift(type)); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6121 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6122 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6123 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6124 | LoadOperandType load_type = GetLoadOperandType(type); |
| 6125 | GetAssembler()->LoadFromOffset(load_type, RegisterFrom(out_loc), obj, full_offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6126 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6127 | } |
| 6128 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6129 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6130 | vixl32::Register temp = temps.Acquire(); |
| 6131 | |
| 6132 | if (has_intermediate_address) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6133 | // We do not need to compute the intermediate address from the array: the |
| 6134 | // input instruction has done it already. See the comment in |
| 6135 | // `TryExtractArrayAccessAddress()`. |
| 6136 | if (kIsDebugBuild) { |
| 6137 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6138 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6139 | } |
| 6140 | temp = obj; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6141 | } else { |
| 6142 | __ Add(temp, obj, data_offset); |
| 6143 | } |
| 6144 | if (maybe_compressed_char_at) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6145 | vixl32::Label uncompressed_load, done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6146 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6147 | __ Lsrs(length, length, 1u); // LSRS has a 16-bit encoding, TST (immediate) does not. |
| 6148 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 6149 | "Expecting 0=compressed, 1=uncompressed"); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6150 | __ B(cs, &uncompressed_load, /* is_far_target= */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6151 | __ Ldrb(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 0)); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6152 | __ B(final_label); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6153 | __ Bind(&uncompressed_load); |
| 6154 | __ Ldrh(RegisterFrom(out_loc), MemOperand(temp, RegisterFrom(index), vixl32::LSL, 1)); |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 6155 | if (done.IsReferenced()) { |
| 6156 | __ Bind(&done); |
| 6157 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6158 | } else { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6159 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6160 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6161 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6162 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6163 | } |
| 6164 | } |
| 6165 | break; |
| 6166 | } |
| 6167 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6168 | case DataType::Type::kReference: { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6169 | // The read barrier instrumentation of object ArrayGet |
| 6170 | // instructions does not support the HIntermediateAddress |
| 6171 | // instruction. |
| 6172 | DCHECK(!(has_intermediate_address && kEmitCompilerReadBarrier)); |
| 6173 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6174 | static_assert( |
| 6175 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6176 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 6177 | // /* HeapReference<Object> */ out = |
| 6178 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6179 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6180 | // Note that a potential implicit null check is handled in this |
| 6181 | // CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier call. |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6182 | DCHECK(!instruction->CanDoImplicitNullCheckOn(instruction->InputAt(0))); |
| 6183 | if (index.IsConstant()) { |
| 6184 | // Array load with a constant index can be treated as a field load. |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6185 | Location maybe_temp = |
| 6186 | (locations->GetTempCount() != 0) ? locations->GetTemp(0) : Location(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6187 | data_offset += Int32ConstantFrom(index) << DataType::SizeShift(type); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6188 | codegen_->GenerateFieldLoadWithBakerReadBarrier(instruction, |
| 6189 | out_loc, |
| 6190 | obj, |
| 6191 | data_offset, |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6192 | maybe_temp, |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6193 | /* needs_null_check= */ false); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6194 | } else { |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 6195 | Location temp = locations->GetTemp(0); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6196 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6197 | out_loc, obj, data_offset, index, temp, /* needs_null_check= */ false); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 6198 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6199 | } else { |
| 6200 | vixl32::Register out = OutputRegister(instruction); |
| 6201 | if (index.IsConstant()) { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6202 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| 6203 | { |
| 6204 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6205 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6206 | GetAssembler()->LoadFromOffset(kLoadWord, out, obj, offset); |
| 6207 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6208 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6209 | // If read barriers are enabled, emit read barriers other than |
| 6210 | // Baker's using a slow path (and also unpoison the loaded |
| 6211 | // reference, if heap poisoning is enabled). |
| 6212 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 6213 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6214 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6215 | vixl32::Register temp = temps.Acquire(); |
| 6216 | |
| 6217 | if (has_intermediate_address) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6218 | // We do not need to compute the intermediate address from the array: the |
| 6219 | // input instruction has done it already. See the comment in |
| 6220 | // `TryExtractArrayAccessAddress()`. |
| 6221 | if (kIsDebugBuild) { |
| 6222 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6223 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6224 | } |
| 6225 | temp = obj; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6226 | } else { |
| 6227 | __ Add(temp, obj, data_offset); |
| 6228 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6229 | { |
| 6230 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6231 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| 6232 | codegen_->LoadFromShiftedRegOffset(type, out_loc, temp, RegisterFrom(index)); |
| 6233 | temps.Close(); |
| 6234 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6235 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6236 | // If read barriers are enabled, emit read barriers other than |
| 6237 | // Baker's using a slow path (and also unpoison the loaded |
| 6238 | // reference, if heap poisoning is enabled). |
| 6239 | codegen_->MaybeGenerateReadBarrierSlow( |
| 6240 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 6241 | } |
| 6242 | } |
| 6243 | break; |
| 6244 | } |
| 6245 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6246 | case DataType::Type::kInt64: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6247 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6248 | // As two macro instructions can be emitted the max size is doubled. |
| 6249 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6250 | if (index.IsConstant()) { |
| 6251 | size_t offset = |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6252 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6253 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), obj, offset); |
| 6254 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6255 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6256 | vixl32::Register temp = temps.Acquire(); |
| 6257 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6258 | GetAssembler()->LoadFromOffset(kLoadWordPair, LowRegisterFrom(out_loc), temp, data_offset); |
| 6259 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6260 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6261 | break; |
| 6262 | } |
| 6263 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6264 | case DataType::Type::kFloat32: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6265 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6266 | // As two macro instructions can be emitted the max size is doubled. |
| 6267 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6268 | vixl32::SRegister out = SRegisterFrom(out_loc); |
| 6269 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6270 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6271 | GetAssembler()->LoadSFromOffset(out, obj, offset); |
| 6272 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6273 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6274 | vixl32::Register temp = temps.Acquire(); |
| 6275 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6276 | GetAssembler()->LoadSFromOffset(out, temp, data_offset); |
| 6277 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6278 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6279 | break; |
| 6280 | } |
| 6281 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6282 | case DataType::Type::kFloat64: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6283 | // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6284 | // As two macro instructions can be emitted the max size is doubled. |
| 6285 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6286 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6287 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6288 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), obj, offset); |
| 6289 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6290 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6291 | vixl32::Register temp = temps.Acquire(); |
| 6292 | __ Add(temp, obj, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6293 | GetAssembler()->LoadDFromOffset(DRegisterFrom(out_loc), temp, data_offset); |
| 6294 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6295 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6296 | break; |
| 6297 | } |
| 6298 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6299 | case DataType::Type::kUint32: |
| 6300 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6301 | case DataType::Type::kVoid: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6302 | LOG(FATAL) << "Unreachable type " << type; |
| 6303 | UNREACHABLE(); |
| 6304 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6305 | } |
| 6306 | |
| 6307 | void LocationsBuilderARMVIXL::VisitArraySet(HArraySet* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6308 | DataType::Type value_type = instruction->GetComponentType(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6309 | |
| 6310 | bool needs_write_barrier = |
| 6311 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6312 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6313 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6314 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6315 | instruction, |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6316 | needs_type_check ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6317 | |
| 6318 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6319 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6320 | if (DataType::IsFloatingPointType(value_type)) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6321 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 6322 | } else { |
| 6323 | locations->SetInAt(2, Location::RequiresRegister()); |
| 6324 | } |
| 6325 | if (needs_write_barrier) { |
| 6326 | // Temporary registers for the write barrier. |
| 6327 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 6328 | locations->AddTemp(Location::RequiresRegister()); |
| 6329 | } |
| 6330 | } |
| 6331 | |
| 6332 | void InstructionCodeGeneratorARMVIXL::VisitArraySet(HArraySet* instruction) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6333 | LocationSummary* locations = instruction->GetLocations(); |
| 6334 | vixl32::Register array = InputRegisterAt(instruction, 0); |
| 6335 | Location index = locations->InAt(1); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6336 | DataType::Type value_type = instruction->GetComponentType(); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6337 | bool needs_type_check = instruction->NeedsTypeCheck(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6338 | bool needs_write_barrier = |
| 6339 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 6340 | uint32_t data_offset = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6341 | mirror::Array::DataOffset(DataType::Size(value_type)).Uint32Value(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6342 | Location value_loc = locations->InAt(2); |
| 6343 | HInstruction* array_instr = instruction->GetArray(); |
| 6344 | bool has_intermediate_address = array_instr->IsIntermediateAddress(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6345 | |
| 6346 | switch (value_type) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6347 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6348 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6349 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6350 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6351 | case DataType::Type::kInt16: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6352 | case DataType::Type::kInt32: { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6353 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6354 | int32_t const_index = Int32ConstantFrom(index); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6355 | uint32_t full_offset = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6356 | data_offset + (const_index << DataType::SizeShift(value_type)); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6357 | StoreOperandType store_type = GetStoreOperandType(value_type); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6358 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6359 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6360 | GetAssembler()->StoreToOffset(store_type, RegisterFrom(value_loc), array, full_offset); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6361 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6362 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6363 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6364 | vixl32::Register temp = temps.Acquire(); |
| 6365 | |
| 6366 | if (has_intermediate_address) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6367 | // We do not need to compute the intermediate address from the array: the |
| 6368 | // input instruction has done it already. See the comment in |
| 6369 | // `TryExtractArrayAccessAddress()`. |
| 6370 | if (kIsDebugBuild) { |
| 6371 | HIntermediateAddress* tmp = array_instr->AsIntermediateAddress(); |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6372 | DCHECK_EQ(Uint64ConstantFrom(tmp->GetOffset()), data_offset); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6373 | } |
| 6374 | temp = array; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6375 | } else { |
| 6376 | __ Add(temp, array, data_offset); |
| 6377 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6378 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6379 | EmissionCheckScope guard(GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6380 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6381 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6382 | } |
| 6383 | break; |
| 6384 | } |
| 6385 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6386 | case DataType::Type::kReference: { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6387 | vixl32::Register value = RegisterFrom(value_loc); |
| 6388 | // TryExtractArrayAccessAddress optimization is never applied for non-primitive ArraySet. |
| 6389 | // See the comment in instruction_simplifier_shared.cc. |
| 6390 | DCHECK(!has_intermediate_address); |
| 6391 | |
| 6392 | if (instruction->InputAt(2)->IsNullConstant()) { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6393 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6394 | // As two macro instructions can be emitted the max size is doubled. |
| 6395 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6396 | // Just setting null. |
| 6397 | if (index.IsConstant()) { |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6398 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6399 | GetAssembler()->StoreToOffset(kStoreWord, value, array, offset); |
| 6400 | } else { |
| 6401 | DCHECK(index.IsRegister()) << index; |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6402 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6403 | vixl32::Register temp = temps.Acquire(); |
| 6404 | __ Add(temp, array, data_offset); |
| 6405 | codegen_->StoreToShiftedRegOffset(value_type, value_loc, temp, RegisterFrom(index)); |
| 6406 | } |
| 6407 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6408 | DCHECK(!needs_write_barrier); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6409 | DCHECK(!needs_type_check); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6410 | break; |
| 6411 | } |
| 6412 | |
| 6413 | DCHECK(needs_write_barrier); |
| 6414 | Location temp1_loc = locations->GetTemp(0); |
| 6415 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 6416 | Location temp2_loc = locations->GetTemp(1); |
| 6417 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6418 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6419 | bool can_value_be_null = instruction->GetValueCanBeNull(); |
| 6420 | vixl32::Label do_store; |
| 6421 | if (can_value_be_null) { |
| 6422 | __ CompareAndBranchIfZero(value, &do_store, /* is_far_target= */ false); |
| 6423 | } |
| 6424 | |
| 6425 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 6426 | if (needs_type_check) { |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6427 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathARMVIXL(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6428 | codegen_->AddSlowPath(slow_path); |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6429 | |
| 6430 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6431 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6432 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6433 | |
| 6434 | // Note that when read barriers are enabled, the type checks |
| 6435 | // are performed without read barriers. This is fine, even in |
| 6436 | // the case where a class object is in the from-space after |
| 6437 | // the flip, as a comparison involving such a type would not |
| 6438 | // produce a false positive; it may of course produce a false |
| 6439 | // negative, in which case we would take the ArraySet slow |
| 6440 | // path. |
| 6441 | |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6442 | { |
| 6443 | // Ensure we record the pc position immediately after the `ldr` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6444 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6445 | vixl32::kMaxInstructionSizeInBytes, |
| 6446 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6447 | // /* HeapReference<Class> */ temp1 = array->klass_ |
| 6448 | __ ldr(temp1, MemOperand(array, class_offset)); |
| 6449 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6450 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6451 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6452 | |
| 6453 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 6454 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 6455 | // /* HeapReference<Class> */ temp2 = value->klass_ |
| 6456 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, value, class_offset); |
| 6457 | // If heap poisoning is enabled, no need to unpoison `temp1` |
| 6458 | // nor `temp2`, as we are comparing two poisoned references. |
| 6459 | __ Cmp(temp1, temp2); |
| 6460 | |
| 6461 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6462 | vixl32::Label do_put; |
| 6463 | __ B(eq, &do_put, /* is_far_target= */ false); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6464 | // If heap poisoning is enabled, the `temp1` reference has |
| 6465 | // not been unpoisoned yet; unpoison it now. |
| 6466 | GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 6467 | |
| 6468 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 6469 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 6470 | // If heap poisoning is enabled, no need to unpoison |
| 6471 | // `temp1`, as we are comparing against null below. |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6472 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6473 | __ Bind(&do_put); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6474 | } else { |
| 6475 | __ B(ne, slow_path->GetEntryLabel()); |
| 6476 | } |
| 6477 | } |
| 6478 | |
| Vladimir Marko | 8fa839c | 2019-05-16 12:50:47 +0000 | [diff] [blame] | 6479 | codegen_->MarkGCCard(temp1, temp2, array, value, /* can_be_null= */ false); |
| 6480 | |
| 6481 | if (can_value_be_null) { |
| 6482 | DCHECK(do_store.IsReferenced()); |
| 6483 | __ Bind(&do_store); |
| 6484 | } |
| 6485 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6486 | vixl32::Register source = value; |
| 6487 | if (kPoisonHeapReferences) { |
| 6488 | // Note that in the case where `value` is a null reference, |
| 6489 | // we do not enter this block, as a null reference does not |
| 6490 | // need poisoning. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6491 | DCHECK_EQ(value_type, DataType::Type::kReference); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6492 | __ Mov(temp1, value); |
| 6493 | GetAssembler()->PoisonHeapReference(temp1); |
| 6494 | source = temp1; |
| 6495 | } |
| 6496 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6497 | { |
| 6498 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6499 | // As two macro instructions can be emitted the max size is doubled. |
| 6500 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| 6501 | if (index.IsConstant()) { |
| 6502 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| 6503 | GetAssembler()->StoreToOffset(kStoreWord, source, array, offset); |
| 6504 | } else { |
| 6505 | DCHECK(index.IsRegister()) << index; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6506 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6507 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 6508 | vixl32::Register temp = temps.Acquire(); |
| 6509 | __ Add(temp, array, data_offset); |
| 6510 | codegen_->StoreToShiftedRegOffset(value_type, |
| 6511 | LocationFrom(source), |
| 6512 | temp, |
| 6513 | RegisterFrom(index)); |
| 6514 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6515 | |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6516 | if (can_value_be_null || !needs_type_check) { |
| 6517 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6518 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6519 | } |
| 6520 | |
| Vladimir Marko | 0dda8c8 | 2019-05-16 12:47:40 +0000 | [diff] [blame] | 6521 | if (slow_path != nullptr) { |
| 6522 | __ Bind(slow_path->GetExitLabel()); |
| 6523 | } |
| 6524 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6525 | break; |
| 6526 | } |
| 6527 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6528 | case DataType::Type::kInt64: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6529 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6530 | // As two macro instructions can be emitted the max size is doubled. |
| 6531 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6532 | Location value = locations->InAt(2); |
| 6533 | if (index.IsConstant()) { |
| 6534 | size_t offset = |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6535 | (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6536 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), array, offset); |
| 6537 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6538 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6539 | vixl32::Register temp = temps.Acquire(); |
| 6540 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6541 | GetAssembler()->StoreToOffset(kStoreWordPair, LowRegisterFrom(value), temp, data_offset); |
| 6542 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6543 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6544 | break; |
| 6545 | } |
| 6546 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6547 | case DataType::Type::kFloat32: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6548 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6549 | // As two macro instructions can be emitted the max size is doubled. |
| 6550 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6551 | Location value = locations->InAt(2); |
| 6552 | DCHECK(value.IsFpuRegister()); |
| 6553 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6554 | size_t offset = (Int32ConstantFrom(index) << TIMES_4) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6555 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), array, offset); |
| 6556 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6557 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6558 | vixl32::Register temp = temps.Acquire(); |
| 6559 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_4)); |
| 6560 | GetAssembler()->StoreSToOffset(SRegisterFrom(value), temp, data_offset); |
| 6561 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6562 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6563 | break; |
| 6564 | } |
| 6565 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6566 | case DataType::Type::kFloat64: { |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6567 | // Ensure that between store and MaybeRecordImplicitNullCheck there are no pools emitted. |
| 6568 | // As two macro instructions can be emitted the max size is doubled. |
| 6569 | EmissionCheckScope guard(GetVIXLAssembler(), 2 * kMaxMacroInstructionSizeInBytes); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6570 | Location value = locations->InAt(2); |
| 6571 | DCHECK(value.IsFpuRegisterPair()); |
| 6572 | if (index.IsConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6573 | size_t offset = (Int32ConstantFrom(index) << TIMES_8) + data_offset; |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6574 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), array, offset); |
| 6575 | } else { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6576 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6577 | vixl32::Register temp = temps.Acquire(); |
| 6578 | __ Add(temp, array, Operand(RegisterFrom(index), vixl32::LSL, TIMES_8)); |
| 6579 | GetAssembler()->StoreDToOffset(DRegisterFrom(value), temp, data_offset); |
| 6580 | } |
| Evgeny Astigeevich | 98416bf | 2019-09-09 14:52:12 +0100 | [diff] [blame] | 6581 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6582 | break; |
| 6583 | } |
| 6584 | |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6585 | case DataType::Type::kUint32: |
| 6586 | case DataType::Type::kUint64: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6587 | case DataType::Type::kVoid: |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6588 | LOG(FATAL) << "Unreachable type " << value_type; |
| 6589 | UNREACHABLE(); |
| 6590 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6591 | } |
| 6592 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6593 | void LocationsBuilderARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6594 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6595 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6596 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6597 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6598 | } |
| 6599 | |
| 6600 | void InstructionCodeGeneratorARMVIXL::VisitArrayLength(HArrayLength* instruction) { |
| 6601 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
| 6602 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| 6603 | vixl32::Register out = OutputRegister(instruction); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6604 | { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 6605 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 6606 | vixl32::kMaxInstructionSizeInBytes, |
| 6607 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 6608 | __ ldr(out, MemOperand(obj, offset)); |
| 6609 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 6610 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6611 | // Mask out compression flag from String's array length. |
| 6612 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6613 | __ Lsr(out, out, 1u); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 6614 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6615 | } |
| 6616 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6617 | void LocationsBuilderARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6618 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6619 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6620 | |
| 6621 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6622 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->GetOffset())); |
| 6623 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 6624 | } |
| 6625 | |
| 6626 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddress(HIntermediateAddress* instruction) { |
| 6627 | vixl32::Register out = OutputRegister(instruction); |
| 6628 | vixl32::Register first = InputRegisterAt(instruction, 0); |
| 6629 | Location second = instruction->GetLocations()->InAt(1); |
| 6630 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6631 | if (second.IsRegister()) { |
| 6632 | __ Add(out, first, RegisterFrom(second)); |
| 6633 | } else { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6634 | __ Add(out, first, Int32ConstantFrom(second)); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 6635 | } |
| 6636 | } |
| 6637 | |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 6638 | void LocationsBuilderARMVIXL::VisitIntermediateAddressIndex( |
| 6639 | HIntermediateAddressIndex* instruction) { |
| 6640 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6641 | } |
| 6642 | |
| 6643 | void InstructionCodeGeneratorARMVIXL::VisitIntermediateAddressIndex( |
| 6644 | HIntermediateAddressIndex* instruction) { |
| 6645 | LOG(FATAL) << "Unreachable " << instruction->GetId(); |
| 6646 | } |
| 6647 | |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6648 | void LocationsBuilderARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 6649 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 6650 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 6651 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 6652 | caller_saves.Add(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 6653 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6654 | |
| 6655 | HInstruction* index = instruction->InputAt(0); |
| 6656 | HInstruction* length = instruction->InputAt(1); |
| 6657 | // If both index and length are constants we can statically check the bounds. But if at least one |
| 6658 | // of them is not encodable ArmEncodableConstantOrRegister will create |
| 6659 | // Location::RequiresRegister() which is not desired to happen. Instead we create constant |
| 6660 | // locations. |
| 6661 | bool both_const = index->IsConstant() && length->IsConstant(); |
| 6662 | locations->SetInAt(0, both_const |
| 6663 | ? Location::ConstantLocation(index->AsConstant()) |
| 6664 | : ArmEncodableConstantOrRegister(index, CMP)); |
| 6665 | locations->SetInAt(1, both_const |
| 6666 | ? Location::ConstantLocation(length->AsConstant()) |
| 6667 | : ArmEncodableConstantOrRegister(length, CMP)); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6668 | } |
| 6669 | |
| 6670 | void InstructionCodeGeneratorARMVIXL::VisitBoundsCheck(HBoundsCheck* instruction) { |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6671 | LocationSummary* locations = instruction->GetLocations(); |
| 6672 | Location index_loc = locations->InAt(0); |
| 6673 | Location length_loc = locations->InAt(1); |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6674 | |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6675 | if (length_loc.IsConstant()) { |
| 6676 | int32_t length = Int32ConstantFrom(length_loc); |
| 6677 | if (index_loc.IsConstant()) { |
| 6678 | // BCE will remove the bounds check if we are guaranteed to pass. |
| 6679 | int32_t index = Int32ConstantFrom(index_loc); |
| 6680 | if (index < 0 || index >= length) { |
| 6681 | SlowPathCodeARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6682 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6683 | codegen_->AddSlowPath(slow_path); |
| 6684 | __ B(slow_path->GetEntryLabel()); |
| 6685 | } else { |
| 6686 | // Some optimization after BCE may have generated this, and we should not |
| 6687 | // generate a bounds check if it is a valid range. |
| 6688 | } |
| 6689 | return; |
| 6690 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6691 | |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6692 | SlowPathCodeARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6693 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6694 | __ Cmp(RegisterFrom(index_loc), length); |
| 6695 | codegen_->AddSlowPath(slow_path); |
| 6696 | __ B(hs, slow_path->GetEntryLabel()); |
| 6697 | } else { |
| 6698 | SlowPathCodeARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6699 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathARMVIXL(instruction); |
| Artem Serov | 2dd053d | 2017-03-08 14:54:06 +0000 | [diff] [blame] | 6700 | __ Cmp(RegisterFrom(length_loc), InputOperandAt(instruction, 0)); |
| 6701 | codegen_->AddSlowPath(slow_path); |
| 6702 | __ B(ls, slow_path->GetEntryLabel()); |
| 6703 | } |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6704 | } |
| 6705 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6706 | void CodeGeneratorARMVIXL::MarkGCCard(vixl32::Register temp, |
| 6707 | vixl32::Register card, |
| 6708 | vixl32::Register object, |
| 6709 | vixl32::Register value, |
| 6710 | bool can_be_null) { |
| 6711 | vixl32::Label is_null; |
| 6712 | if (can_be_null) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6713 | __ CompareAndBranchIfZero(value, &is_null); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6714 | } |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6715 | // Load the address of the card table into `card`. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6716 | GetAssembler()->LoadFromOffset( |
| 6717 | kLoadWord, card, tr, Thread::CardTableOffset<kArmPointerSize>().Int32Value()); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6718 | // Calculate the offset (in the card table) of the card corresponding to |
| 6719 | // `object`. |
| Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 6720 | __ Lsr(temp, object, Operand::From(gc::accounting::CardTable::kCardShift)); |
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 6721 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the |
| 6722 | // `object`'s card. |
| 6723 | // |
| 6724 | // Register `card` contains the address of the card table. Note that the card |
| 6725 | // table's base is biased during its creation so that it always starts at an |
| 6726 | // address whose least-significant byte is equal to `kCardDirty` (see |
| 6727 | // art::gc::accounting::CardTable::Create). Therefore the STRB instruction |
| 6728 | // below writes the `kCardDirty` (byte) value into the `object`'s card |
| 6729 | // (located at `card + object >> kCardShift`). |
| 6730 | // |
| 6731 | // This dual use of the value in register `card` (1. to calculate the location |
| 6732 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load |
| 6733 | // (no need to explicitly load `kCardDirty` as an immediate value). |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6734 | __ Strb(card, MemOperand(card, temp)); |
| 6735 | if (can_be_null) { |
| 6736 | __ Bind(&is_null); |
| 6737 | } |
| 6738 | } |
| 6739 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6740 | void LocationsBuilderARMVIXL::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
| 6741 | LOG(FATAL) << "Unreachable"; |
| 6742 | } |
| 6743 | |
| 6744 | void InstructionCodeGeneratorARMVIXL::VisitParallelMove(HParallelMove* instruction) { |
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6745 | if (instruction->GetNext()->IsSuspendCheck() && |
| 6746 | instruction->GetBlock()->GetLoopInformation() != nullptr) { |
| 6747 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); |
| 6748 | // The back edge will generate the suspend check. |
| 6749 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); |
| 6750 | } |
| 6751 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6752 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 6753 | } |
| 6754 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6755 | void LocationsBuilderARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6756 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 6757 | instruction, LocationSummary::kCallOnSlowPath); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 6758 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6759 | } |
| 6760 | |
| 6761 | void InstructionCodeGeneratorARMVIXL::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 6762 | HBasicBlock* block = instruction->GetBlock(); |
| 6763 | if (block->GetLoopInformation() != nullptr) { |
| 6764 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 6765 | // The back edge will generate the suspend check. |
| 6766 | return; |
| 6767 | } |
| 6768 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 6769 | // The goto will generate the suspend check. |
| 6770 | return; |
| 6771 | } |
| 6772 | GenerateSuspendCheck(instruction, nullptr); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6773 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 13); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6774 | } |
| 6775 | |
| 6776 | void InstructionCodeGeneratorARMVIXL::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 6777 | HBasicBlock* successor) { |
| 6778 | SuspendCheckSlowPathARMVIXL* slow_path = |
| 6779 | down_cast<SuspendCheckSlowPathARMVIXL*>(instruction->GetSlowPath()); |
| 6780 | if (slow_path == nullptr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6781 | slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6782 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathARMVIXL(instruction, successor); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6783 | instruction->SetSlowPath(slow_path); |
| 6784 | codegen_->AddSlowPath(slow_path); |
| 6785 | if (successor != nullptr) { |
| 6786 | DCHECK(successor->IsLoopHeader()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6787 | } |
| 6788 | } else { |
| 6789 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 6790 | } |
| 6791 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 6792 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6793 | vixl32::Register temp = temps.Acquire(); |
| 6794 | GetAssembler()->LoadFromOffset( |
| 6795 | kLoadUnsignedHalfword, temp, tr, Thread::ThreadFlagsOffset<kArmPointerSize>().Int32Value()); |
| 6796 | if (successor == nullptr) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6797 | __ CompareAndBranchIfNonZero(temp, slow_path->GetEntryLabel()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6798 | __ Bind(slow_path->GetReturnLabel()); |
| 6799 | } else { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 6800 | __ CompareAndBranchIfZero(temp, codegen_->GetLabelOf(successor)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6801 | __ B(slow_path->GetEntryLabel()); |
| 6802 | } |
| 6803 | } |
| 6804 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6805 | ArmVIXLAssembler* ParallelMoveResolverARMVIXL::GetAssembler() const { |
| 6806 | return codegen_->GetAssembler(); |
| 6807 | } |
| 6808 | |
| 6809 | void ParallelMoveResolverARMVIXL::EmitMove(size_t index) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6810 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6811 | MoveOperands* move = moves_[index]; |
| 6812 | Location source = move->GetSource(); |
| 6813 | Location destination = move->GetDestination(); |
| 6814 | |
| 6815 | if (source.IsRegister()) { |
| 6816 | if (destination.IsRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6817 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6818 | } else if (destination.IsFpuRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6819 | __ Vmov(SRegisterFrom(destination), RegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6820 | } else { |
| 6821 | DCHECK(destination.IsStackSlot()); |
| 6822 | GetAssembler()->StoreToOffset(kStoreWord, |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6823 | RegisterFrom(source), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6824 | sp, |
| 6825 | destination.GetStackIndex()); |
| 6826 | } |
| 6827 | } else if (source.IsStackSlot()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6828 | if (destination.IsRegister()) { |
| 6829 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 6830 | RegisterFrom(destination), |
| 6831 | sp, |
| 6832 | source.GetStackIndex()); |
| 6833 | } else if (destination.IsFpuRegister()) { |
| 6834 | GetAssembler()->LoadSFromOffset(SRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6835 | } else { |
| 6836 | DCHECK(destination.IsStackSlot()); |
| 6837 | vixl32::Register temp = temps.Acquire(); |
| 6838 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, source.GetStackIndex()); |
| 6839 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6840 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6841 | } else if (source.IsFpuRegister()) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6842 | if (destination.IsRegister()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6843 | __ Vmov(RegisterFrom(destination), SRegisterFrom(source)); |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6844 | } else if (destination.IsFpuRegister()) { |
| 6845 | __ Vmov(SRegisterFrom(destination), SRegisterFrom(source)); |
| 6846 | } else { |
| 6847 | DCHECK(destination.IsStackSlot()); |
| 6848 | GetAssembler()->StoreSToOffset(SRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6849 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6850 | } else if (source.IsDoubleStackSlot()) { |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6851 | if (destination.IsDoubleStackSlot()) { |
| 6852 | vixl32::DRegister temp = temps.AcquireD(); |
| 6853 | GetAssembler()->LoadDFromOffset(temp, sp, source.GetStackIndex()); |
| 6854 | GetAssembler()->StoreDToOffset(temp, sp, destination.GetStackIndex()); |
| 6855 | } else if (destination.IsRegisterPair()) { |
| 6856 | DCHECK(ExpectedPairLayout(destination)); |
| 6857 | GetAssembler()->LoadFromOffset( |
| 6858 | kLoadWordPair, LowRegisterFrom(destination), sp, source.GetStackIndex()); |
| 6859 | } else { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6860 | DCHECK(destination.IsFpuRegisterPair()) << destination; |
| 6861 | GetAssembler()->LoadDFromOffset(DRegisterFrom(destination), sp, source.GetStackIndex()); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6862 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6863 | } else if (source.IsRegisterPair()) { |
| 6864 | if (destination.IsRegisterPair()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6865 | __ Mov(LowRegisterFrom(destination), LowRegisterFrom(source)); |
| 6866 | __ Mov(HighRegisterFrom(destination), HighRegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6867 | } else if (destination.IsFpuRegisterPair()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6868 | __ Vmov(DRegisterFrom(destination), LowRegisterFrom(source), HighRegisterFrom(source)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6869 | } else { |
| 6870 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6871 | DCHECK(ExpectedPairLayout(source)); |
| 6872 | GetAssembler()->StoreToOffset(kStoreWordPair, |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6873 | LowRegisterFrom(source), |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6874 | sp, |
| 6875 | destination.GetStackIndex()); |
| 6876 | } |
| 6877 | } else if (source.IsFpuRegisterPair()) { |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6878 | if (destination.IsRegisterPair()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6879 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), DRegisterFrom(source)); |
| Alexandre Rames | b45fbaa5 | 2016-10-17 14:57:13 +0100 | [diff] [blame] | 6880 | } else if (destination.IsFpuRegisterPair()) { |
| 6881 | __ Vmov(DRegisterFrom(destination), DRegisterFrom(source)); |
| 6882 | } else { |
| 6883 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6884 | GetAssembler()->StoreDToOffset(DRegisterFrom(source), sp, destination.GetStackIndex()); |
| 6885 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6886 | } else { |
| 6887 | DCHECK(source.IsConstant()) << source; |
| 6888 | HConstant* constant = source.GetConstant(); |
| 6889 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
| 6890 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
| 6891 | if (destination.IsRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6892 | __ Mov(RegisterFrom(destination), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6893 | } else { |
| 6894 | DCHECK(destination.IsStackSlot()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6895 | vixl32::Register temp = temps.Acquire(); |
| 6896 | __ Mov(temp, value); |
| 6897 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6898 | } |
| 6899 | } else if (constant->IsLongConstant()) { |
| Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 6900 | int64_t value = Int64ConstantFrom(source); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6901 | if (destination.IsRegisterPair()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6902 | __ Mov(LowRegisterFrom(destination), Low32Bits(value)); |
| 6903 | __ Mov(HighRegisterFrom(destination), High32Bits(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6904 | } else { |
| 6905 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6906 | vixl32::Register temp = temps.Acquire(); |
| 6907 | __ Mov(temp, Low32Bits(value)); |
| 6908 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6909 | __ Mov(temp, High32Bits(value)); |
| 6910 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6911 | temp, |
| 6912 | sp, |
| 6913 | destination.GetHighStackIndex(kArmWordSize)); |
| 6914 | } |
| 6915 | } else if (constant->IsDoubleConstant()) { |
| 6916 | double value = constant->AsDoubleConstant()->GetValue(); |
| 6917 | if (destination.IsFpuRegisterPair()) { |
| Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 6918 | __ Vmov(DRegisterFrom(destination), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6919 | } else { |
| 6920 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 6921 | uint64_t int_value = bit_cast<uint64_t, double>(value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6922 | vixl32::Register temp = temps.Acquire(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6923 | __ Mov(temp, Low32Bits(int_value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6924 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6925 | __ Mov(temp, High32Bits(int_value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6926 | GetAssembler()->StoreToOffset(kStoreWord, |
| 6927 | temp, |
| 6928 | sp, |
| 6929 | destination.GetHighStackIndex(kArmWordSize)); |
| 6930 | } |
| 6931 | } else { |
| 6932 | DCHECK(constant->IsFloatConstant()) << constant->DebugName(); |
| 6933 | float value = constant->AsFloatConstant()->GetValue(); |
| 6934 | if (destination.IsFpuRegister()) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6935 | __ Vmov(SRegisterFrom(destination), value); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6936 | } else { |
| 6937 | DCHECK(destination.IsStackSlot()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6938 | vixl32::Register temp = temps.Acquire(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 6939 | __ Mov(temp, bit_cast<int32_t, float>(value)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6940 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, destination.GetStackIndex()); |
| 6941 | } |
| 6942 | } |
| 6943 | } |
| 6944 | } |
| 6945 | |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6946 | void ParallelMoveResolverARMVIXL::Exchange(vixl32::Register reg, int mem) { |
| 6947 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6948 | vixl32::Register temp = temps.Acquire(); |
| 6949 | __ Mov(temp, reg); |
| 6950 | GetAssembler()->LoadFromOffset(kLoadWord, reg, sp, mem); |
| 6951 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6952 | } |
| 6953 | |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6954 | void ParallelMoveResolverARMVIXL::Exchange(int mem1, int mem2) { |
| 6955 | // TODO(VIXL32): Double check the performance of this implementation. |
| 6956 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6957 | vixl32::Register temp1 = temps.Acquire(); |
| 6958 | ScratchRegisterScope ensure_scratch( |
| 6959 | this, temp1.GetCode(), r0.GetCode(), codegen_->GetNumberOfCoreRegisters()); |
| 6960 | vixl32::Register temp2(ensure_scratch.GetRegister()); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6961 | |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6962 | int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0; |
| 6963 | GetAssembler()->LoadFromOffset(kLoadWord, temp1, sp, mem1 + stack_offset); |
| 6964 | GetAssembler()->LoadFromOffset(kLoadWord, temp2, sp, mem2 + stack_offset); |
| 6965 | GetAssembler()->StoreToOffset(kStoreWord, temp1, sp, mem2 + stack_offset); |
| 6966 | GetAssembler()->StoreToOffset(kStoreWord, temp2, sp, mem1 + stack_offset); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 6967 | } |
| 6968 | |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6969 | void ParallelMoveResolverARMVIXL::EmitSwap(size_t index) { |
| 6970 | MoveOperands* move = moves_[index]; |
| 6971 | Location source = move->GetSource(); |
| 6972 | Location destination = move->GetDestination(); |
| 6973 | UseScratchRegisterScope temps(GetAssembler()->GetVIXLAssembler()); |
| 6974 | |
| 6975 | if (source.IsRegister() && destination.IsRegister()) { |
| 6976 | vixl32::Register temp = temps.Acquire(); |
| 6977 | DCHECK(!RegisterFrom(source).Is(temp)); |
| 6978 | DCHECK(!RegisterFrom(destination).Is(temp)); |
| 6979 | __ Mov(temp, RegisterFrom(destination)); |
| 6980 | __ Mov(RegisterFrom(destination), RegisterFrom(source)); |
| 6981 | __ Mov(RegisterFrom(source), temp); |
| 6982 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
| 6983 | Exchange(RegisterFrom(source), destination.GetStackIndex()); |
| 6984 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
| 6985 | Exchange(RegisterFrom(destination), source.GetStackIndex()); |
| 6986 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6987 | Exchange(source.GetStackIndex(), destination.GetStackIndex()); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6988 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 6989 | vixl32::Register temp = temps.Acquire(); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 6990 | __ Vmov(temp, SRegisterFrom(source)); |
| 6991 | __ Vmov(SRegisterFrom(source), SRegisterFrom(destination)); |
| 6992 | __ Vmov(SRegisterFrom(destination), temp); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 6993 | } else if (source.IsRegisterPair() && destination.IsRegisterPair()) { |
| 6994 | vixl32::DRegister temp = temps.AcquireD(); |
| 6995 | __ Vmov(temp, LowRegisterFrom(source), HighRegisterFrom(source)); |
| 6996 | __ Mov(LowRegisterFrom(source), LowRegisterFrom(destination)); |
| 6997 | __ Mov(HighRegisterFrom(source), HighRegisterFrom(destination)); |
| 6998 | __ Vmov(LowRegisterFrom(destination), HighRegisterFrom(destination), temp); |
| 6999 | } else if (source.IsRegisterPair() || destination.IsRegisterPair()) { |
| 7000 | vixl32::Register low_reg = LowRegisterFrom(source.IsRegisterPair() ? source : destination); |
| 7001 | int mem = source.IsRegisterPair() ? destination.GetStackIndex() : source.GetStackIndex(); |
| 7002 | DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination)); |
| 7003 | vixl32::DRegister temp = temps.AcquireD(); |
| 7004 | __ Vmov(temp, low_reg, vixl32::Register(low_reg.GetCode() + 1)); |
| 7005 | GetAssembler()->LoadFromOffset(kLoadWordPair, low_reg, sp, mem); |
| 7006 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| 7007 | } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7008 | vixl32::DRegister first = DRegisterFrom(source); |
| 7009 | vixl32::DRegister second = DRegisterFrom(destination); |
| 7010 | vixl32::DRegister temp = temps.AcquireD(); |
| 7011 | __ Vmov(temp, first); |
| 7012 | __ Vmov(first, second); |
| 7013 | __ Vmov(second, temp); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7014 | } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7015 | vixl32::DRegister reg = source.IsFpuRegisterPair() |
| 7016 | ? DRegisterFrom(source) |
| 7017 | : DRegisterFrom(destination); |
| 7018 | int mem = source.IsFpuRegisterPair() |
| 7019 | ? destination.GetStackIndex() |
| 7020 | : source.GetStackIndex(); |
| 7021 | vixl32::DRegister temp = temps.AcquireD(); |
| 7022 | __ Vmov(temp, reg); |
| 7023 | GetAssembler()->LoadDFromOffset(reg, sp, mem); |
| 7024 | GetAssembler()->StoreDToOffset(temp, sp, mem); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7025 | } else if (source.IsFpuRegister() || destination.IsFpuRegister()) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 7026 | vixl32::SRegister reg = source.IsFpuRegister() |
| 7027 | ? SRegisterFrom(source) |
| 7028 | : SRegisterFrom(destination); |
| 7029 | int mem = source.IsFpuRegister() |
| 7030 | ? destination.GetStackIndex() |
| 7031 | : source.GetStackIndex(); |
| 7032 | vixl32::Register temp = temps.Acquire(); |
| 7033 | __ Vmov(temp, reg); |
| 7034 | GetAssembler()->LoadSFromOffset(reg, sp, mem); |
| 7035 | GetAssembler()->StoreToOffset(kStoreWord, temp, sp, mem); |
| Alexandre Rames | 9c19bd6 | 2016-10-24 11:50:32 +0100 | [diff] [blame] | 7036 | } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) { |
| 7037 | vixl32::DRegister temp1 = temps.AcquireD(); |
| 7038 | vixl32::DRegister temp2 = temps.AcquireD(); |
| 7039 | __ Vldr(temp1, MemOperand(sp, source.GetStackIndex())); |
| 7040 | __ Vldr(temp2, MemOperand(sp, destination.GetStackIndex())); |
| 7041 | __ Vstr(temp1, MemOperand(sp, destination.GetStackIndex())); |
| 7042 | __ Vstr(temp2, MemOperand(sp, source.GetStackIndex())); |
| 7043 | } else { |
| 7044 | LOG(FATAL) << "Unimplemented" << source << " <-> " << destination; |
| 7045 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7046 | } |
| 7047 | |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7048 | void ParallelMoveResolverARMVIXL::SpillScratch(int reg) { |
| 7049 | __ Push(vixl32::Register(reg)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7050 | } |
| 7051 | |
| Nicolas Geoffray | 13a797b | 2017-03-15 16:41:31 +0000 | [diff] [blame] | 7052 | void ParallelMoveResolverARMVIXL::RestoreScratch(int reg) { |
| 7053 | __ Pop(vixl32::Register(reg)); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7054 | } |
| 7055 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7056 | HLoadClass::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadClassKind( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7057 | HLoadClass::LoadKind desired_class_load_kind) { |
| 7058 | switch (desired_class_load_kind) { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7059 | case HLoadClass::LoadKind::kInvalid: |
| 7060 | LOG(FATAL) << "UNREACHABLE"; |
| 7061 | UNREACHABLE(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7062 | case HLoadClass::LoadKind::kReferrersClass: |
| 7063 | break; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7064 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7065 | case HLoadClass::LoadKind::kBootImageRelRo: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7066 | case HLoadClass::LoadKind::kBssEntry: |
| 7067 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7068 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7069 | case HLoadClass::LoadKind::kJitBootImageAddress: |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7070 | case HLoadClass::LoadKind::kJitTableAddress: |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7071 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7072 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7073 | case HLoadClass::LoadKind::kRuntimeCall: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7074 | break; |
| 7075 | } |
| 7076 | return desired_class_load_kind; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7077 | } |
| 7078 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7079 | void LocationsBuilderARMVIXL::VisitLoadClass(HLoadClass* cls) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7080 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7081 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7082 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7083 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7084 | cls, |
| 7085 | LocationFrom(calling_convention.GetRegisterAt(0)), |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7086 | LocationFrom(r0)); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7087 | DCHECK(calling_convention.GetRegisterAt(0).Is(r0)); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7088 | return; |
| 7089 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7090 | DCHECK(!cls->NeedsAccessCheck()); |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 7091 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7092 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 7093 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7094 | ? LocationSummary::kCallOnSlowPath |
| 7095 | : LocationSummary::kNoCall; |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7096 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7097 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 7098 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7099 | } |
| 7100 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7101 | if (load_kind == HLoadClass::LoadKind::kReferrersClass) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7102 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7103 | } |
| 7104 | locations->SetOut(Location::RequiresRegister()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7105 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { |
| 7106 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| 7107 | // Rely on the type resolution or initialization and marking to save everything we need. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7108 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7109 | } else { |
| 7110 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7111 | } |
| 7112 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7113 | } |
| 7114 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7115 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7116 | // move. |
| 7117 | void InstructionCodeGeneratorARMVIXL::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7118 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7119 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7120 | codegen_->GenerateLoadClassRuntimeCall(cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7121 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 14); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7122 | return; |
| 7123 | } |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7124 | DCHECK(!cls->NeedsAccessCheck()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7125 | |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7126 | LocationSummary* locations = cls->GetLocations(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7127 | Location out_loc = locations->Out(); |
| 7128 | vixl32::Register out = OutputRegister(cls); |
| 7129 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7130 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() |
| 7131 | ? kWithoutReadBarrier |
| 7132 | : kCompilerReadBarrierOption; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7133 | bool generate_null_check = false; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7134 | switch (load_kind) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7135 | case HLoadClass::LoadKind::kReferrersClass: { |
| 7136 | DCHECK(!cls->CanCallRuntime()); |
| 7137 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 7138 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 7139 | vixl32::Register current_method = InputRegisterAt(cls, 0); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7140 | codegen_->GenerateGcRootFieldLoad(cls, |
| 7141 | out_loc, |
| 7142 | current_method, |
| 7143 | ArtMethod::DeclaringClassOffset().Int32Value(), |
| 7144 | read_barrier_option); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7145 | break; |
| 7146 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7147 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7148 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7149 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7150 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7151 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7152 | codegen_->NewBootImageTypePatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7153 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| 7154 | break; |
| 7155 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7156 | case HLoadClass::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7157 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7158 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7159 | codegen_->NewBootImageRelRoPatch(codegen_->GetBootImageOffset(cls)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7160 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7161 | __ Ldr(out, MemOperand(out, /* offset= */ 0)); |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 7162 | break; |
| 7163 | } |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7164 | case HLoadClass::LoadKind::kBssEntry: { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7165 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 7166 | codegen_->NewTypeBssEntryPatch(cls->GetDexFile(), cls->GetTypeIndex()); |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7167 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7168 | // All aligned loads are implicitly atomic consume operations on ARM. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7169 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset= */ 0, read_barrier_option); |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 7170 | generate_null_check = true; |
| 7171 | break; |
| 7172 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7173 | case HLoadClass::LoadKind::kJitBootImageAddress: { |
| 7174 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); |
| 7175 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); |
| 7176 | DCHECK_NE(address, 0u); |
| 7177 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7178 | break; |
| 7179 | } |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 7180 | case HLoadClass::LoadKind::kJitTableAddress: { |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7181 | __ Ldr(out, codegen_->DeduplicateJitClassLiteral(cls->GetDexFile(), |
| 7182 | cls->GetTypeIndex(), |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 7183 | cls->GetClass())); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7184 | // /* GcRoot<mirror::Class> */ out = *out |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7185 | codegen_->GenerateGcRootFieldLoad(cls, out_loc, out, /* offset= */ 0, read_barrier_option); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7186 | break; |
| 7187 | } |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7188 | case HLoadClass::LoadKind::kRuntimeCall: |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 7189 | case HLoadClass::LoadKind::kInvalid: |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 7190 | LOG(FATAL) << "UNREACHABLE"; |
| 7191 | UNREACHABLE(); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7192 | } |
| 7193 | |
| 7194 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 7195 | DCHECK(cls->CanCallRuntime()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7196 | LoadClassSlowPathARMVIXL* slow_path = |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7197 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(cls, cls); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7198 | codegen_->AddSlowPath(slow_path); |
| 7199 | if (generate_null_check) { |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7200 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7201 | } |
| 7202 | if (cls->MustGenerateClinitCheck()) { |
| 7203 | GenerateClassInitializationCheck(slow_path, out); |
| 7204 | } else { |
| 7205 | __ Bind(slow_path->GetExitLabel()); |
| 7206 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7207 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 15); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 7208 | } |
| 7209 | } |
| 7210 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 7211 | void LocationsBuilderARMVIXL::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7212 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7213 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 7214 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); |
| 7215 | } |
| 7216 | |
| 7217 | void InstructionCodeGeneratorARMVIXL::VisitLoadMethodHandle(HLoadMethodHandle* load) { |
| 7218 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); |
| 7219 | } |
| 7220 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 7221 | void LocationsBuilderARMVIXL::VisitLoadMethodType(HLoadMethodType* load) { |
| 7222 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7223 | Location location = LocationFrom(calling_convention.GetRegisterAt(0)); |
| 7224 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); |
| 7225 | } |
| 7226 | |
| 7227 | void InstructionCodeGeneratorARMVIXL::VisitLoadMethodType(HLoadMethodType* load) { |
| 7228 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); |
| 7229 | } |
| 7230 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7231 | void LocationsBuilderARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7232 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7233 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7234 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7235 | if (check->HasUses()) { |
| 7236 | locations->SetOut(Location::SameAsFirstInput()); |
| 7237 | } |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7238 | // Rely on the type initialization to save everything we need. |
| 7239 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7240 | } |
| 7241 | |
| 7242 | void InstructionCodeGeneratorARMVIXL::VisitClinitCheck(HClinitCheck* check) { |
| 7243 | // We assume the class is not null. |
| 7244 | LoadClassSlowPathARMVIXL* slow_path = |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 7245 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathARMVIXL(check->GetLoadClass(), check); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7246 | codegen_->AddSlowPath(slow_path); |
| 7247 | GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0)); |
| 7248 | } |
| 7249 | |
| 7250 | void InstructionCodeGeneratorARMVIXL::GenerateClassInitializationCheck( |
| 7251 | LoadClassSlowPathARMVIXL* slow_path, vixl32::Register class_reg) { |
| 7252 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7253 | vixl32::Register temp = temps.Acquire(); |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7254 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7255 | constexpr uint32_t shifted_visibly_initialized_value = |
| 7256 | enum_cast<uint32_t>(ClassStatus::kVisiblyInitialized) << status_lsb_position; |
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 7257 | |
| Vladimir Marko | bf12191 | 2019-06-04 13:49:05 +0100 | [diff] [blame] | 7258 | const size_t status_offset = mirror::Class::StatusOffset().SizeValue(); |
| 7259 | GetAssembler()->LoadFromOffset(kLoadWord, temp, class_reg, status_offset); |
| 7260 | __ Cmp(temp, shifted_visibly_initialized_value); |
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 7261 | __ B(lo, slow_path->GetEntryLabel()); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7262 | __ Bind(slow_path->GetExitLabel()); |
| 7263 | } |
| 7264 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7265 | void InstructionCodeGeneratorARMVIXL::GenerateBitstringTypeCheckCompare( |
| 7266 | HTypeCheckInstruction* check, |
| 7267 | vixl32::Register temp, |
| 7268 | vixl32::FlagsUpdate flags_update) { |
| 7269 | uint32_t path_to_root = check->GetBitstringPathToRoot(); |
| 7270 | uint32_t mask = check->GetBitstringMask(); |
| 7271 | DCHECK(IsPowerOfTwo(mask + 1)); |
| 7272 | size_t mask_bits = WhichPowerOf2(mask + 1); |
| 7273 | |
| 7274 | // Note that HInstanceOf shall check for zero value in `temp` but HCheckCast needs |
| 7275 | // the Z flag for BNE. This is indicated by the `flags_update` parameter. |
| 7276 | if (mask_bits == 16u) { |
| 7277 | // Load only the bitstring part of the status word. |
| 7278 | __ Ldrh(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7279 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7280 | if (flags_update == SetFlags) { |
| 7281 | __ Cmp(temp, path_to_root); |
| 7282 | } else { |
| 7283 | __ Sub(temp, temp, path_to_root); |
| 7284 | } |
| 7285 | } else { |
| 7286 | // /* uint32_t */ temp = temp->status_ |
| 7287 | __ Ldr(temp, MemOperand(temp, mirror::Class::StatusOffset().Int32Value())); |
| 7288 | if (GetAssembler()->ShifterOperandCanHold(SUB, path_to_root)) { |
| 7289 | // Compare the bitstring bits using SUB. |
| 7290 | __ Sub(temp, temp, path_to_root); |
| 7291 | // Shift out bits that do not contribute to the comparison. |
| 7292 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7293 | } else if (IsUint<16>(path_to_root)) { |
| 7294 | if (temp.IsLow()) { |
| 7295 | // Note: Optimized for size but contains one more dependent instruction than necessary. |
| 7296 | // MOVW+SUB(register) would be 8 bytes unless we find a low-reg temporary but the |
| 7297 | // macro assembler would use the high reg IP for the constant by default. |
| 7298 | // Compare the bitstring bits using SUB. |
| 7299 | __ Sub(temp, temp, path_to_root & 0x00ffu); // 16-bit SUB (immediate) T2 |
| 7300 | __ Sub(temp, temp, path_to_root & 0xff00u); // 32-bit SUB (immediate) T3 |
| 7301 | // Shift out bits that do not contribute to the comparison. |
| 7302 | __ Lsl(flags_update, temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7303 | } else { |
| 7304 | // Extract the bitstring bits. |
| 7305 | __ Ubfx(temp, temp, 0, mask_bits); |
| 7306 | // Check if the bitstring bits are equal to `path_to_root`. |
| 7307 | if (flags_update == SetFlags) { |
| 7308 | __ Cmp(temp, path_to_root); |
| 7309 | } else { |
| 7310 | __ Sub(temp, temp, path_to_root); |
| 7311 | } |
| 7312 | } |
| 7313 | } else { |
| 7314 | // Shift out bits that do not contribute to the comparison. |
| 7315 | __ Lsl(temp, temp, dchecked_integral_cast<uint32_t>(32u - mask_bits)); |
| 7316 | // Check if the shifted bitstring bits are equal to `path_to_root << (32u - mask_bits)`. |
| 7317 | if (flags_update == SetFlags) { |
| 7318 | __ Cmp(temp, path_to_root << (32u - mask_bits)); |
| 7319 | } else { |
| 7320 | __ Sub(temp, temp, path_to_root << (32u - mask_bits)); |
| 7321 | } |
| 7322 | } |
| 7323 | } |
| 7324 | } |
| 7325 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7326 | HLoadString::LoadKind CodeGeneratorARMVIXL::GetSupportedLoadStringKind( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7327 | HLoadString::LoadKind desired_string_load_kind) { |
| 7328 | switch (desired_string_load_kind) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7329 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7330 | case HLoadString::LoadKind::kBootImageRelRo: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7331 | case HLoadString::LoadKind::kBssEntry: |
| 7332 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 7333 | break; |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7334 | case HLoadString::LoadKind::kJitBootImageAddress: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7335 | case HLoadString::LoadKind::kJitTableAddress: |
| 7336 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7337 | break; |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7338 | case HLoadString::LoadKind::kRuntimeCall: |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7339 | break; |
| 7340 | } |
| 7341 | return desired_string_load_kind; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7342 | } |
| 7343 | |
| 7344 | void LocationsBuilderARMVIXL::VisitLoadString(HLoadString* load) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7345 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7346 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7347 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7348 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7349 | locations->SetOut(LocationFrom(r0)); |
| 7350 | } else { |
| 7351 | locations->SetOut(Location::RequiresRegister()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7352 | if (load_kind == HLoadString::LoadKind::kBssEntry) { |
| 7353 | if (!kUseReadBarrier || kUseBakerReadBarrier) { |
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 7354 | // Rely on the pResolveString and marking to save everything we need, including temps. |
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 7355 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7356 | } else { |
| 7357 | // For non-Baker read barrier we have a temp-clobbering call. |
| 7358 | } |
| 7359 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7360 | } |
| 7361 | } |
| 7362 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7363 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not |
| 7364 | // move. |
| 7365 | void InstructionCodeGeneratorARMVIXL::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7366 | LocationSummary* locations = load->GetLocations(); |
| 7367 | Location out_loc = locations->Out(); |
| 7368 | vixl32::Register out = OutputRegister(load); |
| 7369 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 7370 | |
| 7371 | switch (load_kind) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7372 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 7373 | DCHECK(codegen_->GetCompilerOptions().IsBootImage() || |
| 7374 | codegen_->GetCompilerOptions().IsBootImageExtension()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7375 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 7376 | codegen_->NewBootImageStringPatch(load->GetDexFile(), load->GetStringIndex()); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7377 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7378 | return; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7379 | } |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7380 | case HLoadString::LoadKind::kBootImageRelRo: { |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7381 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); |
| 7382 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 7383 | codegen_->NewBootImageRelRoPatch(codegen_->GetBootImageOffset(load)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7384 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7385 | __ Ldr(out, MemOperand(out, /* offset= */ 0)); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7386 | return; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7387 | } |
| 7388 | case HLoadString::LoadKind::kBssEntry: { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7389 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 7390 | codegen_->NewStringBssEntryPatch(load->GetDexFile(), load->GetStringIndex()); |
| Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 7391 | codegen_->EmitMovwMovtPlaceholder(labels, out); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 7392 | // All aligned loads are implicitly atomic consume operations on ARM. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7393 | codegen_->GenerateGcRootFieldLoad( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7394 | load, out_loc, out, /* offset= */ 0, kCompilerReadBarrierOption); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7395 | LoadStringSlowPathARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7396 | new (codegen_->GetScopedAllocator()) LoadStringSlowPathARMVIXL(load); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7397 | codegen_->AddSlowPath(slow_path); |
| 7398 | __ CompareAndBranchIfZero(out, slow_path->GetEntryLabel()); |
| 7399 | __ Bind(slow_path->GetExitLabel()); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7400 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 16); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7401 | return; |
| 7402 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 7403 | case HLoadString::LoadKind::kJitBootImageAddress: { |
| 7404 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); |
| 7405 | DCHECK_NE(address, 0u); |
| 7406 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 7407 | return; |
| 7408 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7409 | case HLoadString::LoadKind::kJitTableAddress: { |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7410 | __ Ldr(out, codegen_->DeduplicateJitStringLiteral(load->GetDexFile(), |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 7411 | load->GetStringIndex(), |
| 7412 | load->GetString())); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7413 | // /* GcRoot<mirror::String> */ out = *out |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 7414 | codegen_->GenerateGcRootFieldLoad( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7415 | load, out_loc, out, /* offset= */ 0, kCompilerReadBarrierOption); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 7416 | return; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 7417 | } |
| 7418 | default: |
| 7419 | break; |
| 7420 | } |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7421 | |
| 7422 | // TODO: Re-add the compiler code to do string dex cache lookup again. |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 7423 | DCHECK_EQ(load->GetLoadKind(), HLoadString::LoadKind::kRuntimeCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7424 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 7425 | __ Mov(calling_convention.GetRegisterAt(0), load->GetStringIndex().index_); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7426 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 7427 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7428 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 17); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7429 | } |
| 7430 | |
| 7431 | static int32_t GetExceptionTlsOffset() { |
| 7432 | return Thread::ExceptionOffset<kArmPointerSize>().Int32Value(); |
| 7433 | } |
| 7434 | |
| 7435 | void LocationsBuilderARMVIXL::VisitLoadException(HLoadException* load) { |
| 7436 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7437 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7438 | locations->SetOut(Location::RequiresRegister()); |
| 7439 | } |
| 7440 | |
| 7441 | void InstructionCodeGeneratorARMVIXL::VisitLoadException(HLoadException* load) { |
| 7442 | vixl32::Register out = OutputRegister(load); |
| 7443 | GetAssembler()->LoadFromOffset(kLoadWord, out, tr, GetExceptionTlsOffset()); |
| 7444 | } |
| 7445 | |
| 7446 | |
| 7447 | void LocationsBuilderARMVIXL::VisitClearException(HClearException* clear) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7448 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7449 | } |
| 7450 | |
| 7451 | void InstructionCodeGeneratorARMVIXL::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 7452 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 7453 | vixl32::Register temp = temps.Acquire(); |
| 7454 | __ Mov(temp, 0); |
| 7455 | GetAssembler()->StoreToOffset(kStoreWord, temp, tr, GetExceptionTlsOffset()); |
| 7456 | } |
| 7457 | |
| 7458 | void LocationsBuilderARMVIXL::VisitThrow(HThrow* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7459 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 7460 | instruction, LocationSummary::kCallOnMainOnly); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 7461 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 7462 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 7463 | } |
| 7464 | |
| 7465 | void InstructionCodeGeneratorARMVIXL::VisitThrow(HThrow* instruction) { |
| 7466 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
| 7467 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
| 7468 | } |
| 7469 | |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7470 | // Temp is used for read barrier. |
| 7471 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { |
| 7472 | if (kEmitCompilerReadBarrier && |
| 7473 | (kUseBakerReadBarrier || |
| 7474 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 7475 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 7476 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 7477 | return 1; |
| 7478 | } |
| 7479 | return 0; |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7480 | } |
| 7481 | |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7482 | // Interface case has 3 temps, one for holding the number of interfaces, one for the current |
| 7483 | // interface pointer, one for loading the current interface. |
| 7484 | // The other checks have one temp for loading the object's class. |
| 7485 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { |
| 7486 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { |
| 7487 | return 3; |
| 7488 | } |
| 7489 | return 1 + NumberOfInstanceOfTemps(type_check_kind); |
| 7490 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7491 | |
| 7492 | void LocationsBuilderARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7493 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 7494 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7495 | bool baker_read_barrier_slow_path = false; |
| 7496 | switch (type_check_kind) { |
| 7497 | case TypeCheckKind::kExactCheck: |
| 7498 | case TypeCheckKind::kAbstractClassCheck: |
| 7499 | case TypeCheckKind::kClassHierarchyCheck: |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7500 | case TypeCheckKind::kArrayObjectCheck: { |
| 7501 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); |
| 7502 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
| 7503 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7504 | break; |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7505 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7506 | case TypeCheckKind::kArrayCheck: |
| 7507 | case TypeCheckKind::kUnresolvedCheck: |
| 7508 | case TypeCheckKind::kInterfaceCheck: |
| 7509 | call_kind = LocationSummary::kCallOnSlowPath; |
| 7510 | break; |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7511 | case TypeCheckKind::kBitstringCheck: |
| 7512 | break; |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7513 | } |
| 7514 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7515 | LocationSummary* locations = |
| 7516 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7517 | if (baker_read_barrier_slow_path) { |
| 7518 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 7519 | } |
| 7520 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7521 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7522 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7523 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7524 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7525 | } else { |
| 7526 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7527 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7528 | // The "out" register is used as a temporary, so it overlaps with the inputs. |
| 7529 | // Note that TypeCheckSlowPathARM uses this register too. |
| 7530 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7531 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7532 | } |
| 7533 | |
| 7534 | void InstructionCodeGeneratorARMVIXL::VisitInstanceOf(HInstanceOf* instruction) { |
| 7535 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7536 | LocationSummary* locations = instruction->GetLocations(); |
| 7537 | Location obj_loc = locations->InAt(0); |
| 7538 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7539 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 7540 | ? vixl32::Register() |
| 7541 | : InputRegisterAt(instruction, 1); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7542 | Location out_loc = locations->Out(); |
| 7543 | vixl32::Register out = OutputRegister(instruction); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7544 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); |
| 7545 | DCHECK_LE(num_temps, 1u); |
| 7546 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7547 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7548 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7549 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7550 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7551 | vixl32::Label done; |
| 7552 | vixl32::Label* const final_label = codegen_->GetFinalLabel(instruction, &done); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7553 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 7554 | |
| 7555 | // Return 0 if `obj` is null. |
| 7556 | // avoid null check if we know obj is not null. |
| 7557 | if (instruction->MustDoNullCheck()) { |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7558 | DCHECK(!out.Is(obj)); |
| 7559 | __ Mov(out, 0); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7560 | __ CompareAndBranchIfZero(obj, final_label, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7561 | } |
| 7562 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7563 | switch (type_check_kind) { |
| 7564 | case TypeCheckKind::kExactCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7565 | ReadBarrierOption read_barrier_option = |
| 7566 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7567 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7568 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7569 | out_loc, |
| 7570 | obj_loc, |
| 7571 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7572 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7573 | read_barrier_option); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7574 | // Classes must be equal for the instanceof to succeed. |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7575 | __ Cmp(out, cls); |
| 7576 | // We speculatively set the result to false without changing the condition |
| 7577 | // flags, which allows us to avoid some branching later. |
| 7578 | __ Mov(LeaveFlags, out, 0); |
| 7579 | |
| 7580 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7581 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7582 | // encoding can be used. |
| 7583 | if (out.IsLow()) { |
| 7584 | // We use the scope because of the IT block that follows. |
| 7585 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7586 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7587 | CodeBufferCheckScope::kExactSize); |
| 7588 | |
| 7589 | __ it(eq); |
| 7590 | __ mov(eq, out, 1); |
| 7591 | } else { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7592 | __ B(ne, final_label, /* is_far_target= */ false); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7593 | __ Mov(out, 1); |
| 7594 | } |
| 7595 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7596 | break; |
| 7597 | } |
| 7598 | |
| 7599 | case TypeCheckKind::kAbstractClassCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7600 | ReadBarrierOption read_barrier_option = |
| 7601 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7602 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7603 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7604 | out_loc, |
| 7605 | obj_loc, |
| 7606 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7607 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7608 | read_barrier_option); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7609 | // If the class is abstract, we eagerly fetch the super class of the |
| 7610 | // object to avoid doing a comparison we know will fail. |
| 7611 | vixl32::Label loop; |
| 7612 | __ Bind(&loop); |
| 7613 | // /* HeapReference<Class> */ out = out->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7614 | GenerateReferenceLoadOneRegister(instruction, |
| 7615 | out_loc, |
| 7616 | super_offset, |
| 7617 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7618 | read_barrier_option); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7619 | // If `out` is null, we use it for the result, and jump to the final label. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7620 | __ CompareAndBranchIfZero(out, final_label, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7621 | __ Cmp(out, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7622 | __ B(ne, &loop, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7623 | __ Mov(out, 1); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7624 | break; |
| 7625 | } |
| 7626 | |
| 7627 | case TypeCheckKind::kClassHierarchyCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7628 | ReadBarrierOption read_barrier_option = |
| 7629 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7630 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7631 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7632 | out_loc, |
| 7633 | obj_loc, |
| 7634 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7635 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7636 | read_barrier_option); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7637 | // Walk over the class hierarchy to find a match. |
| 7638 | vixl32::Label loop, success; |
| 7639 | __ Bind(&loop); |
| 7640 | __ Cmp(out, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7641 | __ B(eq, &success, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7642 | // /* HeapReference<Class> */ out = out->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7643 | GenerateReferenceLoadOneRegister(instruction, |
| 7644 | out_loc, |
| 7645 | super_offset, |
| 7646 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7647 | read_barrier_option); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7648 | // This is essentially a null check, but it sets the condition flags to the |
| 7649 | // proper value for the code that follows the loop, i.e. not `eq`. |
| 7650 | __ Cmp(out, 1); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7651 | __ B(hs, &loop, /* is_far_target= */ false); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7652 | |
| 7653 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7654 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7655 | // encoding can be used. |
| 7656 | if (out.IsLow()) { |
| 7657 | // If `out` is null, we use it for the result, and the condition flags |
| 7658 | // have already been set to `ne`, so the IT block that comes afterwards |
| 7659 | // (and which handles the successful case) turns into a NOP (instead of |
| 7660 | // overwriting `out`). |
| 7661 | __ Bind(&success); |
| 7662 | |
| 7663 | // We use the scope because of the IT block that follows. |
| 7664 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7665 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7666 | CodeBufferCheckScope::kExactSize); |
| 7667 | |
| 7668 | // There is only one branch to the `success` label (which is bound to this |
| 7669 | // IT block), and it has the same condition, `eq`, so in that case the MOV |
| 7670 | // is executed. |
| 7671 | __ it(eq); |
| 7672 | __ mov(eq, out, 1); |
| 7673 | } else { |
| 7674 | // If `out` is null, we use it for the result, and jump to the final label. |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7675 | __ B(final_label); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7676 | __ Bind(&success); |
| 7677 | __ Mov(out, 1); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7678 | } |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7679 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7680 | break; |
| 7681 | } |
| 7682 | |
| 7683 | case TypeCheckKind::kArrayObjectCheck: { |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7684 | ReadBarrierOption read_barrier_option = |
| 7685 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7686 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7687 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7688 | out_loc, |
| 7689 | obj_loc, |
| 7690 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7691 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7692 | read_barrier_option); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7693 | // Do an exact check. |
| 7694 | vixl32::Label exact_check; |
| 7695 | __ Cmp(out, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7696 | __ B(eq, &exact_check, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7697 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7698 | // /* HeapReference<Class> */ out = out->component_type_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7699 | GenerateReferenceLoadOneRegister(instruction, |
| 7700 | out_loc, |
| 7701 | component_offset, |
| 7702 | maybe_temp_loc, |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7703 | read_barrier_option); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7704 | // If `out` is null, we use it for the result, and jump to the final label. |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7705 | __ CompareAndBranchIfZero(out, final_label, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7706 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, out, out, primitive_offset); |
| 7707 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7708 | __ Cmp(out, 0); |
| 7709 | // We speculatively set the result to false without changing the condition |
| 7710 | // flags, which allows us to avoid some branching later. |
| 7711 | __ Mov(LeaveFlags, out, 0); |
| 7712 | |
| 7713 | // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8, |
| 7714 | // we check that the output is in a low register, so that a 16-bit MOV |
| 7715 | // encoding can be used. |
| 7716 | if (out.IsLow()) { |
| 7717 | __ Bind(&exact_check); |
| 7718 | |
| 7719 | // We use the scope because of the IT block that follows. |
| 7720 | ExactAssemblyScope guard(GetVIXLAssembler(), |
| 7721 | 2 * vixl32::k16BitT32InstructionSizeInBytes, |
| 7722 | CodeBufferCheckScope::kExactSize); |
| 7723 | |
| 7724 | __ it(eq); |
| 7725 | __ mov(eq, out, 1); |
| 7726 | } else { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7727 | __ B(ne, final_label, /* is_far_target= */ false); |
| Anton Kirilov | 1e7bb5a | 2017-03-17 12:30:44 +0000 | [diff] [blame] | 7728 | __ Bind(&exact_check); |
| 7729 | __ Mov(out, 1); |
| 7730 | } |
| 7731 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7732 | break; |
| 7733 | } |
| 7734 | |
| 7735 | case TypeCheckKind::kArrayCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7736 | // No read barrier since the slow path will retry upon failure. |
| Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 7737 | // /* HeapReference<Class> */ out = obj->klass_ |
| 7738 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7739 | out_loc, |
| 7740 | obj_loc, |
| 7741 | class_offset, |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7742 | maybe_temp_loc, |
| 7743 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7744 | __ Cmp(out, cls); |
| 7745 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7746 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7747 | instruction, /* is_fatal= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7748 | codegen_->AddSlowPath(slow_path); |
| 7749 | __ B(ne, slow_path->GetEntryLabel()); |
| 7750 | __ Mov(out, 1); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7751 | break; |
| 7752 | } |
| 7753 | |
| 7754 | case TypeCheckKind::kUnresolvedCheck: |
| 7755 | case TypeCheckKind::kInterfaceCheck: { |
| 7756 | // Note that we indeed only call on slow path, but we always go |
| 7757 | // into the slow path for the unresolved and interface check |
| 7758 | // cases. |
| 7759 | // |
| 7760 | // We cannot directly call the InstanceofNonTrivial runtime |
| 7761 | // entry point without resorting to a type checking slow path |
| 7762 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 7763 | // require to assign fixed registers for the inputs of this |
| 7764 | // HInstanceOf instruction (following the runtime calling |
| 7765 | // convention), which might be cluttered by the potential first |
| 7766 | // read barrier emission at the beginning of this method. |
| 7767 | // |
| 7768 | // TODO: Introduce a new runtime entry point taking the object |
| 7769 | // to test (instead of its class) as argument, and let it deal |
| 7770 | // with the read barrier issues. This will let us refactor this |
| 7771 | // case of the `switch` code as it was previously (with a direct |
| 7772 | // call to the runtime not using a type checking slow path). |
| 7773 | // This should also be beneficial for the other cases above. |
| 7774 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7775 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7776 | instruction, /* is_fatal= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7777 | codegen_->AddSlowPath(slow_path); |
| 7778 | __ B(slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7779 | break; |
| 7780 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7781 | |
| 7782 | case TypeCheckKind::kBitstringCheck: { |
| 7783 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7784 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7785 | out_loc, |
| 7786 | obj_loc, |
| 7787 | class_offset, |
| 7788 | maybe_temp_loc, |
| 7789 | kWithoutReadBarrier); |
| 7790 | |
| 7791 | GenerateBitstringTypeCheckCompare(instruction, out, DontCare); |
| 7792 | // If `out` is a low reg and we would have another low reg temp, we could |
| 7793 | // optimize this as RSBS+ADC, see GenerateConditionWithZero(). |
| 7794 | // |
| 7795 | // Also, in some cases when `out` is a low reg and we're loading a constant to IP |
| 7796 | // it would make sense to use CMP+MOV+IT+MOV instead of SUB+CLZ+LSR as the code size |
| 7797 | // would be the same and we would have fewer direct data dependencies. |
| 7798 | codegen_->GenerateConditionWithZero(kCondEQ, out, out); // CLZ+LSR |
| 7799 | break; |
| 7800 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7801 | } |
| 7802 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7803 | if (done.IsReferenced()) { |
| 7804 | __ Bind(&done); |
| 7805 | } |
| 7806 | |
| 7807 | if (slow_path != nullptr) { |
| 7808 | __ Bind(slow_path->GetExitLabel()); |
| 7809 | } |
| 7810 | } |
| 7811 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7812 | void LocationsBuilderARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7813 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7814 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7815 | LocationSummary* locations = |
| 7816 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7817 | locations->SetInAt(0, Location::RequiresRegister()); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7818 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { |
| 7819 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 7820 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); |
| 7821 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); |
| 7822 | } else { |
| 7823 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7824 | } |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7825 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7826 | } |
| 7827 | |
| 7828 | void InstructionCodeGeneratorARMVIXL::VisitCheckCast(HCheckCast* instruction) { |
| 7829 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 7830 | LocationSummary* locations = instruction->GetLocations(); |
| 7831 | Location obj_loc = locations->InAt(0); |
| 7832 | vixl32::Register obj = InputRegisterAt(instruction, 0); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7833 | vixl32::Register cls = (type_check_kind == TypeCheckKind::kBitstringCheck) |
| 7834 | ? vixl32::Register() |
| 7835 | : InputRegisterAt(instruction, 1); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7836 | Location temp_loc = locations->GetTemp(0); |
| 7837 | vixl32::Register temp = RegisterFrom(temp_loc); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7838 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); |
| 7839 | DCHECK_LE(num_temps, 3u); |
| 7840 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); |
| 7841 | Location maybe_temp3_loc = (num_temps >= 3) ? locations->GetTemp(2) : Location::NoLocation(); |
| 7842 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 7843 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 7844 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 7845 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 7846 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); |
| 7847 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 7848 | const uint32_t object_array_data_offset = |
| 7849 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7850 | |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7851 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7852 | SlowPathCodeARMVIXL* type_check_slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7853 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathARMVIXL( |
| 7854 | instruction, is_type_check_slow_path_fatal); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7855 | codegen_->AddSlowPath(type_check_slow_path); |
| 7856 | |
| 7857 | vixl32::Label done; |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 7858 | vixl32::Label* final_label = codegen_->GetFinalLabel(instruction, &done); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7859 | // Avoid null check if we know obj is not null. |
| 7860 | if (instruction->MustDoNullCheck()) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7861 | __ CompareAndBranchIfZero(obj, final_label, /* is_far_target= */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7862 | } |
| 7863 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7864 | switch (type_check_kind) { |
| 7865 | case TypeCheckKind::kExactCheck: |
| 7866 | case TypeCheckKind::kArrayCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7867 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7868 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7869 | temp_loc, |
| 7870 | obj_loc, |
| 7871 | class_offset, |
| 7872 | maybe_temp2_loc, |
| 7873 | kWithoutReadBarrier); |
| 7874 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7875 | __ Cmp(temp, cls); |
| 7876 | // Jump to slow path for throwing the exception or doing a |
| 7877 | // more involved array check. |
| 7878 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 7879 | break; |
| 7880 | } |
| 7881 | |
| 7882 | case TypeCheckKind::kAbstractClassCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7883 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7884 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7885 | temp_loc, |
| 7886 | obj_loc, |
| 7887 | class_offset, |
| 7888 | maybe_temp2_loc, |
| 7889 | kWithoutReadBarrier); |
| 7890 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7891 | // If the class is abstract, we eagerly fetch the super class of the |
| 7892 | // object to avoid doing a comparison we know will fail. |
| 7893 | vixl32::Label loop; |
| 7894 | __ Bind(&loop); |
| 7895 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7896 | GenerateReferenceLoadOneRegister(instruction, |
| 7897 | temp_loc, |
| 7898 | super_offset, |
| 7899 | maybe_temp2_loc, |
| 7900 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7901 | |
| 7902 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7903 | // exception. |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7904 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7905 | |
| 7906 | // Otherwise, compare the classes. |
| 7907 | __ Cmp(temp, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7908 | __ B(ne, &loop, /* is_far_target= */ false); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7909 | break; |
| 7910 | } |
| 7911 | |
| 7912 | case TypeCheckKind::kClassHierarchyCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7913 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7914 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7915 | temp_loc, |
| 7916 | obj_loc, |
| 7917 | class_offset, |
| 7918 | maybe_temp2_loc, |
| 7919 | kWithoutReadBarrier); |
| 7920 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7921 | // Walk over the class hierarchy to find a match. |
| 7922 | vixl32::Label loop; |
| 7923 | __ Bind(&loop); |
| 7924 | __ Cmp(temp, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7925 | __ B(eq, final_label, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7926 | |
| 7927 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7928 | GenerateReferenceLoadOneRegister(instruction, |
| 7929 | temp_loc, |
| 7930 | super_offset, |
| 7931 | maybe_temp2_loc, |
| 7932 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7933 | |
| 7934 | // If the class reference currently in `temp` is null, jump to the slow path to throw the |
| 7935 | // exception. |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7936 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7937 | // Otherwise, jump to the beginning of the loop. |
| 7938 | __ B(&loop); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7939 | break; |
| 7940 | } |
| 7941 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7942 | case TypeCheckKind::kArrayObjectCheck: { |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7943 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7944 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7945 | temp_loc, |
| 7946 | obj_loc, |
| 7947 | class_offset, |
| 7948 | maybe_temp2_loc, |
| 7949 | kWithoutReadBarrier); |
| 7950 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7951 | // Do an exact check. |
| 7952 | __ Cmp(temp, cls); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7953 | __ B(eq, final_label, /* is_far_target= */ false); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7954 | |
| 7955 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 7956 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7957 | GenerateReferenceLoadOneRegister(instruction, |
| 7958 | temp_loc, |
| 7959 | component_offset, |
| 7960 | maybe_temp2_loc, |
| 7961 | kWithoutReadBarrier); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7962 | // If the component type is null, jump to the slow path to throw the exception. |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7963 | __ CompareAndBranchIfZero(temp, type_check_slow_path->GetEntryLabel()); |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7964 | // Otherwise,the object is indeed an array, jump to label `check_non_primitive_component_type` |
| 7965 | // to further check that this component type is not a primitive type. |
| 7966 | GetAssembler()->LoadFromOffset(kLoadUnsignedHalfword, temp, temp, primitive_offset); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7967 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 7968 | __ CompareAndBranchIfNonZero(temp, type_check_slow_path->GetEntryLabel()); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7969 | break; |
| 7970 | } |
| 7971 | |
| 7972 | case TypeCheckKind::kUnresolvedCheck: |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7973 | // We always go into the type check slow path for the unresolved check case. |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7974 | // We cannot directly call the CheckCast runtime entry point |
| 7975 | // without resorting to a type checking slow path here (i.e. by |
| 7976 | // calling InvokeRuntime directly), as it would require to |
| 7977 | // assign fixed registers for the inputs of this HInstanceOf |
| 7978 | // instruction (following the runtime calling convention), which |
| 7979 | // might be cluttered by the potential first read barrier |
| 7980 | // emission at the beginning of this method. |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7981 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 7982 | __ B(type_check_slow_path->GetEntryLabel()); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 7983 | break; |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 7984 | |
| 7985 | case TypeCheckKind::kInterfaceCheck: { |
| 7986 | // Avoid read barriers to improve performance of the fast path. We can not get false |
| 7987 | // positives by doing this. |
| 7988 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 7989 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7990 | temp_loc, |
| 7991 | obj_loc, |
| 7992 | class_offset, |
| 7993 | maybe_temp2_loc, |
| 7994 | kWithoutReadBarrier); |
| 7995 | |
| 7996 | // /* HeapReference<Class> */ temp = temp->iftable_ |
| 7997 | GenerateReferenceLoadTwoRegisters(instruction, |
| 7998 | temp_loc, |
| 7999 | temp_loc, |
| 8000 | iftable_offset, |
| 8001 | maybe_temp2_loc, |
| 8002 | kWithoutReadBarrier); |
| 8003 | // Iftable is never null. |
| 8004 | __ Ldr(RegisterFrom(maybe_temp2_loc), MemOperand(temp, array_length_offset)); |
| 8005 | // Loop through the iftable and check if any class matches. |
| 8006 | vixl32::Label start_loop; |
| 8007 | __ Bind(&start_loop); |
| 8008 | __ CompareAndBranchIfZero(RegisterFrom(maybe_temp2_loc), |
| 8009 | type_check_slow_path->GetEntryLabel()); |
| 8010 | __ Ldr(RegisterFrom(maybe_temp3_loc), MemOperand(temp, object_array_data_offset)); |
| 8011 | GetAssembler()->MaybeUnpoisonHeapReference(RegisterFrom(maybe_temp3_loc)); |
| 8012 | // Go to next interface. |
| 8013 | __ Add(temp, temp, Operand::From(2 * kHeapReferenceSize)); |
| 8014 | __ Sub(RegisterFrom(maybe_temp2_loc), RegisterFrom(maybe_temp2_loc), 2); |
| 8015 | // Compare the classes and continue the loop if they do not match. |
| 8016 | __ Cmp(cls, RegisterFrom(maybe_temp3_loc)); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8017 | __ B(ne, &start_loop, /* is_far_target= */ false); |
| Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 8018 | break; |
| 8019 | } |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 8020 | |
| 8021 | case TypeCheckKind::kBitstringCheck: { |
| 8022 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 8023 | GenerateReferenceLoadTwoRegisters(instruction, |
| 8024 | temp_loc, |
| 8025 | obj_loc, |
| 8026 | class_offset, |
| 8027 | maybe_temp2_loc, |
| 8028 | kWithoutReadBarrier); |
| 8029 | |
| 8030 | GenerateBitstringTypeCheckCompare(instruction, temp, SetFlags); |
| 8031 | __ B(ne, type_check_slow_path->GetEntryLabel()); |
| 8032 | break; |
| 8033 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8034 | } |
| Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 8035 | if (done.IsReferenced()) { |
| 8036 | __ Bind(&done); |
| 8037 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8038 | |
| 8039 | __ Bind(type_check_slow_path->GetExitLabel()); |
| 8040 | } |
| 8041 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8042 | void LocationsBuilderARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8043 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( |
| 8044 | instruction, LocationSummary::kCallOnMainOnly); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8045 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 8046 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 8047 | } |
| 8048 | |
| 8049 | void InstructionCodeGeneratorARMVIXL::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 8050 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject : kQuickUnlockObject, |
| 8051 | instruction, |
| 8052 | instruction->GetDexPc()); |
| 8053 | if (instruction->IsEnter()) { |
| 8054 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 8055 | } else { |
| 8056 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 8057 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8058 | codegen_->MaybeGenerateMarkingRegisterCheck(/* code= */ 18); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 8059 | } |
| 8060 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8061 | void LocationsBuilderARMVIXL::VisitAnd(HAnd* instruction) { |
| 8062 | HandleBitwiseOperation(instruction, AND); |
| 8063 | } |
| 8064 | |
| 8065 | void LocationsBuilderARMVIXL::VisitOr(HOr* instruction) { |
| 8066 | HandleBitwiseOperation(instruction, ORR); |
| 8067 | } |
| 8068 | |
| 8069 | void LocationsBuilderARMVIXL::VisitXor(HXor* instruction) { |
| 8070 | HandleBitwiseOperation(instruction, EOR); |
| 8071 | } |
| 8072 | |
| 8073 | void LocationsBuilderARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction, Opcode opcode) { |
| 8074 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8075 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8076 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8077 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8078 | // Note: GVN reorders commutative operations to have the constant on the right hand side. |
| 8079 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8080 | locations->SetInAt(1, ArmEncodableConstantOrRegister(instruction->InputAt(1), opcode)); |
| 8081 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8082 | } |
| 8083 | |
| 8084 | void InstructionCodeGeneratorARMVIXL::VisitAnd(HAnd* instruction) { |
| 8085 | HandleBitwiseOperation(instruction); |
| 8086 | } |
| 8087 | |
| 8088 | void InstructionCodeGeneratorARMVIXL::VisitOr(HOr* instruction) { |
| 8089 | HandleBitwiseOperation(instruction); |
| 8090 | } |
| 8091 | |
| 8092 | void InstructionCodeGeneratorARMVIXL::VisitXor(HXor* instruction) { |
| 8093 | HandleBitwiseOperation(instruction); |
| 8094 | } |
| 8095 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8096 | void LocationsBuilderARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8097 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8098 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8099 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 |
| 8100 | || instruction->GetResultType() == DataType::Type::kInt64); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8101 | |
| 8102 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8103 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8104 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 8105 | } |
| 8106 | |
| 8107 | void InstructionCodeGeneratorARMVIXL::VisitBitwiseNegatedRight(HBitwiseNegatedRight* instruction) { |
| 8108 | LocationSummary* locations = instruction->GetLocations(); |
| 8109 | Location first = locations->InAt(0); |
| 8110 | Location second = locations->InAt(1); |
| 8111 | Location out = locations->Out(); |
| 8112 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8113 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8114 | vixl32::Register first_reg = RegisterFrom(first); |
| 8115 | vixl32::Register second_reg = RegisterFrom(second); |
| 8116 | vixl32::Register out_reg = RegisterFrom(out); |
| 8117 | |
| 8118 | switch (instruction->GetOpKind()) { |
| 8119 | case HInstruction::kAnd: |
| 8120 | __ Bic(out_reg, first_reg, second_reg); |
| 8121 | break; |
| 8122 | case HInstruction::kOr: |
| 8123 | __ Orn(out_reg, first_reg, second_reg); |
| 8124 | break; |
| 8125 | // There is no EON on arm. |
| 8126 | case HInstruction::kXor: |
| 8127 | default: |
| 8128 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8129 | UNREACHABLE(); |
| 8130 | } |
| 8131 | return; |
| 8132 | |
| 8133 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8134 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 8135 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8136 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8137 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8138 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8139 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8140 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8141 | |
| 8142 | switch (instruction->GetOpKind()) { |
| 8143 | case HInstruction::kAnd: |
| 8144 | __ Bic(out_low, first_low, second_low); |
| 8145 | __ Bic(out_high, first_high, second_high); |
| 8146 | break; |
| 8147 | case HInstruction::kOr: |
| 8148 | __ Orn(out_low, first_low, second_low); |
| 8149 | __ Orn(out_high, first_high, second_high); |
| 8150 | break; |
| 8151 | // There is no EON on arm. |
| 8152 | case HInstruction::kXor: |
| 8153 | default: |
| 8154 | LOG(FATAL) << "Unexpected instruction " << instruction->DebugName(); |
| 8155 | UNREACHABLE(); |
| 8156 | } |
| 8157 | } |
| 8158 | } |
| 8159 | |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8160 | void LocationsBuilderARMVIXL::VisitDataProcWithShifterOp( |
| 8161 | HDataProcWithShifterOp* instruction) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8162 | DCHECK(instruction->GetType() == DataType::Type::kInt32 || |
| 8163 | instruction->GetType() == DataType::Type::kInt64); |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8164 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8165 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8166 | const bool overlap = instruction->GetType() == DataType::Type::kInt64 && |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8167 | HDataProcWithShifterOp::IsExtensionOp(instruction->GetOpKind()); |
| 8168 | |
| 8169 | locations->SetInAt(0, Location::RequiresRegister()); |
| 8170 | locations->SetInAt(1, Location::RequiresRegister()); |
| 8171 | locations->SetOut(Location::RequiresRegister(), |
| 8172 | overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
| 8173 | } |
| 8174 | |
| 8175 | void InstructionCodeGeneratorARMVIXL::VisitDataProcWithShifterOp( |
| 8176 | HDataProcWithShifterOp* instruction) { |
| 8177 | const LocationSummary* const locations = instruction->GetLocations(); |
| 8178 | const HInstruction::InstructionKind kind = instruction->GetInstrKind(); |
| 8179 | const HDataProcWithShifterOp::OpKind op_kind = instruction->GetOpKind(); |
| 8180 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8181 | if (instruction->GetType() == DataType::Type::kInt32) { |
| Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8182 | const vixl32::Register first = InputRegisterAt(instruction, 0); |
| 8183 | const vixl32::Register output = OutputRegister(instruction); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8184 | const vixl32::Register second = instruction->InputAt(1)->GetType() == DataType::Type::kInt64 |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8185 | ? LowRegisterFrom(locations->InAt(1)) |
| 8186 | : InputRegisterAt(instruction, 1); |
| 8187 | |
| Anton Kirilov | 420ee30 | 2017-02-21 18:10:26 +0000 | [diff] [blame] | 8188 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8189 | DCHECK_EQ(kind, HInstruction::kAdd); |
| 8190 | |
| 8191 | switch (op_kind) { |
| 8192 | case HDataProcWithShifterOp::kUXTB: |
| 8193 | __ Uxtab(output, first, second); |
| 8194 | break; |
| 8195 | case HDataProcWithShifterOp::kUXTH: |
| 8196 | __ Uxtah(output, first, second); |
| 8197 | break; |
| 8198 | case HDataProcWithShifterOp::kSXTB: |
| 8199 | __ Sxtab(output, first, second); |
| 8200 | break; |
| 8201 | case HDataProcWithShifterOp::kSXTH: |
| 8202 | __ Sxtah(output, first, second); |
| 8203 | break; |
| 8204 | default: |
| 8205 | LOG(FATAL) << "Unexpected operation kind: " << op_kind; |
| 8206 | UNREACHABLE(); |
| 8207 | } |
| 8208 | } else { |
| 8209 | GenerateDataProcInstruction(kind, |
| 8210 | output, |
| 8211 | first, |
| 8212 | Operand(second, |
| 8213 | ShiftFromOpKind(op_kind), |
| 8214 | instruction->GetShiftAmount()), |
| 8215 | codegen_); |
| 8216 | } |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8217 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8218 | DCHECK_EQ(instruction->GetType(), DataType::Type::kInt64); |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 8219 | |
| 8220 | if (HDataProcWithShifterOp::IsExtensionOp(op_kind)) { |
| 8221 | const vixl32::Register second = InputRegisterAt(instruction, 1); |
| 8222 | |
| 8223 | DCHECK(!LowRegisterFrom(locations->Out()).Is(second)); |
| 8224 | GenerateDataProc(kind, |
| 8225 | locations->Out(), |
| 8226 | locations->InAt(0), |
| 8227 | second, |
| 8228 | Operand(second, ShiftType::ASR, 31), |
| 8229 | codegen_); |
| 8230 | } else { |
| 8231 | GenerateLongDataProc(instruction, codegen_); |
| 8232 | } |
| 8233 | } |
| 8234 | } |
| 8235 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8236 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8237 | void InstructionCodeGeneratorARMVIXL::GenerateAndConst(vixl32::Register out, |
| 8238 | vixl32::Register first, |
| 8239 | uint32_t value) { |
| 8240 | // Optimize special cases for individual halfs of `and-long` (`and` is simplified earlier). |
| 8241 | if (value == 0xffffffffu) { |
| 8242 | if (!out.Is(first)) { |
| 8243 | __ Mov(out, first); |
| 8244 | } |
| 8245 | return; |
| 8246 | } |
| 8247 | if (value == 0u) { |
| 8248 | __ Mov(out, 0); |
| 8249 | return; |
| 8250 | } |
| 8251 | if (GetAssembler()->ShifterOperandCanHold(AND, value)) { |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8252 | __ And(out, first, value); |
| 8253 | } else if (GetAssembler()->ShifterOperandCanHold(BIC, ~value)) { |
| 8254 | __ Bic(out, first, ~value); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8255 | } else { |
| Anton Kirilov | effd5bf | 2017-02-28 16:59:15 +0000 | [diff] [blame] | 8256 | DCHECK(IsPowerOfTwo(value + 1)); |
| 8257 | __ Ubfx(out, first, 0, WhichPowerOf2(value + 1)); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8258 | } |
| 8259 | } |
| 8260 | |
| 8261 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8262 | void InstructionCodeGeneratorARMVIXL::GenerateOrrConst(vixl32::Register out, |
| 8263 | vixl32::Register first, |
| 8264 | uint32_t value) { |
| 8265 | // Optimize special cases for individual halfs of `or-long` (`or` is simplified earlier). |
| 8266 | if (value == 0u) { |
| 8267 | if (!out.Is(first)) { |
| 8268 | __ Mov(out, first); |
| 8269 | } |
| 8270 | return; |
| 8271 | } |
| 8272 | if (value == 0xffffffffu) { |
| 8273 | __ Mvn(out, 0); |
| 8274 | return; |
| 8275 | } |
| 8276 | if (GetAssembler()->ShifterOperandCanHold(ORR, value)) { |
| 8277 | __ Orr(out, first, value); |
| 8278 | } else { |
| 8279 | DCHECK(GetAssembler()->ShifterOperandCanHold(ORN, ~value)); |
| 8280 | __ Orn(out, first, ~value); |
| 8281 | } |
| 8282 | } |
| 8283 | |
| 8284 | // TODO(VIXL): Remove optimizations in the helper when they are implemented in vixl. |
| 8285 | void InstructionCodeGeneratorARMVIXL::GenerateEorConst(vixl32::Register out, |
| 8286 | vixl32::Register first, |
| 8287 | uint32_t value) { |
| 8288 | // Optimize special case for individual halfs of `xor-long` (`xor` is simplified earlier). |
| 8289 | if (value == 0u) { |
| 8290 | if (!out.Is(first)) { |
| 8291 | __ Mov(out, first); |
| 8292 | } |
| 8293 | return; |
| 8294 | } |
| 8295 | __ Eor(out, first, value); |
| 8296 | } |
| 8297 | |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8298 | void InstructionCodeGeneratorARMVIXL::GenerateAddLongConst(Location out, |
| 8299 | Location first, |
| 8300 | uint64_t value) { |
| 8301 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8302 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8303 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8304 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8305 | uint32_t value_low = Low32Bits(value); |
| 8306 | uint32_t value_high = High32Bits(value); |
| 8307 | if (value_low == 0u) { |
| 8308 | if (!out_low.Is(first_low)) { |
| 8309 | __ Mov(out_low, first_low); |
| 8310 | } |
| 8311 | __ Add(out_high, first_high, value_high); |
| 8312 | return; |
| 8313 | } |
| 8314 | __ Adds(out_low, first_low, value_low); |
| Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8315 | if (GetAssembler()->ShifterOperandCanHold(ADC, value_high)) { |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8316 | __ Adc(out_high, first_high, value_high); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8317 | } else { |
| Vladimir Marko | f0a6a1d | 2018-01-08 14:23:56 +0000 | [diff] [blame] | 8318 | DCHECK(GetAssembler()->ShifterOperandCanHold(SBC, ~value_high)); |
| 8319 | __ Sbc(out_high, first_high, ~value_high); |
| Anton Kirilov | dda4396 | 2016-11-21 19:55:20 +0000 | [diff] [blame] | 8320 | } |
| 8321 | } |
| 8322 | |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8323 | void InstructionCodeGeneratorARMVIXL::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 8324 | LocationSummary* locations = instruction->GetLocations(); |
| 8325 | Location first = locations->InAt(0); |
| 8326 | Location second = locations->InAt(1); |
| 8327 | Location out = locations->Out(); |
| 8328 | |
| 8329 | if (second.IsConstant()) { |
| 8330 | uint64_t value = static_cast<uint64_t>(Int64FromConstant(second.GetConstant())); |
| 8331 | uint32_t value_low = Low32Bits(value); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8332 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8333 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8334 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8335 | if (instruction->IsAnd()) { |
| 8336 | GenerateAndConst(out_reg, first_reg, value_low); |
| 8337 | } else if (instruction->IsOr()) { |
| 8338 | GenerateOrrConst(out_reg, first_reg, value_low); |
| 8339 | } else { |
| 8340 | DCHECK(instruction->IsXor()); |
| 8341 | GenerateEorConst(out_reg, first_reg, value_low); |
| 8342 | } |
| 8343 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8344 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8345 | uint32_t value_high = High32Bits(value); |
| 8346 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8347 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8348 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8349 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8350 | if (instruction->IsAnd()) { |
| 8351 | GenerateAndConst(out_low, first_low, value_low); |
| 8352 | GenerateAndConst(out_high, first_high, value_high); |
| 8353 | } else if (instruction->IsOr()) { |
| 8354 | GenerateOrrConst(out_low, first_low, value_low); |
| 8355 | GenerateOrrConst(out_high, first_high, value_high); |
| 8356 | } else { |
| 8357 | DCHECK(instruction->IsXor()); |
| 8358 | GenerateEorConst(out_low, first_low, value_low); |
| 8359 | GenerateEorConst(out_high, first_high, value_high); |
| 8360 | } |
| 8361 | } |
| 8362 | return; |
| 8363 | } |
| 8364 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8365 | if (instruction->GetResultType() == DataType::Type::kInt32) { |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8366 | vixl32::Register first_reg = InputRegisterAt(instruction, 0); |
| 8367 | vixl32::Register second_reg = InputRegisterAt(instruction, 1); |
| 8368 | vixl32::Register out_reg = OutputRegister(instruction); |
| 8369 | if (instruction->IsAnd()) { |
| 8370 | __ And(out_reg, first_reg, second_reg); |
| 8371 | } else if (instruction->IsOr()) { |
| 8372 | __ Orr(out_reg, first_reg, second_reg); |
| 8373 | } else { |
| 8374 | DCHECK(instruction->IsXor()); |
| 8375 | __ Eor(out_reg, first_reg, second_reg); |
| 8376 | } |
| 8377 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8378 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); |
| Artem Serov | 02109dd | 2016-09-23 17:17:54 +0100 | [diff] [blame] | 8379 | vixl32::Register first_low = LowRegisterFrom(first); |
| 8380 | vixl32::Register first_high = HighRegisterFrom(first); |
| 8381 | vixl32::Register second_low = LowRegisterFrom(second); |
| 8382 | vixl32::Register second_high = HighRegisterFrom(second); |
| 8383 | vixl32::Register out_low = LowRegisterFrom(out); |
| 8384 | vixl32::Register out_high = HighRegisterFrom(out); |
| 8385 | if (instruction->IsAnd()) { |
| 8386 | __ And(out_low, first_low, second_low); |
| 8387 | __ And(out_high, first_high, second_high); |
| 8388 | } else if (instruction->IsOr()) { |
| 8389 | __ Orr(out_low, first_low, second_low); |
| 8390 | __ Orr(out_high, first_high, second_high); |
| 8391 | } else { |
| 8392 | DCHECK(instruction->IsXor()); |
| 8393 | __ Eor(out_low, first_low, second_low); |
| 8394 | __ Eor(out_high, first_high, second_high); |
| 8395 | } |
| 8396 | } |
| 8397 | } |
| 8398 | |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8399 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadOneRegister( |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8400 | HInstruction* instruction, |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8401 | Location out, |
| 8402 | uint32_t offset, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8403 | Location maybe_temp, |
| 8404 | ReadBarrierOption read_barrier_option) { |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8405 | vixl32::Register out_reg = RegisterFrom(out); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8406 | if (read_barrier_option == kWithReadBarrier) { |
| 8407 | CHECK(kEmitCompilerReadBarrier); |
| 8408 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8409 | if (kUseBakerReadBarrier) { |
| 8410 | // Load with fast path based Baker's read barrier. |
| 8411 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8412 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8413 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check= */ false); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8414 | } else { |
| 8415 | // Load with slow path based read barrier. |
| 8416 | // Save the value of `out` into `maybe_temp` before overwriting it |
| 8417 | // in the following move operation, as we will need it for the |
| 8418 | // read barrier below. |
| 8419 | __ Mov(RegisterFrom(maybe_temp), out_reg); |
| 8420 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8421 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8422 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
| 8423 | } |
| Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 8424 | } else { |
| 8425 | // Plain load with no read barrier. |
| 8426 | // /* HeapReference<Object> */ out = *(out + offset) |
| 8427 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, out_reg, offset); |
| 8428 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8429 | } |
| 8430 | } |
| 8431 | |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8432 | void InstructionCodeGeneratorARMVIXL::GenerateReferenceLoadTwoRegisters( |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8433 | HInstruction* instruction, |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8434 | Location out, |
| 8435 | Location obj, |
| 8436 | uint32_t offset, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8437 | Location maybe_temp, |
| 8438 | ReadBarrierOption read_barrier_option) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8439 | vixl32::Register out_reg = RegisterFrom(out); |
| 8440 | vixl32::Register obj_reg = RegisterFrom(obj); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8441 | if (read_barrier_option == kWithReadBarrier) { |
| 8442 | CHECK(kEmitCompilerReadBarrier); |
| 8443 | if (kUseBakerReadBarrier) { |
| 8444 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
| 8445 | // Load with fast path based Baker's read barrier. |
| 8446 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8447 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8448 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check= */ false); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8449 | } else { |
| 8450 | // Load with slow path based read barrier. |
| 8451 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8452 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8453 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 8454 | } |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 8455 | } else { |
| 8456 | // Plain load with no read barrier. |
| 8457 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 8458 | GetAssembler()->LoadFromOffset(kLoadWord, out_reg, obj_reg, offset); |
| 8459 | GetAssembler()->MaybeUnpoisonHeapReference(out_reg); |
| 8460 | } |
| 8461 | } |
| 8462 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8463 | void CodeGeneratorARMVIXL::GenerateGcRootFieldLoad( |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8464 | HInstruction* instruction, |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8465 | Location root, |
| 8466 | vixl32::Register obj, |
| 8467 | uint32_t offset, |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8468 | ReadBarrierOption read_barrier_option) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8469 | vixl32::Register root_reg = RegisterFrom(root); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8470 | if (read_barrier_option == kWithReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8471 | DCHECK(kEmitCompilerReadBarrier); |
| 8472 | if (kUseBakerReadBarrier) { |
| 8473 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8474 | // Baker's read barrier are used. |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8475 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8476 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in |
| 8477 | // the Marking Register) to decide whether we need to enter |
| 8478 | // the slow path to mark the GC root. |
| 8479 | // |
| 8480 | // We use shared thunks for the slow path; shared within the method |
| 8481 | // for JIT, across methods for AOT. That thunk checks the reference |
| 8482 | // and jumps to the entrypoint if needed. |
| 8483 | // |
| 8484 | // lr = &return_address; |
| 8485 | // GcRoot<mirror::Object> root = *(obj+offset); // Original reference load. |
| 8486 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8487 | // goto gc_root_thunk<root_reg>(lr) |
| 8488 | // } |
| 8489 | // return_address: |
| Roland Levillain | ba650a4 | 2017-03-06 13:52:32 +0000 | [diff] [blame] | 8490 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8491 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8492 | temps.Exclude(ip); |
| 8493 | bool narrow = CanEmitNarrowLdr(root_reg, obj, offset); |
| 8494 | uint32_t custom_data = EncodeBakerReadBarrierGcRootData(root_reg.GetCode(), narrow); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8495 | |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8496 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u) + /* LDR */ (narrow ? 1u : 0u); |
| 8497 | size_t wide_instructions = /* ADR+CMP+LDR+BNE */ 4u - narrow_instructions; |
| 8498 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8499 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8500 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8501 | vixl32::Label return_address; |
| 8502 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8503 | __ cmp(mr, Operand(0)); |
| 8504 | // Currently the offset is always within range. If that changes, |
| 8505 | // we shall have to split the load the same way as for fields. |
| 8506 | DCHECK_LT(offset, kReferenceLoadMinFarOffset); |
| 8507 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8508 | __ ldr(EncodingSize(narrow ? Narrow : Wide), root_reg, MemOperand(obj, offset)); |
| 8509 | EmitBakerReadBarrierBne(custom_data); |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8510 | __ bind(&return_address); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8511 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8512 | narrow ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_OFFSET |
| 8513 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_OFFSET); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8514 | } else { |
| 8515 | // GC root loaded through a slow path for read barriers other |
| 8516 | // than Baker's. |
| 8517 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 8518 | __ Add(root_reg, obj, offset); |
| 8519 | // /* mirror::Object* */ root = root->Read() |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 8520 | GenerateReadBarrierForRootSlow(instruction, root, root); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8521 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8522 | } else { |
| 8523 | // Plain GC root load with no read barrier. |
| 8524 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 8525 | GetAssembler()->LoadFromOffset(kLoadWord, root_reg, obj, offset); |
| 8526 | // Note that GC roots are not affected by heap poisoning, thus we |
| 8527 | // do not have to unpoison `root_reg` here. |
| 8528 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8529 | MaybeGenerateMarkingRegisterCheck(/* code= */ 19); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8530 | } |
| 8531 | |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8532 | void CodeGeneratorARMVIXL::GenerateUnsafeCasOldValueAddWithBakerReadBarrier( |
| 8533 | vixl::aarch32::Register old_value, |
| 8534 | vixl::aarch32::Register adjusted_old_value, |
| 8535 | vixl::aarch32::Register expected) { |
| 8536 | DCHECK(kEmitCompilerReadBarrier); |
| 8537 | DCHECK(kUseBakerReadBarrier); |
| 8538 | |
| 8539 | // Similar to the Baker RB path in GenerateGcRootFieldLoad(), with an ADD instead of LDR. |
| 8540 | uint32_t custom_data = EncodeBakerReadBarrierUnsafeCasData(old_value.GetCode()); |
| 8541 | |
| 8542 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u); |
| 8543 | size_t wide_instructions = /* ADR+CMP+ADD+BNE */ 4u - narrow_instructions; |
| 8544 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8545 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8546 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
| 8547 | vixl32::Label return_address; |
| 8548 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8549 | __ cmp(mr, Operand(0)); |
| 8550 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8551 | __ add(EncodingSize(Wide), old_value, adjusted_old_value, Operand(expected)); // Preserves flags. |
| 8552 | EmitBakerReadBarrierBne(custom_data); |
| 8553 | __ bind(&return_address); |
| 8554 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8555 | BAKER_MARK_INTROSPECTION_UNSAFE_CAS_ADD_OFFSET); |
| 8556 | } |
| 8557 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8558 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8559 | Location ref, |
| 8560 | vixl32::Register obj, |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8561 | const vixl32::MemOperand& src, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8562 | bool needs_null_check) { |
| 8563 | DCHECK(kEmitCompilerReadBarrier); |
| 8564 | DCHECK(kUseBakerReadBarrier); |
| 8565 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8566 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8567 | // Marking Register) to decide whether we need to enter the slow |
| 8568 | // path to mark the reference. Then, in the slow path, check the |
| 8569 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8570 | // decide whether to mark `ref` or not. |
| 8571 | // |
| 8572 | // We use shared thunks for the slow path; shared within the method |
| 8573 | // for JIT, across methods for AOT. That thunk checks the holder |
| 8574 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 8575 | // it creates a fake dependency and returns to the LDR instruction. |
| 8576 | // |
| 8577 | // lr = &gray_return_address; |
| 8578 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8579 | // goto field_thunk<holder_reg, base_reg>(lr) |
| 8580 | // } |
| 8581 | // not_gray_return_address: |
| 8582 | // // Original reference load. If the offset is too large to fit |
| 8583 | // // into LDR, we use an adjusted base register here. |
| 8584 | // HeapReference<mirror::Object> reference = *(obj+offset); |
| 8585 | // gray_return_address: |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8586 | |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8587 | DCHECK(src.GetAddrMode() == vixl32::Offset); |
| 8588 | DCHECK_ALIGNED(src.GetOffsetImmediate(), sizeof(mirror::HeapReference<mirror::Object>)); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8589 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8590 | bool narrow = CanEmitNarrowLdr(ref_reg, src.GetBaseRegister(), src.GetOffsetImmediate()); |
| 8591 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8592 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8593 | temps.Exclude(ip); |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8594 | uint32_t custom_data = |
| 8595 | EncodeBakerReadBarrierFieldData(src.GetBaseRegister().GetCode(), obj.GetCode(), narrow); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8596 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8597 | { |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8598 | size_t narrow_instructions = |
| 8599 | /* CMP */ (mr.IsLow() ? 1u : 0u) + |
| 8600 | /* LDR+unpoison? */ (narrow ? (kPoisonHeapReferences ? 2u : 1u) : 0u); |
| 8601 | size_t wide_instructions = |
| 8602 | /* ADR+CMP+LDR+BNE+unpoison? */ (kPoisonHeapReferences ? 5u : 4u) - narrow_instructions; |
| 8603 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8604 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8605 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8606 | vixl32::Label return_address; |
| 8607 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8608 | __ cmp(mr, Operand(0)); |
| 8609 | EmitBakerReadBarrierBne(custom_data); |
| 8610 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8611 | __ ldr(EncodingSize(narrow ? Narrow : Wide), ref_reg, src); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8612 | if (needs_null_check) { |
| 8613 | MaybeRecordImplicitNullCheck(instruction); |
| 8614 | } |
| 8615 | // Note: We need a specific width for the unpoisoning NEG. |
| 8616 | if (kPoisonHeapReferences) { |
| 8617 | if (narrow) { |
| 8618 | // The only 16-bit encoding is T1 which sets flags outside IT block (i.e. RSBS, not RSB). |
| 8619 | __ rsbs(EncodingSize(Narrow), ref_reg, ref_reg, Operand(0)); |
| 8620 | } else { |
| 8621 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| 8622 | } |
| 8623 | } |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8624 | __ bind(&return_address); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8625 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8626 | narrow ? BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET |
| 8627 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET); |
| 8628 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8629 | MaybeGenerateMarkingRegisterCheck(/* code= */ 20, /* temp_loc= */ LocationFrom(ip)); |
| Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8630 | } |
| 8631 | |
| Vladimir Marko | 248141f | 2018-08-10 10:40:07 +0100 | [diff] [blame] | 8632 | void CodeGeneratorARMVIXL::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 8633 | Location ref, |
| 8634 | vixl32::Register obj, |
| 8635 | uint32_t offset, |
| 8636 | Location temp, |
| 8637 | bool needs_null_check) { |
| 8638 | DCHECK_ALIGNED(offset, sizeof(mirror::HeapReference<mirror::Object>)); |
| 8639 | vixl32::Register base = obj; |
| 8640 | if (offset >= kReferenceLoadMinFarOffset) { |
| 8641 | base = RegisterFrom(temp); |
| 8642 | static_assert(IsPowerOfTwo(kReferenceLoadMinFarOffset), "Expecting a power of 2."); |
| 8643 | __ Add(base, obj, Operand(offset & ~(kReferenceLoadMinFarOffset - 1u))); |
| 8644 | offset &= (kReferenceLoadMinFarOffset - 1u); |
| 8645 | } |
| 8646 | GenerateFieldLoadWithBakerReadBarrier( |
| 8647 | instruction, ref, obj, MemOperand(base, offset), needs_null_check); |
| 8648 | } |
| 8649 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8650 | void CodeGeneratorARMVIXL::GenerateArrayLoadWithBakerReadBarrier(Location ref, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8651 | vixl32::Register obj, |
| 8652 | uint32_t data_offset, |
| 8653 | Location index, |
| 8654 | Location temp, |
| 8655 | bool needs_null_check) { |
| 8656 | DCHECK(kEmitCompilerReadBarrier); |
| 8657 | DCHECK(kUseBakerReadBarrier); |
| 8658 | |
| 8659 | static_assert( |
| 8660 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 8661 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8662 | ScaleFactor scale_factor = TIMES_4; |
| 8663 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8664 | // Query `art::Thread::Current()->GetIsGcMarking()` (stored in the |
| 8665 | // Marking Register) to decide whether we need to enter the slow |
| 8666 | // path to mark the reference. Then, in the slow path, check the |
| 8667 | // gray bit in the lock word of the reference's holder (`obj`) to |
| 8668 | // decide whether to mark `ref` or not. |
| 8669 | // |
| 8670 | // We use shared thunks for the slow path; shared within the method |
| 8671 | // for JIT, across methods for AOT. That thunk checks the holder |
| 8672 | // and jumps to the entrypoint if needed. If the holder is not gray, |
| 8673 | // it creates a fake dependency and returns to the LDR instruction. |
| 8674 | // |
| 8675 | // lr = &gray_return_address; |
| 8676 | // if (mr) { // Thread::Current()->GetIsGcMarking() |
| 8677 | // goto array_thunk<base_reg>(lr) |
| 8678 | // } |
| 8679 | // not_gray_return_address: |
| 8680 | // // Original reference load. If the offset is too large to fit |
| 8681 | // // into LDR, we use an adjusted base register here. |
| 8682 | // HeapReference<mirror::Object> reference = data[index]; |
| 8683 | // gray_return_address: |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8684 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8685 | DCHECK(index.IsValid()); |
| 8686 | vixl32::Register index_reg = RegisterFrom(index, DataType::Type::kInt32); |
| 8687 | vixl32::Register ref_reg = RegisterFrom(ref, DataType::Type::kReference); |
| 8688 | vixl32::Register data_reg = RegisterFrom(temp, DataType::Type::kInt32); // Raw pointer. |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8689 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8690 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8691 | temps.Exclude(ip); |
| 8692 | uint32_t custom_data = EncodeBakerReadBarrierArrayData(data_reg.GetCode()); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8693 | |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8694 | __ Add(data_reg, obj, Operand(data_offset)); |
| 8695 | { |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8696 | size_t narrow_instructions = /* CMP */ (mr.IsLow() ? 1u : 0u); |
| 8697 | size_t wide_instructions = |
| 8698 | /* ADR+CMP+BNE+LDR+unpoison? */ (kPoisonHeapReferences ? 5u : 4u) - narrow_instructions; |
| 8699 | size_t exact_size = wide_instructions * vixl32::k32BitT32InstructionSizeInBytes + |
| 8700 | narrow_instructions * vixl32::k16BitT32InstructionSizeInBytes; |
| 8701 | ExactAssemblyScope guard(GetVIXLAssembler(), exact_size); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8702 | vixl32::Label return_address; |
| 8703 | EmitAdrCode adr(GetVIXLAssembler(), lr, &return_address); |
| 8704 | __ cmp(mr, Operand(0)); |
| 8705 | EmitBakerReadBarrierBne(custom_data); |
| 8706 | ptrdiff_t old_offset = GetVIXLAssembler()->GetBuffer()->GetCursorOffset(); |
| 8707 | __ ldr(ref_reg, MemOperand(data_reg, index_reg, vixl32::LSL, scale_factor)); |
| 8708 | DCHECK(!needs_null_check); // The thunk cannot handle the null check. |
| 8709 | // Note: We need a Wide NEG for the unpoisoning. |
| 8710 | if (kPoisonHeapReferences) { |
| 8711 | __ rsb(EncodingSize(Wide), ref_reg, ref_reg, Operand(0)); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8712 | } |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 8713 | __ bind(&return_address); |
| Vladimir Marko | 008e09f3 | 2018-08-06 15:42:43 +0100 | [diff] [blame] | 8714 | DCHECK_EQ(old_offset - GetVIXLAssembler()->GetBuffer()->GetCursorOffset(), |
| 8715 | BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 8716 | } |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8717 | MaybeGenerateMarkingRegisterCheck(/* code= */ 21, /* temp_loc= */ LocationFrom(ip)); |
| Roland Levillain | 6070e88 | 2016-11-03 17:51:58 +0000 | [diff] [blame] | 8718 | } |
| 8719 | |
| Roland Levillain | 5daa495 | 2017-07-03 17:23:56 +0100 | [diff] [blame] | 8720 | void CodeGeneratorARMVIXL::MaybeGenerateMarkingRegisterCheck(int code, Location temp_loc) { |
| 8721 | // The following condition is a compile-time one, so it does not have a run-time cost. |
| 8722 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier && kIsDebugBuild) { |
| 8723 | // The following condition is a run-time one; it is executed after the |
| 8724 | // previous compile-time test, to avoid penalizing non-debug builds. |
| 8725 | if (GetCompilerOptions().EmitRunTimeChecksInDebugMode()) { |
| 8726 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 8727 | vixl32::Register temp = temp_loc.IsValid() ? RegisterFrom(temp_loc) : temps.Acquire(); |
| 8728 | GetAssembler()->GenerateMarkingRegisterCheck(temp, |
| 8729 | kMarkingRegisterCheckBreakCodeBaseCode + code); |
| 8730 | } |
| 8731 | } |
| 8732 | } |
| 8733 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8734 | void CodeGeneratorARMVIXL::GenerateReadBarrierSlow(HInstruction* instruction, |
| 8735 | Location out, |
| 8736 | Location ref, |
| 8737 | Location obj, |
| 8738 | uint32_t offset, |
| 8739 | Location index) { |
| 8740 | DCHECK(kEmitCompilerReadBarrier); |
| 8741 | |
| 8742 | // Insert a slow path based read barrier *after* the reference load. |
| 8743 | // |
| 8744 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 8745 | // reference will be carried out by the runtime within the slow |
| 8746 | // path. |
| 8747 | // |
| 8748 | // Note that `ref` currently does not get unpoisoned (when heap |
| 8749 | // poisoning is enabled), which is alright as the `ref` argument is |
| 8750 | // not used by the artReadBarrierSlow entry point. |
| 8751 | // |
| 8752 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8753 | SlowPathCodeARMVIXL* slow_path = new (GetScopedAllocator()) |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8754 | ReadBarrierForHeapReferenceSlowPathARMVIXL(instruction, out, ref, obj, offset, index); |
| 8755 | AddSlowPath(slow_path); |
| 8756 | |
| 8757 | __ B(slow_path->GetEntryLabel()); |
| 8758 | __ Bind(slow_path->GetExitLabel()); |
| 8759 | } |
| 8760 | |
| 8761 | void CodeGeneratorARMVIXL::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8762 | Location out, |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8763 | Location ref, |
| 8764 | Location obj, |
| 8765 | uint32_t offset, |
| 8766 | Location index) { |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8767 | if (kEmitCompilerReadBarrier) { |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8768 | // Baker's read barriers shall be handled by the fast path |
| Roland Levillain | 9983e30 | 2017-07-14 14:34:22 +0100 | [diff] [blame] | 8769 | // (CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier). |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8770 | DCHECK(!kUseBakerReadBarrier); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8771 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 8772 | // by the runtime within the slow path. |
| 8773 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8774 | } else if (kPoisonHeapReferences) { |
| 8775 | GetAssembler()->UnpoisonHeapReference(RegisterFrom(out)); |
| 8776 | } |
| 8777 | } |
| 8778 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8779 | void CodeGeneratorARMVIXL::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 8780 | Location out, |
| 8781 | Location root) { |
| 8782 | DCHECK(kEmitCompilerReadBarrier); |
| 8783 | |
| 8784 | // Insert a slow path based read barrier *after* the GC root load. |
| 8785 | // |
| 8786 | // Note that GC roots are not affected by heap poisoning, so we do |
| 8787 | // not need to do anything special for this here. |
| 8788 | SlowPathCodeARMVIXL* slow_path = |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8789 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathARMVIXL(instruction, out, root); |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 8790 | AddSlowPath(slow_path); |
| 8791 | |
| 8792 | __ B(slow_path->GetEntryLabel()); |
| 8793 | __ Bind(slow_path->GetExitLabel()); |
| 8794 | } |
| 8795 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8796 | // Check if the desired_dispatch_info is supported. If it is, return it, |
| 8797 | // otherwise return a fall-back info that should be used instead. |
| 8798 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorARMVIXL::GetSupportedInvokeStaticOrDirectDispatch( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8799 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 8800 | ArtMethod* method ATTRIBUTE_UNUSED) { |
| Nicolas Geoffray | e807ff7 | 2017-01-23 09:03:12 +0000 | [diff] [blame] | 8801 | return desired_dispatch_info; |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 8802 | } |
| 8803 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8804 | vixl32::Register CodeGeneratorARMVIXL::GetInvokeStaticOrDirectExtraParameter( |
| 8805 | HInvokeStaticOrDirect* invoke, vixl32::Register temp) { |
| 8806 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 8807 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8808 | if (!invoke->GetLocations()->Intrinsified()) { |
| 8809 | return RegisterFrom(location); |
| 8810 | } |
| 8811 | // For intrinsics we allow any location, so it may be on the stack. |
| 8812 | if (!location.IsRegister()) { |
| 8813 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, location.GetStackIndex()); |
| 8814 | return temp; |
| 8815 | } |
| 8816 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 8817 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 8818 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 8819 | // simple and more robust approach rather that trying to determine if that's the case. |
| 8820 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| Scott Wakeling | d5cd497 | 2017-02-03 11:38:35 +0000 | [diff] [blame] | 8821 | if (slow_path != nullptr && slow_path->IsCoreRegisterSaved(RegisterFrom(location).GetCode())) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8822 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(RegisterFrom(location).GetCode()); |
| 8823 | GetAssembler()->LoadFromOffset(kLoadWord, temp, sp, stack_offset); |
| 8824 | return temp; |
| 8825 | } |
| 8826 | return RegisterFrom(location); |
| 8827 | } |
| 8828 | |
| Vladimir Marko | d254f5c | 2017-06-02 15:18:36 +0000 | [diff] [blame] | 8829 | void CodeGeneratorARMVIXL::GenerateStaticOrDirectCall( |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8830 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8831 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8832 | switch (invoke->GetMethodLoadKind()) { |
| 8833 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
| 8834 | uint32_t offset = |
| 8835 | GetThreadOffset<kArmPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 8836 | // temp = thread->string_init_entrypoint |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8837 | GetAssembler()->LoadFromOffset(kLoadWord, RegisterFrom(temp), tr, offset); |
| 8838 | break; |
| 8839 | } |
| 8840 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 8841 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
| 8842 | break; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8843 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 8844 | DCHECK(GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8845 | PcRelativePatchInfo* labels = NewBootImageMethodPatch(invoke->GetTargetMethod()); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8846 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8847 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 8848 | break; |
| 8849 | } |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 8850 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 8851 | uint32_t boot_image_offset = GetBootImageOffset(invoke); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 8852 | PcRelativePatchInfo* labels = NewBootImageRelRoPatch(boot_image_offset); |
| 8853 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8854 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| 8855 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
| 8856 | break; |
| 8857 | } |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8858 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { |
| 8859 | PcRelativePatchInfo* labels = NewMethodBssEntryPatch( |
| 8860 | MethodReference(&GetGraph()->GetDexFile(), invoke->GetDexMethodIndex())); |
| 8861 | vixl32::Register temp_reg = RegisterFrom(temp); |
| 8862 | EmitMovwMovtPlaceholder(labels, temp_reg); |
| Vladimir Marko | d5fd5c3 | 2019-07-02 14:46:32 +0100 | [diff] [blame] | 8863 | // All aligned loads are implicitly atomic consume operations on ARM. |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8864 | GetAssembler()->LoadFromOffset(kLoadWord, temp_reg, temp_reg, /* offset*/ 0); |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8865 | break; |
| 8866 | } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 8867 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: |
| 8868 | __ Mov(RegisterFrom(temp), Operand::From(invoke->GetMethodAddress())); |
| 8869 | break; |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8870 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { |
| 8871 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); |
| 8872 | return; // No code pointer retrieval; the runtime performs the call directly. |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8873 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8874 | } |
| 8875 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8876 | switch (invoke->GetCodePtrLocation()) { |
| 8877 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8878 | { |
| 8879 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 8880 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8881 | vixl32::k32BitT32InstructionSizeInBytes, |
| 8882 | CodeBufferCheckScope::kMaximumSize); |
| 8883 | __ bl(GetFrameEntryLabel()); |
| 8884 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 8885 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8886 | break; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8887 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 8888 | // LR = callee_method->entry_point_from_quick_compiled_code_ |
| 8889 | GetAssembler()->LoadFromOffset( |
| 8890 | kLoadWord, |
| 8891 | lr, |
| 8892 | RegisterFrom(callee_method), |
| 8893 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize).Int32Value()); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8894 | { |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8895 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8896 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 8897 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8898 | vixl32::k16BitT32InstructionSizeInBytes, |
| 8899 | CodeBufferCheckScope::kExactSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8900 | // LR() |
| 8901 | __ blx(lr); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8902 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8903 | } |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8904 | break; |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8905 | } |
| 8906 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8907 | DCHECK(!IsLeafMethod()); |
| 8908 | } |
| 8909 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8910 | void CodeGeneratorARMVIXL::GenerateVirtualCall( |
| 8911 | HInvokeVirtual* invoke, Location temp_location, SlowPathCode* slow_path) { |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8912 | vixl32::Register temp = RegisterFrom(temp_location); |
| 8913 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 8914 | invoke->GetVTableIndex(), kArmPointerSize).Uint32Value(); |
| 8915 | |
| 8916 | // Use the calling convention instead of the location of the receiver, as |
| 8917 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 8918 | // slow path, the arguments have been moved to the right place, so here we are |
| 8919 | // guaranteed that the receiver is the first register of the calling convention. |
| 8920 | InvokeDexCallingConventionARMVIXL calling_convention; |
| 8921 | vixl32::Register receiver = calling_convention.GetRegisterAt(0); |
| 8922 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8923 | { |
| 8924 | // Make sure the pc is recorded immediately after the `ldr` instruction. |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 8925 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8926 | vixl32::kMaxInstructionSizeInBytes, |
| 8927 | CodeBufferCheckScope::kMaximumSize); |
| Alexandre Rames | 374ddf3 | 2016-11-04 10:40:49 +0000 | [diff] [blame] | 8928 | // /* HeapReference<Class> */ temp = receiver->klass_ |
| 8929 | __ ldr(temp, MemOperand(receiver, class_offset)); |
| 8930 | MaybeRecordImplicitNullCheck(invoke); |
| 8931 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8932 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 8933 | // emit a read barrier for the previous class reference load. |
| 8934 | // However this is not required in practice, as this is an |
| 8935 | // intermediate/temporary reference and because the current |
| 8936 | // concurrent copying collector keeps the from-space memory |
| 8937 | // intact/accessible until the end of the marking phase (the |
| 8938 | // concurrent copying collector may not in the future). |
| 8939 | GetAssembler()->MaybeUnpoisonHeapReference(temp); |
| 8940 | |
| Nicolas Geoffray | e2a3aa9 | 2019-11-25 17:52:58 +0000 | [diff] [blame] | 8941 | // If we're compiling baseline, update the inline cache. |
| 8942 | MaybeGenerateInlineCacheCheck(invoke, temp); |
| 8943 | |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8944 | // temp = temp->GetMethodAt(method_offset); |
| 8945 | uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 8946 | kArmPointerSize).Int32Value(); |
| 8947 | GetAssembler()->LoadFromOffset(kLoadWord, temp, temp, method_offset); |
| 8948 | // LR = temp->GetEntryPoint(); |
| 8949 | GetAssembler()->LoadFromOffset(kLoadWord, lr, temp, entry_point); |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 8950 | { |
| 8951 | // Use a scope to help guarantee that `RecordPcInfo()` records the correct pc. |
| 8952 | // blx in T32 has only 16bit encoding that's why a stricter check for the scope is used. |
| 8953 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 8954 | vixl32::k16BitT32InstructionSizeInBytes, |
| 8955 | CodeBufferCheckScope::kExactSize); |
| 8956 | // LR(); |
| 8957 | __ blx(lr); |
| 8958 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); |
| 8959 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 8960 | } |
| 8961 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 8962 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageIntrinsicPatch( |
| 8963 | uint32_t intrinsic_data) { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 8964 | return NewPcRelativePatch(/* dex_file= */ nullptr, intrinsic_data, &boot_image_other_patches_); |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 8965 | } |
| 8966 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 8967 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageRelRoPatch( |
| 8968 | uint32_t boot_image_offset) { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 8969 | return NewPcRelativePatch(/* dex_file= */ nullptr, |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 8970 | boot_image_offset, |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 8971 | &boot_image_other_patches_); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 8972 | } |
| 8973 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8974 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageMethodPatch( |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8975 | MethodReference target_method) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8976 | return NewPcRelativePatch( |
| 8977 | target_method.dex_file, target_method.index, &boot_image_method_patches_); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8978 | } |
| 8979 | |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8980 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewMethodBssEntryPatch( |
| 8981 | MethodReference target_method) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8982 | return NewPcRelativePatch( |
| 8983 | target_method.dex_file, target_method.index, &method_bss_entry_patches_); |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 8984 | } |
| 8985 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8986 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageTypePatch( |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8987 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8988 | return NewPcRelativePatch(&dex_file, type_index.index_, &boot_image_type_patches_); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 8989 | } |
| 8990 | |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8991 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewTypeBssEntryPatch( |
| 8992 | const DexFile& dex_file, dex::TypeIndex type_index) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8993 | return NewPcRelativePatch(&dex_file, type_index.index_, &type_bss_entry_patches_); |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 8994 | } |
| 8995 | |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8996 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewBootImageStringPatch( |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8997 | const DexFile& dex_file, dex::StringIndex string_index) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8998 | return NewPcRelativePatch(&dex_file, string_index.index_, &boot_image_string_patches_); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 8999 | } |
| 9000 | |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9001 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewStringBssEntryPatch( |
| 9002 | const DexFile& dex_file, dex::StringIndex string_index) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9003 | return NewPcRelativePatch(&dex_file, string_index.index_, &string_bss_entry_patches_); |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9004 | } |
| 9005 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9006 | CodeGeneratorARMVIXL::PcRelativePatchInfo* CodeGeneratorARMVIXL::NewPcRelativePatch( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9007 | const DexFile* dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9008 | patches->emplace_back(dex_file, offset_or_index); |
| 9009 | return &patches->back(); |
| 9010 | } |
| 9011 | |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9012 | void CodeGeneratorARMVIXL::EmitEntrypointThunkCall(ThreadOffset32 entrypoint_offset) { |
| 9013 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
| 9014 | DCHECK(!Runtime::Current()->UseJitCompilation()); |
| 9015 | call_entrypoint_patches_.emplace_back(/*dex_file*/ nullptr, entrypoint_offset.Uint32Value()); |
| 9016 | vixl::aarch32::Label* bl_label = &call_entrypoint_patches_.back().label; |
| 9017 | __ bind(bl_label); |
| 9018 | vixl32::Label placeholder_label; |
| 9019 | __ bl(&placeholder_label); // Placeholder, patched at link-time. |
| 9020 | __ bind(&placeholder_label); |
| 9021 | } |
| 9022 | |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9023 | void CodeGeneratorARMVIXL::EmitBakerReadBarrierBne(uint32_t custom_data) { |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9024 | DCHECK(!__ AllowMacroInstructions()); // In ExactAssemblyScope. |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9025 | if (Runtime::Current()->UseJitCompilation()) { |
| 9026 | auto it = jit_baker_read_barrier_slow_paths_.FindOrAdd(custom_data); |
| 9027 | vixl::aarch32::Label* slow_path_entry = &it->second.label; |
| 9028 | __ b(ne, EncodingSize(Wide), slow_path_entry); |
| 9029 | } else { |
| 9030 | baker_read_barrier_patches_.emplace_back(custom_data); |
| 9031 | vixl::aarch32::Label* patch_label = &baker_read_barrier_patches_.back().label; |
| 9032 | __ bind(patch_label); |
| 9033 | vixl32::Label placeholder_label; |
| 9034 | __ b(ne, EncodingSize(Wide), &placeholder_label); // Placeholder, patched at link-time. |
| 9035 | __ bind(&placeholder_label); |
| 9036 | } |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9037 | } |
| 9038 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9039 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateBootImageAddressLiteral(uint32_t address) { |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 9040 | return DeduplicateUint32Literal(address, &uint32_literals_); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9041 | } |
| 9042 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 9043 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitStringLiteral( |
| 9044 | const DexFile& dex_file, |
| 9045 | dex::StringIndex string_index, |
| 9046 | Handle<mirror::String> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9047 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9048 | return jit_string_patches_.GetOrCreate( |
| 9049 | StringReference(&dex_file, string_index), |
| 9050 | [this]() { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9051 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9052 | }); |
| 9053 | } |
| 9054 | |
| 9055 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateJitClassLiteral(const DexFile& dex_file, |
| 9056 | dex::TypeIndex type_index, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 9057 | Handle<mirror::Class> handle) { |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9058 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9059 | return jit_class_patches_.GetOrCreate( |
| 9060 | TypeReference(&dex_file, type_index), |
| 9061 | [this]() { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9062 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ 0u); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9063 | }); |
| 9064 | } |
| 9065 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9066 | void CodeGeneratorARMVIXL::LoadBootImageAddress(vixl32::Register reg, |
| 9067 | uint32_t boot_image_reference) { |
| 9068 | if (GetCompilerOptions().IsBootImage()) { |
| 9069 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 9070 | NewBootImageIntrinsicPatch(boot_image_reference); |
| 9071 | EmitMovwMovtPlaceholder(labels, reg); |
| Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 9072 | } else if (GetCompilerOptions().GetCompilePic()) { |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9073 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels = |
| 9074 | NewBootImageRelRoPatch(boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9075 | EmitMovwMovtPlaceholder(labels, reg); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9076 | __ Ldr(reg, MemOperand(reg, /* offset= */ 0)); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9077 | } else { |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 9078 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9079 | gc::Heap* heap = Runtime::Current()->GetHeap(); |
| 9080 | DCHECK(!heap->GetBootImageSpaces().empty()); |
| 9081 | uintptr_t address = |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9082 | reinterpret_cast<uintptr_t>(heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference); |
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 9083 | __ Ldr(reg, DeduplicateBootImageAddressLiteral(dchecked_integral_cast<uint32_t>(address))); |
| 9084 | } |
| 9085 | } |
| 9086 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9087 | void CodeGeneratorARMVIXL::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, |
| 9088 | uint32_t boot_image_offset) { |
| 9089 | DCHECK(invoke->IsStatic()); |
| 9090 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 9091 | vixl32::Register argument = calling_convention.GetRegisterAt(0); |
| 9092 | if (GetCompilerOptions().IsBootImage()) { |
| 9093 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); |
| 9094 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. |
| 9095 | MethodReference target_method = invoke->GetTargetMethod(); |
| 9096 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; |
| 9097 | PcRelativePatchInfo* labels = NewBootImageTypePatch(*target_method.dex_file, type_idx); |
| 9098 | EmitMovwMovtPlaceholder(labels, argument); |
| 9099 | } else { |
| 9100 | LoadBootImageAddress(argument, boot_image_offset); |
| 9101 | } |
| 9102 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 9103 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 9104 | } |
| 9105 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9106 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9107 | inline void CodeGeneratorARMVIXL::EmitPcRelativeLinkerPatches( |
| 9108 | const ArenaDeque<PcRelativePatchInfo>& infos, |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9109 | ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9110 | for (const PcRelativePatchInfo& info : infos) { |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9111 | const DexFile* dex_file = info.target_dex_file; |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9112 | size_t offset_or_index = info.offset_or_index; |
| 9113 | DCHECK(info.add_pc_label.IsBound()); |
| 9114 | uint32_t add_pc_offset = dchecked_integral_cast<uint32_t>(info.add_pc_label.GetLocation()); |
| 9115 | // Add MOVW patch. |
| 9116 | DCHECK(info.movw_label.IsBound()); |
| 9117 | uint32_t movw_offset = dchecked_integral_cast<uint32_t>(info.movw_label.GetLocation()); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9118 | linker_patches->push_back(Factory(movw_offset, dex_file, add_pc_offset, offset_or_index)); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9119 | // Add MOVT patch. |
| 9120 | DCHECK(info.movt_label.IsBound()); |
| 9121 | uint32_t movt_offset = dchecked_integral_cast<uint32_t>(info.movt_label.GetLocation()); |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9122 | linker_patches->push_back(Factory(movt_offset, dex_file, add_pc_offset, offset_or_index)); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9123 | } |
| 9124 | } |
| 9125 | |
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 9126 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> |
| 9127 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, |
| 9128 | const DexFile* target_dex_file, |
| 9129 | uint32_t pc_insn_offset, |
| 9130 | uint32_t boot_image_offset) { |
| 9131 | DCHECK(target_dex_file == nullptr); // Unused for these patches, should be null. |
| 9132 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 9133 | } |
| 9134 | |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9135 | void CodeGeneratorARMVIXL::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9136 | DCHECK(linker_patches->empty()); |
| 9137 | size_t size = |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9138 | /* MOVW+MOVT for each entry */ 2u * boot_image_method_patches_.size() + |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 9139 | /* MOVW+MOVT for each entry */ 2u * method_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9140 | /* MOVW+MOVT for each entry */ 2u * boot_image_type_patches_.size() + |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9141 | /* MOVW+MOVT for each entry */ 2u * type_bss_entry_patches_.size() + |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9142 | /* MOVW+MOVT for each entry */ 2u * boot_image_string_patches_.size() + |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 9143 | /* MOVW+MOVT for each entry */ 2u * string_bss_entry_patches_.size() + |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9144 | /* MOVW+MOVT for each entry */ 2u * boot_image_other_patches_.size() + |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9145 | call_entrypoint_patches_.size() + |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9146 | baker_read_barrier_patches_.size(); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9147 | linker_patches->reserve(size); |
| Vladimir Marko | 44ca075 | 2019-07-29 10:18:25 +0100 | [diff] [blame] | 9148 | if (GetCompilerOptions().IsBootImage() || GetCompilerOptions().IsBootImageExtension()) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9149 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9150 | boot_image_method_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9151 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9152 | boot_image_type_patches_, linker_patches); |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9153 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( |
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 9154 | boot_image_string_patches_, linker_patches); |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 9155 | } else { |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9156 | DCHECK(boot_image_method_patches_.empty()); |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 9157 | DCHECK(boot_image_type_patches_.empty()); |
| 9158 | DCHECK(boot_image_string_patches_.empty()); |
| Vladimir Marko | 2d06e02 | 2019-07-08 15:45:19 +0100 | [diff] [blame] | 9159 | } |
| 9160 | if (GetCompilerOptions().IsBootImage()) { |
| 9161 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( |
| 9162 | boot_image_other_patches_, linker_patches); |
| 9163 | } else { |
| 9164 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( |
| 9165 | boot_image_other_patches_, linker_patches); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9166 | } |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9167 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( |
| 9168 | method_bss_entry_patches_, linker_patches); |
| 9169 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( |
| 9170 | type_bss_entry_patches_, linker_patches); |
| 9171 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( |
| 9172 | string_bss_entry_patches_, linker_patches); |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9173 | for (const PatchInfo<vixl32::Label>& info : call_entrypoint_patches_) { |
| 9174 | DCHECK(info.target_dex_file == nullptr); |
| 9175 | linker_patches->push_back(linker::LinkerPatch::CallEntrypointPatch( |
| 9176 | info.label.GetLocation(), info.offset_or_index)); |
| 9177 | } |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9178 | for (const BakerReadBarrierPatchInfo& info : baker_read_barrier_patches_) { |
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 9179 | linker_patches->push_back(linker::LinkerPatch::BakerReadBarrierBranchPatch( |
| 9180 | info.label.GetLocation(), info.custom_data)); |
| Vladimir Marko | eee1c0e | 2017-04-21 17:58:41 +0100 | [diff] [blame] | 9181 | } |
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 9182 | DCHECK_EQ(size, linker_patches->size()); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9183 | } |
| 9184 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9185 | bool CodeGeneratorARMVIXL::NeedsThunkCode(const linker::LinkerPatch& patch) const { |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9186 | return patch.GetType() == linker::LinkerPatch::Type::kCallEntrypoint || |
| 9187 | patch.GetType() == linker::LinkerPatch::Type::kBakerReadBarrierBranch || |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9188 | patch.GetType() == linker::LinkerPatch::Type::kCallRelative; |
| 9189 | } |
| 9190 | |
| 9191 | void CodeGeneratorARMVIXL::EmitThunkCode(const linker::LinkerPatch& patch, |
| 9192 | /*out*/ ArenaVector<uint8_t>* code, |
| 9193 | /*out*/ std::string* debug_name) { |
| 9194 | arm::ArmVIXLAssembler assembler(GetGraph()->GetAllocator()); |
| 9195 | switch (patch.GetType()) { |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9196 | case linker::LinkerPatch::Type::kCallRelative: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9197 | // The thunk just uses the entry point in the ArtMethod. This works even for calls |
| 9198 | // to the generic JNI and interpreter trampolines. |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9199 | MemberOffset offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArmPointerSize); |
| 9200 | assembler.LoadFromOffset(arm::kLoadWord, vixl32::pc, vixl32::r0, offset.Int32Value()); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9201 | assembler.GetVIXLAssembler()->Bkpt(0); |
| 9202 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 9203 | *debug_name = "MethodCallThunk"; |
| 9204 | } |
| 9205 | break; |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9206 | } |
| 9207 | case linker::LinkerPatch::Type::kCallEntrypoint: { |
| 9208 | assembler.LoadFromOffset(arm::kLoadWord, vixl32::pc, tr, patch.EntrypointOffset()); |
| 9209 | assembler.GetVIXLAssembler()->Bkpt(0); |
| 9210 | if (GetCompilerOptions().GenerateAnyDebugInfo()) { |
| 9211 | *debug_name = "EntrypointCallThunk_" + std::to_string(patch.EntrypointOffset()); |
| 9212 | } |
| 9213 | break; |
| 9214 | } |
| 9215 | case linker::LinkerPatch::Type::kBakerReadBarrierBranch: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9216 | DCHECK_EQ(patch.GetBakerCustomValue2(), 0u); |
| 9217 | CompileBakerReadBarrierThunk(assembler, patch.GetBakerCustomValue1(), debug_name); |
| 9218 | break; |
| Vladimir Marko | f667508 | 2019-05-17 12:05:28 +0100 | [diff] [blame] | 9219 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9220 | default: |
| 9221 | LOG(FATAL) << "Unexpected patch type " << patch.GetType(); |
| 9222 | UNREACHABLE(); |
| 9223 | } |
| 9224 | |
| 9225 | // Ensure we emit the literal pool if any. |
| 9226 | assembler.FinalizeCode(); |
| 9227 | code->resize(assembler.CodeSize()); |
| 9228 | MemoryRegion code_region(code->data(), code->size()); |
| 9229 | assembler.FinalizeInstructions(code_region); |
| 9230 | } |
| 9231 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9232 | VIXLUInt32Literal* CodeGeneratorARMVIXL::DeduplicateUint32Literal( |
| 9233 | uint32_t value, |
| 9234 | Uint32ToLiteralMap* map) { |
| 9235 | return map->GetOrCreate( |
| 9236 | value, |
| 9237 | [this, value]() { |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9238 | return GetAssembler()->CreateLiteralDestroyedWithPool<uint32_t>(/* value= */ value); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9239 | }); |
| 9240 | } |
| 9241 | |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9242 | void LocationsBuilderARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9243 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9244 | new (GetGraph()->GetAllocator()) LocationSummary(instr, LocationSummary::kNoCall); |
| Artem Serov | 2bbc953 | 2016-10-21 11:51:50 +0100 | [diff] [blame] | 9245 | locations->SetInAt(HMultiplyAccumulate::kInputAccumulatorIndex, |
| 9246 | Location::RequiresRegister()); |
| 9247 | locations->SetInAt(HMultiplyAccumulate::kInputMulLeftIndex, Location::RequiresRegister()); |
| 9248 | locations->SetInAt(HMultiplyAccumulate::kInputMulRightIndex, Location::RequiresRegister()); |
| 9249 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 9250 | } |
| 9251 | |
| 9252 | void InstructionCodeGeneratorARMVIXL::VisitMultiplyAccumulate(HMultiplyAccumulate* instr) { |
| 9253 | vixl32::Register res = OutputRegister(instr); |
| 9254 | vixl32::Register accumulator = |
| 9255 | InputRegisterAt(instr, HMultiplyAccumulate::kInputAccumulatorIndex); |
| 9256 | vixl32::Register mul_left = |
| 9257 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulLeftIndex); |
| 9258 | vixl32::Register mul_right = |
| 9259 | InputRegisterAt(instr, HMultiplyAccumulate::kInputMulRightIndex); |
| 9260 | |
| 9261 | if (instr->GetOpKind() == HInstruction::kAdd) { |
| 9262 | __ Mla(res, mul_left, mul_right, accumulator); |
| 9263 | } else { |
| 9264 | __ Mls(res, mul_left, mul_right, accumulator); |
| 9265 | } |
| 9266 | } |
| 9267 | |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9268 | void LocationsBuilderARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9269 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9270 | LOG(FATAL) << "Unreachable"; |
| 9271 | } |
| 9272 | |
| 9273 | void InstructionCodeGeneratorARMVIXL::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
| 9274 | // Nothing to do, this should be removed during prepare for register allocator. |
| 9275 | LOG(FATAL) << "Unreachable"; |
| 9276 | } |
| 9277 | |
| 9278 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 9279 | void LocationsBuilderARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9280 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9281 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9282 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9283 | if (switch_instr->GetNumEntries() > kPackedSwitchCompareJumpThreshold && |
| 9284 | codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9285 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the table base. |
| 9286 | if (switch_instr->GetStartValue() != 0) { |
| 9287 | locations->AddTemp(Location::RequiresRegister()); // We need a temp for the bias. |
| 9288 | } |
| 9289 | } |
| 9290 | } |
| 9291 | |
| 9292 | // TODO(VIXL): Investigate and reach the parity with old arm codegen. |
| 9293 | void InstructionCodeGeneratorARMVIXL::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 9294 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 9295 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 9296 | LocationSummary* locations = switch_instr->GetLocations(); |
| 9297 | vixl32::Register value_reg = InputRegisterAt(switch_instr, 0); |
| 9298 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 9299 | |
| 9300 | if (num_entries <= kPackedSwitchCompareJumpThreshold || |
| 9301 | !codegen_->GetAssembler()->GetVIXLAssembler()->IsUsingT32()) { |
| 9302 | // Create a series of compare/jumps. |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9303 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9304 | vixl32::Register temp_reg = temps.Acquire(); |
| 9305 | // Note: It is fine for the below AddConstantSetFlags() using IP register to temporarily store |
| 9306 | // the immediate, because IP is used as the destination register. For the other |
| 9307 | // AddConstantSetFlags() and GenerateCompareWithImmediate(), the immediate values are constant, |
| 9308 | // and they can be encoded in the instruction without making use of IP register. |
| 9309 | __ Adds(temp_reg, value_reg, -lower_bound); |
| 9310 | |
| 9311 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 9312 | // Jump to successors[0] if value == lower_bound. |
| 9313 | __ B(eq, codegen_->GetLabelOf(successors[0])); |
| 9314 | int32_t last_index = 0; |
| 9315 | for (; num_entries - last_index > 2; last_index += 2) { |
| 9316 | __ Adds(temp_reg, temp_reg, -2); |
| 9317 | // Jump to successors[last_index + 1] if value < case_value[last_index + 2]. |
| 9318 | __ B(lo, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9319 | // Jump to successors[last_index + 2] if value == case_value[last_index + 2]. |
| 9320 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 2])); |
| 9321 | } |
| 9322 | if (num_entries - last_index == 2) { |
| 9323 | // The last missing case_value. |
| 9324 | __ Cmp(temp_reg, 1); |
| 9325 | __ B(eq, codegen_->GetLabelOf(successors[last_index + 1])); |
| 9326 | } |
| 9327 | |
| 9328 | // And the default for any other value. |
| 9329 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 9330 | __ B(codegen_->GetLabelOf(default_block)); |
| 9331 | } |
| 9332 | } else { |
| 9333 | // Create a table lookup. |
| 9334 | vixl32::Register table_base = RegisterFrom(locations->GetTemp(0)); |
| 9335 | |
| 9336 | JumpTableARMVIXL* jump_table = codegen_->CreateJumpTable(switch_instr); |
| 9337 | |
| 9338 | // Remove the bias. |
| 9339 | vixl32::Register key_reg; |
| 9340 | if (lower_bound != 0) { |
| 9341 | key_reg = RegisterFrom(locations->GetTemp(1)); |
| 9342 | __ Sub(key_reg, value_reg, lower_bound); |
| 9343 | } else { |
| 9344 | key_reg = value_reg; |
| 9345 | } |
| 9346 | |
| 9347 | // Check whether the value is in the table, jump to default block if not. |
| 9348 | __ Cmp(key_reg, num_entries - 1); |
| 9349 | __ B(hi, codegen_->GetLabelOf(default_block)); |
| 9350 | |
| Anton Kirilov | edb2ac3 | 2016-11-30 15:14:10 +0000 | [diff] [blame] | 9351 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9352 | vixl32::Register jump_offset = temps.Acquire(); |
| 9353 | |
| 9354 | // Load jump offset from the table. |
| Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9355 | { |
| 9356 | const size_t jump_size = switch_instr->GetNumEntries() * sizeof(int32_t); |
| 9357 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9358 | (vixl32::kMaxInstructionSizeInBytes * 4) + jump_size, |
| 9359 | CodeBufferCheckScope::kMaximumSize); |
| 9360 | __ adr(table_base, jump_table->GetTableStartLabel()); |
| 9361 | __ ldr(jump_offset, MemOperand(table_base, key_reg, vixl32::LSL, 2)); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9362 | |
| Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9363 | // Jump to target block by branching to table_base(pc related) + offset. |
| 9364 | vixl32::Register target_address = table_base; |
| 9365 | __ add(target_address, table_base, jump_offset); |
| 9366 | __ bx(target_address); |
| Artem Serov | 09a940d | 2016-11-11 16:15:11 +0000 | [diff] [blame] | 9367 | |
| Scott Wakeling | 86e9d26 | 2017-01-18 15:59:24 +0000 | [diff] [blame] | 9368 | jump_table->EmitTable(codegen_); |
| 9369 | } |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9370 | } |
| 9371 | } |
| 9372 | |
| Artem Serov | 02d3783 | 2016-10-25 15:25:33 +0100 | [diff] [blame] | 9373 | // Copy the result of a call into the given target. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9374 | void CodeGeneratorARMVIXL::MoveFromReturnRegister(Location trg, DataType::Type type) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9375 | if (!trg.IsValid()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9376 | DCHECK_EQ(type, DataType::Type::kVoid); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9377 | return; |
| 9378 | } |
| 9379 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9380 | DCHECK_NE(type, DataType::Type::kVoid); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9381 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9382 | Location return_loc = InvokeDexCallingConventionVisitorARMVIXL().GetReturnLocation(type); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9383 | if (return_loc.Equals(trg)) { |
| 9384 | return; |
| 9385 | } |
| 9386 | |
| 9387 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 9388 | // with the last branch. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9389 | if (type == DataType::Type::kInt64) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9390 | TODO_VIXL32(FATAL); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 9391 | } else if (type == DataType::Type::kFloat64) { |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9392 | TODO_VIXL32(FATAL); |
| 9393 | } else { |
| 9394 | // Let the parallel move resolver take care of all of this. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9395 | HParallelMove parallel_move(GetGraph()->GetAllocator()); |
| Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 9396 | parallel_move.AddMove(return_loc, trg, type, nullptr); |
| 9397 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 9398 | } |
| Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 9399 | } |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9400 | |
| xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9401 | void LocationsBuilderARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9402 | LocationSummary* locations = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 9403 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); |
| xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9404 | locations->SetInAt(0, Location::RequiresRegister()); |
| 9405 | locations->SetOut(Location::RequiresRegister()); |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9406 | } |
| 9407 | |
| xueliang.zhong | 8d2c459 | 2016-11-23 17:05:25 +0000 | [diff] [blame] | 9408 | void InstructionCodeGeneratorARMVIXL::VisitClassTableGet(HClassTableGet* instruction) { |
| 9409 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
| 9410 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 9411 | instruction->GetIndex(), kArmPointerSize).SizeValue(); |
| 9412 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9413 | OutputRegister(instruction), |
| 9414 | InputRegisterAt(instruction, 0), |
| 9415 | method_offset); |
| 9416 | } else { |
| 9417 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 9418 | instruction->GetIndex(), kArmPointerSize)); |
| 9419 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9420 | OutputRegister(instruction), |
| 9421 | InputRegisterAt(instruction, 0), |
| 9422 | mirror::Class::ImtPtrOffset(kArmPointerSize).Uint32Value()); |
| 9423 | GetAssembler()->LoadFromOffset(kLoadWord, |
| 9424 | OutputRegister(instruction), |
| 9425 | OutputRegister(instruction), |
| 9426 | method_offset); |
| 9427 | } |
| Artem Serov | 551b28f | 2016-10-18 19:11:30 +0100 | [diff] [blame] | 9428 | } |
| 9429 | |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9430 | static void PatchJitRootUse(uint8_t* code, |
| 9431 | const uint8_t* roots_data, |
| 9432 | VIXLUInt32Literal* literal, |
| 9433 | uint64_t index_in_table) { |
| 9434 | DCHECK(literal->IsBound()); |
| 9435 | uint32_t literal_offset = literal->GetLocation(); |
| 9436 | uintptr_t address = |
| 9437 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); |
| 9438 | uint8_t* data = code + literal_offset; |
| 9439 | reinterpret_cast<uint32_t*>(data)[0] = dchecked_integral_cast<uint32_t>(address); |
| 9440 | } |
| 9441 | |
| 9442 | void CodeGeneratorARMVIXL::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { |
| 9443 | for (const auto& entry : jit_string_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9444 | const StringReference& string_reference = entry.first; |
| 9445 | VIXLUInt32Literal* table_entry_literal = entry.second; |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9446 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9447 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9448 | } |
| 9449 | for (const auto& entry : jit_class_patches_) { |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9450 | const TypeReference& type_reference = entry.first; |
| 9451 | VIXLUInt32Literal* table_entry_literal = entry.second; |
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 9452 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); |
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 9453 | PatchJitRootUse(code, roots_data, table_entry_literal, index_in_table); |
| Artem Serov | c5fcb44 | 2016-12-02 19:19:58 +0000 | [diff] [blame] | 9454 | } |
| 9455 | } |
| 9456 | |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9457 | void CodeGeneratorARMVIXL::EmitMovwMovtPlaceholder( |
| 9458 | CodeGeneratorARMVIXL::PcRelativePatchInfo* labels, |
| 9459 | vixl32::Register out) { |
| Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 9460 | ExactAssemblyScope aas(GetVIXLAssembler(), |
| 9461 | 3 * vixl32::kMaxInstructionSizeInBytes, |
| 9462 | CodeBufferCheckScope::kMaximumSize); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9463 | // TODO(VIXL): Think about using mov instead of movw. |
| 9464 | __ bind(&labels->movw_label); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9465 | __ movw(out, /* operand= */ 0u); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9466 | __ bind(&labels->movt_label); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9467 | __ movt(out, /* operand= */ 0u); |
| Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 9468 | __ bind(&labels->add_pc_label); |
| 9469 | __ add(out, out, pc); |
| 9470 | } |
| 9471 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9472 | #undef __ |
| 9473 | #undef QUICK_ENTRY_POINT |
| 9474 | #undef TODO_VIXL32 |
| 9475 | |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9476 | #define __ assembler.GetVIXLAssembler()-> |
| 9477 | |
| 9478 | static void EmitGrayCheckAndFastPath(ArmVIXLAssembler& assembler, |
| 9479 | vixl32::Register base_reg, |
| 9480 | vixl32::MemOperand& lock_word, |
| 9481 | vixl32::Label* slow_path, |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9482 | int32_t raw_ldr_offset, |
| 9483 | vixl32::Label* throw_npe = nullptr) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9484 | // Load the lock word containing the rb_state. |
| 9485 | __ Ldr(ip, lock_word); |
| 9486 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| Roland Levillain | 14e5a29 | 2018-06-28 12:00:56 +0100 | [diff] [blame] | 9487 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9488 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 9489 | __ Tst(ip, Operand(LockWord::kReadBarrierStateMaskShifted)); |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9490 | __ B(ne, slow_path, /* is_far_target= */ false); |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9491 | // To throw NPE, we return to the fast path; the artificial dependence below does not matter. |
| 9492 | if (throw_npe != nullptr) { |
| 9493 | __ Bind(throw_npe); |
| 9494 | } |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9495 | __ Add(lr, lr, raw_ldr_offset); |
| 9496 | // Introduce a dependency on the lock_word including rb_state, |
| 9497 | // to prevent load-load reordering, and without using |
| 9498 | // a memory barrier (which would be more expensive). |
| 9499 | __ Add(base_reg, base_reg, Operand(ip, LSR, 32)); |
| 9500 | __ Bx(lr); // And return back to the function. |
| 9501 | // Note: The fake dependency is unnecessary for the slow path. |
| 9502 | } |
| 9503 | |
| 9504 | // Load the read barrier introspection entrypoint in register `entrypoint` |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9505 | static vixl32::Register LoadReadBarrierMarkIntrospectionEntrypoint(ArmVIXLAssembler& assembler) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9506 | // The register where the read barrier introspection entrypoint is loaded |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9507 | // is the marking register. We clobber it here and the entrypoint restores it to 1. |
| 9508 | vixl32::Register entrypoint = mr; |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9509 | // entrypoint = Thread::Current()->pReadBarrierMarkReg12, i.e. pReadBarrierMarkIntrospection. |
| 9510 | DCHECK_EQ(ip.GetCode(), 12u); |
| 9511 | const int32_t entry_point_offset = |
| 9512 | Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(ip.GetCode()); |
| 9513 | __ Ldr(entrypoint, MemOperand(tr, entry_point_offset)); |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9514 | return entrypoint; |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9515 | } |
| 9516 | |
| 9517 | void CodeGeneratorARMVIXL::CompileBakerReadBarrierThunk(ArmVIXLAssembler& assembler, |
| 9518 | uint32_t encoded_data, |
| 9519 | /*out*/ std::string* debug_name) { |
| 9520 | BakerReadBarrierKind kind = BakerReadBarrierKindField::Decode(encoded_data); |
| 9521 | switch (kind) { |
| 9522 | case BakerReadBarrierKind::kField: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9523 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9524 | CheckValidReg(base_reg.GetCode()); |
| 9525 | vixl32::Register holder_reg(BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9526 | CheckValidReg(holder_reg.GetCode()); |
| 9527 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 9528 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9529 | temps.Exclude(ip); |
| Roland Levillain | 988c391 | 2019-09-25 19:33:35 +0100 | [diff] [blame] | 9530 | // In the case of a field load, if `base_reg` differs from |
| 9531 | // `holder_reg`, the offset was too large and we must have emitted (during the construction |
| 9532 | // of the HIR graph, see `art::HInstructionBuilder::BuildInstanceFieldAccess`) and preserved |
| 9533 | // (see `art::PrepareForRegisterAllocation::VisitNullCheck`) an explicit null check before |
| 9534 | // the load. Otherwise, for implicit null checks, we need to null-check the holder as we do |
| 9535 | // not necessarily do that check before going to the thunk. |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9536 | vixl32::Label throw_npe_label; |
| 9537 | vixl32::Label* throw_npe = nullptr; |
| 9538 | if (GetCompilerOptions().GetImplicitNullChecks() && holder_reg.Is(base_reg)) { |
| 9539 | throw_npe = &throw_npe_label; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9540 | __ CompareAndBranchIfZero(holder_reg, throw_npe, /* is_far_target= */ false); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9541 | } |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9542 | // Check if the holder is gray and, if not, add fake dependency to the base register |
| 9543 | // and return to the LDR instruction to load the reference. Otherwise, use introspection |
| 9544 | // to load the reference and call the entrypoint that performs further checks on the |
| 9545 | // reference and marks it if needed. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9546 | vixl32::Label slow_path; |
| 9547 | MemOperand lock_word(holder_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 9548 | const int32_t raw_ldr_offset = (width == BakerReadBarrierWidth::kWide) |
| 9549 | ? BAKER_MARK_INTROSPECTION_FIELD_LDR_WIDE_OFFSET |
| 9550 | : BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_OFFSET; |
| Vladimir Marko | 7a69505 | 2018-04-12 10:26:50 +0100 | [diff] [blame] | 9551 | EmitGrayCheckAndFastPath( |
| 9552 | assembler, base_reg, lock_word, &slow_path, raw_ldr_offset, throw_npe); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9553 | __ Bind(&slow_path); |
| 9554 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 9555 | raw_ldr_offset; |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9556 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9557 | if (width == BakerReadBarrierWidth::kWide) { |
| 9558 | MemOperand ldr_half_address(lr, ldr_offset + 2); |
| 9559 | __ Ldrh(ip, ldr_half_address); // Load the LDR immediate half-word with "Rt | imm12". |
| 9560 | __ Ubfx(ip, ip, 0, 12); // Extract the offset imm12. |
| 9561 | __ Ldr(ip, MemOperand(base_reg, ip)); // Load the reference. |
| 9562 | } else { |
| 9563 | MemOperand ldr_address(lr, ldr_offset); |
| 9564 | __ Ldrh(ip, ldr_address); // Load the LDR immediate, encoding T1. |
| 9565 | __ Add(ep_reg, // Adjust the entrypoint address to the entrypoint |
| 9566 | ep_reg, // for narrow LDR. |
| 9567 | Operand(BAKER_MARK_INTROSPECTION_FIELD_LDR_NARROW_ENTRYPOINT_OFFSET)); |
| 9568 | __ Ubfx(ip, ip, 6, 5); // Extract the imm5, i.e. offset / 4. |
| 9569 | __ Ldr(ip, MemOperand(base_reg, ip, LSL, 2)); // Load the reference. |
| 9570 | } |
| 9571 | // Do not unpoison. With heap poisoning enabled, the entrypoint expects a poisoned reference. |
| 9572 | __ Bx(ep_reg); // Jump to the entrypoint. |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9573 | break; |
| 9574 | } |
| 9575 | case BakerReadBarrierKind::kArray: { |
| 9576 | vixl32::Register base_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9577 | CheckValidReg(base_reg.GetCode()); |
| 9578 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9579 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9580 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 9581 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9582 | temps.Exclude(ip); |
| 9583 | vixl32::Label slow_path; |
| 9584 | int32_t data_offset = |
| 9585 | mirror::Array::DataOffset(Primitive::ComponentSize(Primitive::kPrimNot)).Int32Value(); |
| 9586 | MemOperand lock_word(base_reg, mirror::Object::MonitorOffset().Int32Value() - data_offset); |
| 9587 | DCHECK_LT(lock_word.GetOffsetImmediate(), 0); |
| 9588 | const int32_t raw_ldr_offset = BAKER_MARK_INTROSPECTION_ARRAY_LDR_OFFSET; |
| 9589 | EmitGrayCheckAndFastPath(assembler, base_reg, lock_word, &slow_path, raw_ldr_offset); |
| 9590 | __ Bind(&slow_path); |
| 9591 | const int32_t ldr_offset = /* Thumb state adjustment (LR contains Thumb state). */ -1 + |
| 9592 | raw_ldr_offset; |
| 9593 | MemOperand ldr_address(lr, ldr_offset + 2); |
| 9594 | __ Ldrb(ip, ldr_address); // Load the LDR (register) byte with "00 | imm2 | Rm", |
| 9595 | // i.e. Rm+32 because the scale in imm2 is 2. |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9596 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9597 | __ Bfi(ep_reg, ip, 3, 6); // Insert ip to the entrypoint address to create |
| 9598 | // a switch case target based on the index register. |
| 9599 | __ Mov(ip, base_reg); // Move the base register to ip0. |
| 9600 | __ Bx(ep_reg); // Jump to the entrypoint's array switch case. |
| 9601 | break; |
| 9602 | } |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9603 | case BakerReadBarrierKind::kGcRoot: |
| 9604 | case BakerReadBarrierKind::kUnsafeCas: { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9605 | // Check if the reference needs to be marked and if so (i.e. not null, not marked yet |
| 9606 | // and it does not have a forwarding address), call the correct introspection entrypoint; |
| 9607 | // otherwise return the reference (or the extracted forwarding address). |
| 9608 | // There is no gray bit check for GC roots. |
| 9609 | vixl32::Register root_reg(BakerReadBarrierFirstRegField::Decode(encoded_data)); |
| 9610 | CheckValidReg(root_reg.GetCode()); |
| 9611 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9612 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9613 | BakerReadBarrierWidth width = BakerReadBarrierWidthField::Decode(encoded_data); |
| 9614 | UseScratchRegisterScope temps(assembler.GetVIXLAssembler()); |
| 9615 | temps.Exclude(ip); |
| 9616 | vixl32::Label return_label, not_marked, forwarding_address; |
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 9617 | __ CompareAndBranchIfZero(root_reg, &return_label, /* is_far_target= */ false); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9618 | MemOperand lock_word(root_reg, mirror::Object::MonitorOffset().Int32Value()); |
| 9619 | __ Ldr(ip, lock_word); |
| 9620 | __ Tst(ip, LockWord::kMarkBitStateMaskShifted); |
| 9621 | __ B(eq, ¬_marked); |
| 9622 | __ Bind(&return_label); |
| 9623 | __ Bx(lr); |
| 9624 | __ Bind(¬_marked); |
| 9625 | static_assert(LockWord::kStateShift == 30 && LockWord::kStateForwardingAddress == 3, |
| 9626 | "To use 'CMP ip, #modified-immediate; BHS', we need the lock word state in " |
| 9627 | " the highest bits and the 'forwarding address' state to have all bits set"); |
| 9628 | __ Cmp(ip, Operand(0xc0000000)); |
| 9629 | __ B(hs, &forwarding_address); |
| Vladimir Marko | dcd117e | 2018-04-19 11:54:00 +0100 | [diff] [blame] | 9630 | vixl32::Register ep_reg = LoadReadBarrierMarkIntrospectionEntrypoint(assembler); |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9631 | // Adjust the art_quick_read_barrier_mark_introspection address in kBakerCcEntrypointRegister |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9632 | // to one of art_quick_read_barrier_mark_introspection_{gc_roots_{wide,narrow},unsafe_cas}. |
| 9633 | DCHECK(kind != BakerReadBarrierKind::kUnsafeCas || width == BakerReadBarrierWidth::kWide); |
| 9634 | int32_t entrypoint_offset = |
| 9635 | (kind == BakerReadBarrierKind::kGcRoot) |
| 9636 | ? (width == BakerReadBarrierWidth::kWide) |
| 9637 | ? BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_WIDE_ENTRYPOINT_OFFSET |
| 9638 | : BAKER_MARK_INTROSPECTION_GC_ROOT_LDR_NARROW_ENTRYPOINT_OFFSET |
| 9639 | : BAKER_MARK_INTROSPECTION_UNSAFE_CAS_ENTRYPOINT_OFFSET; |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9640 | __ Add(ep_reg, ep_reg, Operand(entrypoint_offset)); |
| 9641 | __ Mov(ip, root_reg); |
| 9642 | __ Bx(ep_reg); |
| 9643 | __ Bind(&forwarding_address); |
| 9644 | __ Lsl(root_reg, ip, LockWord::kForwardingAddressShift); |
| 9645 | __ Bx(lr); |
| 9646 | break; |
| 9647 | } |
| 9648 | default: |
| 9649 | LOG(FATAL) << "Unexpected kind: " << static_cast<uint32_t>(kind); |
| 9650 | UNREACHABLE(); |
| 9651 | } |
| 9652 | |
| Vladimir Marko | 966b46f | 2018-08-03 10:20:19 +0000 | [diff] [blame] | 9653 | // For JIT, the slow path is considered part of the compiled method, |
| 9654 | // so JIT should pass null as `debug_name`. Tests may not have a runtime. |
| 9655 | DCHECK(Runtime::Current() == nullptr || |
| 9656 | !Runtime::Current()->UseJitCompilation() || |
| 9657 | debug_name == nullptr); |
| 9658 | if (debug_name != nullptr && GetCompilerOptions().GenerateAnyDebugInfo()) { |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9659 | std::ostringstream oss; |
| 9660 | oss << "BakerReadBarrierThunk"; |
| 9661 | switch (kind) { |
| 9662 | case BakerReadBarrierKind::kField: |
| 9663 | oss << "Field"; |
| 9664 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 9665 | oss << "Wide"; |
| 9666 | } |
| 9667 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data) |
| 9668 | << "_r" << BakerReadBarrierSecondRegField::Decode(encoded_data); |
| 9669 | break; |
| 9670 | case BakerReadBarrierKind::kArray: |
| 9671 | oss << "Array_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 9672 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9673 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9674 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 9675 | break; |
| 9676 | case BakerReadBarrierKind::kGcRoot: |
| 9677 | oss << "GcRoot"; |
| 9678 | if (BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide) { |
| 9679 | oss << "Wide"; |
| 9680 | } |
| 9681 | oss << "_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 9682 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9683 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9684 | break; |
| Vladimir Marko | d887ed8 | 2018-08-14 13:52:12 +0000 | [diff] [blame] | 9685 | case BakerReadBarrierKind::kUnsafeCas: |
| 9686 | oss << "UnsafeCas_r" << BakerReadBarrierFirstRegField::Decode(encoded_data); |
| 9687 | DCHECK_EQ(kBakerReadBarrierInvalidEncodedReg, |
| 9688 | BakerReadBarrierSecondRegField::Decode(encoded_data)); |
| 9689 | DCHECK(BakerReadBarrierWidthField::Decode(encoded_data) == BakerReadBarrierWidth::kWide); |
| 9690 | break; |
| Vladimir Marko | ca1e038 | 2018-04-11 09:58:41 +0000 | [diff] [blame] | 9691 | } |
| 9692 | *debug_name = oss.str(); |
| 9693 | } |
| 9694 | } |
| 9695 | |
| 9696 | #undef __ |
| 9697 | |
| Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 9698 | } // namespace arm |
| 9699 | } // namespace art |